FollowTaskMapper.xml
8.04 KB
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
134
135
136
137
138
139
<?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="cn.fw.valhalla.dao.mapper.FollowTaskMapper">
<select
id="followList"
resultType="cn.fw.valhalla.domain.dto.FollowPoolDTO"
parameterType="cn.fw.valhalla.domain.query.FollowPoolQueryVO"
>
select *
from (SELECT t1.id,
ifnull(t2.plate_no, t3.plate_no) plate_no,
t1.type type,
t1.changed redistribution,
case t1.finished when 1 then t1.finish_user when 0 then t1.follow_user end user_id,
case t1.finished when 1 then t1.finish_shop when 0 then t1.follow_shop end shop_id,
(select count(1) from follow_record t4
where t4.task_id = t1.id
and t4.user_id = if(t1.finished = 1, t1.finish_user, t1.follow_user)
and t4.follow_time is not null ) times,
TIMESTAMPDIFF(HOUR, now(), t1.deadline) remaining,
case t1.finished
when 1 then 2
when 0 then 3
end state,
t1.finish_time finish_time,
case t1.finished when 1 then null when 0 then t1.deadline end defeat_time,
if((select count(1) from approve_record t5
where t5.data_id = t1.id and t5.passed = 1) != 0, 1, 3) initiative,
t1.group_id group_id,
t2.id customer_id,
t1.origin_shop,
t1.finish_shop,
t1.finished,
t1.state origin_state
FROM follow_task t1
left join customer t2 on t1.customer_id = t2.id
left join accident_pool t3 on t1.customer_id = t3.id
where t1.state = 3
and ((t1.finished = 0 and
t1.deadline >= #{condition.startTime} and t1.deadline < #{condition.endTime}) or
(t1.finished = 1 and
t1.finish_time >= #{condition.startTime} and t1.finish_time < #{condition.endTime}))
union
SELECT t1.id,
ifnull(t2.plate_no, t3.plate_no) plate_no,
t1.type type,
0 redistribution,
t1.origin_user user_id,
t1.origin_shop shop_id,
(select count(1) from follow_record t4
where t4.task_id = t1.id
and t4.user_id = t1.origin_user
and t4.follow_time is not null) times,
TIMESTAMPDIFF(HOUR, now(), t1.deadline) remaining,
case t1.changed
when 1 then 3
when 0 then if(t1.finished = 0, 3, 2)
end state,
t1.finish_time finish_time,
t1.change_user_time defeat_time,
if((select count(1) from approve_record t5
where t5.data_id = t1.id and t5.passed = 1) != 0, 1, 2) initiative,
t1.group_id group_id,
t2.id customer_id,
t1.origin_shop,
t1.finish_shop,
t1.finished,
t1.state origin_state
FROM follow_task t1
left join customer t2 on t1.customer_id = t2.id
left join accident_pool t3 on t1.customer_id = t3.id
where t1.state = 3
and t1.type != 3
and ((t1.finished = 0 and
t1.deadline >= #{condition.startTime} and t1.deadline < #{condition.endTime}) or
(t1.finished = 1 and
t1.finish_time >= #{condition.startTime} and t1.finish_time < #{condition.endTime}))
union
SELECT t1.id,
ifnull(t2.plate_no, t3.plate_no) plate_no,
t1.type type,
t1.changed redistribution,
t1.follow_user user_id,
t1.follow_shop shop_id,
(select count(1) from follow_record t4
where t4.task_id = t1.id
and t4.user_id = t1.follow_user
and t4.follow_time is not null) times,
TIMESTAMPDIFF(HOUR, now(), t1.deadline) remaining,
1 state,
t1.finish_time finish_time,
null defeat_time,
null initiative,
t1.group_id group_id,
t2.id customer_id,
t1.origin_shop,
t1.finish_shop,
t1.finished,
t1.state origin_state
FROM follow_task t1
left join customer t2 on t1.customer_id = t2.id
left join accident_pool t3 on t1.customer_id = t3.id
where t1.state = 2
and t1.begin_time < #{condition.endTime}
and t1.deadline >= #{condition.endTime}) followPool
<where>
<if test="condition.groupId !=null">
and followPool.group_id = #{condition.groupId}
</if>
<if test="condition.plateNo != null and condition.plateNo !='' ">
and followPool.plate_no like concat('%', #{condition.plateNo}, '%')
</if>
<if test="condition.type !=null">
and followPool.type = #{condition.type}
</if>
<if test="condition.shopId !=null">
and followPool.shop_id = #{condition.shopId}
</if>
<if test="condition.userId !=null">
and followPool.user_id = #{condition.userId}
</if>
<if test="condition.redistribution !=null">
and followPool.redistribution = #{condition.redistribution}
</if>
<if test="condition.state !=null">
and followPool.state = #{condition.state}
</if>
<if test="condition.initiative !=null">
and followPool.initiative = #{condition.initiative}
</if>
</where>
<if test="condition.orderString != null and condition.orderString !='' ">
${condition.orderString}
</if>
limit #{startIndex},#{pageSize};
</select>
</mapper>