测点映射表保存修改

This commit is contained in:
huguanghan 2025-01-15 16:41:51 +08:00
parent 3658bf02e8
commit f6e44fb493

View File

@ -32,6 +32,7 @@ import com.das.modules.node.mapper.SysCommunicationLinkMapper;
import com.das.modules.node.mapper.SysImpTabMappingMapper; import com.das.modules.node.mapper.SysImpTabMappingMapper;
import com.das.modules.node.mapper.SysNodeMapper; import com.das.modules.node.mapper.SysNodeMapper;
import com.das.modules.node.service.SysNodeService; import com.das.modules.node.service.SysNodeService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -407,10 +408,6 @@ public class SysNodeServiceImpl implements SysNodeService {
*/ */
@Override @Override
public void saveMappingList(List<SysTabMappingVo> impList) { public void saveMappingList(List<SysTabMappingVo> impList) {
try {
if (!CollectionUtils.isEmpty(impList)) {
List<SysTabMapping> list = new ArrayList<>();
if (impList.get(0).getProtocol() == 9 || impList.get(0).getProtocol() == 17){ if (impList.get(0).getProtocol() == 9 || impList.get(0).getProtocol() == 17){
Map<Long, Integer> collect = sysImptabmappingMapper.getMappingInfoListByLinkId(impList.get(0).getLinkId()).stream().collect(Collectors.toMap(SysTabMappingVo::getId, SysTabMappingVo::getMeasPointType, (value1, value2) -> value1)); Map<Long, Integer> collect = sysImptabmappingMapper.getMappingInfoListByLinkId(impList.get(0).getLinkId()).stream().collect(Collectors.toMap(SysTabMappingVo::getId, SysTabMappingVo::getMeasPointType, (value1, value2) -> value1));
List<SysTabMappingVo> analogList = impList.stream().filter(item -> collect.get(item.getId()) == 138).collect(Collectors.toList()); List<SysTabMappingVo> analogList = impList.stream().filter(item -> collect.get(item.getId()) == 138).collect(Collectors.toList());
@ -423,6 +420,9 @@ public class SysNodeServiceImpl implements SysNodeService {
throw new ServiceException("检查顺序,排序不能重复"); throw new ServiceException("检查顺序,排序不能重复");
} }
} }
try {
if (!CollectionUtils.isEmpty(impList)) {
List<SysTabMapping> list = new ArrayList<>();
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
for (SysTabMappingVo imp : impList) { for (SysTabMappingVo imp : impList) {
SysTabMapping rec = sysImptabmappingMapper.selectById(imp.getId()); SysTabMapping rec = sysImptabmappingMapper.selectById(imp.getId());
@ -540,12 +540,19 @@ public class SysNodeServiceImpl implements SysNodeService {
private Boolean checkOrderRepeated(List<SysTabMappingVo> mappings) { private Boolean checkOrderRepeated(List<SysTabMappingVo> mappings) {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
List<SysTabMappingVo> 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; Boolean orderRepeated = false;
try { try {
// 提取所有的 order 字段转换为 Set // 提取所有的 order 字段转换为 Set
Set<String> orderSet = new HashSet<>(); Set<String> orderSet = new HashSet<>();
orderRepeated = mappings.stream() orderRepeated = orderCollect.stream()
.map(SysTabMappingVo::getParams) // 提取 param 字段 .map(SysTabMappingVo::getParams) // 提取 param 字段
.map(param -> { .map(param -> {
try { try {
@ -558,7 +565,11 @@ public class SysNodeServiceImpl implements SysNodeService {
}) })
.anyMatch(order -> { .anyMatch(order -> {
if (StringUtils.isNotEmpty(order)){ if (StringUtils.isNotEmpty(order)){
return !orderSet.add(order); boolean b = !orderSet.add(order);
if (b){
log.error("排序重复{}",order);
}
return b;
} }
return false; return false;
}); });