Просмотр исходного кода

feat(EquipmentController):根据流程标识按罐体分组获取设备列表

HMY 8 месяцев назад
Родитель
Сommit
bdf07e41a6

+ 11 - 1
admin/src/main/java/com/dcs/hnyz/controller/EquipmentController.java

@@ -156,7 +156,7 @@ public class EquipmentController extends BaseController
     }
 
     /**
-     * 根据流程标识获取对应的设备组信息
+     * 根据流程标识获取对应的设备组信息(根据设备种类进行划分)
      */
     @GetMapping("/getPageEquipmentGroupByFlowCode/{flowCode}")
     @ApiOperation(value = "根据流程标识获取对应的设备组信息")
@@ -164,6 +164,16 @@ public class EquipmentController extends BaseController
         return success(equipmentService.getPageEquipmentGroupByFlowCode(flowCode));
     }
 
+    /**
+     * 根据流程标识获取设备组信息(根据罐体设备进行划分)
+     * @param response
+     */
+    @GetMapping("/getPageEquipmentGroupByTankByFlowCode/{flowCode}")
+    @ApiOperation(value = "根据流程标识获取设备组信息(按罐体设备进行划分)")
+    public AjaxResult getPageEquipmentGroupByTankByFlowCode(HttpServletResponse response, @PathVariable String flowCode) {
+        return success(equipmentService.getPageEquipmentGroupByTankByFlowCode(flowCode));
+    }
+
     @PostMapping("/importTemplate")
     public void importTemplate(HttpServletResponse response)
     {

+ 1 - 1
admin/src/main/java/com/dcs/hnyz/enums/DeviceTypeEnum.java

@@ -13,7 +13,7 @@ public enum DeviceTypeEnum {
      * 设备类型
      */
     VALVE_WITH_FEEDBACK("1", "有反馈阀门"),
-    PUMP("2", ""),
+    PUMP("2", "电机"),
     TANK("3", "罐体"),
     SENSOR("4", "传感器"),
     VALVE_NO_FEEDBACK("5", "无反馈阀门"),

+ 2 - 0
admin/src/main/java/com/dcs/hnyz/mapper/EquipmentMapper.java

@@ -30,4 +30,6 @@ public interface EquipmentMapper extends BaseMapper<Equipment>
     public List<EquipmentFormVO> selectEquipmentForm(Equipment equipment);
 
     int updateEquipmentByPlcId(Long plcId);
+
+    List<Equipment> getEquipmentsByParentId(Long equipmentId);
 }

+ 7 - 0
admin/src/main/java/com/dcs/hnyz/service/IEquipmentService.java

@@ -116,4 +116,11 @@ public interface IEquipmentService
     Map<String,List<Equipment>> getPageEquipmentGroupByFlowCode(String flowCode);
 
     String importEquipment(List<Equipment> equipmentList, boolean updateSupport, String operName);
+
+    /**
+     * 根据流程编码按罐体设备分组 获取设备组信息
+     * @param flowCode
+     * @return
+     */
+    Map<String,List<Equipment>> getPageEquipmentGroupByTankByFlowCode(String flowCode);
 }

+ 1 - 1
admin/src/main/java/com/dcs/hnyz/service/impl/EquipmentParamServiceImpl.java

