From bd46f203b0d30a3d33b7c51ae9a528e4807477e1 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 17 九月 2026 17:17:16 +0800
Subject: [PATCH] feat: 1.检验单详情温湿度 2.报告编制样品外观.平均值优化

---
 inspect-server/src/main/resources/mapper/InsSampleMapper.xml |  241 ++++++++++++++++++++++++++---------------------
 1 files changed, 132 insertions(+), 109 deletions(-)

diff --git a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
index fc3d7da..c540fb2 100644
--- a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
+++ b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
@@ -61,6 +61,7 @@
         <result property="tell" column="tell" jdbcType="VARCHAR"/>
         <result property="lastValue" column="last_value" jdbcType="VARCHAR"/>
         <result property="insResult" column="ip_ins_result" jdbcType="INTEGER"/>
+        <result property="isBinding" column="ip_is_binding" jdbcType="INTEGER"/>
         <result property="state" column="state" jdbcType="INTEGER"/>
         <result property="insBushId" column="ins_bush_id" jdbcType="INTEGER"/>
         <result property="insSampleId" column="ins_sample_id" jdbcType="INTEGER"/>
@@ -69,6 +70,7 @@
         <result property="createTime" column="ip_create_time" jdbcType="TIMESTAMP"/>
         <result property="updateTime" column="ip_update_time" jdbcType="TIMESTAMP"/>
         <result property="templateId" column="template_id" jdbcType="INTEGER"/>
+        <result property="templateRowIndex" column="template_row_index" jdbcType="INTEGER"/>
         <result property="methodS" column="method_s"/>
         <result property="tell" column="tell"/>
         <result property="dic" column="dic"/>
@@ -141,15 +143,17 @@
                man_day,
                bsm,
                ask,
-               `last_value`,
-               ip.ins_result  ip_ins_result,
-               state,
+                `last_value`,
+                ip.ins_result  ip_ins_result,
+                ip.is_binding  ip_is_binding,
+                state,
                ins_sample_id,
                ip.create_user ip_create_user,
                ip.update_user ip_update_user,
                ip.create_time ip_create_time,
                ip.update_time ip_update_time,
                template_id,
+               template_row_index,
                ipr.ins_value,
                ipr.com_value,
                ipr.equip_value,
@@ -162,16 +166,38 @@
                ip.structure_item_parameter_id
     </sql>
 
+    <!--
+        鐩寸粦妯℃澘璁㈠崟涓嶄緷璧� ins_product銆傞�氳繃璁㈠崟妯℃澘蹇収鍜屽崟鏍峰搧鏍囧噯缁撴瀯璇嗗埆锛�
+        鍒楄〃銆佷换鍔″垏鎹㈠強璇︽儏缁熶竴浣跨敤鍥哄畾浠诲姟瀹為獙瀹も�滄柊鑱氣�濄��
+    -->
+    <sql id="directTemplateOrderJoin">
+        LEFT JOIN (
+            SELECT DISTINCT iost.ins_order_id
+            FROM ins_order_standard_template iost
+            INNER JOIN ins_order dto ON dto.id = iost.ins_order_id
+            INNER JOIN ins_sample dts ON dts.ins_order_id = dto.id
+            WHERE dts.standard_method_list_id IS NULL
+              AND (dts.factory IS NULL OR TRIM(dts.factory) = '')
+              AND (dts.sample_type IS NULL OR TRIM(dts.sample_type) = '')
+              AND (dts.model IS NULL OR TRIM(dts.model) = '')
+              AND (dto.factory IS NULL OR TRIM(dto.factory) = '')
+              AND (dto.sample_type IS NULL OR TRIM(dto.sample_type) = '')
+        ) direct_template ON direct_template.ins_order_id = io.id
+    </sql>
+
 
     <select id="findInsSampleAndOrder" resultType="com.ruoyi.inspect.vo.InsOrderPlanVO">
