diff --git a/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java b/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java index 08b6b2ff..02f1743b 100644 --- a/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java +++ b/das/src/main/java/com/das/modules/node/service/impl/SysNodeServiceImpl.java @@ -32,6 +32,7 @@ import com.das.modules.node.mapper.SysCommunicationLinkMapper; import com.das.modules.node.mapper.SysImpTabMappingMapper; import com.das.modules.node.mapper.SysNodeMapper; import com.das.modules.node.service.SysNodeService; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; @@ -407,22 +408,21 @@ public class SysNodeServiceImpl implements SysNodeService { */ @Override public void saveMappingList(List impList) { + if (impList.get(0).getProtocol() == 9 || impList.get(0).getProtocol() == 17){ + Map collect = sysImptabmappingMapper.getMappingInfoListByLinkId(impList.get(0).getLinkId()).stream().collect(Collectors.toMap(SysTabMappingVo::getId, SysTabMappingVo::getMeasPointType, (value1, value2) -> value1)); + List analogList = impList.stream().filter(item -> collect.get(item.getId()) == 138).collect(Collectors.toList()); + List accumulator = impList.stream().filter(item -> collect.get(item.getId()) == 139).collect(Collectors.toList()); + List discrete = impList.stream().filter(item -> collect.get(item.getId()) == 140).collect(Collectors.toList()); + List setPoint = impList.stream().filter(item -> collect.get(item.getId()) == 146).collect(Collectors.toList()); + List control = impList.stream().filter(item -> collect.get(item.getId()) == 147).collect(Collectors.toList()); + //校验param里面order不重复 + if (checkOrderRepeated(analogList) || checkOrderRepeated(accumulator) || checkOrderRepeated(discrete) || checkOrderRepeated(setPoint) || checkOrderRepeated(control)){ + throw new ServiceException("检查顺序,排序不能重复"); + } + } try { if (!CollectionUtils.isEmpty(impList)) { List list = new ArrayList<>(); - - if (impList.get(0).getProtocol() == 9 || impList.get(0).getProtocol() == 17){ - Map collect = sysImptabmappingMapper.getMappingInfoListByLinkId(impList.get(0).getLinkId()).stream().collect(Collectors.toMap(SysTabMappingVo::getId, SysTabMappingVo::getMeasPointType, (value1, value2) -> value1)); - List analogList = impList.stream().filter(item -> collect.get(item.getId()) == 138).collect(Collectors.toList()); - List accumulator = impList.stream().filter(item -> collect.get(item.getId()) == 139).collect(Collectors.toList()); - List discrete = impList.stream().filter(item -> collect.get(item.getId()) == 140).collect(Collectors.toList()); - List setPoint = impList.stream().filter(item -> collect.get(item.getId()) == 146).collect(Collectors.toList()); - List control = impList.stream().filter(item -> collect.get(item.getId()) == 147).collect(Collectors.toList()); - //校验param里面order不重复 - if (checkOrderRepeated(analogList) || checkOrderRepeated(accumulator) || checkOrderRepeated(discrete) || checkOrderRepeated(setPoint) || checkOrderRepeated(control)){ - throw new ServiceException("检查顺序,排序不能重复"); - } - } SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); for (SysTabMappingVo imp : impList) { SysTabMapping rec = sysImptabmappingMapper.selectById(imp.getId()); @@ -540,12 +540,19 @@ public class SysNodeServiceImpl implements SysNodeService { private Boolean checkOrderRepeated(List mappings) { ObjectMapper objectMapper = new ObjectMapper(); - + List orderCollect = mappings.stream().filter(item -> { + try { + JsonNode jsonNode = objectMapper.readTree(item.getParams()); + return StringUtils.isNotEmpty(jsonNode.get("order").asText()); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); Boolean orderRepeated = false; try { // 提取所有的 order 字段,转换为 Set Set orderSet = new HashSet<>(); - orderRepeated = mappings.stream() + orderRepeated = orderCollect.stream() .map(SysTabMappingVo::getParams) // 提取 param 字段 .map(param -> { try { @@ -558,7 +565,11 @@ public class SysNodeServiceImpl implements SysNodeService { }) .anyMatch(order -> { if (StringUtils.isNotEmpty(order)){ - return !orderSet.add(order); + boolean b = !orderSet.add(order); + if (b){ + log.error("排序重复{}",order); + } + return b; } return false; });