From 642e72cfc130d1871d959552d791ecab52493949 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期一, 09 十二月 2024 02:19:33 +0800
Subject: [PATCH] mysql online拆分

---
 ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml |   66 ++++++++++++++++++++-------------
 1 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml
index 3fd35dc..d522659 100644
--- a/ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml
+++ b/ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml
@@ -98,7 +98,12 @@
 
     <select id="selectTMonitorList" resultType="com.ycl.platform.domain.vo.TMonitorVO">
         select m.id, m.serial_number, name, site_type, mac_addr, ip, camera_fun_type, longitude, latitude,
-        camera_capture_area, p.online as onState, civil_code, d.dept_id, d.dept_name, d.area, p.province_tag_video,p.province_tag_car,p.province_tag_face,p.dept_tag,
+        camera_capture_area,
+        CASE
+        WHEN p.online = 1 AND p.ping_online = 1 THEN 1
+        WHEN p.online = -1 OR p.ping_online = -1 THEN -1
+        ELSE 0
+        END AS onState, civil_code, d.dept_id, d.dept_name, d.area, p.province_tag_video,p.province_tag_car,p.province_tag_face,p.dept_tag,
         IF(COUNT(w.id) OVER() > 0, '鏄�', '鍚�') AS error, u.unit_name,p.recovery_time,p.reason,p.start_time,p.end_time, w.work_order_no
         from t_monitor m
         left join t_yw_point p on m.serial_number = p.serial_number and p.deleted = 0
@@ -136,7 +141,9 @@
                 #{cameraCaptureArea}
             </if>
             <if test="time !=null and time !=''">and TIMESTAMPDIFF(DAY, p.recovery_time, NOW()) <![CDATA[<=]]> #{time}</if>
