From b69ca5e06f8f5c56f8b1270370a81bcecf57bfe7 Mon Sep 17 00:00:00 2001
From: 叶松 <2217086471@qq.com>
Date: 星期四, 30 十一月 2023 14:07:24 +0800
Subject: [PATCH] Merge branch 'master' of http://111.30.93.211:10101/r/supipe

---
 hd/pipe/secure/src/main/resources/mapping/RegionInspectionRecordMapper.xml |  131 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 105 insertions(+), 26 deletions(-)

diff --git a/hd/pipe/secure/src/main/resources/mapping/RegionInspectionRecordMapper.xml b/hd/pipe/secure/src/main/resources/mapping/RegionInspectionRecordMapper.xml
index 988783d..741dde0 100644
--- a/hd/pipe/secure/src/main/resources/mapping/RegionInspectionRecordMapper.xml
+++ b/hd/pipe/secure/src/main/resources/mapping/RegionInspectionRecordMapper.xml
@@ -3,7 +3,7 @@
 <mapper namespace="com.thhy.secure.modules.biz.regionInspection.mapper.RegionInspectionRecordMapper">
 
     <insert id="insertIMG">
-        insert into t_region_inspection_record
+        insert into t_region_inspection_record_img
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="id != null">
                 id,
@@ -153,11 +153,17 @@
     <delete id="delete">
         delete from t_region_inspection_record where  id=#{id,jdbcType=VARCHAR}
     </delete>
+    <delete id="deleteIMG">
+        delete from t_region_inspection_record_img where  regionInspectionRecordId=#{regionInspectionRecordId,jdbcType=VARCHAR}
+    </delete>
 
     <delete id="deleteByRegionInspectionId">
         delete from t_region_inspection_record where  regionInspectionId=#{regionInspectionId,jdbcType=VARCHAR}
     </delete>
 
+    <select id="selectImgByRecordId" resultType="com.thhy.secure.modules.biz.regionInspection.entity.RegionInspectionRecordImgEntity">
+        select * from t_region_inspection_record_img where regionInspectionRecordId = #{regionInspectionRecordId}
+    </select>
     <select id="selectPageList" resultType="com.thhy.secure.modules.biz.regionInspection.entity.RegionInspectionRecordEntity">
         SELECT  a.userId,
                 a.regionInspectionId,
@@ -165,7 +171,7 @@
                 a.task,
                 a.region,
                 a.realName,
