From e4265f964201bb0c4a6e80152c25018e618f3bcc Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 15 七月 2025 11:51:45 +0800
Subject: [PATCH] 检验任务数据重复处理
---
inspect-server/src/main/resources/mapper/InsSampleMapper.xml | 151 +++++++++++++++++++++++++++++++++-----------------
1 files changed, 99 insertions(+), 52 deletions(-)
diff --git a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
index 9c9f99f..fc3d7da 100644
--- a/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
+++ b/inspect-server/src/main/resources/mapper/InsSampleMapper.xml
@@ -164,11 +164,14 @@
<select id="findInsSampleAndOrder" resultType="com.ruoyi.inspect.vo.InsOrderPlanVO">
- select * from(select * from(
+ SELECT *
+ FROM (
SELECT
- a.*,ios.ins_state,ios.verify_tell,verify_user
- FROM
- (
+ a.*,
+ ios.ins_state,
+ ios.verify_tell,
+ ios.verify_user
+ FROM (
SELECT
io.id,
io.entrust_code,
@@ -176,81 +179,125 @@
io.appointed,
io.send_time,
io.order_type,
- case when
- io.type_source = 0
- then io.sample_view
- else io.sample end sample,
+ CASE WHEN io.type_source = 0 THEN io.sample_view ELSE io.sample END AS sample,
GROUP_CONCAT(DISTINCT isa.model SEPARATOR ' ') AS sample_model,
- userName,
- checkName,
- ip.son_laboratory,
+ MAX(isu.userName) AS userName,
+ MAX(isu2.checkName) AS checkName,
+ GROUP_CONCAT(DISTINCT ip.son_laboratory) AS son_laboratory,
io.ins_time,
io.laboratory,
io.type_source,
io.ifs_inventory_id,
- ira.id ins_report_id,
- ira.url,
- ira.url_s,
- ira.temp_url_pdf,
- iiq.is_copper
- FROM
- ins_order io
- LEFT JOIN ins_sample isa ON isa.ins_order_id = io.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
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
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
- WHERE u.state=0
- <if test="sonLaboratory!= null and sonLaboratory != ''">
- and son_laboratory=#{sonLaboratory}
+ 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}
</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,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}
+ 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}
</if>
GROUP BY ins_sample_id
- ORDER BY ins_sample_id
- )isu2 ON isu2.ins_sample_id = io.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 send_time is not null
+
+ WHERE io.state = 1
+ AND io.send_time IS NOT NULL
+
<if test="isCheck != null">
- <if test="userName !=null and userName!=''">
- and checkName like CONCAT ('%', #{userName},'%')
+ <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>
</if>
+
<if test="isCheck == null">
- <if test="userName !=null and userName!=''">
- and userName like CONCAT ('%', #{userName},'%')
+ <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>
</if>
- <if test="sonLaboratory!= null and sonLaboratory != ''">
- and ip.son_laboratory = #{sonLaboratory}
+
+ <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>
- GROUP BY
- ip.son_laboratory,
- io.id
+
+ GROUP BY io.id
) a
- 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
- <if test="laboratory!=null and laboratory!=''">
- and laboratory=#{laboratory}
+
+ 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}
</if>
- )A
+ ) 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
+
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
${ew.customSqlSegment}
</if>
- ORDER BY send_time asc
+
+ ORDER BY send_time ASC
+
</select>
<select id="inspectionOrderDetailsTaskSwitching" resultType="com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo">
--
Gitblit v1.9.3