From bcc80a6833abe9f24abdb978f7c7f01b664a574f Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期二, 18 二月 2025 14:48:45 +0800
Subject: [PATCH] 优化调整

---
 cnas-server/src/main/resources/mapper/DeviceMapper.xml |   84 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/cnas-server/src/main/resources/mapper/DeviceMapper.xml b/cnas-server/src/main/resources/mapper/DeviceMapper.xml
index 40bcc1f..4a8ddca 100644
--- a/cnas-server/src/main/resources/mapper/DeviceMapper.xml
+++ b/cnas-server/src/main/resources/mapper/DeviceMapper.xml
@@ -3,7 +3,6 @@
         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.yuanchu.mom.mapper.DeviceMapper">
-
     <select id="selectDeviceParameter" resultType="com.yuanchu.mom.pojo.Device">
         select * from(
         select id,
@@ -103,23 +102,98 @@
         SEPARATOR ';'
         ) AS insProductItem,
         u.name ,
-        l.laboratory_name
+        l.laboratory_name,
+        cmr.next_calibration_date nextCalibrationDateTwo,
+        CASE
+        WHEN cmr.next_calibration_date IS NULL THEN 0
+        WHEN cmr.next_calibration_date BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 45 DAY) THEN 1
+        ELSE 0
+        END AS status
         FROM
         device d
         LEFT JOIN `user` u ON u.id = d.equipment_manager
         LEFT JOIN laboratory l ON l.id = d.subordinate_departments_id
+        LEFT JOIN (SELECT
+        device_id,
+        type,
+        MAX(next_calibration_date) AS next_calibration_date
+        FROM
+        device_metric_record
+        GROUP BY
+        device_id )cmr ON d.id = cmr.device_id
         LEFT JOIN structure_item_parameter sip ON FIND_IN_SET(sip.id, d.ins_product_ids)
+        <where>
+            <if test="laboratoryNameIsNull != null and laboratoryNameIsNull == true">
+                l.laboratory_name is null
+            </if>
+            AND cmr.type = 'calibrate' or cmr.type is null or cmr.type = ''
+        </where>
         GROUP BY
         d.id,
-        u.name, l.laboratory_name
+        u.name, l.laboratory_name,cmr.next_calibration_date,status
         ) a
         <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
             ${ew.customSqlSegment}
         </if>
     </select>
 
-    <select id="getInspectionItemSubclass" resultType="java.lang.String">
-        SELECT ip.inspection_item_subclass FROM ins_product ip
+    <select id="getInspectionItemSubclass" resultType="map">
+        SELECT ip.inspection_item,
+               if(ip.inspection_item_subclass is not null and ip.inspection_item_subclass != '',
+                  ip.inspection_item_subclass, ip.inspection_item) inspection_item_subclass
+        FROM ins_product ip
         where ip.ins_sample_id = #{id}
     </select>
+
+
+    <resultMap id="treeDeviceDto" type="map">
+        <result property="label" column="laboratory_name"/>
+        <result property="value" column="value" />
+        <collection property="children" resultMap="storagePointMap" javaType="List"/>
+    </resultMap>
+
+    <resultMap id="storagePointMap" type="map">
+        <result property="value" column="value"/>
+        <result property="label" column="storage_point"/>
+        <collection property="children" resultMap="deviceNameMap" javaType="List"/>
+    </resultMap>
+
+    <resultMap id="deviceNameMap" type="map">
+        <result property="value" column="id"/>
+        <result property="label" column="device_name"/>
+    </resultMap>
+    <select id="treeDevice" resultMap="treeDeviceDto">
+        select
+        d.id,
+        case when l.laboratory_name is null || l.laboratory_name ='' then '鍏朵粬' else l.laboratory_name end as laboratory_name,
+        case when d.large_category is null || d.large_category ='' then '鍏朵粬' else d.large_category end as storage_point,
+        d.device_name,
+        null as value
+        from device d
+        LEFT JOIN laboratory l ON l.id = d.subordinate_departments_id
+        <where>
+            <if test="deviceName!=null and deviceName!=''">
+                and device_name like concat('%',#{deviceName},'%')
+            </if>
+        </where>
+        order by l.laboratory_name desc, d.large_category desc
+    </select>
+    <select id="selectDeviceByCode" resultType="com.yuanchu.mom.dto.DeviceDto">
+        SELECT d.*,
+               GROUP_CONCAT(DISTINCT inspection_item SEPARATOR ';') AS ins_product_item,
+               l.laboratory_name,
+               u1.name                                                 equipmentManager_name,
+               u2.name                                                 authorized_person_name
+        FROM device d
+                 LEFT JOIN structure_item_parameter sip ON FIND_IN_SET(sip.id, d.ins_product_ids)
+                 LEFT JOIN laboratory l ON d.subordinate_departments_id = l.id
+                 LEFT JOIN user u1 ON u1.id = d.equipment_manager
+                 LEFT JOIN user u2 ON u2.id = d.authorized_person
+        WHERE d.id = #{id}
+
+        GROUP BY d.id,
+                 l.laboratory_name,
+                 u1.name,
+                 u2.name
+    </select>
 </mapper>

--
Gitblit v1.9.3