SopTaskInfoMapper.xml
14.6 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?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.com.glsx.dj.mindworkplate.mapper.sop.SopTaskInfoMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.sop.SopTaskInfo" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="sop_id" property="sopId" jdbcType="VARCHAR" />
<result column="staff_uuid" property="staffUuid" jdbcType="VARCHAR" />
<result column="staff_name" property="staffName" jdbcType="VARCHAR" />
<result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
<result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
<result column="staff_phone" property="staffPhone" jdbcType="VARCHAR" />
<result column="step" property="step" jdbcType="INTEGER" />
<result column="task_status" property="taskStatus" jdbcType="INTEGER" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
<result column="task_period" property="taskPeriod" jdbcType="INTEGER" />
<result column="config_id" property="configId" jdbcType="INTEGER" />
<result column="business_scene_type_name" property="businessSceneTypeName" jdbcType="VARCHAR" />
<result column="main_brand" property="mainBrand" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="SopTaskInfoMap" extends="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO">
<result column="total" property="total" />
<result column="progress" property="progress" jdbcType="DECIMAL"/>
<result column="ratio" property="ratio" jdbcType="DECIMAL"/>
</resultMap>
<resultMap id="SopTaskInfoDTO" extends="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO">
<association property="config" javaType="cn.com.glsx.dj.mindworkplate.model.sop.SopTaskConfig">
<id column="config_id" property="id" jdbcType="INTEGER" />
<id column="store_penetration_monthly" property="storePenetrationMonthly" jdbcType="DECIMAL" />
<id column="store_penetration_weekly" property="storePenetrationWeekly" jdbcType="DECIMAL" />
<id column="inspection_score" property="inspectionScore" jdbcType="DECIMAL" />
<id column="study_day" property="studyDay" jdbcType="INTEGER" />
<id column="finish_time" property="finishTime" jdbcType="TIMESTAMP" />
<id column="punish_type" property="punishType" jdbcType="TINYINT" />
<id column="effective_type" property="effectiveType" jdbcType="TINYINT" />
<id column="effective_time" property="effectiveTime" jdbcType="TIMESTAMP" />
</association>
</resultMap>
<resultMap id="RecordingMap" type="cn.com.glsx.dj.mindworkplate.model.sop.RecordingInfo">
<result column="recordingId" property="recordingId" />
<result column="customerName" property="customerName" />
<result column="customerCar" property="customerCar" />
<result column="customerCharacter" property="customerCharacter" />
<result column="duration" property="duration" />
<result column="inspectionScore" property="inspectionScore" />
</resultMap>
<sql id="Base_Column_List" >
<!--
WARNING - @mbg.generated
-->
id, sop_id, staff_uuid, staff_name, merchant_id, merchant_name, staff_phone, step,
task_status, created_by, created_date, updated_by, updated_date, deleted_flag, task_period, config_id
</sql>
<select id="listLatestSopTaskInfo" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskSearchDTO" resultMap="BaseResultMap">
select t1.id, t1.sop_id, t1.staff_uuid, t1.staff_name, t1.merchant_id, t1.merchant_name, t1.staff_phone, t1.step, t1.created_date,t1.task_status
from sop_task_info t1
left join sop_task_info t2 on t1.staff_phone = t2.staff_phone and t1.created_date < t2.created_date and t2.deleted_flag = 'N'
<where>
t1.deleted_flag = 'N' and t2.id is null
<include refid="condition"></include>
</where>
order by t1.created_date desc
</select>
<select id="listLatestSopTaskInfoGroupStep" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskSearchDTO" resultMap="BaseResultMap">
select t1.id, t1.sop_id, t1.staff_uuid, t1.staff_name, t1.merchant_id, t1.merchant_name, t1.staff_phone, t1.step, t1.created_date,t1.task_status
from sop_task_info t1
inner join (
select t1.staff_phone, t1.step, max(t1.created_date) as max_date
from sop_task_info t1
where t1.deleted_flag = 'N'
<include refid="condition"></include>
group by t1.staff_phone, t1.step
) t2 on t1.staff_phone = t2.staff_phone and t1.step = t2.step and t1.created_date = t2.max_date
where t1.deleted_flag = 'N'
order by t1.created_date desc
</select>
<select id="listUnfinishedLatestSopTaskInfoByUuids" resultMap="BaseResultMap">
select t1.sop_id, t1.staff_uuid, t1.staff_name, t1.staff_phone, t1.step, t1.task_status,t1.merchant_id
from sop_task_info t1
left join sop_task_info t2 on t1.staff_uuid = t2.staff_uuid and t1.created_date < t2.created_date and t1.merchant_id = t2.merchant_id and t2.deleted_flag = 'N'
<where>
t1.deleted_flag = 'N' and t2.id is null and t1.task_status in (0,2)
and t1.staff_uuid in
<foreach item="item" index="index" collection="idList" open="(" separator="," close=")">
#{item}
</foreach>
<!--and date(t1.created_date + interval ifnull(t1.task_period, 0) day) > current_date()-->
</where>
</select>
<sql id="condition">
<if test="staffPhone != null and staffPhone != ''">
and t1.staff_phone = #{staffPhone}
</if>
<if test="staffPhoneList != null and staffPhoneList.size() > 0">
and t1.staff_phone in
<foreach item="item" index="index" collection="staffPhoneList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="staffUuid != null and staffUuid != ''">
and t1.staff_uuid = #{staffUuid}
</if>
<if test="step != null">
and t1.step = #{step}
</if>
<if test="taskStatus != null">
and t1.task_status = #{taskStatus}
</if>
<if test="stepList != null">
and t1.step in
<foreach item="item" index="index" collection="stepList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="taskStatusList != null">
and t1.task_status in
<foreach item="item" index="index" collection="taskStatusList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="startTime != null">
and t1.created_date >= #{startTime}
</if>
<if test="endTime != null">
and t1.created_date <= #{endTime}
</if>
</sql>
<select id="listSopTaskInfoByIds" resultMap="BaseResultMap">
select *
from sop_task_info
<where>
deleted_flag = 'N' and step = #{step}
<if test="sopIdList != null and sopIdList.size() > 0">
and sop_id in
<foreach item="item" index="index" collection="sopIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="phoneList != null and phoneList.size() > 0">
and staff_phone in
<foreach item="item" index="index" collection="phoneList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</select>
<update id="batchUpdateTaskStatusById">
<foreach collection="list" item="item" index="index" separator=";">
update sop_task_info
set task_status = #{item.taskStatus}, updated_date = #{item.updatedDate}, updated_by = #{item.updatedBy}
where id = #{item.id}
</foreach>
</update>
<update id="batchUpdateStep2TaskStatus">
<foreach collection="list" item="item" index="index" separator=";">
update sop_task_info
set task_status = #{item.taskStatus}, updated_date = #{item.updatedDate}, updated_by = #{item.updatedBy}
where step = 1 and sop_id = #{item.sopId} and staff_phone = #{item.staffPhone}
</foreach>
</update>
<select id="countStaffTask" resultMap="SopTaskInfoMap">
select staff_uuid, count(*) as total
from sop_task_info
<where>
deleted_flag = 'N' and task_status in (0,2)
and staff_uuid in
<foreach item="item" index="index" collection="uuidList" open="(" separator="," close=")">
#{item}
</foreach>
</where>
group by staff_uuid
having count(*) > 0
</select>
<sql id="listSopTaskInfoCondition">
t1.deleted_flag = 'N'
<if test="staffPhone != null and staffPhone != ''">
and t1.staff_phone = #{staffPhone}
</if>
<if test="staffUuid != null and staffUuid != ''">
and t1.staff_uuid = #{staffUuid}
</if>
<if test="step != null">
and t1.step = #{step}
</if>
<if test="taskStatus != null">
and t1.task_status = #{taskStatus}
</if>
<if test="taskStatusList != null and taskStatusList.size() > 0">
and t1.task_status in
<foreach collection="taskStatusList" close=")" open="(" separator="," item="item">
#{item}
</foreach>
</if>
</sql>
<select id="listSopTaskInfo" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO" resultMap="BaseResultMap">
select t1.id, t1.sop_id, t1.staff_uuid, t1.staff_name, t1.merchant_id, t1.merchant_name, t1.staff_phone, t1.step,
t1.task_status, t1.created_date, t1.task_period
from sop_task_info t1
<where>
<include refid="listSopTaskInfoCondition" />
</where>
</select>
<select id="listSopTaskInfoDTO" parameterType="cn.com.glsx.dj.mindworkplate.dto.sop.SopTaskInfoDTO" resultMap="SopTaskInfoDTO">
select t1.*,
t2.store_penetration_monthly, t2.store_penetration_weekly, t2.inspection_score, t2.study_day, t2.finish_time, t2.punish_type, t2.effective_type, t2.effective_time
from sop_task_info t1
left join sop_task_config t2 on t1.config_id = t2.id and t2.deleted_flag = 'N'
<where>
<include refid="listSopTaskInfoCondition" />
</where>
</select>
<select id="listRecordingInfo" resultMap="RecordingMap">
select t3.id as recordingId,t3.score as inspectionScore,t6.customer_type as customerCharacter,t1.customer_name as customerName,t1.car_model as customerCar,t2.recording_duration as duration
from reception_customer_info t1
left join inspection_badge_recordings t2 on t2.reception_id =t1.id
left join inspection_conversation_batch t3 on t2.id =t3.record_id
left join inspection_employee_badge t4 on t2.badge_id =t4.badge_id
left join inspection_defence t6 on (t3.id=t6.batch_id and t6.deleted_flag ='N')
left join ( select
distinct dclgoc.customer_phone
from dj_car_life_goods_order dclgo
left join dj_car_life_goods_sub_order dclgso
on dclgo.order_code = dclgso.order_code and dclgso.deleted_flag = 'N'
left join dj_car_life_goods_order_customer dclgoc
on dclgoc.order_code = dclgo.order_code and dclgoc.deleted_flag = 'N'
left join dj_car_life_pay_order dclpo on dclpo.order_code = dclgo.order_code and dclpo.deleted_flag = 'N'
where dclgo.deleted_flag = 'N' and dclgo.scene_type = 0
and dclgo.status in (4, 6) and upgrade_flag = 'Y' and dclpo.success_date like concat('%',#{checkDate},'%')) t5 on t1.phone_number =t5.customer_phone
<where>
t5.customer_phone is null and t3.id is not null and t2.check_type=1 and t3.score < #{score} and t1.reception_start_time like concat('%',#{checkDate},'%')
and t1.staff_uuid = #{uuid} and t1.merchant_id = #{merchantId}
</where>
</select>
<select id="listBadLabels" resultType="java.lang.String">
select t3.group_name
from recording_check_result t1
inner join recording_tag_value t2 on t1.tag_id =t2.id
inner join recording_tag_group t3 on t2.tag_groupid =t3.id
where t1.batch_id = #{batchId} and t2.value_name='差'
</select>
<select id="getStaffTodayTaskIndicators" resultMap="SopTaskInfoMap">
select
count(distinct stdt.id) total,
ROUND(100 * count(distinct case when stdt.status = 2 then stdt.id end)
/ NULLIF(count(distinct case when stdt.status != 0 then stdt.id end), 0), 1) progress
from sop_task_info sti
left join sop_task_detail_info stdi on sti.id = stdi.sop_task_id and stdi.deleted_flag = 'N'
left join sop_task_pad_push stpp on stpp.task_id = stdi.id
left join pad_message_box pmb on pmb.id = stpp.msg_bos_id
left join sop_task_detail_tag stdt on stdi.business_id = stdt.business_id and stdt.deleted_flag = 'N'
where sti.deleted_flag = 'N' and stpp.del_flag = 'N' and pmb.del_flag = 'N'
and stdi.created_date >= CURDATE() and sti.staff_phone = #{condition.staffPhone}
group by sti.staff_phone
</select>
<select id="getStaffTodayTaskRatio" resultMap="SopTaskInfoMap">
select valid_employees,total_employees,
ROUND(100 * valid_employees / NULLIF(total_employees, 0), 2) AS ratio
FROM (
SELECT COUNT(DISTINCT sti.staff_phone) AS total_employees
FROM sop_task_info sti
LEFT JOIN sop_task_detail_info stdi ON sti.id = stdi.sop_task_id AND stdi.deleted_flag = 'N'
WHERE sti.deleted_flag = 'N'
AND stdi.created_date >= CURDATE()
) total_stats,
(
SELECT
COUNT(DISTINCT sti.staff_phone) AS valid_employees
FROM sop_task_info sti
LEFT JOIN sop_task_detail_info stdi ON sti.id = stdi.sop_task_id AND stdi.deleted_flag = 'N'
WHERE sti.deleted_flag = 'N'
AND stdi.task_status = 2
AND stdi.created_date >= CURDATE()
) valid_stats;
</select>
<select id="getSopInspectionChart" resultType="cn.com.glsx.dj.mindworkplate.model.RecordingCheckResult">
select t3.group_name tagGroupName, avg(case when sti.id is not null then t1.score else 0 end) score
from recording_tag_group t3
left join recording_tag_value t2 on t2.tag_groupid =t3.id and t2.deleted_flag = 'N'
left join recording_check_result t1 on t1.tag_id =t2.id and t1.deleted_flag = 'N'
left join sop_task_detail_info stdi on stdi.batch_id = t1.batch_id and t1.deleted_flag = 'N'
AND stdi.created_date >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
AND stdi.created_date <![CDATA[ < ]]> DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
left join sop_task_info sti on stdi.sop_task_id = sti.id and stdi.deleted_flag = 'N'
<if test="condition.staffPhone != null and condition.staffPhone != ''">
and sti.staff_phone = #{condition.staffPhone}
</if>
where t3.deleted_flag = 'N'
group by t3.group_name
</select>
</mapper>