diff --git a/das/src/main/java/com/das/common/constant/BaseIotModelType.java b/das/src/main/java/com/das/common/constant/MeasType.java similarity index 82% rename from das/src/main/java/com/das/common/constant/BaseIotModelType.java rename to das/src/main/java/com/das/common/constant/MeasType.java index 1c70fc62..e8885248 100644 --- a/das/src/main/java/com/das/common/constant/BaseIotModelType.java +++ b/das/src/main/java/com/das/common/constant/MeasType.java @@ -2,9 +2,10 @@ package com.das.common.constant; /** * @author chenhaojie - * + * @date 2019/8/26 15:08 + * @description: 测量类型 */ -public interface BaseIotModelType { +public interface MeasType { /** * 遥测量 @@ -30,4 +31,4 @@ public interface BaseIotModelType { * 遥调量 */ int TYPE_PSR_SETPOINT = 146; -} \ No newline at end of file +} diff --git a/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java b/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java index 9f2da697..4f68cadc 100644 --- a/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java +++ b/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelFieldMapper.java @@ -23,4 +23,12 @@ public interface SysIotModelFieldMapper extends BaseMapperPlus queryAllFiledNames(@Param("deviceId") Long deviceId); String queryModelCodeByDeviceId(@Param("deviceId") Long deviceId); + + /** + * 根据物模型id查询模型属性列表 + * @param modelId 物模型id + * @return + */ + List selectModelFieldListByModelId(@Param("modelId") Long modelId); + } diff --git a/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelServiceMapper.java b/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelServiceMapper.java index b62fe9e5..855788bd 100644 --- a/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelServiceMapper.java +++ b/das/src/main/java/com/das/modules/equipment/mapper/SysIotModelServiceMapper.java @@ -9,6 +9,8 @@ import com.das.modules.equipment.entity.SysIotModelServices; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + @Mapper public interface SysIotModelServiceMapper extends BaseMapperPlus { @@ -18,4 +20,11 @@ public interface SysIotModelServiceMapper extends BaseMapperPlus selectModelServiceListByModelId(@Param("modelId") Long modelId); + } diff --git a/das/src/main/java/com/das/modules/node/controller/SysNodeController.java b/das/src/main/java/com/das/modules/node/controller/SysNodeController.java index d4e05401..fbaf017d 100644 --- a/das/src/main/java/com/das/modules/node/controller/SysNodeController.java +++ b/das/src/main/java/com/das/modules/node/controller/SysNodeController.java @@ -155,40 +155,48 @@ public class SysNodeController { return R.success(typeVoList); } - /** 获取映射表信息 */ + /** + * 获取映射表信息 + * @param queryParam 查询条件(LinkId 和 MeasType) + * @return 返回前端呈现表格数据 + */ @PostMapping("/link/getMappingList") - public R getMappingList(@RequestBody SysImptabmappingDto sysImptabmappingDto) { + public R getMappingList(@RequestBody QueryTabMappingParamDto queryParam) { //判断是否有权限 boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_ADMIN.toString()); if(!hasPermission){ return R.fail("没有节点管理权限"); } - if (sysImptabmappingDto.getLinkId() == null) { + if (queryParam.getLinkId() == null) { throw new ServiceException("参数缺失"); } - List list = sysNodeService.getMappingList(sysImptabmappingDto); + List list = sysNodeService.getMappingList(queryParam); return R.success(list); } - /** 获取绑定的设备列表信息 */ + /** + * 获取链路绑定的设备列表 + * @param queryParam 查询条件 只用到 LinkId + * @return 设备列表 + */ @PostMapping("/link/getBindDeviceTree") - public R getBindDeviceTree(@RequestBody SysImptabmappingDto sysImptabmappingDto) { + public R getBindDeviceTree(@RequestBody QueryTabMappingParamDto queryParam) { //判断是否有权限 boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_ADMIN.toString()); if(!hasPermission){ return R.fail("没有节点管理权限"); } - if (sysImptabmappingDto.getLinkId() == null) { + if (queryParam.getLinkId() == null) { throw new ServiceException("参数缺失"); } - List list = sysNodeService.getBindDeviceTree(sysImptabmappingDto.getLinkId()); + List list = sysNodeService.getBindDeviceTree(queryParam.getLinkId()); return R.success(list); } /** 绑定设备信息 */ - @PostMapping("/link/bindDeviceMeas") + @PostMapping("/link/bindDevices") public R bindMeas(@RequestBody BindEquipmentDto bindEquipmentDto) { //判断是否有权限 @@ -196,13 +204,13 @@ public class SysNodeController { if(!hasPermission){ return R.fail("没有节点管理权限"); } - sysNodeService.bindDeviceMeas(bindEquipmentDto.getEquipmentId(), bindEquipmentDto.getLinkId()); + sysNodeService.bindDevices(bindEquipmentDto.getEquipmentList(), bindEquipmentDto.getLinkId()); return R.success(); } /** 保存测点信息 */ @PostMapping("/link/saveMappingList") - public R saveMappingList(@RequestBody List impList) { + public R saveMappingList(@RequestBody List impList) { //判断是否有权限 boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_ADMIN.toString()); @@ -215,10 +223,10 @@ public class SysNodeController { /** 导出测点信息成json文件 */ @PostMapping("/link/exportMappingList") - public void exportMappingList(HttpServletRequest request, HttpServletResponse response, @RequestBody SysImptabmappingDto sysImptabmappingDto) throws IOException { + public void exportMappingList(HttpServletRequest request, HttpServletResponse response, @RequestBody QueryTabMappingParamDto queryParam) throws IOException { - sysNodeService.exportMappingList(sysImptabmappingDto,request,response); + sysNodeService.exportMappingList(queryParam,request,response); } diff --git a/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentDto.java b/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentDto.java index 98ddc169..34152122 100644 --- a/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentDto.java +++ b/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentDto.java @@ -6,11 +6,20 @@ import lombok.Data; import java.util.List; +/** + * @author chenhaojie + * @description: 链路绑定设备列表 + */ @Data public class BindEquipmentDto { - private List equipmentId; - + /** + * 链路ID + */ @JsonSerialize(using = ToStringSerializer.class) private Long linkId; + /** + * 设备信息列表(包含设备id和设备地址) + */ + private List equipmentList; } diff --git a/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentInfoDto.java b/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentInfoDto.java index 1f5820b3..6760ea6d 100644 --- a/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentInfoDto.java +++ b/das/src/main/java/com/das/modules/node/domain/dto/BindEquipmentInfoDto.java @@ -4,15 +4,32 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; -import java.util.List; - +/** + * @author houwei + * @date 2024-10-25 + * @description: 链路映射表中单条记录,绑定设备信息(设备id,测点序号) + */ @Data public class BindEquipmentInfoDto { - + /** + * 设备ID + */ @JsonSerialize(using = ToStringSerializer.class) - private Long equipmentId; + private Long id; - private Integer porder; + /** + * 设备名称 + */ + private String name; + /** + * 设备物模型ID + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long iotModelId; + + /** + * 设备地址 + */ private String iotAddr; } diff --git a/das/src/main/java/com/das/modules/node/domain/dto/ImptabmappingDto.java b/das/src/main/java/com/das/modules/node/domain/dto/QueryTabMappingParamDto.java similarity index 53% rename from das/src/main/java/com/das/modules/node/domain/dto/ImptabmappingDto.java rename to das/src/main/java/com/das/modules/node/domain/dto/QueryTabMappingParamDto.java index 625c6b1a..aed98060 100644 --- a/das/src/main/java/com/das/modules/node/domain/dto/ImptabmappingDto.java +++ b/das/src/main/java/com/das/modules/node/domain/dto/QueryTabMappingParamDto.java @@ -6,21 +6,21 @@ import lombok.Data; import java.io.Serializable; +/* + * @author houwei + * @date 2024-10-25 + * @description: 查询链路映射表的 参数对象 + */ @Data -public class ImptabmappingDto implements Serializable { - +public class QueryTabMappingParamDto implements Serializable { + /* + * 链路id + */ @JsonSerialize(using = ToStringSerializer.class) private Long linkId; - - @JsonSerialize(using = ToStringSerializer.class) - private Long equipmentId; - - @JsonSerialize(using = ToStringSerializer.class) - private Long id; - + /* + * 量测数据类型 + * 138:模拟量,139:累积量,140:离散量 + */ private Integer type; - - private String params; - - private String name; } diff --git a/das/src/main/java/com/das/modules/node/domain/dto/SysImptabmappingDto.java b/das/src/main/java/com/das/modules/node/domain/dto/SysImptabmappingDto.java deleted file mode 100644 index 6e6ef65e..00000000 --- a/das/src/main/java/com/das/modules/node/domain/dto/SysImptabmappingDto.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.das.modules.node.domain.dto; - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import lombok.Data; - -import java.io.Serializable; - -@Data -public class SysImptabmappingDto implements Serializable { - - @JsonSerialize(using = ToStringSerializer.class) - private Long linkId; - - private Integer type; -} diff --git a/das/src/main/java/com/das/modules/node/domain/vo/ConfigUpdateVo.java b/das/src/main/java/com/das/modules/node/domain/vo/ConfigUpdateVo.java index 96c4713c..d387260e 100644 --- a/das/src/main/java/com/das/modules/node/domain/vo/ConfigUpdateVo.java +++ b/das/src/main/java/com/das/modules/node/domain/vo/ConfigUpdateVo.java @@ -15,11 +15,12 @@ public class ConfigUpdateVo { private Long createTime; - private String nodeId; + @JsonSerialize(using = ToStringSerializer.class) + private Long nodeId; private List links; - private List equipments; + private List equipments; public ConfigUpdateVo() { diff --git a/das/src/main/java/com/das/modules/node/domain/vo/EquipmentAndMappingVo.java b/das/src/main/java/com/das/modules/node/domain/vo/EquipmentAndMappingVo.java new file mode 100644 index 00000000..2f41f32e --- /dev/null +++ b/das/src/main/java/com/das/modules/node/domain/vo/EquipmentAndMappingVo.java @@ -0,0 +1,28 @@ +package com.das.modules.node.domain.vo; + +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 EquipmentAndMappingVo { + /** + * 设备id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 设备名称 + */ + private String name; + + /** + * 设备Iot 地址 对应设备表中的 iot_addr 字段 + */ + private String addr; + + private List attrs; + private List services; +} diff --git a/das/src/main/java/com/das/modules/node/domain/vo/EquipmentVo.java b/das/src/main/java/com/das/modules/node/domain/vo/EquipmentVo.java index c842325f..101c6457 100644 --- a/das/src/main/java/com/das/modules/node/domain/vo/EquipmentVo.java +++ b/das/src/main/java/com/das/modules/node/domain/vo/EquipmentVo.java @@ -1,21 +1,35 @@ package com.das.modules.node.domain.vo; -import com.fasterxml.jackson.databind.JsonNode; 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 EquipmentVo { + /** + * 设备id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long id; - @JsonSerialize(using = ToStringSerializer.class) - private Long id; + /** + * 设备名称 + */ + private String name; - private String addr; + /** + * 对应的物模型ID + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long iotModelId; - private List attrs; - - private List services; + /** + * 设备Iot 地址 对应设备表中的 iot_addr 字段 + */ + private String iotAddr; } diff --git a/das/src/main/java/com/das/modules/node/domain/vo/ImptabmappingVo.java b/das/src/main/java/com/das/modules/node/domain/vo/ImptabmappingVo.java deleted file mode 100644 index 13470f29..00000000 --- a/das/src/main/java/com/das/modules/node/domain/vo/ImptabmappingVo.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.das.modules.node.domain.vo; - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import lombok.Data; -import org.springframework.boot.configurationprocessor.json.JSONObject; - - -/** - * 映射表前端回显 - * - * @author guchengwei - */ -@Data -public class ImptabmappingVo { - - private String name; - - @JsonSerialize(using = ToStringSerializer.class) - private Long equipmentId; - - @JsonSerialize(using = ToStringSerializer.class) - private Long id; - - private String equipmentName; - - private String equipmentCode; - - private Integer porder; - - private String params; - - private String code; -} diff --git a/das/src/main/java/com/das/modules/node/domain/vo/LinkVo.java b/das/src/main/java/com/das/modules/node/domain/vo/LinkVo.java index 8ed59a27..84a5180f 100644 --- a/das/src/main/java/com/das/modules/node/domain/vo/LinkVo.java +++ b/das/src/main/java/com/das/modules/node/domain/vo/LinkVo.java @@ -6,15 +6,25 @@ import lombok.Data; @Data public class LinkVo { - - @JsonSerialize(using = ToStringSerializer.class) + /** + * 链路ID + */ + @JsonSerialize(using = ToStringSerializer.class) private Long linkId; - + /** + * 链路名称 + */ private String linkName; - //协议号 + /** + * 协议号 + */ private Integer protocol; - //协议参数 + /** + * 协议参数 + */ private Object params; - + /** + * 关联的设备列表,设备id字符串列表 + */ private String[] devices; } diff --git a/das/src/main/java/com/das/modules/node/domain/vo/SysImptabmappingVo.java b/das/src/main/java/com/das/modules/node/domain/vo/SysImptabmappingVo.java deleted file mode 100644 index 22317e54..00000000 --- a/das/src/main/java/com/das/modules/node/domain/vo/SysImptabmappingVo.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.das.modules.node.domain.vo; - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import lombok.Data; - - -/** - * 映射表前端回显 - * - * @author guchengwei - */ -@Data -public class SysImptabmappingVo { - - @JsonSerialize(using = ToStringSerializer.class) - private Long id; - - @JsonSerialize(using = ToStringSerializer.class) - private Long linkId; - - private String linkName; - - @JsonSerialize(using = ToStringSerializer.class) - private Long equipmentId; - - private String equipmentName; - - private String equipmentAttribute; - - private String equipmentService; - - private Integer porder; - - private String params; - - private String IotAddr; - - private Integer revision; -} diff --git a/das/src/main/java/com/das/modules/node/domain/vo/SysTabMappingVo.java b/das/src/main/java/com/das/modules/node/domain/vo/SysTabMappingVo.java new file mode 100644 index 00000000..f74498a5 --- /dev/null +++ b/das/src/main/java/com/das/modules/node/domain/vo/SysTabMappingVo.java @@ -0,0 +1,62 @@ +package com.das.modules.node.domain.vo; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; + + +/** + * + * @author guchengwei + * @description: 映射表前端回显 + */ +@Data +public class SysTabMappingVo { + /** + * 映射表记录id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + /** + * 链路id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long linkId; + /** + * 链路名称 + */ + private String linkName; + /** + * 设备id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long equipmentId; + /** + * 设备名称 + */ + private String equipmentName; + /** + * 测点类型 + */ + private Integer measPointType; + /** + * 测点编码 + */ + private String measPointCode; + /** + * 测点名称 + */ + private String measPointName; + /** + * 是否高频 + */ + private Integer highSpeed; + /** + * 测点序号 + */ + private Integer porder; + /** + * 参数 + */ + private String params; +} diff --git a/das/src/main/java/com/das/modules/node/entity/SysImptabmapping.java b/das/src/main/java/com/das/modules/node/entity/SysTabMapping.java similarity index 73% rename from das/src/main/java/com/das/modules/node/entity/SysImptabmapping.java rename to das/src/main/java/com/das/modules/node/entity/SysTabMapping.java index 7e7bca82..69fb1a5f 100644 --- a/das/src/main/java/com/das/modules/node/entity/SysImptabmapping.java +++ b/das/src/main/java/com/das/modules/node/entity/SysTabMapping.java @@ -16,18 +16,15 @@ import java.io.Serial; /** - *

- * 映射表信息 - *

- * - * @author chenhaojie + * @author houwei + * @description: 映射表实例 */ @EqualsAndHashCode(callSuper = true) @TableName("sys_imptabmapping") @Data @NoArgsConstructor @AllArgsConstructor -public class SysImptabmapping extends BaseEntity { +public class SysTabMapping extends BaseEntity { @Serial private static final long serialVersionUID = 1L; @@ -53,16 +50,28 @@ public class SysImptabmapping extends BaseEntity { private Long equipmentId; /** - * 对应设备属性 + * 测点类型 */ - @TableField("equipment_attribute") - private String equipmentAttribute; + @TableField("meas_point_type") + private Integer measPointType; /** - * 对应设备服务 + * 测点编码 */ - @TableField("equipment_service") - private String equipmentService; + @TableField("meas_point_code") + private String measPointCode; + + /** + * 测点名称 + */ + @TableField("meas_point_name") + private String measPointName; + + /** + * 是否高频 + */ + @TableField("highspeed") + private Integer highSpeed; @TableField("porder") private Integer porder; diff --git a/das/src/main/java/com/das/modules/node/mapper/SysImpTabMappingMapper.java b/das/src/main/java/com/das/modules/node/mapper/SysImpTabMappingMapper.java new file mode 100644 index 00000000..6076381a --- /dev/null +++ b/das/src/main/java/com/das/modules/node/mapper/SysImpTabMappingMapper.java @@ -0,0 +1,54 @@ +package com.das.modules.node.mapper; + + +import com.das.modules.auth.mapper.BaseMapperPlus; +import com.das.modules.node.domain.vo.EquipmentVo; +import com.das.modules.node.domain.vo.SysTabMappingVo; +import com.das.modules.node.entity.SysTabMapping; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @description: 映射表相关操作Mapper + */ +@Mapper +public interface SysImpTabMappingMapper extends BaseMapperPlus { + /** + * 根据linkeId 获取该链路下所有的映射表配置信息 + * @param linkId 链路id + * @return 映射表记录列表 + */ + List getMappingInfoListByLinkId(@Param("linkId") Long linkId); + + /** + * 获取该链路下 对应类型的映射表配置信息 + * @param linkId 链路id + * @param type 测点类型 + * @return 映射表记录列表 + */ + List getMappingInfoListByLinkIdAndType(@Param("linkId") Long linkId, @Param("type") Integer type); + + /** + * 根据linkId 和设备id 获取该链路下 对应类型的映射表配置信息 + * @param linkId 链路id + * @param deviceId 设备id + * @return 映射表记录列表 + */ + List getMappingInfoListByLinkIdAndDeviceId(@Param("linkId") Long linkId, @Param("deviceId") Long deviceId); + + /** + * 根据linkId 获取该链路下绑定的设备信息 + * @param linkId 链路id + * @return 设备列表 + */ + List getBindDeviceByLink(@Param("linkId") Long linkId); + + /** + * 根据链路id删除对应的映射表记录 + * @param linkId 链路id + */ + void deleteMappingByLinkId(@Param("linkId") Long linkId); + +} diff --git a/das/src/main/java/com/das/modules/node/mapper/SysImptabmappingMapper.java b/das/src/main/java/com/das/modules/node/mapper/SysImptabmappingMapper.java deleted file mode 100644 index 7bba68ef..00000000 --- a/das/src/main/java/com/das/modules/node/mapper/SysImptabmappingMapper.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.das.modules.node.mapper; - - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.das.modules.auth.mapper.BaseMapperPlus; -import com.das.modules.node.domain.dto.SysCommunicationLinkDto; -import com.das.modules.node.domain.vo.ImptabmappingVo; -import com.das.modules.node.domain.vo.IotModelVo; -import com.das.modules.node.domain.vo.SysCommunicationLinkVo; -import com.das.modules.node.domain.vo.SysImptabmappingVo; -import com.das.modules.node.entity.SysCommunicationLink; -import com.das.modules.node.entity.SysImptabmapping; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -@Mapper -public interface SysImptabmappingMapper extends BaseMapperPlus { - List getMappingList(Long linkId, Integer type); - - List getMappingControlList(Long linkId, Integer type); - - List getBindDevice(Long linkId); - - void deleteBindDevice(Long linkId); - - List getEquipmentId(Long linkId); - - List getIotModelFieldByDeviceId(@Param("deviceId") Long deviceId); - - List getIotModelServiceByDeviceId(@Param("deviceId") Long deviceId); - - List getIotModelServiceByEquipmentId(Long equipmentId); - - String getIotAddrByEquipmentId(Long equipmentId); - - String getAttributeCode(Long equipmentId, Integer type, String name); - - String getServiceCode(Long equipmentId, Integer type, String name); - - List getMappingInfoList(Long linkId); -} diff --git a/das/src/main/java/com/das/modules/node/service/SysNodeService.java b/das/src/main/java/com/das/modules/node/service/SysNodeService.java index 0af0ef54..cb70dc5b 100644 --- a/das/src/main/java/com/das/modules/node/service/SysNodeService.java +++ b/das/src/main/java/com/das/modules/node/service/SysNodeService.java @@ -1,18 +1,15 @@ package com.das.modules.node.service; import com.das.common.utils.PageDataInfo; -import com.das.modules.equipment.domain.dto.SysEquipmentDto; import com.das.modules.node.domain.dto.*; -import com.das.modules.node.domain.vo.ImptabmappingVo; +import com.das.modules.node.domain.vo.EquipmentVo; import com.das.modules.node.domain.vo.SysCommunicationLinkVo; -import com.das.modules.node.domain.vo.SysImptabmappingVo; import com.das.modules.node.domain.vo.SysNodeVo; +import com.das.modules.node.domain.vo.SysTabMappingVo; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; -import java.text.ParseException; import java.util.List; public interface SysNodeService { @@ -32,14 +29,29 @@ public interface SysNodeService { void deleteSysCommunicationLink(Long id); - List getMappingList(SysImptabmappingDto sysImptabmappingDto); + /** + * 查询设备映射列表 + * @param queryParam 查询条件 linkId 链路ID和 type 量测类型 + * @return + */ + List getMappingList(QueryTabMappingParamDto queryParam); - List getBindDeviceTree(Long linkId); - void bindDeviceMeas(List equipmentId, Long linkId); + /** + * 获取链路已经绑定的设备信息 + * @param linkId 链路id + * @return 绑定的设备信息 + */ + List getBindDeviceTree(Long linkId); - void saveMappingList(List impList); + void bindDevices(List equipmentList, Long linkId); - void exportMappingList(SysImptabmappingDto sysImptabmappingDto,HttpServletRequest request, HttpServletResponse response); + /** + * 保存映射表配置信息 + * @param impList 配置的表格数据 + */ + void saveMappingList(List impList); + + void exportMappingList(QueryTabMappingParamDto sysImptabmappingDto,HttpServletRequest request, HttpServletResponse response); boolean importMappingList(String linkId, MultipartFile file); diff --git a/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java b/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java index 4d5a30a7..7994163d 100644 --- a/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java +++ b/das/src/main/java/com/das/modules/node/service/impl/DataServiceImpl.java @@ -1,7 +1,7 @@ package com.das.modules.node.service.impl; import cn.hutool.core.util.IdUtil; -import com.das.common.constant.BaseIotModelType; +import com.das.common.constant.MeasType; import com.das.common.utils.AdminRedisTemplate; import com.das.modules.equipment.domain.vo.IotModelFieldVo; import com.das.modules.equipment.entity.SysIotModelField; @@ -13,7 +13,7 @@ import com.das.modules.node.domain.bo.TerminalMessage; import com.das.modules.node.domain.vo.*; import com.das.modules.node.handler.NodeMessageHandler; 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.service.DataService; import com.das.modules.node.service.TDEngineService; import com.fasterxml.jackson.databind.JsonNode; @@ -29,7 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; -import java.text.MessageFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; @@ -39,6 +38,8 @@ import java.util.stream.Collectors; @Slf4j @Service public class DataServiceImpl implements DataService { + private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); + private Disruptor disruptor = null; private RingBuffer ringBuffer = null; @@ -50,7 +51,7 @@ public class DataServiceImpl implements DataService { SysCommunicationLinkMapper sysCommunicationLinkMapper; @Resource - SysImptabmappingMapper sysImptabmappingMapper; + SysImpTabMappingMapper sysImptabmappingMapper; @Resource private NodeMessageHandler nodeMessageHandler; @@ -113,14 +114,12 @@ public class DataServiceImpl implements DataService { public JsonNode sendTerminalConfig(Long nodeId) { ConfigUpdateVo configUpdateVo = new ConfigUpdateVo(); List links = new ArrayList<>(); - List equipments = new ArrayList<>(); - List equipmentList = new ArrayList<>(); + List equipments = new ArrayList<>(); try { // 获取所有的链路信息 List sysCommunicationLinkVoList = sysCommunicationLinkMapper.querySysCommunicationLink(nodeId); for (SysCommunicationLinkVo sysCommunicationLinkVo : sysCommunicationLinkVoList) { - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode jsonNode = objectMapper.readTree(sysCommunicationLinkVo.getParams()); + JsonNode jsonNode = JSON_MAPPER.readTree(sysCommunicationLinkVo.getParams()); LinkVo linkVo = new LinkVo(); linkVo.setLinkId(sysCommunicationLinkVo.getId()); linkVo.setLinkName(sysCommunicationLinkVo.getLinkName()); @@ -128,65 +127,64 @@ public class DataServiceImpl implements DataService { linkVo.setProtocol(sysCommunicationLinkVo.getProtocol()); List stringList = new ArrayList<>(); // 获取关联的设备Id - equipmentList = sysImptabmappingMapper.getEquipmentId(sysCommunicationLinkVo.getId()); - for (Long equipmentId : equipmentList) { - stringList.add(String.valueOf(equipmentId)); + List 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); links.add(linkVo); - for (Long equipmentId : equipmentList) { + + for (EquipmentVo dev : equipmentList) { + HashMap map = new HashMap<>(); - ObjectMapper equipObjectMapper = new ObjectMapper(); - ObjectNode equipJsonNode = equipObjectMapper.convertValue(map, ObjectNode.class); - List newIotModelFieldList = new ArrayList<>(); - List newIotModelServiceList = new ArrayList<>(); - // 根据设备Id获取对应的物模型属性和动作 - List iotModelFieldList = sysImptabmappingMapper.getIotModelFieldByDeviceId(equipmentId); - List iotModelServiceList = sysImptabmappingMapper.getIotModelServiceByDeviceId(equipmentId); - if (!CollectionUtils.isEmpty(iotModelFieldList)) { - for (IotModelVo info : iotModelFieldList) { + ObjectNode equipJsonNode = JSON_MAPPER.convertValue(map, ObjectNode.class); + + List attrs = new ArrayList<>(); + List services= new ArrayList<>(); + + List tabMappingVoList = sysImptabmappingMapper.getMappingInfoListByLinkIdAndDeviceId(sysCommunicationLinkVo.getId(), dev.getId()); + + if (!CollectionUtils.isEmpty(tabMappingVoList)) { + for (SysTabMappingVo info : tabMappingVoList) { NewIotModelVo newIotModelVo = new NewIotModelVo(); - newIotModelVo.setName(info.getEquipmentAttribute()); - newIotModelVo.setHighSpeed(info.getHighSpeed()); + newIotModelVo.setName(info.getMeasPointCode()); if (info.getParams() == null) { newIotModelVo.setParams(equipJsonNode); } else { - newIotModelVo.setParams(equipObjectMapper.readTree(info.getParams().toString())); + newIotModelVo.setParams(JSON_MAPPER.readTree(info.getParams().toString())); } - if (info.getAttributeType() == BaseIotModelType.TYPE_PSR_ANALOG) { + + Integer pointType = info.getMeasPointType(); + + if (pointType == MeasType.TYPE_PSR_ANALOG) { + newIotModelVo.setHighSpeed(info.getHighSpeed()); newIotModelVo.setType("yc"); - } else if (info.getAttributeType() == BaseIotModelType.TYPE_PSR_ACCUMULATOR) { + attrs.add(newIotModelVo); + } else if (pointType == MeasType.TYPE_PSR_ACCUMULATOR) { + newIotModelVo.setHighSpeed(info.getHighSpeed()); newIotModelVo.setType("ym"); - } else if (info.getAttributeType() == BaseIotModelType.TYPE_PSR_DISCRETE) { + attrs.add(newIotModelVo); + } else if (pointType == MeasType.TYPE_PSR_DISCRETE) { + newIotModelVo.setHighSpeed(info.getHighSpeed()); newIotModelVo.setType("yx"); - } - newIotModelFieldList.add(newIotModelVo); - } - } - if (!CollectionUtils.isEmpty(iotModelServiceList)){ - for (IotModelVo info : iotModelServiceList) { - NewIotModelVo newIotModelVo = new NewIotModelVo(); - newIotModelVo.setName(info.getEquipmentService()); - if (info.getParams() == null) { - newIotModelVo.setParams(equipJsonNode); - } else { - newIotModelVo.setParams(equipObjectMapper.readTree(info.getParams().toString())); - } - if (info.getServiceType() == BaseIotModelType.TYPE_PSR_SETPOINT) { + attrs.add(newIotModelVo); + }else if (pointType == MeasType.TYPE_PSR_SETPOINT) { newIotModelVo.setType("yt"); - } else if (info.getServiceType() == BaseIotModelType.TYPE_PSR_CONTROL) { + services.add(newIotModelVo); + } else if (pointType == MeasType.TYPE_PSR_CONTROL) { newIotModelVo.setType("yk"); - } - newIotModelServiceList.add(newIotModelVo); + services.add(newIotModelVo); + } } } - EquipmentVo equipment = new EquipmentVo(); - equipment.setAddr(iotModelFieldList.get(0).getIotAddr()); - equipment.setId(equipmentId); - equipment.setAttrs(newIotModelFieldList); - equipment.setServices(newIotModelServiceList); + + EquipmentAndMappingVo equipment = new EquipmentAndMappingVo(); + equipment.setAddr(dev.getIotAddr()); + equipment.setId(dev.getId()); + equipment.setAttrs(attrs); + equipment.setServices(services); equipments.add(equipment); } } @@ -194,12 +192,11 @@ public class DataServiceImpl implements DataService { log.error("获取设备配置信息失败", e); } configUpdateVo.setCreateTime(System.currentTimeMillis()); - configUpdateVo.setNodeId(String.valueOf(nodeId)); + configUpdateVo.setNodeId(nodeId); configUpdateVo.setVersion(1); configUpdateVo.setLinks(links); configUpdateVo.setEquipments(equipments); - ObjectMapper mapper = new ObjectMapper(); - JsonNode jsonNode = mapper.valueToTree(configUpdateVo); + JsonNode jsonNode = JSON_MAPPER.valueToTree(configUpdateVo); long time = System.currentTimeMillis(); @@ -209,7 +206,7 @@ public class DataServiceImpl implements DataService { .time(time) .data(jsonNode) .build(); - nodeMessageHandler.sendActionMessage(Long.valueOf(nodeId), configUpdate); + nodeMessageHandler.sendActionMessage(nodeId, configUpdate); return jsonNode; } 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 e09e5669..ce3af2a8 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 @@ -11,22 +11,21 @@ import com.das.common.utils.SequenceUtils; import com.das.modules.auth.domain.vo.SysUserVo; import com.das.modules.auth.entity.SysOrg; import com.das.modules.auth.mapper.SysOrgMapper; -import com.das.modules.equipment.domain.vo.BaseImptabmappingVo; +import com.das.modules.equipment.domain.vo.SysIotModelFieldVo; +import com.das.modules.equipment.domain.vo.SysIotModelServiceVo; import com.das.modules.equipment.mapper.SysEquipmentMapper; -import com.das.modules.equipment.mapper.SysIotModelMapper; +import com.das.modules.equipment.mapper.SysIotModelFieldMapper; +import com.das.modules.equipment.mapper.SysIotModelServiceMapper; import com.das.modules.node.constant.NodeConstant; import com.das.modules.node.disruptor.TerminalMessageEventHandler; import com.das.modules.node.domain.bo.TerminalMessage; import com.das.modules.node.domain.dto.*; -import com.das.modules.node.domain.vo.ImptabmappingVo; -import com.das.modules.node.domain.vo.SysCommunicationLinkVo; -import com.das.modules.node.domain.vo.SysImptabmappingVo; -import com.das.modules.node.domain.vo.SysNodeVo; +import com.das.modules.node.domain.vo.*; import com.das.modules.node.entity.SysCommunicationLink; -import com.das.modules.node.entity.SysImptabmapping; import com.das.modules.node.entity.SysNode; +import com.das.modules.node.entity.SysTabMapping; 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.service.SysNodeService; import com.fasterxml.jackson.databind.ObjectMapper; @@ -35,28 +34,20 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import java.io.*; -import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.stream.Collectors; +import java.util.*; @Transactional(rollbackFor = Exception.class) @Service @Slf4j public class SysNodeServiceImpl implements SysNodeService { + private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); @Autowired private SysNodeMapper sysNodeMapper; @@ -69,11 +60,17 @@ public class SysNodeServiceImpl implements SysNodeService { private SysOrgMapper sysOrgMapper; @Autowired - private SysImptabmappingMapper sysImptabmappingMapper; + private SysImpTabMappingMapper sysImptabmappingMapper; @Autowired private SysEquipmentMapper sysEquipmentMapper; + @Autowired + SysIotModelFieldMapper iotModelFieldMapper; + + @Autowired + SysIotModelServiceMapper iotModelServiceMapper; + @Autowired TerminalMessageEventHandler terminalMessageEventHandler; @@ -186,96 +183,156 @@ public class SysNodeServiceImpl implements SysNodeService { sysCommunicationLinkMapper.deleteById(id); } + /** + * 查询物模型列表 + * @param queryParam 查询条件 linkId 链路ID和 type 量测类型 + * @return + */ @Override - public List getMappingList(SysImptabmappingDto sysImptabmappingDto) { - // 138模拟量 139累积量 140离散量 146遥调 147遥控 - Integer type = sysImptabmappingDto.getType(); - List list = new ArrayList<>(); - // 根据类型获取物模型属性或者动作编码 - if (type == 138 || type == 139 || type == 140) { - list = sysImptabmappingMapper.getMappingList(sysImptabmappingDto.getLinkId(), type); - } else if (type == 146 || type == 147) { - list = sysImptabmappingMapper.getMappingControlList(sysImptabmappingDto.getLinkId(), type); - } - - return list; + public List getMappingList(QueryTabMappingParamDto queryParam) { + return sysImptabmappingMapper.getMappingInfoListByLinkIdAndType(queryParam.getLinkId(),queryParam.getType()); } + /** + * 获取链路已经绑定的设备信息 + * @param linkId 链路id + * @return 绑定的设备信息 + */ @Override - public List getBindDeviceTree(Long linkId) { - List bindDeviceList = sysImptabmappingMapper.getBindDevice(linkId); - return bindDeviceList; + public List getBindDeviceTree(Long linkId) { + return sysImptabmappingMapper.getBindDeviceByLink(linkId); } + /** + * 链路绑定多个设备 + * @param equipmentList 设备列表 + * @param linkId 链路id + */ @Override - public void bindDeviceMeas(List equipmentId, Long linkId) { - List addList = new ArrayList<>(); - List addList2 = new ArrayList<>(); - if (CollectionUtils.isEmpty(equipmentId)) { - sysImptabmappingMapper.deleteBindDevice(linkId); + public void bindDevices(List equipmentList, Long linkId) { + SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); + + // 如果绑定设备列表为空,则清空映射表 + if (CollectionUtils.isEmpty(equipmentList)) { + sysImptabmappingMapper.deleteMappingByLinkId(linkId); } // 先更新设备地址 - for (BindEquipmentInfoDto info : equipmentId) { + for (BindEquipmentInfoDto info : equipmentList) { // 更新设备表里面的设备地址 - sysEquipmentMapper.updateIotAddr(info.getEquipmentId(), info.getIotAddr()); + sysEquipmentMapper.updateIotAddr(info.getId(), info.getIotAddr()); + } + + // 先根据链路Id获取已经配置好的映射表信息列表 + List mappingVoList=sysImptabmappingMapper.getMappingInfoListByLinkId(linkId); + //将已经配置好的映射表,按设备id,测点类型,测点code 做一个map; + Map mappingVoMap = new HashMap<>(mappingVoList.size()); + for (SysTabMappingVo mappingVo : mappingVoList) { + String key = mappingVo.getEquipmentId() + "_" + mappingVo.getMeasPointType() + "_" + mappingVo.getMeasPointCode(); + mappingVoMap.put(key,mappingVo); } - // 获取已经绑定的设备 - List bindDeviceList = sysImptabmappingMapper.getBindDevice(linkId); - //过滤 -// equipmentId.removeIf(item -> addList2.contains(item.getEquipmentId())); - SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); - addSysImptabmapping(equipmentId, linkId, sysUserVo, addList); + List addList = new ArrayList<>(); + //过滤已经存在的记录 + Set PassedMappingIds = new HashSet<>(); + + // 根据绑定的设备列表,获取对应的物模型相关信息 + for (BindEquipmentInfoDto info : equipmentList) { + Long modelId = info.getIotModelId(); + if(modelId==null||modelId==0){ + continue; + } + + List iotModelVoList = iotModelFieldMapper.selectModelFieldListByModelId(modelId); + for (SysIotModelFieldVo iotModelVo : iotModelVoList) { + String key = info.getId() + "_" + iotModelVo.getAttributeType() + "_" + iotModelVo.getAttributeCode(); + if(mappingVoMap.containsKey(key)){ + SysTabMappingVo item = mappingVoMap.get(key); + PassedMappingIds.add(item.getId()); + }else{ + SysTabMapping mapping = new SysTabMapping(); + mapping.setId(SequenceUtils.generateId()); + mapping.setLinkId(linkId); + mapping.setEquipmentId(info.getId()); + mapping.setMeasPointType(iotModelVo.getAttributeType()); + mapping.setMeasPointCode(iotModelVo.getAttributeCode()); + mapping.setMeasPointName(iotModelVo.getAttributeName()); + mapping.setHighSpeed(iotModelVo.getHighSpeed()); + mapping.setPorder(iotModelVo.getPorder()); + mapping.setCreatedBy(sysUserVo.getAccount()); + mapping.setRevision(1); + addList.add(mapping); + } + } + + List iotServiceVoList = iotModelServiceMapper.selectModelServiceListByModelId(modelId); + for (SysIotModelServiceVo iotServiceVo : iotServiceVoList) { + String key = info.getId() + "_" + iotServiceVo.getServiceType() + "_" + iotServiceVo.getServiceCode(); + if(mappingVoMap.containsKey(key)){ + SysTabMappingVo item = mappingVoMap.get(key); + PassedMappingIds.add(item.getId()); + }else{ + SysTabMapping mapping = new SysTabMapping(); + mapping.setId(SequenceUtils.generateId()); + mapping.setLinkId(linkId); + mapping.setEquipmentId(info.getId()); + mapping.setMeasPointType(iotServiceVo.getServiceType()); + mapping.setMeasPointCode(iotServiceVo.getServiceCode()); + mapping.setMeasPointName(iotServiceVo.getServiceName()); + mapping.setPorder(iotServiceVo.getPorder()); + mapping.setCreatedBy(sysUserVo.getAccount()); + mapping.setRevision(1); + addList.add(mapping); + } + } + } + //批量更新 if (!CollectionUtils.isEmpty(addList)) { - sysImptabmappingMapper.deleteBindDevice(linkId); sysImptabmappingMapper.insertOrUpdateBatch(addList); } + //删除为匹配的历史配置 + for(SysTabMappingVo item : mappingVoMap.values()){ + if(!PassedMappingIds.contains(item.getId())){ + sysImptabmappingMapper.deleteById(item.getId()); + } + } } + /** + * 保存映射表配置列表 + * @param impList 配置的表格数据 + */ @Override - public void saveMappingList(List impList) { + public void saveMappingList(List impList) { try { if (!CollectionUtils.isEmpty(impList)) { - List list = new ArrayList<>(); - SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); - for (ImptabmappingDto imp : impList) { - SysImptabmapping sysImptabmapping = new SysImptabmapping(); - // 更新记录 - sysImptabmapping.setId(imp.getId()); + List list = new ArrayList<>(); - if (imp.getType() == 138 || imp.getType() == 139 || imp.getType() == 140) { - // 获取属性编码 - String code = sysImptabmappingMapper.getAttributeCode(imp.getEquipmentId(), imp.getType(), imp.getName()); - sysImptabmapping.setEquipmentAttribute(code); - } else if (imp.getType() == 146 || imp.getType() == 147) { - // 获取动作编码 - String code = sysImptabmappingMapper.getServiceCode(imp.getEquipmentId(), imp.getType(), imp.getName()); - sysImptabmapping.setEquipmentService(code); - } - sysImptabmapping.setUpdatedTime(new Date()); - sysImptabmapping.setUpdatedBy(sysUserVo.getAccount()); - sysImptabmapping.setParams(imp.getParams()); - list.add(sysImptabmapping); + SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); + for (SysTabMappingVo imp : impList) { + SysTabMapping rec = sysImptabmappingMapper.selectById(imp.getId()); + rec.setUpdatedTime(new Date()); + rec.setUpdatedBy(sysUserVo.getAccount()); + rec.setParams(imp.getParams()); + rec.setRevision(rec.getRevision() + 1); + list.add(rec); } if (!CollectionUtils.isEmpty(list)) { sysImptabmappingMapper.insertOrUpdateBatch(list); } } } catch (Exception e) { - log.error("删除所有记录失败", e); + log.error("保存映射表失败", e); } - } @Override - public void exportMappingList(SysImptabmappingDto sysImptabmappingDto, HttpServletRequest request, HttpServletResponse response) { + public void exportMappingList(QueryTabMappingParamDto sysImptabmappingDto, HttpServletRequest request, HttpServletResponse response) { // 根据链路Id获取映射表信息并导出成json文件 - List list = sysImptabmappingMapper.getMappingInfoList(sysImptabmappingDto.getLinkId()); - ObjectMapper mapper = new ObjectMapper(); + List list = sysImptabmappingMapper.getMappingInfoListByLinkId(sysImptabmappingDto.getLinkId()); try { - String jsonContent = mapper.writeValueAsString(list); + String jsonContent = JSON_MAPPER.writeValueAsString(list); OutputStream os = null; if (response != null) { response.reset(); @@ -297,48 +354,81 @@ public class SysNodeServiceImpl implements SysNodeService { @Override public boolean importMappingList(String linkId, MultipartFile file) { boolean flag = false; + + // 先根据链路Id获取已经配置好的映射表信息列表 + List mappingVoList=sysImptabmappingMapper.getMappingInfoListByLinkId(Long.valueOf(linkId)); + //将已经配置好的映射表,按设备id,测点类型,测点code 做一个map; + Map mappingVoMap = new HashMap<>(mappingVoList.size()); + for (SysTabMappingVo mappingVo : mappingVoList) { + String key = mappingVo.getEquipmentId() + "_" + mappingVo.getMeasPointType() + "_" + mappingVo.getMeasPointCode(); + mappingVoMap.put(key,mappingVo); + } + + //过滤已经存在的记录 + Set PassedMappingIds = new HashSet<>(); + try { SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY); - List addList = new ArrayList<>(); + List addList = new ArrayList<>(); String content = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8)) .lines() .reduce("", (accumulator, _item) -> accumulator + _item); - ObjectMapper objectMapper = new ObjectMapper(); - List list = objectMapper.readValue(content, objectMapper.getTypeFactory().constructCollectionType(List.class, SysImptabmappingVo.class)); - for (SysImptabmappingVo info : list) { - SysImptabmapping newInfo = new SysImptabmapping(); - newInfo.setId(SequenceUtils.generateId()); + List list = JSON_MAPPER.readValue(content, JSON_MAPPER.getTypeFactory().constructCollectionType(List.class, SysTabMappingVo.class)); + for (SysTabMappingVo info : list) { + SysTabMapping newInfo = new SysTabMapping(); + + String key = info.getEquipmentId() + "_" + info.getMeasPointType() + "_" + info.getMeasPointCode(); + if(mappingVoMap.containsKey(key)){ + SysTabMappingVo item = mappingVoMap.get(key); + newInfo.setId(item.getId()); + PassedMappingIds.add(item.getId()); + }else{ + newInfo.setId(SequenceUtils.generateId()); + } + newInfo.setLinkId(Long.valueOf(linkId)); - newInfo.setEquipmentAttribute(info.getEquipmentAttribute()); newInfo.setEquipmentId(info.getEquipmentId()); - newInfo.setEquipmentService(info.getEquipmentService()); + + newInfo.setMeasPointType(info.getMeasPointType()); + newInfo.setMeasPointCode(info.getMeasPointCode()); + newInfo.setMeasPointName(info.getMeasPointName()); + newInfo.setHighSpeed(info.getHighSpeed()); + newInfo.setParams(info.getParams()); newInfo.setPorder(info.getPorder()); - newInfo.setRevision(1); newInfo.setCreatedTime(new Date()); newInfo.setUpdatedTime(new Date()); newInfo.setCreatedBy(sysUserVo.getAccount()); newInfo.setUpdatedBy(sysUserVo.getAccount()); + newInfo.setRevision(1); addList.add(newInfo); } if (!CollectionUtils.isEmpty(addList)) { sysImptabmappingMapper.insertBatch(addList); flag = true; } + + //删除为匹配的历史配置 + for(SysTabMappingVo item : mappingVoMap.values()){ + if(!PassedMappingIds.contains(item.getId())){ + sysImptabmappingMapper.deleteById(item.getId()); + } + } + flag = true; } catch (IOException e) { log.error("导入映射表失败 ", e); flag = false; } + return flag; } @Override public void deviceCommand(DeviceCommandDto device) { try { - HashMap map = new HashMap<>(); - ObjectMapper objectMapper = new ObjectMapper(); + Map map = new HashMap<>(); String cmd = NodeConstant.DEVICE_CONTROL; Long time = System.currentTimeMillis(); @@ -353,7 +443,7 @@ public class SysNodeServiceImpl implements SysNodeService { } // 将 HashMap 转换为 JsonNode - ObjectNode jsonNode = objectMapper.convertValue(map, ObjectNode.class); + ObjectNode jsonNode = JSON_MAPPER.convertValue(map, ObjectNode.class); TerminalMessage configUpdate = TerminalMessage.builder() .cmd(cmd) .cmdId(String.valueOf(device.getDeviceId())) @@ -370,7 +460,6 @@ public class SysNodeServiceImpl implements SysNodeService { public void deviceSetPoint(DeviceSetPointDto device) { try { HashMap map = new HashMap<>(); - ObjectMapper objectMapper = new ObjectMapper(); String cmd = NodeConstant.DEVICE_CONTROL; Long time = System.currentTimeMillis(); @@ -385,7 +474,7 @@ public class SysNodeServiceImpl implements SysNodeService { } // 将 HashMap 转换为 JsonNode - ObjectNode jsonNode = objectMapper.convertValue(map, ObjectNode.class); + ObjectNode jsonNode = JSON_MAPPER.convertValue(map, ObjectNode.class); TerminalMessage configUpdate = TerminalMessage.builder() .cmd(cmd) .cmdId(String.valueOf(device.getDeviceId())) @@ -413,72 +502,4 @@ public class SysNodeServiceImpl implements SysNodeService { } return currentActiveNodeId; } - - // 绑定设备的测点信息,不是绑定设备到映射表 - private void addSysImptabmapping(List equipmentId, Long linkId, SysUserVo sysUserVo, List addList) { - - // 获取设备的测点信息 - for (BindEquipmentInfoDto info : equipmentId) { - List fieldList = sysEquipmentMapper.getEquipmentAttributeInfo(info.getEquipmentId()); - // 获取映射表相关信息 - List serviceList = sysEquipmentMapper.getEquipmentServiceInfo(info.getEquipmentId()); - - if (!CollectionUtils.isEmpty(fieldList)) { - for (BaseImptabmappingVo field : fieldList) { - List fieldImpList = sysEquipmentMapper.getAttributeImpInfo(field.getCode(), info.getEquipmentId(), linkId); - if (!CollectionUtils.isEmpty(fieldImpList)) { - for (BaseImptabmappingVo fieldImp : fieldImpList) { - if(field.getCode().equals(fieldImp.getCode())) { - SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); - sysImptabmapping.setEquipmentAttribute(field.getCode()); - sysImptabmapping.setParams(fieldImp.getParams()); - addList.add(sysImptabmapping); - } - } - } else { - SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); - sysImptabmapping.setEquipmentAttribute(field.getCode()); - addList.add(sysImptabmapping); - } - } - } - if (!CollectionUtils.isEmpty(serviceList)) { - for (BaseImptabmappingVo service : serviceList) { - List serviceImpList = sysEquipmentMapper.getServiceImpInfo(service.getCode(), info.getEquipmentId(), linkId); - - if (!CollectionUtils.isEmpty(serviceImpList)) { - for (BaseImptabmappingVo serviceImp : serviceImpList) { - if(service.getCode().equals(serviceImp.getCode())) { - SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); - sysImptabmapping.setEquipmentService(service.getCode()); - sysImptabmapping.setParams(serviceImp.getParams()); - addList.add(sysImptabmapping); - } - } - }else { - SysImptabmapping sysImptabmapping = getSysImptabmapping(linkId, sysUserVo, info); - sysImptabmapping.setEquipmentService(service.getCode()); - addList.add(sysImptabmapping); - } - } - } - - } - - - } - - private static SysImptabmapping getSysImptabmapping(Long linkId, SysUserVo sysUserVo, BindEquipmentInfoDto info) { - SysImptabmapping sysImptabmapping = new SysImptabmapping(); - sysImptabmapping.setEquipmentId(info.getEquipmentId()); - sysImptabmapping.setLinkId(linkId); - sysImptabmapping.setId(SequenceUtils.generateId()); - sysImptabmapping.setCreatedTime(new Date()); - sysImptabmapping.setUpdatedTime(new Date()); - sysImptabmapping.setCreatedBy(sysUserVo.getAccount()); - sysImptabmapping.setUpdatedBy(sysUserVo.getAccount()); - sysImptabmapping.setRevision(1); - sysImptabmapping.setPorder(info.getPorder()); - return sysImptabmapping; - } } diff --git a/das/src/main/resources/mapper/SysImpTabMappingMapper.xml b/das/src/main/resources/mapper/SysImpTabMappingMapper.xml new file mode 100644 index 00000000..f6b09211 --- /dev/null +++ b/das/src/main/resources/mapper/SysImpTabMappingMapper.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + delete from sys_imptabmapping where link_id = #{linkId} + + diff --git a/das/src/main/resources/mapper/SysImptabmappingMapper.xml b/das/src/main/resources/mapper/SysImptabmappingMapper.xml deleted file mode 100644 index af03a126..00000000 --- a/das/src/main/resources/mapper/SysImptabmappingMapper.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - delete from sys_imptabmapping where link_id = #{linkId} - - - - - - - - - - - - - - - - - - - diff --git a/das/src/main/resources/mapper/SysIotModelFieldMapper.xml b/das/src/main/resources/mapper/SysIotModelFieldMapper.xml index 1468de4a..cbd5de72 100644 --- a/das/src/main/resources/mapper/SysIotModelFieldMapper.xml +++ b/das/src/main/resources/mapper/SysIotModelFieldMapper.xml @@ -52,5 +52,7 @@ where se.id = #{deviceId} - + diff --git a/das/src/main/resources/mapper/SysIotModelServiceMapper.xml b/das/src/main/resources/mapper/SysIotModelServiceMapper.xml index 612b5251..a836b3e4 100644 --- a/das/src/main/resources/mapper/SysIotModelServiceMapper.xml +++ b/das/src/main/resources/mapper/SysIotModelServiceMapper.xml @@ -40,4 +40,8 @@ + +