fuliqi
2024-08-07 9b81ed8ec15cc4b3f46c7a630512a268b3a74d74
ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml
@@ -346,7 +346,102 @@
        <if test="dateRange != null and dateRange.size > 0">
            AND DATE_FORMAT(w.create_time, '%Y-%m') BETWEEN #{dateRange[0]} AND #{dateRange[1]}
        </if>
        GROUP BY months
        ORDER BY months
    </select>
    <select id="monitorTotal" resultType="com.ycl.platform.domain.vo.screen.MonitorTotalVO">
        SELECT
            '视频' as type,
            COUNT(p1.id) AS totalNum,
            COUNT(p2.id) AS errorNum,
            COUNT(p1.id) - COUNT(p2.id) AS normalNum
        FROM t_monitor
        LEFT JOIN t_yw_point p1 ON t_monitor.serial_number = p1.serial_number <if test="dataScope == 1"> AND p1.province_tag = 'province' </if>
        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number AND p2.recovery = 1 <if test="dataScope == 1"> AND p2.province_tag = 'province' </if>
        WHERE INSTR(camera_fun_type, 1)
        <if test="deptId != null"> AND p1.dept_id = #{deptId} AND p2.dept_id = #{deptId} </if>
        UNION ALL
        SELECT
            '车辆' as type,
            COUNT(p1.id) AS totalNum,
            COUNT(p2.id) AS errorNum,
            COUNT(p1.id) - COUNT(p2.id) AS normalNum
        FROM t_monitor
        LEFT JOIN t_yw_point p1 ON t_monitor.serial_number = p1.serial_number <if test="dataScope == 1"> AND p1.province_tag = 'province' </if>
        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number AND p2.recovery = 1 <if test="dataScope == 1"> AND p2.province_tag = 'province' </if>
        WHERE INSTR(camera_fun_type, 2)
        <if test="deptId != null"> AND p1.dept_id = #{deptId} AND p2.dept_id = #{deptId} </if>
        UNION ALL
        SELECT
            '人脸' as type,
            COUNT(p1.id) AS totalNum,
            COUNT(p2.id) AS errorNum,
            COUNT(p1.id) - COUNT(p2.id) AS normalNum
        FROM t_monitor
        LEFT JOIN t_yw_point p1 ON t_monitor.serial_number = p1.serial_number <if test="dataScope == 1"> AND p1.province_tag = 'province' </if>
        LEFT JOIN t_yw_point p2 ON t_monitor.serial_number = p2.serial_number AND p2.recovery = 1 <if test="dataScope == 1"> AND p2.province_tag = 'province' </if>
        WHERE INSTR(camera_fun_type, 3)
        <if test="deptId != null"> AND p1.dept_id = #{deptId} AND p2.dept_id = #{deptId} </if>
    </select>
    <select id="monitorRate" resultType="com.ycl.platform.domain.vo.screen.MonitorRateVO">
        SELECT
            *
        FROM
            -- 人脸设备
            (
                SELECT
                    d.area,
                    IFNULL(ROUND((COUNT(m.id) - COUNT(m2.id)) / COUNT(m.id) * 100, 2), 0) AS faceRate,
                    COUNT(m.id) - COUNT(m2.id) AS faceNormalNum,
                    COUNT(m2.id) AS faceErrorNum
                FROM
                    sys_dept d
                        LEFT JOIN t_yw_point p ON p.dept_id = d.dept_id AND p.deleted = 0 <if test="dataScope == 1"> AND p.province_tag = 'province' </if>
                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.recovery = 1 <if test="dataScope == 1"> AND p2.province_tag = 'province' </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)
                WHERE d.del_flag = 0 AND d.area IS NOT NULL
                GROUP BY d.area, d.dept_id
                ORDER BY d.dept_id
            ) a
        INNER JOIN
            -- 车辆设备
            (
                SELECT
                    d.area,
                    IFNULL(ROUND((COUNT(m.id) - COUNT(m2.id)) / COUNT(m.id) * 100, 2), 0) AS carRate,
                    COUNT(m.id) - COUNT(m2.id) AS carNormalNum,
                    COUNT(m2.id) AS carErrorNum
                FROM
                    sys_dept d
                        LEFT JOIN t_yw_point p ON p.dept_id = d.dept_id AND p.deleted = 0 <if test="dataScope == 1"> AND p.province_tag = 'province' </if>
                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.recovery = 1 <if test="dataScope == 1"> AND p2.province_tag = 'province' </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)
                WHERE d.del_flag = 0 AND d.area IS NOT NULL
                GROUP BY d.area, d.dept_id
                ORDER BY d.dept_id
            ) b ON a.area = b.area
        INNER JOIN
            -- 视频设备
            (
                SELECT
                    d.area,
                    IFNULL(ROUND((COUNT(m.id) - COUNT(m2.id)) / COUNT(m.id) * 100, 2), 0) AS videoRate,
                    COUNT(m.id) - COUNT(m2.id) AS videoNormalNum,
                    COUNT(m2.id) AS videoErrorNum
                FROM
                    sys_dept d
                        LEFT JOIN t_yw_point p ON p.dept_id = d.dept_id AND p.deleted = 0 <if test="dataScope == 1"> AND p.province_tag = 'province' </if>
                        LEFT JOIN t_yw_point p2 ON p2.dept_id = d.dept_id AND p2.deleted = 0 AND p2.recovery = 1 <if test="dataScope == 1"> AND p2.province_tag = 'province' </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)
                WHERE d.del_flag = 0 AND d.area IS NOT NULL
                GROUP BY d.area, d.dept_id
                ORDER BY d.dept_id
            ) c ON a.area = c.area
    </select>
</mapper>