From 464fe41610a39c3a06f070d5a01c930134ff0163 Mon Sep 17 00:00:00 2001
From: zf <1603559716@qq.com>
Date: 星期三, 30 八月 2023 09:05:05 +0800
Subject: [PATCH] 检查统计

---
 src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml b/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml
index ec4215d..5122a01 100644
--- a/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml
+++ b/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml
@@ -62,5 +62,61 @@
     </if>
     order by a.create_time desc
   </select>
-
+  <select id="companyStatisticInspection" resultType="com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO">
+    SELECT
+      count( 1 ) checkCompanyCount,
+      sum( l.endCount ) endTotal,
+      sum( l.toDoCount ) toDoTotal,
+      sum( l.checkCount ) checkTotal,
+      sum( l.unRectifyCount ) unRectifyTotal,
+      sum( l.rectifyCount ) rectifyTotal,
+      sum( l.hdCount ) AS hdTotal
+    FROM
+      (
+        SELECT
+          s.checked_company_id,
+          count( s.`status` = 2 OR NULL ) endCount,
+          count( s.`status` = 1 OR NULL ) toDoCount,
+          count( 1 ) AS checkCount,
+          sum( t.unRectify ) AS unRectifyCount,
+          sum( t.rectify ) AS rectifyCount,
+          sum( t.hd ) AS hdCount
+        FROM
+          safety_self_inspection s
+            INNER JOIN company c ON c.id = s.checked_company_id
+            LEFT JOIN (
+            SELECT
+              h.self_Inspection_id,
+              count( h.`status` = - 1 OR NULL ) unRectify,
+              count( h.`status` = 1 OR NULL ) rectify,
+              count( 1 ) hd
+            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="params.startTime != null" >
+            and s.inspection_time <![CDATA[ >= ]]> #{params.startTime}
+          </if>
+          <if test="params.endTime != null " >
+            and s.inspection_time <![CDATA[ <= ]]> #{params.endTime}
+          </if>
+          <if test="params.province != null and params.province != ''" >
+            and c.province = #{params.province}
+          </if>
+          <if test="params.city != null and params.city != ''" >
+            and c.city = #{params.city}
+          </if>
+          <if test="params.area != null and params.area != ''" >
+            and c.area = #{params.area}
+          </if>
+        GROUP BY
+          s.checked_company_id
+      ) l
+  </select>
 </mapper>

--
Gitblit v1.9.2