-        SELECT *
-        FROM (
+        select * from(select * from(
         SELECT
         a.*,
-        ios.ins_state,
+        CASE
+            WHEN ios.ins_state IS NULL AND a.direct_template = 1 THEN 0
+            ELSE ios.ins_state
+        END AS ins_state,
         ios.verify_tell,
-        ios.verify_user
-        FROM (
+        verify_user
+        FROM
+        (
         SELECT
         io.id,
         io.entrust_code,
@@ -179,131 +205,106 @@
         io.appointed,
         io.send_time,
         io.order_type,
-        CASE WHEN io.type_source = 0 THEN io.sample_view ELSE io.sample END AS sample,
+        case when
+        io.type_source = 0
+        then io.sample_view
+        else io.sample end sample,
         GROUP_CONCAT(DISTINCT isa.model SEPARATOR ' ') AS sample_model,
-        MAX(isu.userName) AS userName,
-        MAX(isu2.checkName) AS checkName,
-        GROUP_CONCAT(DISTINCT ip.son_laboratory) AS son_laboratory,
+        userName,
+        checkName,
+        CASE
+            WHEN direct_template.ins_order_id IS NOT NULL THEN '鏂拌仛'
+            ELSE ip.son_laboratory
+        END AS son_laboratory,
+        CASE WHEN direct_template.ins_order_id IS NOT NULL THEN 1 ELSE 0 END AS direct_template,
         io.ins_time,
         io.laboratory,
         io.type_source,
         io.ifs_inventory_id,
-        MAX(ira.id) AS ins_report_id,
-        MAX(ira.url) AS url,
-        MAX(ira.url_s) AS url_s,
-        MAX(ira.temp_url_pdf) AS temp_url_pdf,
-        MAX(iiq.is_copper) AS is_copper
-        FROM ins_order io
-        INNER JOIN ins_sample isa ON isa.ins_order_id = io.id
+        ira.id ins_report_id,
+        ira.url,
+        ira.url_s,
+        ira.temp_url_pdf,
+        iiq.is_copper,
+        iiq.is_split_order,
+        iiq.material_prop AS material_prop
+        FROM
+        ins_order io
+        LEFT JOIN ins_sample isa ON isa.ins_order_id = io.id
         LEFT JOIN ins_report ira ON ira.ins_order_id = io.id
         LEFT JOIN ifs_inventory_quantity iiq ON iiq.id = io.ifs_inventory_id
+        <include refid="directTemplateOrderJoin"/>
         LEFT JOIN (
-        SELECT
-        ins_sample_id,
-        GROUP_CONCAT(DISTINCT uu.name SEPARATOR ',') AS userName
-        FROM ins_sample_user u
-        INNER JOIN user uu ON u.user_id = uu.id
-        WHERE u.state = 0
-        <if test="sonLaboratory != null and sonLaboratory != ''">
-            AND u.son_laboratory = #{sonLaboratory}
+        SELECT ins_sample_id,GROUP_CONCAT( DISTINCT uu.name SEPARATOR ',') AS userName
+        FROM ins_sample_user u LEFT JOIN  user uu ON u.user_id = uu.id
+        WHERE u.state=0
+        <if test="sonLaboratory!= null and sonLaboratory != ''">
+            and son_laboratory=#{sonLaboratory}
         </if>
         GROUP BY ins_sample_id
+        ORDER BY ins_sample_id
         ) isu ON isu.ins_sample_id = io.id
         LEFT JOIN (
-        SELECT
-        ins_sample_id,
-        MAX(uu.name) AS checkName
-        FROM ins_sample_user u
-        INNER JOIN user uu ON u.user_id = uu.id
-        WHERE u.state = 1
-        <if test="sonLaboratory != null and sonLaboratory != ''">
-            AND u.son_laboratory = #{sonLaboratory}
+        SELECT ins_sample_id,uu.name checkName
+        FROM ins_sample_user u LEFT JOIN  user uu ON u.user_id = uu.id
+        WHERE u.state=1
+        <if test="sonLaboratory!= null and sonLaboratory != ''">
+            and son_laboratory=#{sonLaboratory}
         </if>
         GROUP BY ins_sample_id
-        ) isu2 ON isu2.ins_sample_id = io.id
+        ORDER BY ins_sample_id
+        )isu2 ON isu2.ins_sample_id = io.id
         LEFT JOIN ins_product ip ON ip.ins_sample_id = isa.id
-
-        WHERE io.state = 1
-        AND io.send_time IS NOT NULL
-
+        WHERE io.state = 1 and send_time is not null
         <if test="isCheck != null">
-            <if test="userName != null and userName != ''">
-                AND EXISTS (
-                SELECT 1
-                FROM ins_sample_user iu
-                JOIN user u ON iu.user_id = u.id
-                WHERE iu.ins_sample_id = io.id
-                AND iu.state = 1
-                AND u.name LIKE CONCAT('%', #{userName}, '%')
-                <if test="sonLaboratory != null and sonLaboratory != ''">
-                    AND iu.son_laboratory = #{sonLaboratory}
-                </if>
-                )
+            <if test="userName !=null and userName!=''">
+                and checkName like CONCAT ('%', #{userName},'%')
             </if>
         </if>
-
         <if test="isCheck == null">
-            <if test="userName != null and userName != ''">
-                AND EXISTS (
-                SELECT 1
-                FROM ins_sample_user iu
-                JOIN user u ON iu.user_id = u.id
-                WHERE iu.ins_sample_id = io.id
-                AND iu.state = 0
-                AND u.name LIKE CONCAT('%', #{userName}, '%')
-                <if test="sonLaboratory != null and sonLaboratory != ''">
-                    AND iu.son_laboratory = #{sonLaboratory}
-                </if>
-                )
+            <if test="userName !=null and userName!=''">
+                and userName like CONCAT ('%', #{userName},'%')
             </if>
         </if>
-
-        <if test="sonLaboratory != null and sonLaboratory != ''">
-            AND EXISTS (
-            SELECT 1
-            FROM ins_product ip2
-            WHERE ip2.ins_sample_id = isa.id
-            AND ip2.son_laboratory = #{sonLaboratory}
-            )
+        <if test="sonLaboratory!= null and sonLaboratory != ''">
+            and CASE
+                    WHEN direct_template.ins_order_id IS NOT NULL THEN '鏂拌仛'
+                    ELSE ip.son_laboratory
+                END = #{sonLaboratory}
         </if>
-
-        GROUP BY io.id
+        GROUP BY
+        CASE
+            WHEN direct_template.ins_order_id IS NOT NULL THEN '鏂拌仛'
+            ELSE ip.son_laboratory
+        END,
+        io.id
         ) a
-
-        LEFT JOIN (
-        SELECT *
-        FROM (
-        SELECT *,
-        ROW_NUMBER() OVER (PARTITION BY ins_order_id ORDER BY update_time DESC, id DESC) AS rn
-        FROM ins_order_state
-        ) ios
-        WHERE ios.rn = 1
-        <if test="sonLaboratory != null and sonLaboratory != ''">
-            AND ios.laboratory = #{sonLaboratory}
+        LEFT JOIN ins_order_state ios ON ios.ins_order_id = a.id AND ios.laboratory = a.son_laboratory
+        ORDER BY
+        a.type DESC,
+        a.id
+        ) b
+        where (ins_state is not null or direct_template = 1)
+        <if test="laboratory!=null and laboratory!=''">
+            and laboratory=#{laboratory}
         </if>
-        ) ios ON ios.ins_order_id = a.id
-
-        WHERE ios.ins_state IS NOT NULL
-
-        <if test="laboratory != null and laboratory != ''">
-            AND a.laboratory = #{laboratory}
-        </if>
-
-        ORDER BY a.type DESC, a.id
-        ) A
-
+        )A
         <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
             ${ew.customSqlSegment}
         </if>
-
-        ORDER BY send_time ASC
+        ORDER BY send_time desc
 
     </select>
 
     <select id="inspectionOrderDetailsTaskSwitching" resultType="com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo">
         select * from(
         SELECT
-        a.*,ios.ins_state,ios.verify_tell,isu2.order_user_id,<!--(ios.verify_user = #{userId})--> verify_user
+        a.*,
+        CASE
+            WHEN ios.ins_state IS NULL AND a.direct_template = 1 THEN 0
+            ELSE ios.ins_state
+        END AS ins_state,
+        ios.verify_tell,isu2.order_user_id,<!--(ios.verify_user = #{userId})--> verify_user
         FROM
         (
         SELECT
@@ -315,12 +316,17 @@
         group_concat(distinct isa.sample,' ') sampleType,
         isu.user_id,
         user.name userName,
-        ip.son_laboratory,
+        CASE
+            WHEN direct_template.ins_order_id IS NOT NULL THEN '鏂拌仛'
+            ELSE ip.son_laboratory
+        END AS son_laboratory,
+        CASE WHEN direct_template.ins_order_id IS NOT NULL THEN 1 ELSE 0 END AS direct_template,
         io.ins_time,
         io.laboratory
         FROM
         ins_order io
         LEFT JOIN ins_sample isa ON isa.ins_order_id = io.id
+        <include refid="directTemplateOrderJoin"/>
         LEFT JOIN ( <!--SELECT * FROM ins_sample_user GROUP BY ins_sample_id, user_id -->
         SELECT *
         FROM ins_sample_user u
@@ -343,7 +349,10 @@
         </if>
         OR isu.user_id is NULL
         GROUP BY
-        ip.son_laboratory,
+        CASE
+            WHEN direct_template.ins_order_id IS NOT NULL THEN '鏂拌仛'
+            ELSE ip.son_laboratory
+        END,
         io.id
         ) a
         LEFT JOIN ins_order_state ios ON ios.ins_order_id = a.id AND ios.laboratory = a.son_laboratory
@@ -355,7 +364,7 @@
         OR user_id is NULL
         ) isu2 on
         isu2.ins_sample_id = a.id
-        where ins_state is not null
+        where (ins_state is not null or direct_template = 1)
         <if test="laboratory != null and laboratory != ''">
             and a.laboratory=#{laboratory}
         </if>
@@ -401,6 +410,7 @@
                tell,
                `last_value`,
                ip.ins_result  ip_ins_result,
+               ip.is_binding  ip_is_binding,
                state,
                ins_sample_id,
                ip.create_user ip_create_user,
@@ -443,7 +453,7 @@
                ip.sample_type ip_sample_type,
                ip.sample      ip_sample,
                ip.model       ip_model,
-               son_laboratory,
+               ip.son_laboratory,
                ip.unit        ip_unit,
                price,
                man_hour,
@@ -460,6 +470,7 @@
                ask,
                `last_value`,
                ip.ins_result  ip_ins_result,
+               ip.is_binding  ip_is_binding,
                state,
                ins_sample_id,
                ip.create_user ip_create_user,
@@ -480,8 +491,18 @@
                  left join ins_product ip on isa.id = ip.ins_sample_id
                  left join ins_product_result ipr on ip.id = ipr.ins_product_id
         where ins_order_id = #{id}
-          and state = 1
-          and ip.son_laboratory = #{laboratory}
+          and (
+              (ip.state = 1 and ip.son_laboratory = #{laboratory})
+              or (
+                  ip.id is null
+                  and #{laboratory} = '鏂拌仛'
+                  and exists (
+                      select 1
+                      from ins_order_standard_template iost
+                      where iost.ins_order_id = isa.ins_order_id
+                  )
+              )
+          )
     </select>
     <select id="getSampleEn" resultType="java.lang.String">
         select name_en
@@ -550,6 +571,7 @@
                tell,
                `last_value`,
                ip.ins_result  ip_ins_result,
+               ip.is_binding  ip_is_binding,
                state,
                ins_sample_id,
                ip.create_user ip_create_user,
@@ -562,12 +584,13 @@
                ipr.equip_value,
                ip.method_s,
                ip.radius,
+               ip.structure_item_parameter_id,
                isa.special_standard_method
         from ins_sample isa
                  left join ins_product ip on isa.id = ip.ins_sample_id
                  left join ins_product_result ipr on ip.id = ipr.ins_product_id
         where ins_order_id = #{id}
-          and ip.standard_method_list_id is not null
+          and (ip.standard_method_list_id is not null or ip.template_row_index is not null)
           and state = 1
           and ip.is_binding != 1
         order by ip.sort asc,
@@ -588,7 +611,7 @@
           and ip.son_laboratory = #{laboratory}
           and ins_fiber_id is null
           and ins_fibers_id is null
-          and standard_method_list_id is not null
+          and (standard_method_list_id is not null or template_row_index is not null)
         /* 鐢电紗閰嶇疆鏍囪瘑 */
         <if test="cableTag == null or cableTag == ''">
             and ip.cable_tag is null
@@ -615,7 +638,7 @@
         and ip.son_laboratory = #{laboratory}
         and ins_fiber_id is null
         and ins_fibers_id is null
-        and standard_method_list_id is not null
+        and (standard_method_list_id is not null or template_row_index is not null)
         and ip.raw_material_tag = #{rawMaterialTag}
         order by sort asc
     </select>

--
Gitblit v1.9.3