配置下发修改
This commit is contained in:
parent
db85443f02
commit
137e31af31
@ -20,8 +20,6 @@ public class ConfigUpdateVo {
|
||||
|
||||
private List<LinkVo> links;
|
||||
|
||||
private List<EquipmentAndMappingVo> equipments;
|
||||
|
||||
public ConfigUpdateVo() {
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class LinkVo {
|
||||
/**
|
||||
@ -26,5 +28,5 @@ public class LinkVo {
|
||||
/**
|
||||
* 关联的设备列表,设备id字符串列表
|
||||
*/
|
||||
private String[] devices;
|
||||
private List<EquipmentAndMappingVo> devices;
|
||||
}
|
||||
|
@ -63,4 +63,9 @@ public class SysTabMappingVo {
|
||||
* 参数
|
||||
*/
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 协议号
|
||||
*/
|
||||
private Integer protocol;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.das.modules.node.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.das.common.constant.MeasType;
|
||||
import com.das.common.utils.AdminRedisTemplate;
|
||||
@ -44,6 +46,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -131,7 +134,6 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
public JsonNode sendTerminalConfig(Long nodeId) {
|
||||
ConfigUpdateVo configUpdateVo = new ConfigUpdateVo();
|
||||
List<LinkVo> links = new ArrayList<>();
|
||||
List<EquipmentAndMappingVo> equipments = new ArrayList<>();
|
||||
try {
|
||||
// 获取所有的链路信息
|
||||
List<SysCommunicationLinkVo> sysCommunicationLinkVoList = sysCommunicationLinkMapper.querySysCommunicationLink(nodeId);
|
||||
@ -142,14 +144,10 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
linkVo.setLinkName(sysCommunicationLinkVo.getLinkName());
|
||||
linkVo.setParams(jsonNode);
|
||||
linkVo.setProtocol(sysCommunicationLinkVo.getProtocol());
|
||||
List<String> stringList = new ArrayList<>();
|
||||
// 获取关联的设备Id
|
||||
// 获取关联的设备所有属性
|
||||
List<EquipmentVo> equipmentList = sysImptabmappingMapper.getBindDeviceByLink(sysCommunicationLinkVo.getId());
|
||||
for (EquipmentVo dev : equipmentList) {
|
||||
stringList.add(String.valueOf(dev.getId()));
|
||||
}
|
||||
String[] stringArray = stringList.toArray(new String[0]);
|
||||
linkVo.setDevices(stringArray);
|
||||
|
||||
List<EquipmentAndMappingVo> equipmentAndMappingVoList = new ArrayList<>();
|
||||
links.add(linkVo);
|
||||
|
||||
for (EquipmentVo dev : equipmentList) {
|
||||
@ -162,6 +160,11 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
|
||||
List<SysTabMappingVo> tabMappingVoList = sysImptabmappingMapper.getMappingInfoListByLinkIdAndDeviceId(sysCommunicationLinkVo.getId(), dev.getId());
|
||||
|
||||
if (sysCommunicationLinkVo.getProtocol() == 17 || sysCommunicationLinkVo.getProtocol() == 9){
|
||||
List<SysTabMappingVo> orderMappingVoList = tabMappingVoList.stream().filter(item -> ObjectUtil.isNotEmpty(JSONObject.parseObject(item.getParams()).get("order"))).collect(Collectors.toList());
|
||||
tabMappingVoList.clear();
|
||||
tabMappingVoList.addAll(orderMappingVoList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(tabMappingVoList)) {
|
||||
for (SysTabMappingVo info : tabMappingVoList) {
|
||||
|
||||
@ -202,8 +205,10 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
equipment.setId(dev.getId());
|
||||
equipment.setAttrs(attrs);
|
||||
equipment.setServices(services);
|
||||
equipments.add(equipment);
|
||||
equipmentAndMappingVoList.add(equipment);
|
||||
}
|
||||
//改成list
|
||||
linkVo.setDevices(equipmentAndMappingVoList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取设备配置信息失败", e);
|
||||
@ -212,7 +217,6 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
configUpdateVo.setNodeId(nodeId);
|
||||
configUpdateVo.setVersion(1);
|
||||
configUpdateVo.setLinks(links);
|
||||
configUpdateVo.setEquipments(equipments);
|
||||
log.info("下发配置为{}", configUpdateVo);
|
||||
JsonNode jsonNode = JSON_MAPPER.valueToTree(configUpdateVo);
|
||||
|
||||
@ -225,7 +229,9 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
.data(jsonNode)
|
||||
.build();
|
||||
sendActionMessage(nodeId, configUpdate);
|
||||
System.out.println(jsonNode);
|
||||
return jsonNode;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.das.common.config.SessionUtil;
|
||||
import com.das.common.constant.MeasType;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.utils.BeanCopyUtils;
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.common.utils.PageQuery;
|
||||
@ -14,6 +15,7 @@ import com.das.modules.auth.entity.SysOrg;
|
||||
import com.das.modules.auth.mapper.SysOrgMapper;
|
||||
import com.das.modules.equipment.domain.vo.SysIotModelFieldVo;
|
||||
import com.das.modules.equipment.domain.vo.SysIotModelServiceVo;
|
||||
import com.das.modules.equipment.entity.SysIotModelField;
|
||||
import com.das.modules.equipment.mapper.SysEquipmentMapper;
|
||||
import com.das.modules.equipment.mapper.SysIotModelFieldMapper;
|
||||
import com.das.modules.equipment.mapper.SysIotModelServiceMapper;
|
||||
@ -32,6 +34,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.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@ -48,6 +51,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Service
|
||||
@ -352,8 +356,21 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
if (!CollectionUtils.isEmpty(impList)) {
|
||||
List<SysTabMapping> list = new ArrayList<>();
|
||||
|
||||
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));
|
||||
List<SysTabMappingVo> analogList = impList.stream().filter(item -> collect.get(item.getId()) == 138).collect(Collectors.toList());
|
||||
List<SysTabMappingVo> accumulator = impList.stream().filter(item -> collect.get(item.getId()) == 139).collect(Collectors.toList());
|
||||
List<SysTabMappingVo> discrete = impList.stream().filter(item -> collect.get(item.getId()) == 140).collect(Collectors.toList());
|
||||
List<SysTabMappingVo> setPoint = impList.stream().filter(item -> collect.get(item.getId()) == 146).collect(Collectors.toList());
|
||||
List<SysTabMappingVo> control = impList.stream().filter(item -> collect.get(item.getId()) == 147).collect(Collectors.toList());
|
||||
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) {
|
||||
//校验param里面order不重复
|
||||
|
||||
SysTabMapping rec = sysImptabmappingMapper.selectById(imp.getId());
|
||||
rec.setUpdatedTime(new Date());
|
||||
rec.setUpdatedBy(sysUserVo.getAccount());
|
||||
@ -466,4 +483,29 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
private Boolean checkOrderRepeated(List<SysTabMappingVo> mappings) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
Boolean orderRepeated = false;
|
||||
try {
|
||||
// 提取所有的 order 字段,转换为 Set
|
||||
Set<String> orderSet = new HashSet<>();
|
||||
orderRepeated = mappings.stream()
|
||||
.map(SysTabMappingVo::getParams) // 提取 param 字段
|
||||
.map(param -> {
|
||||
try {
|
||||
// 解析 JSON 并提取 order
|
||||
JsonNode jsonNode = objectMapper.readTree(param);
|
||||
return jsonNode.get("order").asText();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON 解析失败: " + param, e);
|
||||
}
|
||||
})
|
||||
.anyMatch(order -> !orderSet.add(order));
|
||||
}catch (Exception e){
|
||||
log.error("校验order不重复失败:{}",e);
|
||||
}
|
||||
return orderRepeated;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user