UPDATE: 修改被检设备批量导入逻辑。

This commit is contained in:
贾同学
2025-09-23 14:54:29 +08:00
parent 84f9e61e57
commit 80c383a746

View File

@@ -778,7 +778,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
} }
int count = this.count(queryWrapper); int count = this.count(queryWrapper);
if (count > 0) { if (count > 0) {
throw new BusinessException(DetectionResponseEnum.PQ_DEV_REPEAT); throw new BusinessException(DetectionResponseEnum.PQ_DEV_REPEAT, "" + param.getName() + "】被检设备已存在");
} }
} }
@@ -1179,10 +1179,23 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
@Transactional @Transactional
public boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId) { public boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId) {
if (CollUtil.isNotEmpty(contrastDevExcelList)) { if (CollUtil.isNotEmpty(contrastDevExcelList)) {
List<PqMonitor> monitorList = new ArrayList<>(); // 根据设备名称分组
List<PqDev> oldDevList = contrastDevExcelList.stream().map(devExcel -> { Map<String, List<ContrastDevExcel>> listMap = contrastDevExcelList.stream()
.collect(Collectors.groupingBy(ContrastDevExcel::getName, LinkedHashMap::new, Collectors.toList()));
List<PqDev> oldDevList = new ArrayList<>(listMap.size());
List<PqMonitor> finalMonitorList = new ArrayList<>();
for (Map.Entry<String, List<ContrastDevExcel>> entry : listMap.entrySet()) {
String name = entry.getKey();
List<ContrastDevExcel> devExcelList = entry.getValue();
// 监测点数据
List<PqMonitorExcel> pqMonitorExcelList = devExcelList.stream()
.map(ContrastDevExcel::getPqMonitorExcelList)
.filter(Objects::nonNull)
.flatMap(List::stream)
.collect(Collectors.toList());
// 取第一条为设备基本信息
ContrastDevExcel devExcel = devExcelList.get(0);
PqDev pqDev = BeanUtil.copyProperties(devExcel, PqDev.class); PqDev pqDev = BeanUtil.copyProperties(devExcel, PqDev.class);
if (pqDev.getEncryptionFlag() == 1) { if (pqDev.getEncryptionFlag() == 1) {
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) { if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries())); pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
@@ -1194,43 +1207,47 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
DevType devType = devTypeService.getByName(pqDev.getDevType()); DevType devType = devTypeService.getByName(pqDev.getDevType());
if (ObjectUtil.isNull(devType)) { if (ObjectUtil.isNull(devType)) {
throw new BusinessException(DetectionResponseEnum.DEV_TYPE_NOT_EXIST); throw new BusinessException(DetectionResponseEnum.DEV_TYPE_NOT_EXIST);
} else { }
pqDev.setDevType(devType.getId()); // 校验监测点数量
int devChns = devType.getDevChns();
Integer devChns = devType.getDevChns(); if (pqMonitorExcelList.size() != devChns) {
List<Integer> numList = devExcel.getPqMonitorExcelList().stream().map(monitorExcel -> monitorExcel.getNum()).collect(Collectors.toList()); throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL, "" + name + "】的设备类型必须具备" + devChns + "个监测点信息!");
if (CollUtil.isNotEmpty(numList)) { }
Integer max = CollectionUtil.max(numList); List<Integer> numList = pqMonitorExcelList.stream().map(PqMonitorExcel::getNum).collect(Collectors.toList());
Integer min = CollectionUtil.min(numList); // 判断是否有重复的num
if (min < 1 || max > devChns) { Set<Integer> uniqueNumSet = new HashSet<>(numList);
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE); if (uniqueNumSet.size() != numList.size()) {
} throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT);
if (min == max && numList.size() > 1) { }
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT); Integer max = CollectionUtil.max(numList);
} Integer min = CollectionUtil.min(numList);
} if (min < 1 || max > devChns) {
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE);
} }
pqDev.setDevType(devType.getId());
pqDev.setImportFlag(1); pqDev.setImportFlag(1);
pqDev.setId(UUID.randomUUID().toString().replaceAll("-", "")); pqDev.setId(UUID.randomUUID().toString().replaceAll("-", ""));
pqDev.setCreateId(pqDev.getName()); //导入时设备序列号默认与设备名称相同 pqDev.setCreateId(pqDev.getName()); //导入时设备序列号默认与设备名称相同
List<PqMonitor> monitorList = new ArrayList<>();
StringBuilder sb = new StringBuilder(); // 根据num排序
for (int i = 0; i < devExcel.getPqMonitorExcelList().size(); i++) { pqMonitorExcelList.sort(Comparator.comparingInt(PqMonitorExcel::getNum));
PqMonitor monitor = BeanUtil.copyProperties(devExcel.getPqMonitorExcelList().get(i), PqMonitor.class); for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
if (StrUtil.isBlank(monitor.getName())) { PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
continue;
}
sb.append(monitor.getNum() + StrUtil.COMMA);
monitor.setDevId(pqDev.getId()); monitor.setDevId(pqDev.getId());
monitorList.add(monitor); monitorList.add(monitor);
} }
if (sb.length() > 0) { StringBuilder inspectChannelBuilder = new StringBuilder();
pqDev.setInspectChannel(sb.replace(sb.length() - 1, sb.length(), "").toString()); for (int i = 1; i <= devChns; i++) {
inspectChannelBuilder.append(i);
if (i < devChns) {
inspectChannelBuilder.append(",");
}
} }
return pqDev; pqDev.setInspectChannel(inspectChannelBuilder.toString());
}).collect(Collectors.toList()); oldDevList.add(pqDev);
finalMonitorList.addAll(monitorList);
}
//逆向可视化 //逆向可视化
this.reverseVisualizeProvinceDev(oldDevList, patternId); this.reverseVisualizeProvinceDev(oldDevList, patternId);
@@ -1259,7 +1276,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
PqDev newDev = newDevList.stream().filter(dev -> dev.getHarmSysId().equals(oldDev.getHarmSysId())).findFirst().orElse(null); PqDev newDev = newDevList.stream().filter(dev -> dev.getHarmSysId().equals(oldDev.getHarmSysId())).findFirst().orElse(null);
if (ObjectUtil.isNotNull(newDev)) { if (ObjectUtil.isNotNull(newDev)) {
newDevList.remove(newDev); newDevList.remove(newDev);
monitorList.stream() finalMonitorList.stream()
.filter(monitor -> monitor.getDevId().equals(newDev.getId())) .filter(monitor -> monitor.getDevId().equals(newDev.getId()))
.forEach(monitor -> monitor.setDevId(oldDev.getId())); .forEach(monitor -> monitor.setDevId(oldDev.getId()));
BeanUtil.copyProperties(newDev, oldDev, "id"); BeanUtil.copyProperties(newDev, oldDev, "id");
@@ -1287,8 +1304,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
.in("pq_monitor.Dev_Id", devIdList); .in("pq_monitor.Dev_Id", devIdList);
pqMonitorService.remove(wrapper); pqMonitorService.remove(wrapper);
} }
pqMonitorService.reverseVisualizeMonitor(monitorList); pqMonitorService.reverseVisualizeMonitor(finalMonitorList);
pqMonitorService.saveBatch(monitorList); pqMonitorService.saveBatch(finalMonitorList);
return true; return true;
} }
return false; return false;
@@ -1404,11 +1421,6 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
pqDev.setDelegate(delegateDictData.getId()); pqDev.setDelegate(delegateDictData.getId());
} }
} }
// pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
// pqDev.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());
// pqDev.setCheckState(CheckStateEnum.UNCHECKED.getValue());
// pqDev.setReportState(DevReportStateEnum.UNCHECKED.getValue());
// pqDev.setCheckResult(CheckResultEnum.UNCHECKED.getValue());
pqDev.setState(DataStateEnum.ENABLE.getCode()); pqDev.setState(DataStateEnum.ENABLE.getCode());
}); });
} }