@@ -89,7 +89,7 @@ public class EquipmentParamServiceImpl implements IEquipmentParamService {
     public int updateEquipmentParam(EquipmentParam equipmentParam) {
         LambdaQueryWrapper<EquipmentParam> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(EquipmentParam::getCode, equipmentParam.getCode());
-        wrapper.ne(EquipmentParam::getEquipmentId, equipmentParam.getEquipmentId());
+        wrapper.ne(EquipmentParam::getRegisterId, equipmentParam.getRegisterId());
         EquipmentParam ep = equipmentParamMapper.selectOne(wrapper);
         if (ep != null) {
             throw new CustomException("该寄存器标识已存在");

+ 22 - 0
admin/src/main/java/com/dcs/hnyz/service/impl/EquipmentServiceImpl.java

@@ -439,4 +439,26 @@ public class EquipmentServiceImpl implements IEquipmentService {
         }
         return successMsg.toString();
     }
+
+    @Override
+    public Map<String, List<Equipment>> getPageEquipmentGroupByTankByFlowCode(String flowCode) {
+        Map<String, List<Equipment>> map = new HashMap<>();
+        Flow flow = flowService.getFlowByCode(flowCode);
+        if (flow == null) {
+            throw new CustomException("该流程编码不存在");
+        }
+        // 查询该流程下所有罐体设备(TANK)
+        List<Equipment> tankList = equipmentMapper.selectList(new LambdaQueryWrapper<Equipment>()
+                .apply("FIND_IN_SET({0}, flow_ids)", flow.getFlowId())
+                .eq(Equipment::getEquipmentType, DeviceTypeEnum.TANK.getCode()));
+        //按罐体进行分类
+        for (Equipment tank : tankList) {
+            // 查找该罐体关联的设备列表
+            List<Equipment> relatedEquipments = equipmentMapper.getEquipmentsByParentId(tank.getEquipmentId());
+            // 以罐体的code作为key,关联设备列表作为value
+            map.put(tank.getTitle()+'-'+tank.getEquipmentName(), relatedEquipments);
+        }
+        return map;
+    }
+
 }

+ 56 - 34
admin/src/main/resources/mapper/hnyzdcs/EquipmentMapper.xml

@@ -1,62 +1,84 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.dcs.hnyz.mapper.EquipmentMapper">
-    
+
     <resultMap type="Equipment" id="EquipmentResult">
-        <result property="equipmentId"    column="equipment_id"    />
-        <result property="equipmentName"    column="equipment_name"    />
-        <result property="flowIds"    column="flow_ids"    />
-        <result property="pageIds"    column="page_ids"    />
-        <result property="code"    column="code"    />
-        <result property="equipmentType"    column="equipment_type"    />
-        <result property="plcId"    column="plc_id"    />
+        <result property="equipmentId" column="equipment_id"/>
+        <result property="equipmentName" column="equipment_name"/>
+        <result property="flowIds" column="flow_ids"/>
+        <result property="pageIds" column="page_ids"/>
+        <result property="code" column="code"/>
+        <result property="equipmentType" column="equipment_type"/>
+        <result property="plcId" column="plc_id"/>
         <result property="ipAddress" column="ip_address"/>
         <result property="port" column="port"/>
         <result property="protocolId" column="protocol_id"/>
     </resultMap>
 
     <sql id="selectEquipmentVo">
-        select equipment_id, equipment_name, flow_ids,page_ids, code, equipment_type, plc_id, ip_address, port, protocol_id from equipment
+        select equipment_id,
+               equipment_name,
+               flow_ids,
+               page_ids,
+               code,
+               title,
+               equipment_type,
+               plc_id,
+               ip_address,
+               port,
+               protocol_id
+        from equipment
     </sql>
 
     <select id="selectEquipmentList" parameterType="Equipment" resultMap="EquipmentResult">
         <include refid="selectEquipmentVo"/>
-        <where>  
-            <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
-            <if test="flowIds != null  and flowIds != ''"> and FIND_IN_SET(#{flowIds}, flow_ids) </if>
-            <if test="pageIds != null  and pageIds != ''"> and FIND_IN_SET(#{pageIds}, page_ids) </if>
-            <if test="code != null  and code != ''"> and code like concat('%', #{code}, '%')</if>
-            <if test="equipmentType != null  and equipmentType != ''"> and equipment_type = #{equipmentType}</if>
-            <if test="plcId != null "> and plc_id = #{plcId}</if>
-            <if test="protocolId != null"> and protocol_id = #{protocolId}</if>
-            <if test="status !=null and status !=''"> and status = #{status}</if>
-            <if test="delFlag == null"> and del_flag = '0'</if>
+        <where>
+            <if test="equipmentName != null  and equipmentName != ''">and equipment_name like concat('%',
+                #{equipmentName}, '%')
+            </if>
+            <if test="flowIds != null  and flowIds != ''">and FIND_IN_SET(#{flowIds}, flow_ids)</if>
+            <if test="pageIds != null  and pageIds != ''">and FIND_IN_SET(#{pageIds}, page_ids)</if>
+            <if test="code != null  and code != ''">and code like concat('%', #{code}, '%')</if>
+            <if test="equipmentType != null  and equipmentType != ''">and equipment_type = #{equipmentType}</if>
+            <if test="plcId != null ">and plc_id = #{plcId}</if>
+            <if test="protocolId != null">and protocol_id = #{protocolId}</if>
+            <if test="status !=null and status !=''">and status = #{status}</if>
+            <if test="delFlag == null">and del_flag = '0'</if>
         </where>
     </select>
 
     <select id="selectEquipmentForm" resultType="com.dcs.hnyz.domain.vo.EquipmentFormVO">
         select * from equipment
         <where>
-            <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
-            <if test="flowIds != null  and flowIds != ''"> and FIND_IN_SET(#{flowIds}, flow_ids) </if>
-            <if test="pageIds != null  and pageIds != ''"> and FIND_IN_SET(#{pageIds}, page_ids) </if>
-            <if test="code != null  and code != ''"> and code like concat('%', #{code}, '%')</if>
-            <if test="equipmentType != null  and equipmentType != ''"> and equipment_type = #{equipmentType}</if>
-            <if test="plcId != null "> and plc_id = #{plcId}</if>
-            <if test="protocolId != null"> and protocol_id = #{protocolId}</if>
-            <if test="status != null  and status != ''"> and status = #{status}</if>
-            <if test="delFlag == null"> and del_flag = '0'</if>
+            <if test="equipmentName != null  and equipmentName != ''">and equipment_name like concat('%',
+                #{equipmentName}, '%')
+            </if>
+            <if test="flowIds != null  and flowIds != ''">and FIND_IN_SET(#{flowIds}, flow_ids)</if>
+            <if test="pageIds != null  and pageIds != ''">and FIND_IN_SET(#{pageIds}, page_ids)</if>
+            <if test="code != null  and code != ''">and code like concat('%', #{code}, '%')</if>
+            <if test="equipmentType != null  and equipmentType != ''">and equipment_type = #{equipmentType}</if>
+            <if test="plcId != null ">and plc_id = #{plcId}</if>
+            <if test="protocolId != null">and protocol_id = #{protocolId}</if>
+            <if test="status != null  and status != ''">and status = #{status}</if>
+            <if test="delFlag == null">and del_flag = '0'</if>
         </where>
     </select>
+    <select id="getEquipmentsByParentId" resultType="com.dcs.hnyz.domain.Equipment">
+        <include refid="selectEquipmentVo"/>
+        WHERE equipment_id IN (
+        SELECT relation_id FROM equipment_param WHERE equipment_id = #{equipmentId}
+        )
+    </select>
 
     <update id="updateEquipmentByPlcId">
         UPDATE equipment e
-            JOIN plc_info p ON e.plc_id = p.plc_id
-        SET e.protocol_id = p.protocol_id,
-            e.port = p.port,
-            e.ip_address = p.ip_address
+            JOIN plc_info p
+        ON e.plc_id = p.plc_id
+            SET e.protocol_id = p.protocol_id,
+                e.port = p.port,
+                e.ip_address = p.ip_address
         WHERE e.plc_id = #{plcId}
     </update>