优化通道数据异常时的入库逻辑
parent
b843958ed7
commit
6ecf8af6ca
|
@ -665,18 +665,18 @@ public class XmlUtil {
|
||||||
}
|
}
|
||||||
String value = annotation.value();
|
String value = annotation.value();
|
||||||
boolean subVal = value.contains(".");
|
boolean subVal = value.contains(".");
|
||||||
Element element1 = element.element(value);
|
|
||||||
if (element1 == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!subVal) {
|
if (!subVal) {
|
||||||
|
Element element1 = element.element(value);
|
||||||
|
if (element1 == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// 无下级数据
|
// 无下级数据
|
||||||
Object fieldVal = element1.isTextOnly() ? element1.getText() : loadElement(element1, field.getType());
|
Object fieldVal = element1.isTextOnly() ? element1.getText() : loadElement(element1, field.getType());
|
||||||
Object o = simpleTypeDeal(field.getType(), fieldVal);
|
Object o = simpleTypeDeal(field.getType(), fieldVal);
|
||||||
ReflectionUtils.setField(field, t, o);
|
ReflectionUtils.setField(field, t, o);
|
||||||
} else {
|
} else {
|
||||||
String[] pathArray = value.split(".");
|
String[] pathArray = value.split("\\.");
|
||||||
Element subElement = element1;
|
Element subElement = element;
|
||||||
for (String path : pathArray) {
|
for (String path : pathArray) {
|
||||||
subElement = subElement.element(path);
|
subElement = subElement.element(path);
|
||||||
if (subElement == null) {
|
if (subElement == null) {
|
||||||
|
|
|
@ -92,6 +92,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||||
List<DeviceChannel> addChannels = new ArrayList<>();
|
List<DeviceChannel> addChannels = new ArrayList<>();
|
||||||
List<DeviceChannel> updateChannels = new ArrayList<>();
|
List<DeviceChannel> updateChannels = new ArrayList<>();
|
||||||
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
|
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
|
||||||
|
int result = 0;
|
||||||
if (channels != null && !channels.isEmpty()) {
|
if (channels != null && !channels.isEmpty()) {
|
||||||
List<DeviceChannel> channelList = channelMapper.queryChannelsByDeviceDbId(device.getId());
|
List<DeviceChannel> channelList = channelMapper.queryChannelsByDeviceDbId(device.getId());
|
||||||
if (channelList.isEmpty()) {
|
if (channelList.isEmpty()) {
|
||||||
|
@ -120,42 +121,60 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||||
DeviceChannel deviceChannelInDb = channelsInStore.get(channel.getDeviceDbId() + channel.getDeviceId());
|
DeviceChannel deviceChannelInDb = channelsInStore.get(channel.getDeviceDbId() + channel.getDeviceId());
|
||||||
if ( deviceChannelInDb != null) {
|
if ( deviceChannelInDb != null) {
|
||||||
channel.setId(deviceChannelInDb.getId());
|
channel.setId(deviceChannelInDb.getId());
|
||||||
|
channel.setUpdateTime(now);
|
||||||
updateChannels.add(channel);
|
updateChannels.add(channel);
|
||||||
}else {
|
}else {
|
||||||
addChannels.add(channel);
|
|
||||||
channel.setCreateTime(now);
|
channel.setCreateTime(now);
|
||||||
|
channel.setUpdateTime(now);
|
||||||
|
addChannels.add(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int limitCount = 50;
|
Set<String> channelSet = new HashSet<>();
|
||||||
if (addChannels.size() > 0) {
|
// 滤重
|
||||||
if (addChannels.size() > limitCount) {
|
List<DeviceChannel> addChannelList = new ArrayList<>();
|
||||||
for (int i = 0; i < addChannels.size(); i += limitCount) {
|
List<DeviceChannel> updateChannelList = new ArrayList<>();
|
||||||
|
addChannels.forEach(channel -> {
|
||||||
|
if (channelSet.add(channel.getDeviceId())) {
|
||||||
|
addChannelList.add(channel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
channelSet.clear();
|
||||||
|
updateChannels.forEach(channel -> {
|
||||||
|
if (channelSet.add(channel.getDeviceId())) {
|
||||||
|
updateChannelList.add(channel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
int limitCount = 500;
|
||||||
|
if (!addChannelList.isEmpty()) {
|
||||||
|
if (addChannelList.size() > limitCount) {
|
||||||
|
for (int i = 0; i < addChannelList.size(); i += limitCount) {
|
||||||
int toIndex = i + limitCount;
|
int toIndex = i + limitCount;
|
||||||
if (i + limitCount > addChannels.size()) {
|
if (i + limitCount > addChannelList.size()) {
|
||||||
toIndex = addChannels.size();
|
toIndex = addChannelList.size();
|
||||||
}
|
}
|
||||||
channelMapper.batchAdd(addChannels.subList(i, toIndex));
|
result += channelMapper.batchAdd(addChannelList.subList(i, toIndex));
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
channelMapper.batchAdd(addChannels);
|
result += channelMapper.batchAdd(addChannelList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updateChannels.size() > 0) {
|
if (!updateChannelList.isEmpty()) {
|
||||||
if (updateChannels.size() > limitCount) {
|
if (updateChannelList.size() > limitCount) {
|
||||||
for (int i = 0; i < updateChannels.size(); i += limitCount) {
|
for (int i = 0; i < updateChannelList.size(); i += limitCount) {
|
||||||
int toIndex = i + limitCount;
|
int toIndex = i + limitCount;
|
||||||
if (i + limitCount > updateChannels.size()) {
|
if (i + limitCount > updateChannelList.size()) {
|
||||||
toIndex = updateChannels.size();
|
toIndex = updateChannelList.size();
|
||||||
}
|
}
|
||||||
channelMapper.batchUpdate(updateChannels.subList(i, toIndex));
|
result += channelMapper.batchUpdate(updateChannelList.subList(i, toIndex));
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
channelMapper.batchUpdate(updateChannels);
|
result += channelMapper.batchUpdate(updateChannelList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return addChannels.size() + updateChannels.size();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue