From 6bbcdd0d1beeca74251f63ea42b9ee8349e97902 Mon Sep 17 00:00:00 2001
From: chenlu <1320612696@qq.com>
Date: 星期二, 15 七月 2025 10:19:54 +0800
Subject: [PATCH] 优化在制品查询速度

---
 north-glass-erp/src/main/resources/mapper/pp/ReworkMapper.xml |  324 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 283 insertions(+), 41 deletions(-)

diff --git a/north-glass-erp/src/main/resources/mapper/pp/ReworkMapper.xml b/north-glass-erp/src/main/resources/mapper/pp/ReworkMapper.xml
index c9ea9ce..93ef507 100644
--- a/north-glass-erp/src/main/resources/mapper/pp/ReworkMapper.xml
+++ b/north-glass-erp/src/main/resources/mapper/pp/ReworkMapper.xml
@@ -5,62 +5,304 @@
 <!--杩斿伐鏁版嵁-->
 
 <mapper namespace="com.example.erp.mapper.pp.ReworkMapper">
-    <resultMap id="reworkDataTitle" type="com.example.erp.entity.pp.Rework">
 
-
-    </resultMap>
 
 
     <!--鑾峰彇杩斿伐鏁版嵁-->
-    <select id="queryRework" resultMap="reworkDataTitle">
-        select * from rework
-        <!--<where>
-
-            create_time <![CDATA[>=]]> #{startTime} and create_time <![CDATA[<=]]> #{endTime}}
-            &lt;!&ndash;杩斿伐缂栧彿&ndash;&gt;
-            <if test="rework_id!=null and rework != ''">
-                and rework_id = #{reworkId}
+    <select id="SelectRework" >
+        select
+        r.id,
+        r.review_status,
+        r.rework_team,
+        r.rework_id,
+        r.process_id,
+        r.order_id,
+        r.order_sort,
+        o.project,
+        o.batch,
+        od.product_name,
+        r.technology_number,
+        ogd.glass_address,
+        r.rework_num,
+        od.width,
+        od.height,
+        od.shape,
+        r.rework_type,
+        r.rework_reason,
+        r.responsible_team,
+        r.responsible_personnel,
+        r.responsible_equipment,
+        r.rework_area,
+        r.quality_inspector,
+        r.rework_processes,
+        r.reviewer,
+        date(r.create_time) as create_time,
+        date(r.update_time) as update_time,
+        JSON_UNQUOTE( JSON_EXTRACT( od.other_columns, '$.S01' )) AS glassNumber,
+        r.reporting_work_id
+        from pp.rework r left join sd.order_detail od on r.order_id=od.order_id and r.order_sort=od.order_number
+        left join sd.`order` o on r.order_id = o.order_id
+        left join (select * from sd.order_glass_detail group by order_id,order_number) as ogd
+        on r.order_id = ogd.order_id and r.order_sort = ogd.order_number
+        <where>
+            date(r.create_time)>=#{startDate} and date(r.create_time) &lt;= #{endDate}
+            and o.create_order>0
+            <if test="rework.reworkId != null and rework.reworkId != ''">
+                and r.rework_id regexp #{rework.reworkId}
             </if>
-            &lt;!&ndash;娴佺▼鍗″彿&ndash;&gt;
-            <if test="process_id != null and process_id != ''">
-                and process_id=#{processId}
+            <if test="rework.reworkTeam != null and rework.reworkTeam != ''">
+                and r.rework_team regexp #{rework.reworkTeam}
             </if>
-            &lt;!&ndash;杩斿伐绫诲瀷&ndash;&gt;
-            <if test="rework_Type != null and rework_Type!=''">
-                and rework_Type=#{rework_Type}
+            <if test="rework.orderId != null and rework.orderId != ''">
+                and r.order_id regexp #{rework.orderId}
             </if>
-            &lt;!&ndash;杩斿伐鍘熷洜&ndash;&gt;
-            <if test="rework_Reason != null and rework_Reason!=''">
-                and rework_Reason=#{rework_Reason}
+            <if test="rework.reportingWorkId != null and rework.reportingWorkId != ''">
+                and r.reporting_work_id regexp #{rework.reportingWorkId}
             </if>
-            &lt;!&ndash;杩斿伐宸ュ簭&ndash;&gt;
-            <if test="rework_Processes != null and rework_Processes!=''">
-                and rework_Processes=#{rework_Processes}
+            <if test="rework.processId != null and rework.processId != ''">
+                and r.process_id regexp #{rework.processId}
             </if>
