zhanghua
2023-09-08 7ef4892f9f24f941aca37e6b3991b808a0aca619
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ycl.mapper.unlawful.UnlawfulMapper">
    <!--    获取总数-->
    <select id="getTotal" resultType="java.lang.Integer">
        SELECT count(*)
        FROM `ums_base_case` AS ubc
        JOIN ums_violations AS uv ON ubc.id = uv.id
        <if test="type==true">
            INNER JOIN ums_data_dictionary AS t4 ON uv.grade_id = t4.id
        </if>
        <if test="street==true">
            INNER JOIN ums_sccg_region r on ubc.street_id = r.id
        </if>
        <if test="video==true">
            INNER JOIN ums_video_point v on uv.video_point_id = v.id
        </if>
        WHERE ubc.category = 1
 
        <if test="startTime !='' and endTime !='' and startTime!=null and endTime !=null">
            and ubc.create_time between #{startTime} and #{endTime}
        </if>
    </select>
 
    <!--    按照违规类型统计-->
    <select id="getDataByType" resultType="com.ycl.dto.statistics.UnlawfulDto">
        SELECT
        t4.id id,
        t4.NAME name,
        COUNT(DISTINCT ubc.id) count,
        sum(case when ubc.state >4 then 1 ELSE 0 END ) register,
        sum(case when ubc.state =4 then 1 ELSE 0 END ) notRegister,
        sum(case when ubc.state =9 then 1 ELSE 0 END ) closing,
        sum(case when ubc.state =3 then 1 ELSE 0 END ) relearn,
        sum(case when ubc.state =8 then 1 ELSE 0 END ) checked
        FROM
        `ums_base_case` AS ubc
        JOIN ums_violations AS uv ON ubc.id = uv.id
        LEFT JOIN ums_data_dictionary AS t4 ON uv.grade_id = t4.id
        LEFT JOIN ums_sccg_region t5 ON ubc.street_id = t5.id
        WHERE
        ubc.category =1
        and t4.`name` is NOT NULL
        <if test="startTime !='' and endTime !='' and startTime!=null and endTime !=null">
            and ubc.create_time between #{startTime} and #{endTime}
        </if>
        group by t4.id
        ORDER BY t4.id
    </select>
 
    <!--    按照区域统计-->
    <select id="getDataByStreet" resultType="com.ycl.dto.statistics.UnlawfulDto">
        SELECT
        ubc.street_id id,
        t5.region_name name,
        COUNT( DISTINCT ubc.id ) count,
        sum( CASE WHEN ubc.state > 4 THEN 1 ELSE 0 END ) register,
        sum( CASE WHEN ubc.state = 4 THEN 1 ELSE 0 END ) notRegister,
        sum( CASE WHEN ubc.state = 9 THEN 1 ELSE 0 END ) closing,
        sum( CASE WHEN ubc.state = 3 THEN 1 ELSE 0 END ) relearn,
        sum( CASE WHEN ubc.state = 8 THEN 1 ELSE 0 END ) checked
        FROM
        `ums_base_case` AS ubc
        JOIN ums_violations AS uv ON ubc.id = uv.id
        LEFT JOIN ums_data_dictionary AS t3 ON uv.category_id = t3.id
        LEFT JOIN ums_data_dictionary AS t4 ON uv.type_id = t4.id
        LEFT JOIN ums_sccg_region t5 ON ubc.street_id = t5.id
        WHERE
        ubc.category = 1
        AND t5.region_name IS NOT NULL
        <if test="startTime !='' and endTime !='' and startTime!=null and endTime !=null">
            and ubc.create_time between #{startTime} and #{endTime}
        </if>
        GROUP BY ubc.street_id
        ORDER BY ubc.street_id
    </select>
 
    <!--    按照报警时间-->
    <select id="getDataByTime" resultType="com.ycl.dto.statistics.UnlawfulDto">
        SELECT
        DATE_FORMAT(ubc.alarm_time,'%Y-%m-%d') NAME,
        COUNT( DISTINCT ubc.id ) count,
        sum( CASE WHEN ubc.state > 4 THEN 1 ELSE 0 END ) register,
        sum( CASE WHEN ubc.state = 4 THEN 1 ELSE 0 END ) notRegister,
        sum( CASE WHEN ubc.state = 9 THEN 1 ELSE 0 END ) closing,
        sum( CASE WHEN ubc.state = 3 THEN 1 ELSE 0 END ) relearn,
        sum( CASE WHEN ubc.state = 8 THEN 1 ELSE 0 END ) checked
        FROM
        `ums_base_case` AS ubc
        JOIN ums_violations AS uv ON ubc.id = uv.id
        WHERE
        ubc.category = 1
        <if test="startTime !='' and endTime !='' and startTime!=null and endTime !=null">
            and ubc.alarm_time between #{startTime} and #{endTime}
        </if>
        GROUP BY
        DATE_FORMAT(ubc.alarm_time,'%Y-%m-%d')
        ORDER BY
        DATE_FORMAT(ubc.alarm_time,'%Y-%m-%d') desc
    </select>
 
    <select id="getDataByPoint" resultType="com.ycl.dto.statistics.UnlawfulDto">
        SELECT
        vp.id id,
        vp.NAME name,
        COUNT(DISTINCT ubc.id) count,
        sum(case when ubc.state >4 then 1 ELSE 0 END ) register,
        sum(case when ubc.state =4 then 1 ELSE 0 END ) notRegister,
        sum(case when ubc.state =9 then 1 ELSE 0 END ) closing,
        sum(case when ubc.state =3 then 1 ELSE 0 END ) relearn,
        sum(case when ubc.state =8 then 1 ELSE 0 END ) checked
        FROM
        `ums_base_case` AS ubc
        JOIN ums_violations AS uv ON ubc.id = uv.id
        LEFT JOIN ums_video_point vp ON uv.video_point_id = vp.id
        WHERE
        ubc.category =1
        and vp.`name` is NOT NULL
        <if test="startTime !='' and endTime !='' and startTime!=null and endTime !=null">
            and ubc.alarm_time between #{startTime} and #{endTime}
        </if>
        group by vp.id
        ORDER BY vp.id
    </select>
</mapper>