Merge remote-tracking branch 'origin/master'

# Conflicts:
#	detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java
This commit is contained in:
caozehui
2025-09-25 08:48:44 +08:00
36 changed files with 6786 additions and 230 deletions

View File

@@ -355,12 +355,13 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
pqDevVO.setDevKey(EncryptionUtil.decoderString(1, pqDevVO.getDevKey()));
}
if (StrUtil.isNotBlank(pqDevVO.getCheckBy())) {
SysUser user = userService.getById(pqDevVO.getCheckBy());
if (ObjectUtil.isNotNull(user)) {
pqDevVO.setCheckBy(user.getName());
SysUser sysUser = userService.getById(pqDevVO.getCheckBy());
if (ObjectUtil.isNotNull(sysUser)) {
pqDevVO.setCheckBy(sysUser.getName());
} else {
pqDevVO.setCheckBy(pqDevVO.getCheckBy());
}
}
DevType devType = devTypeService.getById(pqDevVO.getDevType());
if (ObjectUtil.isNotNull(devType)) {
pqDevVO.setDevChns(devType.getDevChns());
@@ -794,7 +795,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
}
int count = this.count(queryWrapper);
if (count > 0) {
throw new BusinessException(DetectionResponseEnum.PQ_DEV_REPEAT);
throw new BusinessException(DetectionResponseEnum.PQ_DEV_REPEAT, "" + param.getName() + "】被检设备已存在");
}
}
@@ -1195,10 +1196,23 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
@Transactional
public boolean importContrastDev(List<ContrastDevExcel> contrastDevExcelList, String patternId, String planId) {
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);
if (pqDev.getEncryptionFlag() == 1) {
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
@@ -1210,43 +1224,47 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
DevType devType = devTypeService.getByName(pqDev.getDevType());
if (ObjectUtil.isNull(devType)) {
throw new BusinessException(DetectionResponseEnum.DEV_TYPE_NOT_EXIST);
} else {
pqDev.setDevType(devType.getId());
Integer devChns = devType.getDevChns();
List<Integer> numList = devExcel.getPqMonitorExcelList().stream().map(monitorExcel -> monitorExcel.getNum()).collect(Collectors.toList());
if (CollUtil.isNotEmpty(numList)) {
Integer max = CollectionUtil.max(numList);
Integer min = CollectionUtil.min(numList);
if (min < 1 || max > devChns) {
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_OUT_OF_RANGE);
}
if (min == max && numList.size() > 1) {
throw new BusinessException(DetectionResponseEnum.MONITOR_NUM_REPEAT);
}
}
}
// 校验监测点数量
int devChns = devType.getDevChns();
if (pqMonitorExcelList.size() != devChns) {
throw new BusinessException(DetectionResponseEnum.IMPORT_DATA_FAIL, "" + name + "】的设备类型必须具备" + devChns + "个监测点信息!");
}
List<Integer> numList = pqMonitorExcelList.stream().map(PqMonitorExcel::getNum).collect(Collectors.toList());
// 判断是否有重复的num
Set<Integer> uniqueNumSet = new HashSet<>(numList);
if (uniqueNumSet.size() != numList.size()) {
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.setId(UUID.randomUUID().toString().replaceAll("-", ""));
pqDev.setCreateId(pqDev.getName()); //导入时设备序列号默认与设备名称相同
StringBuilder sb = new StringBuilder();
for (int i = 0; i < devExcel.getPqMonitorExcelList().size(); i++) {
PqMonitor monitor = BeanUtil.copyProperties(devExcel.getPqMonitorExcelList().get(i), PqMonitor.class);
if (StrUtil.isBlank(monitor.getName())) {
continue;
}
sb.append(monitor.getNum() + StrUtil.COMMA);
List<PqMonitor> monitorList = new ArrayList<>();
// 根据num排序
pqMonitorExcelList.sort(Comparator.comparingInt(PqMonitorExcel::getNum));
for (PqMonitorExcel pqMonitorExcel : pqMonitorExcelList) {
PqMonitor monitor = BeanUtil.copyProperties(pqMonitorExcel, PqMonitor.class);
monitor.setDevId(pqDev.getId());
monitorList.add(monitor);
}
if (sb.length() > 0) {
pqDev.setInspectChannel(sb.replace(sb.length() - 1, sb.length(), "").toString());
StringBuilder inspectChannelBuilder = new StringBuilder();
for (int i = 1; i <= devChns; i++) {
inspectChannelBuilder.append(i);
if (i < devChns) {
inspectChannelBuilder.append(",");
}
}
return pqDev;
}).collect(Collectors.toList());
pqDev.setInspectChannel(inspectChannelBuilder.toString());
oldDevList.add(pqDev);
finalMonitorList.addAll(monitorList);
}
//逆向可视化
this.reverseVisualizeProvinceDev(oldDevList, patternId);
@@ -1275,7 +1293,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
PqDev newDev = newDevList.stream().filter(dev -> dev.getHarmSysId().equals(oldDev.getHarmSysId())).findFirst().orElse(null);
if (ObjectUtil.isNotNull(newDev)) {
newDevList.remove(newDev);
monitorList.stream()
finalMonitorList.stream()
.filter(monitor -> monitor.getDevId().equals(newDev.getId()))
.forEach(monitor -> monitor.setDevId(oldDev.getId()));
BeanUtil.copyProperties(newDev, oldDev, "id");
@@ -1303,8 +1321,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
.in("pq_monitor.Dev_Id", devIdList);
pqMonitorService.remove(wrapper);
}
pqMonitorService.reverseVisualizeMonitor(monitorList);
pqMonitorService.saveBatch(monitorList);
pqMonitorService.reverseVisualizeMonitor(finalMonitorList);
pqMonitorService.saveBatch(finalMonitorList);
return true;
}
return false;
@@ -1420,11 +1438,6 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
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());
});
}