-            &lt;!&ndash;杩斿伐鏁伴噺&ndash;&gt;
-            <if test="rework_Num != null and rework_Num!=''">
-                and rework_Num=#{rework_Num}
+            <if test="rework.project != null and rework.project != ''">
+                and o.project regexp #{rework.project}
             </if>
-            &lt;!&ndash;杩斿伐鐝粍&ndash;&gt;
-            <if test="rework_Team != null and rework_Team!=''">
-                and rework_Team=#{rework_Team}
+            <if test="rework.batch != null and rework.batch != ''">
+                and o.batch regexp #{rework.batch}
             </if>
-            &lt;!&ndash;瀹℃牳浜�&ndash;&gt;
-            <if test="reviewer != null and reviewer!=''">
-                and reviewer=#{reviewer}
+            <if test="rework.orderSort != null and rework.orderSort != ''">
+                and r.order_sort regexp #{rework.orderSort}
             </if>
-            &lt;!&ndash;瀹℃牳鐘舵��&ndash;&gt;
-            <if test="review_Status != null and review_Status!=''">
-                and review_Status=#{review_Status}
+            <if test="rework.buildingNumber != null and rework.buildingNumber != ''">
+                and od.building_number regexp #{rework.buildingNumber}
             </if>
-            &lt;!&ndash;杩斿伐闈㈢Н&ndash;&gt;
-            <if test="rework_Area != null and rework_Area!=''">
-                and rework_Area=#{rework_Area}
+            <if test="rework.productName != null and rework.productName != ''">
+                and od.product_name regexp #{rework.productName}
             </if>
-
-        </where>-->
-
+            <if test="rework.technologyNumber != null and rework.technologyNumber != ''">
+                and r.technology_number regexp #{rework.technologyNumber}
+            </if>
+            <if test="rework.qualityInspector != null and rework.qualityInspector != ''">
+                and r.quality_inspector regexp #{rework.qualityInspector}
+            </if>
+            <if test="rework.width != null and rework.width != ''">
+                and od.width regexp #{rework.width}
+            </if>
+            <if test="rework.height != null and rework.height != ''">
+                and od.height regexp #{rework.height}
+            </if>
+            <if test="rework.shape != null and rework.shape != ''">
+                and od.shape regexp #{rework.shape}
+            </if>
+            <if test="rework.reworkNum != null and rework.reworkNum != ''">
+                and r.rework_num regexp #{rework.reworkNum}
+            </if>
+            <if test="rework.glassAddress != null and rework.glassAddress != ''">
+                and ogd.glass_address regexp #{rework.glassAddress}
+            </if>
+            <if test="rework.responsibleTeam != null and rework.responsibleTeam != ''">
+                and r.responsible_team regexp #{rework.responsibleTeam}
+            </if>
+            <if test="rework.responsibleEquipment != null and rework.responsibleEquipment != ''">
+                and r.responsible_equipment regexp #{rework.responsibleEquipment}
+            </if>
+            <if test="rework.responsiblePersonnel != null and rework.responsiblePersonnel != ''">
+                and r.responsible_personnel regexp #{rework.responsiblePersonnel}
+            </if>
+            <if test="rework.reworkType != null and rework.reworkType != ''">
+                and r.rework_type regexp #{rework.reworkType}
+            </if>
+            <if test="rework.reworkReason != null and rework.reworkReason != ''">
+                and r.rework_reason regexp #{rework.reworkReason}
+            </if>
+            <if test="rework.reworkArea != null and rework.reworkArea != ''">
+                and r.rework_area regexp #{rework.reworkArea}
+            </if>
+            <if test="rework.qualityInspector != null and rework.qualityInspector != ''">
+                and r.quality_inspector regexp #{rework.qualityInspector}
+            </if>
+            <if test="rework.reworkProcesses != null and rework.reworkProcesses != ''">
+                and r.rework_processes regexp #{rework.reworkProcesses}
+            </if>
+            <if test="rework.reviewer != null and rework.reviewer != ''">
+                and r.reviewer regexp #{rework.reviewer}
+            </if>
+        </where>
+         order by r.review_status,r.id desc limit #{offset},#{pageSize};
     </select>
 
