puzhibing
2023-02-15 2811bab657aab4145b65a45a824fb63e93b58e30
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
<?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.stylefeng.guns.modular.system.dao.DriverActivityMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.DriverActivity">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="companyId" property="companyId" />
        <result column="insertTime" property="insertTime" />
        <result column="status" property="status" />
        <result column="remark" property="remark" />
        <result column="startTime" property="startTime" />
        <result column="endTime" property="endTime" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, companyId, insertTime, status, remark, startTime, endTime
    </sql>
    <select  id="getList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT
            a.*, IFNULL(o1.number, 0) + IFNULL(o2.number, 0) + IFNULL(o3.number, 0) number
        FROM
            t_driver_activity a
        LEFT JOIN (
            SELECT
                COUNT(h.id) number,
                o.driverActivityId
            FROM
                t_driver_activity_history h
            LEFT JOIN t_driver_activity_online o ON h.activityId = o.id
            WHERE
                h.type = 3
                AND h.carryOut=2
            GROUP BY
                o.driverActivityId
        ) o1 ON o1.driverActivityId = a.id
        LEFT JOIN (
            SELECT
                COUNT(h.id) number,
                o.driverActivityId
            FROM
                t_driver_activity_history h
            LEFT JOIN t_driver_activity_order o ON h.activityId = o.id
            WHERE
                h.type = 4
                AND h.carryOut=2
            GROUP BY
                o.driverActivityId
        ) o2 ON o2.driverActivityId = a.id
        LEFT JOIN (
            SELECT
                COUNT(h.id) number,
                o.driverActivityId
            FROM
                t_driver_activity_history h
            LEFT JOIN t_driver_activity_registered o ON h.activityId = o.id
            WHERE
                h.type != 3
            AND h.type != 4
            AND h.carryOut=2
            GROUP BY
                o.driverActivityId
        ) o3 ON o3.driverActivityId = a.id
        WHERE 1=1
        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
            and (a.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
        </if>
        <if test="name != null and name !=''">
            and a.name like CONCAT('%',#{name},'%')
        </if>
        <if test="companyType != null and companyType !='' and companyType!=1">
            and a.companyType=#{companyType}
        </if>
        <if test="companyId != null and companyId !='' and companyType!=1">
            and a.companyId=#{companyId}
        </if>
        order by a.id desc
    </select>
</mapper>