Pu Zhibing
2025-05-16 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
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
<?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.DriverActivityHistoryMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.DriverActivityHistory">
        <id column="id" property="id"/>
        <result column="day" property="day"/>
        <result column="driverId" property="driverId"/>
        <result column="type" property="type"/>
        <result column="activityId" property="activityId"/>
        <result column="carryOut" property="carryOut"/>
        <result column="money" property="money"/>
        <result column="insertTime" property="insertTime"/>
 
    </resultMap>
 
 
 
    <select id="query" resultType="map">
        select
        a.*,
        CASE WHEN b.num = 0 THEN 2 ELSE 1 END as carryOut
        from (
        select
        DATE_FORMAT(`day`, '%Y-%m-%d') as time,
        DATE_FORMAT(`day`, '%Y-%m-%d') as paramTime
        from t_driver_activity_history where driverId = #{driverId} group by `day`
        ) as a
        left join (select `day`, count(id) as num from t_driver_activity_history where driverId = #{driverId} and carryOut = 1 group by `day`) b on (a.time = b.`day`) order by a.time desc limit #{pageNum}, #{size}
    </select>
 
    <select id="queryList" resultType="DriverActivityHistory">
        select
        id as id,
        `day` as `day`,
        driverId as driverId,
        `type` as `type`,
        activityId as activityId,
        carryOut as carryOut,
        money as money,
        insertTime as insertTime
        from t_driver_activity_history where `day` between #{start} and #{end} and driverActivityId in (select id from t_driver_activity where status = 3 and now() between startTime and endTime)
        <if test="null != type">
            and `type` = #{type}
        </if>
        <if test="null != carryOut">
            and carryOut = #{carryOut}
        </if>
        <if test="null != driverId">
            and driverId = #{driverId}
        </if>
    </select>
    
    
    
    <select id="queryHistoryList" resultType="DriverActivityHistory">
        select
        id as id,
        `day` as `day`,
        driverId as driverId,
        `type` as `type`,
        activityId as activityId,
        carryOut as carryOut,
        money as money,
        insertTime as insertTime
        from t_driver_activity_history where `day` between #{start} and #{end}
        <if test="null != type">
            and `type` = #{type}
        </if>
        <if test="null != carryOut">
            and carryOut = #{carryOut}
        </if>
        <if test="null != driverId">
            and driverId = #{driverId}
        </if>
    </select>
</mapper>