+    <select id="SelectReworkPageTotal" >
+        select CEILING(count(zu.id)/#{pageSize}) as 'pageTotal',
+        count(zu.id) as 'total'
+        from (select r.id as id
+              from pp.rework r
+                       left join sd.order_detail od on r.order_id = od.order_id and r.order_sort = od.order_number
+                       left join sd.`order` o on r.order_id = o.order_id
+                        left join (select * from sd.order_glass_detail group by order_id,order_number) as ogd
+                                 on r.order_id = ogd.order_id and r.order_sort = ogd.order_number
+        <where>
+            date(r.create_time)>=#{startDate} and date(r.create_time) &lt;= #{endDate}
+            and o.create_order>0
+            <if test="rework.reworkId != null and rework.reworkId != ''">
+                and r.rework_id regexp #{rework.reworkId}
+            </if>
+            <if test="rework.reworkTeam != null and rework.reworkTeam != ''">
+                and r.rework_team regexp #{rework.reworkTeam}
+            </if>
+            <if test="rework.orderId != null and rework.orderId != ''">
+                and r.order_id regexp #{rework.orderId}
+            </if>
+            <if test="rework.reportingWorkId != null and rework.reportingWorkId != ''">
+                and r.reporting_work_id regexp #{rework.reportingWorkId}
+            </if>
+            <if test="rework.processId != null and rework.processId != ''">
+                and r.process_id regexp #{rework.processId}
+            </if>
+            <if test="rework.project != null and rework.project != ''">
+                and o.project regexp #{rework.project}
+            </if>
+            <if test="rework.batch != null and rework.batch != ''">
+                and o.batch regexp #{rework.batch}
+            </if>
+            <if test="rework.orderSort != null and rework.orderSort != ''">
+                and r.order_sort regexp #{rework.orderSort}
+            </if>
+            <if test="rework.buildingNumber != null and rework.buildingNumber != ''">
+                and od.building_number regexp #{rework.buildingNumber}
+            </if>
+            <if test="rework.productName != null and rework.productName != ''">
+                and od.product_name regexp #{rework.productName}
+            </if>
+            <if test="rework.technologyNumber != null and rework.technologyNumber != ''">
+                and r.technology_number regexp #{rework.technologyNumber}
+            </if>
+            <if test="rework.qualityInspector != null and rework.qualityInspector != ''">
+                and r.quality_inspector regexp #{rework.qualityInspector}
+            </if>
+            <if test="rework.width != null and rework.width != ''">
+                and od.width regexp #{rework.width}
+            </if>
+            <if test="rework.height != null and rework.height != ''">
+                and od.height regexp #{rework.height}
+            </if>
+            <if test="rework.shape != null and rework.shape != ''">
+                and od.shape regexp #{rework.shape}
+            </if>
+            <if test="rework.reworkNum != null and rework.reworkNum != ''">
+                and r.rework_num regexp #{rework.reworkNum}
+            </if>
+            <if test="rework.glassAddress != null and rework.glassAddress != ''">
+                and ogd.glass_address regexp #{rework.glassAddress}
+            </if>
+            <if test="rework.responsibleTeam != null and rework.responsibleTeam != ''">
+                and r.responsible_team regexp #{rework.responsibleTeam}
+            </if>
+            <if test="rework.responsibleEquipment != null and rework.responsibleEquipment != ''">
+                and r.responsible_equipment regexp #{rework.responsibleEquipment}
+            </if>
+            <if test="rework.responsiblePersonnel != null and rework.responsiblePersonnel != ''">
+                and r.responsible_personnel regexp #{rework.responsiblePersonnel}
+            </if>
+            <if test="rework.reworkType != null and rework.reworkType != ''">
+                and r.rework_type regexp #{rework.reworkType}
+            </if>
+            <if test="rework.reworkReason != null and rework.reworkReason != ''">
+                and r.rework_reason regexp #{rework.reworkReason}
+            </if>
+            <if test="rework.reworkArea != null and rework.reworkArea != ''">
+                and r.rework_area regexp #{rework.reworkArea}
+            </if>
+            <if test="rework.qualityInspector != null and rework.qualityInspector != ''">
+                and r.quality_inspector regexp #{rework.qualityInspector}
+            </if>
+            <if test="rework.reworkProcesses != null and rework.reworkProcesses != ''">
+                and r.rework_processes regexp #{rework.reworkProcesses}
+            </if>
+            <if test="rework.reviewer != null and rework.reviewer != ''">
+                and r.reviewer regexp #{rework.reviewer}
+            </if>
+        </where>
+        ) as zu;
+    </select>
+
+    <select id="getSelectRework">
+        select o.order_id as orderId,
+               dd.reporting_work_id as reportingWorkId,
+               rw.process_id as processId,
+               o.project,
+               o.batch,
+               dd.id as reviewer,
+               dd.order_number as orderSort,
+               od.product_name as productName,
+               dd.technology_number as technologyNumber,
+               ogd.glass_address as glassAddress,
+               dd.breakage_quantity-dd.quantity as reworkNum,
+               od.width,
+               od.height,
+               od.shape,
+               dd.breakage_quantity-dd.quantity as breakageQuantity,
+               dd.return_process as reworkProcesses,
+               dd.breakage_reason as reworkReason,
+               dd.breakage_type as reworkType,
+               dd.responsible_personnel as responsiblePersonnel,
+               dd.responsible_equipment as responsibleEquipment,
+               dd.responsible_team as responsibleTeam,
+               ROUND((dd.breakage_quantity-dd.quantity) * od.width * od.height / 1000000, 2) as reworkArea,
+               rw.quality_inspector as qualityInspector
+        from pp.damage_details dd
+                 left join	pp.reporting_work_detail rwd on dd.reporting_work_id = rwd.reporting_work_id and dd.order_number=rwd.order_number
+                                                               and dd.technology_number=rwd.technology_number and rwd.review_status>0
+                 left join pp.reporting_work rw on dd.reporting_work_id = rw.reporting_work_id
+
+                 left join sd.`order` o on rw.order_id = o.order_id
+                 left join sd.order_detail od on rw.order_id = od.order_id and dd.order_number = od.order_number
+                 left join (select * from sd.order_glass_detail group by order_id,order_number) as ogd
+                           on rw.order_id = ogd.order_id and dd.order_number = ogd.order_number
+
+        where  dd.breakage_quantity-dd.quantity>0 and dd.available=1 and o.create_order>0 and  rw.reviewed_state>=0
+        order by dd.id desc
+    </select>
+
+
+    <select id="getMaximum" >
+        select count(*) from pp.rework where  date(create_time)=CURDATE()
+    </select>
+
+    <select id="getMaxFlowCard" >
+        select count(*) from pp.flow_card where project_no=#{processId}
+    </select>
+
+    <insert id="insertRework"  useGeneratedKeys="true" >
+        insert into pp.rework(rework_id,reporting_work_id,process_id,order_id, order_sort, technology_number, responsible_team,
+                              responsible_personnel, rework_type, rework_reason, rework_processes, rework_num,
+                              rework_area, rework_team,responsible_equipment,quality_inspector, reviewer, review_status, create_time)
+        values (
+                   #{oddNumber}, #{rework.reportingWorkId},#{rework.processId},#{rework.orderId},#{rework.orderSort},#{rework.technologyNumber},#{rework.responsibleTeam},
+                #{rework.responsiblePersonnel},#{rework.reworkType},#{rework.reworkReason},#{rework.reworkProcesses},#{rework.reworkNum},
+                #{rework.reworkArea},#{rework.reworkTeam},#{rework.responsibleEquipment},#{rework.qualityInspector},'',0,now()
+               )
+    </insert>
+
+    <update id="updateRework"  >
+        update pp.rework set reviewer=#{userName},review_status=1,update_time=now() where id=#{rework.id}
+    </update>
+
+    <update id="updateDamageDetails"  >
+        update pp.damage_details set quantity=quantity+#{rework.reworkNum} where id=#{rework.reviewer}
+    </update>
+
+    <delete id="deleteReworkMp">
+        delete from pp.rework where rework_id=#{patchId}
+    </delete>
+
+    <update id="updateReworkDdMp">
+        update pp.damage_details set patch_status=0,quantity=quantity-#{reworkNum}
+        where reporting_work_id=#{reportingWorkId} and order_number=#{orderSort} and technology_number=#{technologyNumber}
+    </update>
+
+    <update id="updateReworkBgMp">
+        update pp.reporting_work_detail set patch_status=0
+        where reporting_work_id=#{reportingWorkId} and order_number=#{orderSort} and technology_number=#{technologyNumber}
+    </update>
+
+
 
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0