-                IF(a.completeRegionNum = a.needRegionNum,"完成","未完成") statusName,
+                IF(a.completeRegionNum = a.needRegionNum,"已完成","待巡检") statusName,
                 IF(a.completeRegionNum = a.needRegionNum,1,0) status
         FROM (
                      SELECT
@@ -193,21 +199,67 @@
                         <if test="regionInspectionId !=null and regionInspectionId !=''">
                             and t.regionInspectionId = #{regionInspectionId}
                         </if>
+                        <if test="userId !=null and userId !=''">
+                            and t.userId = #{userId}
+                        </if>
+                        <if test="startTime != null and endTime != null and startTime !='' and endTime != ''">
+                            and t.inspectionTime BETWEEN str_to_date(#{startTime}, "%Y-%m-%d %H:%i:%s") and str_to_date(#{endTime}, "%Y-%m-%d %H:%i:%s")
+                        </if>
+
         GROUP BY t.regionInspectionId,t.userId
                      )a
-
         WHERE 1=1
-        <if test="status !=null and status !='' and status ==0">
+        <if test="intStatus!=null and intStatus ==0">
             and a.completeRegionNum != a.needRegionNum
         </if>
-        <if test="status !=null and status !='' and status ==1">
+        <if test="intStatus!=null and intStatus ==1">
             and a.completeRegionNum = a.needRegionNum
         </if>
-        <if test="startTime != null and endTime != null and startTime !='' and endTime != ''">
-            and a.inspectionTime BETWEEN #{startTime} and #{endTime}
+        <if test="page != null and limit != null">
+            limit #{page},#{limit}
         </if>
     </select>
-
+    <select id="selectCount" resultType="java.lang.Integer">
+        SELECT  count(0)
+        FROM (
+                SELECT
+                    t.userId ,
+                    t.regionInspectionId,
+                    MIN(t.inspectionTime) inspectionTime,
+                    tri.task task,
+                    GROUP_CONCAT(DISTINCT trhi.region) region,
+                    spu.real_name realName,
+                    SUM(t.`status`)/(SELECT count(regionInspectionId) FROM t_region_inspection_hazard_inform WHERE regionInspectionId =  t.regionInspectionId) completeRegionNum,
+                    (SELECT count(regionInspectionId) FROM t_region_inspection_hazard_inform WHERE regionInspectionId =  t.regionInspectionId) needRegionNum
+                from
+                t_region_inspection_record t
+                LEFT JOIN t_region_inspection tri on tri.id = t.regionInspectionId
+                LEFT JOIN t_region_inspection_hazard_inform trihi on trihi.regionInspectionId = t.regionInspectionId
+                LEFT JOIN t_region_hazard_inform trhi on trhi.id = trihi.regionHazardInformId
+                LEFT JOIN sys_plat_user spu on spu.user_id = t.userId
+                WHERE 1=1
+                <if test="realName !=null and realName !=''">
+                    and spu.real_name REGEXP #{realName}
+                </if>
+                <if test="companyId !=null and companyId !=''">
+                    and tri.companyId = #{companyId}
+                </if>
+                <if test="regionInspectionId !=null and regionInspectionId !=''">
+                    and t.regionInspectionId = #{regionInspectionId}
+                </if>
+                <if test="startTime != null and endTime != null and startTime !='' and endTime != ''">
+                    and t.inspectionTime BETWEEN str_to_date(#{startTime}, "%Y-%m-%d %H:%i:%s") and str_to_date(#{endTime}, "%Y-%m-%d %H:%i:%s")
+                </if>
+                GROUP BY t.regionInspectionId,t.userId
+        )a
+        WHERE 1=1
+        <if test="intStatus!=null and intStatus ==0">
+            and a.completeRegionNum != a.needRegionNum
+        </if>
+        <if test="intStatus!=null and intStatus ==1">
+            and a.completeRegionNum = a.needRegionNum
+        </if>
+    </select>
     <select id="selectInfo" resultType="com.thhy.secure.modules.biz.regionInspection.entity.RegionInspectionEntity">
         SELECT
                 t.id regionInspectionId,
@@ -228,6 +280,7 @@
 
     <select id="regionInfo" resultType="com.thhy.secure.modules.biz.regionInspection.entity.RegionInspectionRecordEntity">
         SELECT
+                t.id,
                 t.userId,
                 t.regionInspectionId,
                 t.regionHazardInformId,
@@ -236,7 +289,8 @@
                 t.result result,
                 GROUP_CONCAT(timg.imgPath) imgPaths,
                 t.location,
-                spu.real_name realName
+                spu.real_name realName,
+                t.status
         FROM t_region_inspection_record t
                      LEFT JOIN t_region_inspection_record_img timg on t.id = timg.regionInspectionRecordId
                      LEFT JOIN t_region_hazard_inform rhi on rhi.id = t.regionHazardInformId
@@ -246,27 +300,52 @@
     </select>
 
     <select id="selectAppList" resultType="java.util.Map">
+        select * from (
         SELECT
-                a.id,
-                MIN( b.inspectionTime ) inspectionTime,
-                a.`status`,
-                a.task,
-                GROUP_CONCAT(DISTINCT d.region) region
-        FROM
-                t_region_inspection a
-                        LEFT JOIN t_region_inspection_record b ON b.regionInspectionId = a.id
-                        LEFT JOIN t_region_inspection_hazard_inform c ON c.regionInspectionId = a.id
-                        LEFT JOIN t_region_hazard_inform d ON c.regionHazardInformId = d.id
-                        LEFT JOIN t_region_inspection_user e on e.regionInspectionId = a.id
-        WHERE a.companyId = #{companyId} and  e.userId = #{userId}
-        <if test="status != null and status != ''">
-            and a.status = #{status}
+        tri.id,
+        t.userId ,
+        t.regionInspectionId,
+        MIN(t.inspectionTime) inspectionTime,
+        tri.task task,
+        GROUP_CONCAT(DISTINCT trhi.region) region,
+        spu.real_name realName,
+        if(
+        SUM(t.`status`)/(SELECT count(regionInspectionId) FROM t_region_inspection_hazard_inform WHERE
+        regionInspectionId = t.regionInspectionId)
+        =
+        (SELECT count(regionInspectionId) FROM t_region_inspection_hazard_inform WHERE regionInspectionId =
+        t.regionInspectionId)
+        ,1,0) status
+        from
+        t_region_inspection_record t
+        LEFT JOIN t_region_inspection tri on tri.id = t.regionInspectionId
+        LEFT JOIN t_region_inspection_hazard_inform trihi on trihi.regionInspectionId = t.regionInspectionId
+        LEFT JOIN t_region_hazard_inform trhi on trhi.id = trihi.regionHazardInformId
+        LEFT JOIN sys_plat_user spu on spu.user_id = t.userId
+        WHERE 1=1
+        <if test="userId != null and userId != ''">
+            and t.userId = #{userId}
         </if>
         <if test="startTime != null and endTime != null and startTime !='' and endTime != ''">
-            and b.inspectionTime BETWEEN #{startTime} and #{endTime}
+            and t.inspectionTime BETWEEN str_to_date(#{startTime}, "%Y-%m-%d %H:%i:%s") and str_to_date(#{endTime},
+            "%Y-%m-%d %H:%i:%s")
         </if>
-        GROUP BY
-                a.id
+        GROUP BY t.regionInspectionId,t.userId
+    ) entity where 1=1
+        <if test="status != null and status != ''">
+            and entity.status = #{status}
+        </if>
+
+    </select>
+
+    <select id="selectPlatUserId" resultType="java.lang.String">
+        SELECT
+            plat_id platId
+        FROM sys_users
+        WHERE user_id= #{userId,jdbcType=VARCHAR}
+    </select>
+    <select id="getPlatUser" resultType="java.util.Map">
+        SELECT * FROM sys_plat_user where user_id = #{userId}
     </select>
 
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3