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
126
127
128
129
130
131
132
133
<?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.TaskDetailMapper">
 
    <select id="getTaskDetailList" resultType="com.stylefeng.guns.modular.system.model.vo.TaskDetailList">
        select
            a.id,
            a.code,
            b.`name`,
            b.type,
            a.status,
            ifnull(c.num, 0) as vehicleNum,
            DATE_FORMAT(a.execution_time, '%Y-%m-%d %H:%i:%s') as executionTime
        from t_task_detail a
        left join t_patrol_task b on (a.patrol_task_id = b.id)
        left join (select task_detail_id, count(1) as num from t_task_detail_vehicles group by task_detail_id) c on (a.id = c.task_detail_id)
        where a.del_flag = 0
        <if test="null != item.code and '' != item.code">
            and a.code like CONCAT('%', #{item.code}, '%')
        </if>
 
        <if test="null != item.status and item.status.size() > 0">
            and a.status in
            <foreach collection="item.status" item="item" index="index" open="(" separator="," close=")">
                    #{item}
            </foreach>
        </if>
        <if test="null != item.type">
            and b.type = #{item.type}
        </if>
        <if test="null != item.name and '' != item.name">
            and b.name like CONCAT('%', #{item.name}, '%')
        </if>
        <if test="null != item.startTime and null != item.endTime">
            and a.execution_time between #{item.startTime} and #{item.endTime}
        </if>
        order by a.execution_time desc
    </select>
    
    
    <select id="getTaskRecordList" resultType="com.stylefeng.guns.modular.system.model.vo.TaskRecordList">
        select
            a.id,
            b.type,
            b.`name`,
            a.`status`,
            a.execution_time as executionTime,
            ifnull(c.num, 0) as vehicleNum,
            ifnull(d.num, 0) as unexecutedQuantity,
            ifnull(e.num, 0) as offlineNum,
            ifnull(f.num, 0) as normalNum,
            ifnull(g.num, 0) as abnormalNum,
            ROUND(ifnull(((ifnull(e.num, 0) + ifnull(f.num, 0) + ifnull(g.num, 0)) / ifnull(c.num, 0) * 100), 0), 2) as schedule,
            if(h.num > 0, 0, 1) as authStatus
        from t_task_detail a
         left join t_patrol_task b on (a.patrol_task_id = b.id)
         left join (select task_detail_id, count(1) as num from t_task_detail_vehicles group by task_detail_id) c on (a.id = c.task_detail_id)
         left join (select task_detail_id, count(1) as num from t_task_detail_vehicles where `status` = 1 group by task_detail_id) d on (a.id = d.task_detail_id)
         left join (select task_detail_id, count(1) as num from t_task_detail_vehicles where `status` = 4 group by task_detail_id) e on (a.id = e.task_detail_id)
         left join (select task_detail_id, count(1) as num from t_task_detail_vehicles where `status` = 3 group by task_detail_id) f on (a.id = f.task_detail_id)
         left join (select task_detail_id, count(1) as num from t_task_detail_vehicles where `status` = 5 group by task_detail_id) g on (a.id = g.task_detail_id)
         left join (select task_detail_id, count(1) as num from t_task_detail_vehicles_channel
                                                           where artificial_status = 1
                                                           <if test="null != item.sysStatus">
                                                              and sys_status = #{item.sysStatus}
                                                          </if>
                                                                                               group by task_detail_id) h on (a.id = h.task_detail_id)
        where a.del_flag = 0
        <if test="null != item.code and '' != item.code">
            and a.code like CONCAT('%', #{item.code}, '%')
        </if>
        <if test="null != item.status and item.status.size() > 0">
            and a.status in
            <foreach collection="item.status" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="null != item.type">
            and b.type = #{item.type}
        </if>
        <if test="null != item.name and '' != item.name">
            and b.name like CONCAT('%', #{item.name}, '%')
        </if>
        <if test="null != item.startTime and null != item.endTime">
            and a.execution_time between #{item.startTime} and #{item.endTime}
        </if>
        order by a.execution_time desc
    </select>
    
    
    <select id="getDownloadTaskRecord" resultType="map">
        select
        c.`name`,
        if(c.type = 1, '定时任务', '实时任务') as taskType,
        DATE_FORMAT(b.execution_time, '%Y-%m-%d %H:%i:%s') as executionTime,
        a.`status`,
        a.vehicleNum,
        a.companyName,
        if(d.artificial_status = 1, d.sys_status, d.artificial_status) as vehiclesStatus,
        d.image_url as imageUrl,
        d.sys_status as sysStatus,
        DATE_FORMAT(d.sys_create_time, '%Y-%m-%d %H:%i:%s') as sysCreateTime,
        d.artificial_status as artificialStatus,
        d.remark,
        e.`name` as artificialUser,
        DATE_FORMAT(d.artificial_create_time, '%Y-%m-%d %H:%i:%s') as artificialCreateTime
        from t_task_detail_vehicles a
        left join t_task_detail b on (a.task_detail_id = b.id)
        left join t_patrol_task c on (a.patrol_task_id = c.id)
        left join t_task_detail_vehicles_channel d on (a.id = d.task_detail_vehicles_id)
        left join sys_user e on (d.artificial_user_id = e.id)
        where b.del_flag = 0
        <if test="null != ids and ids.size() > 0">
            and b.id in
            <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="null != code and '' != code">
            and b.code like CONCAT('%', #{code}, '%')
        </if>
        <if test="null != status and status.size() > 0">
            and b.status in
            <foreach collection="status" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="null != sysStatus">
            and d.sys_status = #{sysStatus}
        </if>
        order by b.execution_time desc
    </select>
</mapper>