HomeMapper.xml
13.3 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
<?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.reports.mapper.HomeMapper">
<resultMap type="cn.com.glsx.dj.reports.dto.EffectiveInsureOrderDTO" id="EffectiveMap">
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="phone" jdbcType="VARCHAR" property="phone"/>
<result column="stand_no" jdbcType="VARCHAR" property="standNo"/>
<result column="success_date" jdbcType="TIMESTAMP" property="successDate"/>
</resultMap>
<resultMap id="homeStatisticVo" type="cn.com.glsx.dj.reports.vo.HomeStatisticVO">
<result column="number" property="number" jdbcType="INTEGER" />
<result column="date" property="date" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="orderChannelCodeVO" type="cn.com.glsx.dj.reports.vo.ChannelCodeVO">
<result column="channel_code" property="channelCode" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="shopDataListVOMap" type="cn.com.glsx.dj.reports.vo.ShopDataListVO">
<result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
<result column="ydhCount" jdbcType="INTEGER" property="ydhCount" />
<result column="gzqCount" jdbcType="INTEGER" property="gzqCount" />
<result column="gpsCount" jdbcType="INTEGER" property="gpsCount" />
<result column="jlyCount" jdbcType="INTEGER" property="jlyCount" />
<result column="hsjCount" jdbcType="INTEGER" property="hsjCount" />
<result column="allCount" jdbcType="INTEGER" property="allCount"/>
</resultMap>
<select id="getOrderChannelCode" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="orderChannelCodeVO">
select dvi.channel_code
from dj_insure_order dvi
where dvi.deleted_flag = 'N'
and dvi.channel_code IS NOT NULL
and dvi.insurance_status = 1
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and dvi.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
group by dvi.channel_code
</select>
<!-- 新增保单数 -->
<select id="incrInsurances" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultType="int">
SELECT COUNT(dvi.id) FROM dj_insure_order dvi
WHERE 1 = 1
and dvi.insurance_status=1
and dvi.success_date IS NOT NULL
<if test="record.channelCode != null and record.channelCode !=''">
and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
</if>
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and dvi.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
</select>
<!-- 根绝时间范围查询新增保单数 -->
<select id="getInsuranceByTimeRange" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="homeStatisticVo" >
SELECT COUNT(dvi.id) AS number,
<choose>
<when test="record.timeRange == 1 or record.timeRange == 2">
DATE_FORMAT(dvi.success_date, '%H') AS date
</when>
<otherwise>
DATE_FORMAT(dvi.success_date, '%Y-%m-%d') AS date
</otherwise>
</choose>
FROM dj_insure_order dvi
WHERE 1 = 1
and dvi.insurance_status = 1
and dvi.success_date IS NOT NULL
<if test="record.channelCode != null and record.channelCode !=''">
and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
</if>
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and dvi.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
<choose>
<when test="record.timeRange == 1 or record.timeRange == 2">
GROUP BY DATE_FORMAT(dvi.success_date, '%H')
</when>
<otherwise>
GROUP BY DATE_FORMAT(dvi.success_date, '%Y-%m-%d')
</otherwise>
</choose>
</select>
<select id="getIncrAppBindingByTimeRange" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="homeStatisticVo" >
SELECT COUNT(db.id) AS number,
<choose>
<when test="record.timeRange == 1 or record.timeRange == 2">
DATE_FORMAT(db.updated_date, '%H') AS date
</when>
<otherwise>
DATE_FORMAT(db.updated_date, '%Y-%m-%d') AS date
</otherwise>
</choose>
FROM dj_app_binding db left join dj_insure_order dvi on db.sn = dvi.sub_device_sn
WHERE 1 = 1
and db.bind_status=1
and dvi.insurance_status = 1
and dvi.success_date IS NOT NULL
<if test="record.channelCode != null and record.channelCode !=''">
and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
</if>
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
and db.updated_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and dvi.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
<choose>
<when test="record.timeRange == 1 or record.timeRange == 2">
GROUP BY DATE_FORMAT(db.updated_date, '%H')
</when>
<otherwise>
GROUP BY DATE_FORMAT(db.updated_date, '%Y-%m-%d')
</otherwise>
</choose>
</select>
<!-- 新增绑定数 -->
<select id="incrBinding" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultType="int">
SELECT COUNT(dvi.id) FROM dj_app_binding db left join dj_insure_order dvi on db.sn = dvi.sub_device_sn
WHERE 1 = 1
and db.bind_status=1
and dvi.insurance_status = 1
and dvi.success_date IS NOT NULL
<if test="record.channelCode != null and record.channelCode !=''">
and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
</if>
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
and db.updated_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and dvi.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
</select>
<!-- 所有激活的设备 -->
<select id="totalActiveDevice" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultType="int">
SELECT COUNT(dti.sn) from dj_insure_device dti
LEFT JOIN dj_insure_order dvi ON dti.vehicle_id = dvi.vehicle_id
WHERE dti.is_active=1
and dvi.insurance_status =1
AND dvi.deleted_flag='N' and dti.deleted_flag='N'
<if test="record.channelCode != null and record.channelCode !=''">
and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
</if>
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and dvi.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
</select>
<!-- 激活且在线的设备 -->
<select id="onlineActiveDevice" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultType="int">
SELECT COUNT(ddl.sn) from dj_insure_device dti
LEFT JOIN dj_device_login ddl ON ddl.sn=dti.sn
LEFT JOIN dj_insure_order dvi ON dti.vehicle_id = dvi.vehicle_id
WHERE dti.is_active=1
and dvi.insurance_status=1
and ddl.last_gprs_time >= date_add(NOW(), interval -3 day)
and ddl.last_gprs_time <= NOW()
and dvi.deleted_flag='N'
<if test="record.channelCode != null and record.channelCode !=''">
and dvi.channel_code = #{record.channelCode,jdbcType=VARCHAR}
</if>
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
and dvi.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and dvi.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
</select>
<select id="incrDataCount" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="shopDataListVOMap">
SELECT
SUM(CASE WHEN d.device_type='2' THEN 1 ELSE 0 END) ydhCount,
SUM(CASE WHEN d.device_type='8' THEN 1 WHEN d.device_type='4' THEN 1 ELSE 0 END) gpsCount,
SUM(CASE WHEN d.device_type='6' THEN 1 ELSE 0 END) jlyCount,
SUM(CASE WHEN d.device_type='12134' THEN 1 ELSE 0 END) hsjCount,
COUNT(o.id) AS allCount
FROM dj_insure_order o LEFT JOIN dj_insure_device d ON o.sub_device_sn = d.sn
WHERE o.insurance_status=1
AND d.sn IS NOT NULL
AND d.device_type in('2','6','8','12134','4')
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
AND o.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and o.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
</select>
<select id="incrShopDataList" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="shopDataListVOMap">
select * from(
SELECT
(SELECT m.merchant_name FROM dj_system_merchant m WHERE m.merchant_id=o.merchant_id) AS merchant_name,
SUM(CASE WHEN d.device_type='2' THEN 1 ELSE 0 END) ydhCount,
SUM(CASE WHEN d.device_type='8' THEN 1 WHEN d.device_type='4' THEN 1 ELSE 0 END) gpsCount,
SUM(CASE WHEN d.device_type='6' THEN 1 ELSE 0 END) jlyCount,
SUM(CASE WHEN d.device_type='12134' THEN 1 ELSE 0 END) hsjCount,
COUNT(o.id) AS allCount
FROM dj_insure_order o LEFT JOIN dj_insure_device d ON o.sub_device_sn = d.sn
WHERE o.insurance_status=1
AND d.sn IS NOT NULL
AND d.device_type in('2','6','8','12134','4')
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
AND o.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and o.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
GROUP BY o.merchant_id
)tp where allCount>0
</select>
<select id="incrDataMixList" parameterType="cn.com.glsx.dj.reports.vo.HomeQueryVO" resultMap="shopDataListVOMap">
SELECT * FROM(
SELECT
(SELECT m.merchant_name FROM dj_system_merchant m WHERE m.merchant_id=o.merchant_id) AS merchant_name,
SUM(CASE WHEN d.device_type='2' THEN 1 ELSE 0 END) ydhCount,
SUM(CASE WHEN d.device_type='8' THEN 1 WHEN d.device_type='4' THEN 1 ELSE 0 END) gpsCount,
SUM(CASE WHEN d.device_type='6' THEN 1 ELSE 0 END) jlyCount,
SUM(CASE WHEN d.device_type='12134' THEN 1 ELSE 0 END) hsjCount,
COUNT(o.id) AS allCount
FROM dj_insure_order o LEFT JOIN dj_insure_device d ON o.sub_device_sn = d.sn
WHERE o.insurance_status=1
AND d.sn IS NOT NULL
AND d.device_type in('2','6','8','12134','4')
<if test="record.startDate != null and record.endDate != null and record.startDate !='' and record.endDate !=''">
AND o.success_date BETWEEN #{record.startDate,jdbcType=VARCHAR} AND #{record.endDate,jdbcType=VARCHAR}
</if>
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and o.merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
GROUP BY o.merchant_id
) tp
<choose>
<when test="record.dimension != null and record.dimension==5">
ORDER BY allCount DESC
</when>
<when test="record.dimension != null and record.dimension==4">
ORDER BY ydhCount DESC
</when>
<when test="record.dimension != null and record.dimension==3">
ORDER BY gpsCount DESC
</when>
<when test="record.dimension != null and record.dimension==2">
ORDER BY jlyCount DESC
</when>
<otherwise>
ORDER BY allCount DESC
</otherwise>
</choose>
LIMIT 0,5
</select>
</mapper>