-            <if test="onState != null ">and p.online = #{onState}</if>
+            <if test="onState != null and onState = 1">and (p.online = #{onState} and p.ping_online = #{onState})</if>
+            <if test="onState != null and onState = -1">and (p.online = #{onState} or p.ping_online = #{onState})</if>
+            <if test="onState != null and onState = 0">and (p.online = #{onState} and p.ping_online = #{onState})</if>
             <if test="civilCode != null  and civilCode != ''">and civil_code = #{civilCode}</if>
             <if test="integratedDevice != null ">and integrated_device = #{integratedDevice}</if>
             <if test="cameraBrand != null ">and camera_brand = #{cameraBrand}</if>
@@ -163,7 +170,12 @@
     </select>
 
     <select id="exportTMonitorList" resultType="com.ycl.platform.domain.excel.TMonitorExp">
-        select m.id, m.serial_number, name, ip, camera_fun_type,p.online as onState,
+        select m.id, m.serial_number, name, ip, camera_fun_type,
+        CASE
+        WHEN p.online = 1 AND p.ping_online = 1 THEN 1
+        WHEN p.online = -1 OR p.ping_online = -1 THEN -1
+        ELSE 0
+        END AS onState,
         d.dept_name, p.id as pointId,p.province_tag_video,p.province_tag_car,p.province_tag_face,p.dept_tag,p.important_tag,p.important_command_image_tag,u.unit_name as managementUnit
         from t_monitor m
         left join t_yw_point p on m.serial_number = p.serial_number and p.deleted = 0
@@ -185,7 +197,9 @@
             <if test="cameraFunType != null  and cameraFunType != ''">and camera_fun_type like concat('%',
                 #{cameraFunType}, '%')
             </if>
-            <if test="onState != null ">and p.online = #{onState}</if>
+            <if test="onState != null and onState = 1">and (p.online = #{onState} and p.ping_online = #{onState})</if>
+            <if test="onState != null and onState = -1">and (p.online = #{onState} or p.ping_online = #{onState})</if>
+            <if test="onState != null and onState = 0">and (p.online = #{onState} and p.ping_online = #{onState})</if>
             <if test="civilCode != null  and civilCode != ''">and civil_code = #{civilCode}</if>
         </where>
     </select>
@@ -377,10 +391,10 @@
     </delete>
     <select id="getVideoCount" resultType="java.util.Map">
         SELECT count(*) AS totalPosts,
-        IFNULL(SUM(IF(p.online = 1, 1, 0)), 0) AS totalMembers,
-        IFNULL(SUM(IF(p.online = -1, 1, 0)), 0) AS postsPercentage,
-        IFNULL(SUM(IF(p.online = 0, 1, 0)), 0) AS unknownNumbers,
-        IFNULL(ROUND(SUM(IF(p.online = 1 , 1, 0)) / count(*) * 100, 2), 0) as viewsPercentage
+        IFNULL(SUM(IF((p.online = 1 and p.ping_online = 1), 1, 0)), 0) AS totalMembers,
+        IFNULL(SUM(IF((p.online = -1 or p.ping_online = -1), 1, 0)), 0) AS postsPercentage,
+        IFNULL(SUM(IF((p.online = 0 and p.ping_online = 0), 1, 0)), 0) AS unknownNumbers,
+        IFNULL(ROUND(SUM(IF((p.online = 1 and p.online= 1), 1, 0)) / count(*) * 100, 2), 0) as viewsPercentage
         FROM t_monitor m
         left join t_yw_point p on m.serial_number = p.serial_number
         left join sys_dept d on p.dept_id = d.dept_id and d.del_flag = 0
@@ -404,10 +418,10 @@
 
     <select id="recoveryException" resultType="java.util.Map">
         SELECT count(*) AS totalPosts,
-        IFNULL(SUM(IF(p.online = 1, 1, 0)), 0) AS totalMembers,
-        IFNULL(SUM(IF(p.online = -1, 1, 0)), 0) AS postsPercentage,
-        IFNULL(SUM(IF(p.online = 0, 1, 0)), 0) AS unknownNumbers,
-        IFNULL(ROUND(SUM(IF(p.online = 1 , 1, 0)) / count(*) * 100, 2), 0) as viewsPercentage
+        IFNULL(SUM(IF((p.online = 1 and p.ping_online = 1), 1, 0)), 0) AS totalMembers,
+        IFNULL(SUM(IF((p.online = -1 or p.ping_online = -1), 1, 0)), 0) AS postsPercentage,
+        IFNULL(SUM(IF((p.online = 0 and p.ping_online = 0), 1, 0)), 0) AS unknownNumbers,
+        IFNULL(ROUND(SUM(IF((p.online = 1 and p.ping_online = 1), 1, 0)) / count(*) * 100, 2), 0) as viewsPercentage
         FROM t_monitor m
         left join t_yw_point p on m.serial_number = p.serial_number
         left join sys_dept d on p.dept_id = d.dept_id and d.del_flag = 0
@@ -490,8 +504,8 @@
             COUNT(p3.id)  AS normalNum
         FROM t_monitor
         LEFT JOIN t_yw_point p1 ON t_monitor.serial_number = p1.serial_number AND p1.examine_status = 1<if test="dataScope == 1"> AND p1.province_tag_video = 1 </if><if test="dataScope == 3"> AND p1.dept_tag = 1 </if><if test="deptId != null"> AND p1.dept_id = #{deptId} </if>
-        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number  AND p2.examine_status = 1 AND p2.online = -1 AND p1.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_video = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if><if test="deptId != null"> AND p2.dept_id = #{deptId} </if>
-        LEFT JOIN t_yw_point p3 ON t_monitor.serial_number = p3.serial_number  AND p3.examine_status = 1 AND p3.online = 1  AND p1.id = p3.id<if test="dataScope == 1"> AND p3.province_tag_video = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if><if test="deptId != null"> AND p3.dept_id = #{deptId} </if>
+        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number  AND p2.examine_status = 1 AND (p2.online = -1 OR p2.ping_online = -1) AND p1.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_video = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if><if test="deptId != null"> AND p2.dept_id = #{deptId} </if>
+        LEFT JOIN t_yw_point p3 ON t_monitor.serial_number = p3.serial_number  AND p3.examine_status = 1 AND (p3.online = 1 AND p3.ping_online = 1 ) AND p1.id = p3.id<if test="dataScope == 1"> AND p3.province_tag_video = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if><if test="deptId != null"> AND p3.dept_id = #{deptId} </if>
         WHERE INSTR(camera_fun_type, 1)
         UNION ALL
         SELECT
@@ -501,8 +515,8 @@
             COUNT(p3.id) AS normalNum
         FROM t_monitor
         LEFT JOIN t_yw_point p1 ON t_monitor.serial_number = p1.serial_number AND p1.examine_status = 1 <if test="dataScope == 1"> AND p1.province_tag_car = 1 </if><if test="dataScope == 3"> AND p1.dept_tag = 1 </if><if test="deptId != null"> AND p1.dept_id = #{deptId} </if>
-        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number AND p2.examine_status = 1 AND p2.online = -1 AND p1.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_car = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if><if test="deptId != null"> AND p2.dept_id = #{deptId} </if>
-        LEFT JOIN t_yw_point p3 ON t_monitor.serial_number = p3.serial_number  AND p3.examine_status = 1 AND p3.online = 1 AND p1.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_car = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if><if test="deptId != null"> AND p3.dept_id = #{deptId} </if>
+        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number AND p2.examine_status = 1 AND (p2.online = -1 OR p2.ping_online = -1) AND p1.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_car = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if><if test="deptId != null"> AND p2.dept_id = #{deptId} </if>
+        LEFT JOIN t_yw_point p3 ON t_monitor.serial_number = p3.serial_number  AND p3.examine_status = 1 AND (p3.online = 1 AND p3.ping_online = 1 ) AND p1.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_car = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if><if test="deptId != null"> AND p3.dept_id = #{deptId} </if>
         WHERE INSTR(camera_fun_type, 2)
         UNION ALL
         SELECT
@@ -512,8 +526,8 @@
             COUNT(p3.id) AS normalNum
         FROM t_monitor
         LEFT JOIN t_yw_point p1 ON t_monitor.serial_number = p1.serial_number  AND p1.examine_status = 1 <if test="dataScope == 1"> AND p1.province_tag_face = 1 </if><if test="dataScope == 3"> AND p1.dept_tag = 1 </if><if test="deptId != null"> AND p1.dept_id = #{deptId} </if>
-        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number  AND p2.examine_status = 1 AND p2.online = -1 AND p1.id = p2.id<if test="dataScope == 1"> AND p2.province_tag_face = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if><if test="deptId != null"> AND p2.dept_id = #{deptId} </if>
-        LEFT JOIN t_yw_point p3 ON t_monitor.serial_number = p3.serial_number  AND p3.examine_status = 1 AND p3.online = 1  AND p1.id = p3.id<if test="dataScope == 1"> AND p3.province_tag_face = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if><if test="deptId != null"> AND p3.dept_id = #{deptId} </if>
+        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number  AND p2.examine_status = 1 AND (p2.online = -1 OR p2.ping_online = -1) AND p1.id = p2.id<if test="dataScope == 1"> AND p2.province_tag_face = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if><if test="deptId != null"> AND p2.dept_id = #{deptId} </if>
+        LEFT JOIN t_yw_point p3 ON t_monitor.serial_number = p3.serial_number  AND p3.examine_status = 1 AND (p3.online = 1 AND p3.ping_online = 1 ) AND p1.id = p3.id<if test="dataScope == 1"> AND p3.province_tag_face = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if><if test="deptId != null"> AND p3.dept_id = #{deptId} </if>
         WHERE INSTR(camera_fun_type, 3)
     </select>
     <select id="monitorRate" resultType="com.ycl.platform.domain.vo.screen.MonitorRateVO">
@@ -530,8 +544,8 @@
                 FROM
                     sys_dept d
                         LEFT JOIN t_yw_point p ON p.dept_id = d.dept_id AND p.deleted = 0  AND p.examine_status = 1 <if test="dataScope == 1"> AND p.province_tag_face = 1 </if><if test="dataScope == 3"> AND p.dept_tag = 1 </if>
-                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.online = -1 AND p2.examine_status = 1 AND p.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_face = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if>
-                        LEFT JOIN t_yw_point p3 ON p3.dept_id = d.dept_id AND p3.deleted = 0 AND p3.online = 1 AND p3.examine_status = 1 AND p.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_face = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if>
+                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND (p2.online = -1 OR p2.ping_online = -1) AND p2.examine_status = 1 AND p.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_face = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if>
+                        LEFT JOIN t_yw_point p3 ON p3.dept_id = d.dept_id AND p3.deleted = 0 AND (p3.online = 1 AND p3.ping_online = 1 ) AND p.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_face = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if>
                         LEFT JOIN t_monitor m ON m.serial_number = p.serial_number AND INSTR(m.camera_fun_type, 3)
                         LEFT JOIN t_monitor m2 ON m2.serial_number = p2.serial_number AND INSTR(m2.camera_fun_type, 3)
                         LEFT JOIN t_monitor m3 ON m3.serial_number = p3.serial_number AND INSTR(m3.camera_fun_type, 3)
@@ -550,8 +564,8 @@
                 FROM
                     sys_dept d
                         LEFT JOIN t_yw_point p ON p.dept_id = d.dept_id AND p.deleted = 0 AND p.examine_status = 1 <if test="dataScope == 1"> AND p.province_tag_car = 1 </if><if test="dataScope == 3"> AND p.dept_tag = 1 </if>
-                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.examine_status = 1 AND p2.online = -1 AND p.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_car = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if>
-                        LEFT JOIN t_yw_point p3 ON p3.dept_id = d.dept_id AND p3.deleted = 0 AND p3.examine_status = 1 AND p3.online = 1 AND p.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_car = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if>
+                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.examine_status = 1 AND (p2.online = -1 OR p2.ping_online = -1)  AND p.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_car = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if>
+                        LEFT JOIN t_yw_point p3 ON p3.dept_id = d.dept_id AND p3.deleted = 0 AND p3.examine_status = 1 AND (p3.online = 1 AND p3.ping_online = 1 ) AND p.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_car = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if>
                         LEFT JOIN t_monitor m ON m.serial_number = p.serial_number AND INSTR(m.camera_fun_type, 2)
                         LEFT JOIN t_monitor m2 ON m2.serial_number = p2.serial_number AND INSTR(m2.camera_fun_type, 2)
                         LEFT JOIN t_monitor m3 ON m3.serial_number = p3.serial_number AND INSTR(m3.camera_fun_type, 2)
@@ -570,8 +584,8 @@
                 FROM
                     sys_dept d
                         LEFT JOIN t_yw_point p ON p.dept_id = d.dept_id AND p.deleted = 0 AND p.examine_status = 1 <if test="dataScope == 1"> AND p.province_tag_video = 1 </if><if test="dataScope == 3"> AND p.dept_tag = 1 </if>
-                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.examine_status = 1 AND p2.online = -1 AND p.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_video = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if>
-                        LEFT JOIN t_yw_point p3 ON p3.dept_id = d.dept_id AND p3.deleted = 0 AND p3.examine_status = 1 AND p3.online = 1 AND p.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_video  = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if>
+                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.examine_status = 1 AND (p2.online = -1 OR p2.ping_online = -1)  AND p.id = p2.id <if test="dataScope == 1"> AND p2.province_tag_video = 1 </if><if test="dataScope == 3"> AND p2.dept_tag = 1 </if>
+                        LEFT JOIN t_yw_point p3 ON p3.dept_id = d.dept_id AND p3.deleted = 0 AND p3.examine_status = 1 AND (p3.online = 1 AND p3.ping_online = 1 ) AND p.id = p3.id <if test="dataScope == 1"> AND p3.province_tag_video  = 1 </if><if test="dataScope == 3"> AND p3.dept_tag = 1 </if>
                         LEFT JOIN t_monitor m ON m.serial_number = p.serial_number AND INSTR(m.camera_fun_type, 1)
                         LEFT JOIN t_monitor m2 ON m2.serial_number = p2.serial_number AND INSTR(m2.camera_fun_type, 1)
                         LEFT JOIN t_monitor m3 ON m3.serial_number = p3.serial_number AND INSTR(m3.camera_fun_type, 1)
@@ -650,7 +664,7 @@
         where p.online != 0 and p.examine_status = 1
     </select>
 
-    <update id="updateOnline">
+    <update id="updateOnlineFromUyOrHk">
         <foreach collection="onlineList" item="online" separator=";">
             UPDATE
             t_yw_point
@@ -668,7 +682,7 @@
             t_yw_point p
             LEFT JOIN t_monitor m on p.serial_number = m.serial_number
             SET
-            p.online = #{online},
+            p.ping_online = #{online},
             p.update_time = #{date}
             WHERE m.ip in
             <foreach collection="ipList" open="(" close=")" separator="," item="ip">

--
Gitblit v1.8.0