From 3fdea1ab6ab545de0a25573318ecd838de3be576 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 17 九月 2026 15:54:13 +0800
Subject: [PATCH] feat: 1.检验任务查询优化 2.模板时间和地点保存

---
 inspect-server/src/main/resources/mapper/InsSampleMapper.xml |   83 +++++++++++++++++++++++++++++++++++------
 1 files changed, 71 insertions(+), 12 deletions(-)

diff --git a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
index f433304..c540fb2 100644
--- a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
+++ b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
@@ -166,11 +166,36 @@
                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
-        a.*,ios.ins_state,ios.verify_tell,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,
+        verify_user
         FROM
         (
         SELECT
@@ -187,7 +212,11 @@
         GROUP_CONCAT(DISTINCT isa.model SEPARATOR ' ') AS sample_model,
         userName,
         checkName,
-        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,
         io.type_source,
@@ -204,6 +233,7 @@
         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 LEFT JOIN  user uu ON u.user_id = uu.id
@@ -237,10 +267,16 @@
             </if>
         </if>
         <if test="sonLaboratory!= null and sonLaboratory != ''">
-            and ip.son_laboratory = #{sonLaboratory}
+            and CASE
+                    WHEN direct_template.ins_order_id IS NOT NULL THEN '鏂拌仛'
+                    ELSE ip.son_laboratory
+                END = #{sonLaboratory}
         </if>
         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
@@ -248,7 +284,7 @@
         a.type DESC,
         a.id
         ) b
-        where ins_state is not null
+        where (ins_state is not null or direct_template = 1)
         <if test="laboratory!=null and laboratory!=''">
             and laboratory=#{laboratory}
         </if>
@@ -263,7 +299,12 @@
     <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
@@ -275,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
@@ -303,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
@@ -315,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>
@@ -404,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,
@@ -442,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

--
Gitblit v1.9.3