From 3c8f3a7b74f62a9053cd9d860d8f1d37454712eb Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: 星期一, 04 九月 2023 17:53:59 +0800
Subject: [PATCH] back

---
 src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml |  108 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 92 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml b/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml
index a2eb5b0..8292ab2 100644
--- a/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml
+++ b/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml
@@ -3,6 +3,7 @@
 <mapper namespace="com.gk.hotwork.Mapper.InspectionHiddenDangerMapper" >
      <update id="delByInspectionItemId">
        update inspection_hidden_danger set valid_flag = 0 , update_time = #{inspectionHiddenDanger.updateTime},update_by = #{inspectionHiddenDanger.updateBy}
+        where self_inspection_item_id = #{inspectionHiddenDanger.selfInspectionItemId}
      </update>
 
     <update id="delByIds">
@@ -16,31 +17,57 @@
 
     </update>
 
-    <select id="selectPages" resultType="com.gk.hotwork.Domain.SafetySelfInspection">
+    <select id="selectPages" resultType="com.gk.hotwork.Domain.SafetySelfInspectionDO">
         SELECT
-            s.*
+        l.*
         FROM
-            safety_self_inspection s
-            LEFT JOIN inspection_hidden_danger h ON s.id = h.self_inspection_id
-            left join company as co on s.checked_company_id = co.id
+        (
+        SELECT
+        t.*,
+        ( CASE WHEN t.unRectifyCount = t.hdTocalCount THEN - 1 WHEN t.rectifyCount = t.hdTocalCount THEN 2 ELSE 1 END ) rectificationStatus
+        FROM
+        (
+        SELECT
+        s.*,
+        count( h.`status` = - 1 OR NULL ) unRectifyCount,
+        count( h.`status` = 1 OR NULL ) rectifyCount,
+        count( h.`status` ) hdTocalCount,
+        count( h.LEVEL = 1 OR NULL ) sameAsCount,
+        count( h.LEVEL = 2 OR NULL ) majorCount
+        FROM
+        safety_self_inspection s
+        LEFT JOIN inspection_hidden_danger h ON s.id = h.self_inspection_id
         WHERE
-            s.valid_flag = 1
-          AND h.valid_flag = 1
-          AND h.id IS NOT NULL
+        s.valid_flag = 1
+        AND h.valid_flag = 1
+        AND h.id IS NOT NULL
+        GROUP BY
+        s.id
+        ) t
+        ) l
+        LEFT JOIN company AS co ON l.checked_company_id = co.id
+        WHERE
+        1 =1
         <if test="params.inspectionName != null  and params.inspectionName != ''">
-            and s.inspection_name like concat("%",#{params.inspectionName},"%")
+            and l.inspection_name like concat("%",#{params.inspectionName},"%")
+        </if>
+        <if test="params.checkedCompanyId != null and params.checkedCompanyId != ''">
+            and l.checked_company_id = #{params.checkedCompanyId}
         </if>
         <if test="params.checkedCompanyName != null and params.checkedCompanyName != ''">
-            and h.checked_company_name like concat("%",#{params.checkedCompanyName},"%")
+            and l.checked_company_name like concat("%",#{params.checkedCompanyName},"%")
         </if>
         <if test="params.flag != null  and params.flag != '' ">
-            and s.flag = #{params.flag}
+            and l.flag = #{params.flag}
+        </if>
+        <if test="params.rectificationStatus != null  and params.rectificationStatus != '' ">
+            and l.rectificationStatus = #{params.rectificationStatus}
         </if>
         <if test="params.inspectionStartTime != null and params.inspectionStartTime != ''" >
-            and s.inspection_time <![CDATA[ >= ]]> #{params.inspectionStartTime}
+            and l.inspection_time <![CDATA[ >= ]]> #{params.inspectionStartTime}
         </if>
         <if test="params.inspectionEndTime != null and params.inspectionEndTime != ''" >
-            and s.inspection_time <![CDATA[ <= ]]> #{params.inspectionEndTime}
+            and l.inspection_time <![CDATA[ <= ]]> #{params.inspectionEndTime}
         </if>
         <if test="params.province != null and params.province != ''" >
             and co.province = #{params.province}
@@ -51,9 +78,7 @@
         <if test="params.area != null and params.area != ''" >
             and co.area = #{params.area}
         </if>
-        GROUP BY
-            s.id
-        ORDER BY s.create_time
+        ORDER BY l.create_time desc
     </select>
     <select id="inspectionHdangerlist" resultType="com.gk.hotwork.Domain.InspectionHiddenDanger">
         SELECT
@@ -79,5 +104,56 @@
         and h.self_inspection_id = #{selfInspectionId}
     </select>
 
+    <select id="getStatisticHiddenDanger" resultType="com.gk.hotwork.Domain.Do.CompanyInspectionCountDO">
+        select
+            l.checked_company_id as companyId,
+            count(l.id) as checkTotal,
+            sum(l.unRectifyTotal) as sUnReTotal,
+            sum(l.reTotal) as sReTotal,
+            sum(l.hdTocal) as sHdTotal,
+            sum(l.saTotal) as sSaTotal,
+            sum(l.maTotal) as sMaTotal,
+            sum(l.saReTotal) as sSaReTotal,
+            sum(l.maReTotal) as sMaReTotal
+        from (
+                 SELECT
+                     s.id,
+                     s.checked_company_id,
+                     t.*
+                 FROM
+                     safety_self_inspection s
+                         INner JOIN company c on s.checked_company_id = c.id
+                         LEFT JOIN (
+                         SELECT
+                             h.self_Inspection_id,
+                             count( h.`status` = - 1 OR NULL ) unRectifyTotal,
+                             count( h.`status` = 1 OR NULL ) reTotal,
+                             count( h.`status` ) hdTocal,
+                             count( h.LEVEL = 1 OR NULL ) saTotal,
+                             count( h.LEVEL = 2 OR NULL ) maTotal,
+                             count( h.LEVEL = 1 AND h.`status` = 1 OR NULL ) saReTotal,
+                             count( h.LEVEL = 2 AND h.`status` = 1 OR NULL ) maReTotal
+                         FROM
+                             inspection_hidden_danger h
+                         WHERE
+                             h.valid_flag = 1
+                         GROUP BY
+                             h.self_Inspection_id
+                     ) t ON t.self_Inspection_id = s.id
+                 WHERE
+                        s.valid_flag = 1
+                        and s.flag = 2
+                    <if test="query.startTime != null" >
+                        and s.inspection_time <![CDATA[ >= ]]> #{query.startTime}
+                    </if>
+                    <if test="query.endTime != null" >
+                        and s.inspection_time <![CDATA[ <= ]]> #{query.endTime}
+                    </if>
+                    <if test="query.area != null and query.area != ''" >
+                        and c.area = #{query.area}
+                    </if>
+             ) l
+        GROUP BY l.checked_company_id
+    </select>
 
 </mapper>

--
Gitblit v1.9.2