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
<?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.equipment.OrgGridMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ycl.entity.equipment.OrgGrid">
        <id column="id" property="id" />
        <result column="worker" property="worker" />
        <result column="contact" property="contact" />
        <result column="area" property="area" />
        <result column="region" property="region" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, worker, contact, area, region
    </sql>
    <select id="statisticsGridMap" resultType="com.ycl.vo.cockpit.statisticsEvents.GridMapVO">
        SELECT
            *
        FROM
            (
                SELECT
                    og.id,
                    og.`name`,
                    og.region,
                    COUNT( DISTINCT v.id ) eventCount ,
                    sum(case WHEN v.video_point_id is not null then 1 else 0 END ) aiCount
                FROM
                    ums_org_grid og
                        LEFT JOIN ums_base_case bc ON og.id = bc.grid_id
                        LEFT JOIN ums_violations v ON v.id = bc.id
 
                    <if test="beginTime!=null">
                      and  bc.alarm_time BETWEEN #{beginTime} and #{endTime}
                    </if>
                GROUP BY
                    og.id,
                    og.`name`
            ) v_case
                LEFT JOIN ( SELECT grid_id, COUNT( id ) videoCount FROM ums_video_point GROUP BY grid_id ) AS v_video ON v_case.id = v_video.grid_id
    </select>
 
</mapper>