|
|
@@ -13,6 +13,7 @@ import com.dcs.hnyz.domain.vo.EquipmentFormVO;
|
|
|
import com.dcs.hnyz.enums.DeviceTypeEnum;
|
|
|
import com.dcs.hnyz.mapper.EquipmentMapper;
|
|
|
import com.dcs.hnyz.service.*;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
@@ -38,7 +39,7 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
|
|
private IFlowService flowService;
|
|
|
|
|
|
@Resource
|
|
|
- private CommunicationProtocolServiceImpl communicationProtocolService;
|
|
|
+ private ICommunicationProtocolService communicationProtocolService;
|
|
|
|
|
|
@Resource
|
|
|
private IPlcInfoService plcInfoService;
|
|
|
@@ -47,7 +48,7 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
|
|
private IEquipmentParamService equipmentParamService;
|
|
|
|
|
|
@Resource
|
|
|
- private AlarmEventServiceImpl alarmEventService;
|
|
|
+ private IAlarmEventService alarmEventService;
|
|
|
|
|
|
@Resource
|
|
|
private IPageControlService pageControlService;
|
|
|
@@ -77,14 +78,50 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Equipment> selectEquipmentExportList(Equipment equipment) {
|
|
|
+ public List<EquipmentFormVO> selectEquipmentExportList(Equipment equipment) {
|
|
|
List<Equipment> list = equipmentMapper.selectEquipmentList(equipment);
|
|
|
-// 过滤掉没有protocolId的
|
|
|
- List<Equipment> collect = list.stream().filter(e -> e.getProtocolId() != null).collect(Collectors.toList());
|
|
|
- List<CommunicationProtocol> commProtocolList = communicationProtocolService.getCommProtocolList();
|
|
|
- for (Equipment e : collect) {
|
|
|
- e.setProtocolCode(commProtocolList.stream().filter(cp -> cp.getProtocolId().equals(e.getProtocolId())).findFirst().get().getCode());
|
|
|
- }
|
|
|
+
|
|
|
+ // 把协议列表转成 Map<protocolId, code>
|
|
|
+ Map<Integer, String> protocolMap = communicationProtocolService.getCommProtocolList().stream()
|
|
|
+ .collect(Collectors.toMap(CommunicationProtocol::getProtocolId, CommunicationProtocol::getCode));
|
|
|
+
|
|
|
+ Map<Long, String> pageMap = pageControlService.getPageList().stream()
|
|
|
+ .collect(Collectors.toMap(PageControl::getPageId, PageControl::getPageCode));
|
|
|
+
|
|
|
+ List<Flow> flowList = flowService.getFlowList();
|
|
|
+ Map<Long, String> flowMap = flowList.stream()
|
|
|
+ .collect(Collectors.toMap(Flow::getFlowId, Flow::getFlowCode));
|
|
|
+
|
|
|
+ // 过滤 + 复制 + 填充 protocolCode
|
|
|
+ List<EquipmentFormVO> collect = list.stream()
|
|
|
+ .filter(e -> e.getProtocolId() != null) // 过滤掉 protocolId == null 的
|
|
|
+ .map(e -> {
|
|
|
+ EquipmentFormVO equipmentFormVO = new EquipmentFormVO();
|
|
|
+ BeanUtils.copyProperties(e, equipmentFormVO);
|
|
|
+ // 安全地设置协议编码(防止 map.get 返回 null)
|
|
|
+ equipmentFormVO.setProtocolCode(protocolMap.getOrDefault(e.getProtocolId(), "未配置"));
|
|
|
+ // 将页面ID转换为页面编码字符串
|
|
|
+ if (equipmentFormVO.getPageIds() != null) {
|
|
|
+ List<String> ids = Arrays.asList(equipmentFormVO.getPageIds().split(","));
|
|
|
+ equipmentFormVO.setPageCodes(ids.stream()
|
|
|
+ .map(id -> pageMap.get(Long.valueOf(id)))
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ } else {
|
|
|
+ equipmentFormVO.setPageCodes("未配置");
|
|
|
+ }
|
|
|
+ // 将流程ID转换为流程编码字符串
|
|
|
+ if (equipmentFormVO.getFlowIds() != null) {
|
|
|
+ List<String> ids = Arrays.asList(equipmentFormVO.getFlowIds().split(","));
|
|
|
+ equipmentFormVO.setFlowCodes(ids.stream()
|
|
|
+ .map(id -> flowMap.get(Long.valueOf(id)))
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ } else {
|
|
|
+ equipmentFormVO.setFlowCodes("未配置");
|
|
|
+ }
|
|
|
+ return equipmentFormVO;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
return collect;
|
|
|
}
|
|
|
|
|
|
@@ -391,9 +428,9 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String importEquipment(List<Equipment> equipmentList, boolean isUpdateSupport, String operName) {
|
|
|
+ public String importEquipment(List<EquipmentFormVO> equipmentFormVOList, boolean isUpdateSupport, String operName) {
|
|
|
|
|
|
- if (StringUtils.isNull(equipmentList) || equipmentList.size() == 0)
|
|
|
+ if (StringUtils.isNull(equipmentFormVOList) || equipmentFormVOList.size() == 0)
|
|
|
{
|
|
|
throw new ServiceException("导入设备数据不能为空!");
|
|
|
}
|
|
|
@@ -403,30 +440,78 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
|
List<PlcInfo> plcInfoList = plcInfoService.getPlcList();
|
|
|
List<CommunicationProtocol> protocolList = communicationProtocolService.getCommProtocolList();
|
|
|
- for (Equipment equipment : equipmentList)
|
|
|
+ Map<String, Long> plcMap = plcInfoList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ p -> p.getIpAddress() + ":" + p.getPort(),
|
|
|
+ PlcInfo::getPlcId
|
|
|
+ ));
|
|
|
+
|
|
|
+ Map<String, Integer> protocolMap = protocolList.stream()
|
|
|
+ .collect(Collectors.toMap(CommunicationProtocol::getCode, CommunicationProtocol::getProtocolId));
|
|
|
+
|
|
|
+ Map<String, Long> pageMap = pageControlService.getPageList().stream()
|
|
|
+ .collect(Collectors.toMap(PageControl::getPageCode, PageControl::getPageId));
|
|
|
+
|
|
|
+ List<Flow> flowList = flowService.getFlowList();
|
|
|
+ Map<String, Long> flowMap = flowList.stream()
|
|
|
+ .collect(Collectors.toMap(Flow::getFlowCode, Flow::getFlowId));
|
|
|
+
|
|
|
+ for (EquipmentFormVO equipmentFormVO : equipmentFormVOList)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
// 验证是否存在这个设备
|
|
|
- Equipment e = equipmentMapper.selectOne(new QueryWrapper<Equipment>().eq("code", equipment.getCode()));
|
|
|
+ Equipment e = equipmentMapper.selectOne(new QueryWrapper<Equipment>().eq("code", equipmentFormVO.getCode()));
|
|
|
+ Equipment equipment = new Equipment();
|
|
|
+ BeanUtils.copyProperties(equipmentFormVO, equipment);
|
|
|
if (StringUtils.isNull(e))
|
|
|
{
|
|
|
// TODO 获取设备类型字符串查询设备类型库 填充相应的设备类型 id
|
|
|
// TODO 模糊查询设备流程和页面 填充相应的流程和页面 id 没有命中需返回消息提示无页面
|
|
|
// 识别设备的PLC
|
|
|
- if (equipment.getIpAddress() != null && equipment.getPort() != null && plcInfoList.size() > 0) {
|
|
|
- PlcInfo plcInfo = plcInfoList.stream().filter(p -> p.getIpAddress().equals(equipment.getIpAddress()) && p.getPort().equals(equipment.getPort())).findFirst().orElse(null);
|
|
|
- if (plcInfo != null) {
|
|
|
- equipment.setPlcId(plcInfo.getPlcId());
|
|
|
+ if (equipmentFormVO.getIpAddress() != null && equipmentFormVO.getPort() != null) {
|
|
|
+ Long plcInfoId = plcMap.get(equipmentFormVO.getIpAddress() + ":" + equipmentFormVO.getPort());
|
|
|
+ if (plcInfoId != null) {
|
|
|
+ equipment.setPlcId(plcInfoId);
|
|
|
}
|
|
|
}
|
|
|
// 识别设备的通信协议
|
|
|
- if (equipment.getProtocolCode() != null && protocolList.size() > 0) {
|
|
|
- CommunicationProtocol protocol = protocolList.stream().filter(p -> p.getCode().equals(equipment.getProtocolCode())).findFirst().orElse(null);
|
|
|
- if (protocol != null) {
|
|
|
- equipment.setProtocolId(protocol.getProtocolId());
|
|
|
+ if (equipmentFormVO.getProtocolCode() != null) {
|
|
|
+ Integer protocolId = protocolMap.get(equipmentFormVO.getProtocolCode());
|
|
|
+ if (protocolId != null) {
|
|
|
+ equipment.setProtocolId(protocolId);
|
|
|
+ } else {
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、设备 " + equipmentFormVO.getCode() + " 协议Code" + equipmentFormVO.getProtocolCode() + "不存在,请检查!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 识别设备流程(将 flowCodes 转为 flowIds)
|
|
|
+ if (equipmentFormVO.getFlowCodes() != null && !equipmentFormVO.getFlowCodes().trim().isEmpty()) {
|
|
|
+ String flowIds = Arrays.stream(equipmentFormVO.getFlowCodes().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .map(flowMap::get)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ if (flowIds.isEmpty()) {
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、设备 " + equipmentFormVO.getCode() + " 未识别到任何流程编码,请检查!");
|
|
|
+ } else {
|
|
|
+ equipment.setFlowIds(flowIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 识别设备页面(将 pageCodes 转为 pageIds)
|
|
|
+ if (equipmentFormVO.getPageCodes() != null && !equipmentFormVO.getPageCodes().trim().isEmpty()) {
|
|
|
+ String pageIds = Arrays.stream(equipmentFormVO.getPageCodes().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .map(pageMap::get)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ if (pageIds.isEmpty()) {
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、设备 " + equipmentFormVO.getCode() + " 未识别到任何页面编码,请检查!");
|
|
|
} else {
|
|
|
- failureMsg.append("<br/>" + failureNum + "、设备 " + equipment.getCode() + " 协议Code" + e.getProtocolCode() + "不存在,请检查!");
|
|
|
+ equipment.setPageIds(pageIds);
|
|
|
}
|
|
|
}
|
|
|
equipment.setCreateBy(operName);
|
|
|
@@ -437,6 +522,36 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
|
|
}
|
|
|
else if (isUpdateSupport)
|
|
|
{
|
|
|
+ // 识别设备流程(将 flowCodes 转为 flowIds)
|
|
|
+ if (equipmentFormVO.getFlowCodes() != null && !equipmentFormVO.getFlowCodes().trim().isEmpty()) {
|
|
|
+ String flowIds = Arrays.stream(equipmentFormVO.getFlowCodes().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .map(flowMap::get)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ if (flowIds.isEmpty()) {
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、设备 " + equipmentFormVO.getCode() + " 未识别到任何流程编码,请检查!");
|
|
|
+ } else {
|
|
|
+ equipment.setFlowIds(flowIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 识别设备页面(将 pageCodes 转为 pageIds)
|
|
|
+ if (equipmentFormVO.getPageCodes() != null && !equipmentFormVO.getPageCodes().trim().isEmpty()) {
|
|
|
+ String pageIds = Arrays.stream(equipmentFormVO.getPageCodes().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .map(pageMap::get)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ if (pageIds.isEmpty()) {
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、设备 " + equipmentFormVO.getCode() + " 未识别到任何页面编码,请检查!");
|
|
|
+ } else {
|
|
|
+ equipment.setPageIds(pageIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
equipment.setCreateBy(operName);
|
|
|
// equipment.setStatus("0");
|
|
|
equipmentMapper.insert(equipment);
|
|
|
@@ -452,7 +567,7 @@ public class EquipmentServiceImpl implements IEquipmentService {
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
failureNum++;
|
|
|
- String msg = "<br/>" + failureNum + "、设备 " + equipment.getCode() + " 导入失败:";
|
|
|
+ String msg = "<br/>" + failureNum + "、设备 " + equipmentFormVO.getCode() + " 导入失败:";
|
|
|
failureMsg.append(msg + e.getMessage());
|
|
|
// log.error(msg, e);
|
|
|
}
|