OrderVipcardDetailSmapper.xml
18.9 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<?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.zteits.order.mapper.smapper.OrderVipcardDetailSmapper" >
<resultMap id="BaseResultMap" type="com.zteits.order.domain.OrderVipcardDetail">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="detail_order_id" jdbcType="VARCHAR" property="detailOrderId" />
<result column="order_id" jdbcType="VARCHAR" property="orderId" />
<result column="vip_card_no" jdbcType="VARCHAR" property="vipCardNo" />
<result column="order_type" jdbcType="INTEGER" property="orderType" />
<result column="person_card_no" jdbcType="VARCHAR" property="personCardNo" />
<result column="card_type" jdbcType="INTEGER" property="cardType" />
<result column="car_type" jdbcType="INTEGER" property="carType" />
<result column="terminal_source" jdbcType="INTEGER" property="terminalSource" />
<result column="card_act_amount" jdbcType="BIGINT" property="cardActAmount" />
<result column="order_dicount_fee" jdbcType="BIGINT" property="orderDicountFee" />
<result column="price" jdbcType="BIGINT" property="price" />
<result column="buy_num" jdbcType="INTEGER" property="buyNum" />
<result column="use_type" jdbcType="INTEGER" property="useType" />
<result column="pl_no" jdbcType="VARCHAR" property="plNo" />
<result column="pl_name" jdbcType="VARCHAR" property="plName" />
<result column="person_cust_id" jdbcType="VARCHAR" property="personCustId" />
<result column="car_number" jdbcType="VARCHAR" property="carNumber" />
<result column="eff_date" jdbcType="TIMESTAMP" property="effDate" />
<result column="exp_date" jdbcType="TIMESTAMP" property="expDate" />
<result column="invoice_state" jdbcType="INTEGER" property="invoiceState" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="data_state" jdbcType="INTEGER" property="dataState" />
<result column="create_emp_id" jdbcType="VARCHAR" property="createEmpId" />
<result column="create_name" jdbcType="VARCHAR" property="createName" />
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
<result column="modify_emp_id" jdbcType="VARCHAR" property="modifyEmpId" />
<result column="modify_name" jdbcType="VARCHAR" property="modifyName" />
<result column="modify_date" jdbcType="TIMESTAMP" property="modifyDate" />
</resultMap>
<sql id="Base_Column_List">
id, detail_order_id, order_id, vip_card_no, order_type, person_card_no, card_type,
car_type, terminal_source, card_act_amount, order_dicount_fee, price, buy_num, use_type,
pl_no, pl_name, person_cust_id, car_number, eff_date, exp_date, invoice_state, remark,
data_state, create_emp_id, create_name, create_date, modify_emp_id, modify_name,
modify_date
</sql>
<!--批量保存会员卡订单明细信息-->
<insert id="batchInsertOrderVipcardDetail" >
<selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into order_vipcard_detail (detail_order_id, order_id, vip_card_no,
order_type, person_card_no, card_type,
car_type, terminal_source, card_act_amount,
order_dicount_fee, price, buy_num,
use_type, pl_no, pl_name,
person_cust_id, car_number, eff_date,
exp_date, remark, data_state,
create_emp_id, create_name, create_date,
modify_emp_id, modify_name, modify_date
)
values
<foreach collection="orderVipcardDetailList" item="item" index="index" separator=",">
(#{item.detailOrderId,jdbcType=VARCHAR}, #{item.orderId,jdbcType=VARCHAR}, #{item.vipCardNo,jdbcType=VARCHAR},
#{item.orderType,jdbcType=INTEGER}, #{item.personCardNo,jdbcType=VARCHAR}, #{item.cardType,jdbcType=INTEGER},
#{item.carType,jdbcType=INTEGER}, #{item.terminalSource,jdbcType=INTEGER}, #{item.cardActAmount,jdbcType=BIGINT},
#{item.orderDicountFee,jdbcType=BIGINT}, #{item.price,jdbcType=BIGINT}, #{item.buyNum,jdbcType=INTEGER},
#{item.useType,jdbcType=INTEGER}, #{item.plNo,jdbcType=VARCHAR}, #{item.plName,jdbcType=VARCHAR},
#{item.personCustId,jdbcType=VARCHAR}, #{item.carNumber,jdbcType=VARCHAR}, #{item.effDate,jdbcType=TIMESTAMP},
#{item.expDate,jdbcType=TIMESTAMP}, #{item.remark,jdbcType=VARCHAR}, #{item.dataState,jdbcType=INTEGER},
#{item.createEmpId,jdbcType=VARCHAR}, #{item.createName,jdbcType=VARCHAR}, #{item.createDate,jdbcType=TIMESTAMP},
#{item.modifyEmpId,jdbcType=VARCHAR}, #{item.modifyName,jdbcType=VARCHAR}, #{item.modifyDate,jdbcType=TIMESTAMP}
)
</foreach>
</insert>
<!-- 通过会员卡订单ID or 详情明细主键查询会员卡详情对象 -->
<select id="queryOrderVipcardDetailByOrderIdOrId" resultMap="BaseResultMap" parameterType="com.zteits.clouds.api.dto.order.vipcardorder.param.OrderVipcardQueryByOrderIdReq" >
select
<include refid="Base_Column_List" />
from order_vipcard_detail
where 1=1
<if test="id != null ">
and id = #{id,jdbcType=BIGINT}
</if>
<if test="orderId != null and orderId !='' ">
and order_id = #{orderId,jdbcType=VARCHAR}
</if>
<choose>
<when test="dataState != null">
and data_state = #{dataState,jdbcType=INTEGER}
</when>
<otherwise>
and data_state = 1
</otherwise>
</choose>
</select>
<!--分页查询-会员卡记录(订单管理-会员卡记录页面)-->
<select id="queryVipCardOrderInfoForPage" parameterType="com.zteits.clouds.api.dto.order.vipcardorder.param.QueryVipCardOrderPageReq"
resultType="com.zteits.order.domain.sdo.VipCardBuyInfoDO">
select
a.person_card_no as custCardNo,
a.car_number as carNumber,
a.card_type as cardType,
a.buy_num as num,
a.price as price,
a.eff_date as effDate,
a.exp_date as expDate,
a.create_date as createDate,
a.order_dicount_fee as orderDicountFee,
a.card_act_amount as totalAmount,
a.order_type as orderType,
a.person_cust_id as personCustId
from order_vipcard_detail a,order_vipcard b
where a.data_state=1
and b.data_state=1
and a.order_id=b.order_id
and b.order_state in(40,50) /**订单状态 10:待核算、20:待支付、30:支付中,40:已支付、50:已完成*/
<if test="plNos != null and plNos.size >0">
and a.pl_no in
<foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
#{plNo}
</foreach>
</if>
<if test="beginTime !=null and beginTime!=''">
<![CDATA[and a.create_date >= #{beginTime}]]>
</if>
<if test="endTime !=null and endTime!='' ">
<![CDATA[and a.create_date <= #{endTime}]]>
</if>
<if test="carNumber != null and carNumber !=''">
and a.car_number=#{carNumber}
</if>
order by a.create_date DESC
</select>
<!--通过个人会员卡Ids查询会员卡支付方式-->
<select id="queryVipCardPayType" resultType="com.zteits.order.domain.sdo.VipCardBuyPayTypeDO">
SELECT
a.person_card_no as personCardId,
a.invoice_state as invoiceState,
b.pay_type as payType,
b.order_act_fee as orderActFee,
b.pay_finish_time as payFinishTime
FROM
order_vipcard_detail a, pay_order b
where 1=1
and a.order_id=b.rlt_order_id
and b.order_big_type='300' /**关联的订单大类型: 300:会员卡订单*/
<if test="custCardNos != null and custCardNos.size >0">
and a.person_card_no in
<foreach collection="custCardNos" open="(" close=")" item="custCardNo" separator=",">
#{custCardNo}
</foreach>
</if>
group by a.person_card_no,a.invoice_state ,b.pay_type, b.order_act_fee ,b.pay_finish_time
order by b.pay_finish_time desc
</select>
<!--通过个人会员卡Ids查询会员卡支付方式-->
<select id="queryVipCardDetails" resultMap="BaseResultMap"
parameterType="com.zteits.clouds.api.dto.order.vipcardorder.param.QueryVipcardDetailsReq">
select
<include refid="Base_Column_List" />
from order_vipcard_detail
where 1=1
<if test="orderIds != null and orderIds.size >0">
and order_id in
<foreach collection="orderIds" open="(" close=")" item="orderId" separator=",">
#{orderId}
</foreach>
</if>
<if test="orderIds == null || orderIds.size == 0">
and order_id in
(
select b.order_id
FROM order_vipcard a ,
order_vipcard_detail b
where a.order_id = b.order_id
and a.order_state = #{orderState}
and b.invoice_state = #{invoiceState}
and b.person_cust_id = #{custId}
)
</if>
</select>
<!-- 通过个人会员卡Id 修改 订单会员卡详情 -->
<update id="updateVipcardDetailByPersonCardNo" parameterType="com.zteits.order.domain.OrderVipcardDetail">
update order_vipcard_detail
<set>
<if test="detailOrderId != null">
detail_order_id = #{detailOrderId,jdbcType=VARCHAR},
</if>
<if test="orderId != null">
order_id = #{orderId,jdbcType=VARCHAR},
</if>
<if test="orderType != null">
order_type = #{orderType,jdbcType=INTEGER},
</if>
<if test="vipCardNo != null">
vip_card_no = #{vipCardNo,jdbcType=VARCHAR},
</if>
<if test="cardType != null">
card_type = #{cardType,jdbcType=INTEGER},
</if>
<if test="carType != null">
car_type = #{carType,jdbcType=INTEGER},
</if>
<if test="terminalSource != null">
terminal_source = #{terminalSource,jdbcType=INTEGER},
</if>
<if test="cardActAmount != null">
card_act_amount = #{cardActAmount,jdbcType=BIGINT},
</if>
<if test="orderDicountFee != null">
order_dicount_fee = #{orderDicountFee,jdbcType=BIGINT},
</if>
<if test="price != null">
price = #{price,jdbcType=BIGINT},
</if>
<if test="buyNum != null">
buy_num = #{buyNum,jdbcType=INTEGER},
</if>
<if test="useType != null">
use_type = #{useType,jdbcType=INTEGER},
</if>
<if test="plNo != null">
pl_no = #{plNo,jdbcType=VARCHAR},
</if>
<if test="plName != null">
pl_name = #{plName,jdbcType=VARCHAR},
</if>
<if test="personCustId != null">
person_cust_id = #{personCustId,jdbcType=VARCHAR},
</if>
<if test="carNumber != null">
car_number = #{carNumber,jdbcType=VARCHAR},
</if>
<if test="effDate != null">
eff_date = #{effDate,jdbcType=TIMESTAMP},
</if>
<if test="expDate != null">
exp_date = #{expDate,jdbcType=TIMESTAMP},
</if>
<if test="invoiceState != null">
invoice_state = #{invoiceState,jdbcType=INTEGER},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="dataState != null">
data_state = #{dataState,jdbcType=INTEGER},
</if>
<if test="createEmpId != null">
create_emp_id = #{createEmpId,jdbcType=VARCHAR},
</if>
<if test="createName != null">
create_name = #{createName,jdbcType=VARCHAR},
</if>
<if test="createDate != null">
create_date = #{createDate,jdbcType=TIMESTAMP},
</if>
<if test="modifyEmpId != null">
modify_emp_id = #{modifyEmpId,jdbcType=VARCHAR},
</if>
<if test="modifyName != null">
modify_name = #{modifyName,jdbcType=VARCHAR},
</if>
<if test="modifyDate != null">
modify_date = #{modifyDate,jdbcType=TIMESTAMP},
</if>
</set>
where person_card_no = #{personCardNo,jdbcType=VARCHAR}
</update>
<!-- 通过会员卡Id 查询orderId -->
<select id="queryOrderIDByPersonCardNo" parameterType="java.lang.String" resultType="java.lang.String">
select order_id from order_vipcard_detail where person_card_no = #{personCardNo,jdbcType=VARCHAR}
</select>
<!-- 通过会员卡订单详情id查询开发票状态 -->
<select id="queryInvoiceStateByDetailOrderId" parameterType="java.lang.String" resultType="java.lang.Integer">
select invoice_state from order_vipcard_detail where detail_order_id = #{detailOrderId,jdbcType=VARCHAR} limit 1
</select>
<!-- 分类统计会员卡收入 -->
<select id="staticVipCardIncomeByPlNo" resultType="com.zteits.order.domain.IncomeStatisticVipCardDay">
SELECT
IFNULL(SUM(CASE WHEN t.card_type=1 THEN t.card_act_amount ELSE 0 END),0) yearCardFee,
IFNULL(SUM(CASE WHEN t.card_type=2 THEN t.card_act_amount ELSE 0 END),0) halfYearCardFee,
IFNULL(SUM(CASE WHEN t.card_type=3 THEN t.card_act_amount ELSE 0 END),0) seasonCardFee,
IFNULL(SUM(CASE WHEN t.card_type=4 THEN t.card_act_amount ELSE 0 END),0) monthCardFee,
IFNULL(SUM(CASE WHEN t.card_type=5 THEN t.card_act_amount ELSE 0 END),0) dayCardFee
FROM order_vipcard_detail t,order_vipcard o
WHERE t.data_state = 1
AND o.order_id = t.order_id
AND o.order_state in(40,50)
AND t.card_type in(1,2,3,4,5) /** 卡类型 1-年卡;2-半年卡;3-季卡;4-月卡;5-日卡 */
AND t.pl_no = #{plNo}
AND t.create_date >= #{startDate}
AND t.create_date < #{endDate}
</select>
<!-- 查询已购买会员卡汇总数据 -->
<select id="queryVipCardOrderDetailTotal" parameterType="com.zteits.clouds.api.dto.bill.vipcard.param.VipCardCustInfoBuyReq" resultType="com.zteits.order.domain.sdo.OrderVipcardDetailBuyDO">
select
sum(aa.card_act_amount) as cardActAmount,
sum(aa.order_dicount_fee) as cardActDicountAmount,
<![CDATA[sum(case when aa.carNumTotal > 1 then
1
else
aa.carNumTotal
end) as carNumTotal,]]>
aa.card_type as cardType,
<![CDATA[sum(case when aa.recentExpcarNumTotal > 1 then
1
else
aa.recentExpcarNumTotal
end ) as recentExpcarNumTotal]]>
from (SELECT
sum(a.card_act_amount) as card_act_amount,
sum(a.order_dicount_fee) as order_dicount_fee,
a.card_type,
a.car_number,
<![CDATA[count(case when a.exp_date >= now() then
a.car_number
end) as carNumTotal,]]>
<![CDATA[count(case when a.exp_date >= now() and a.exp_date <= date_add(now(), interval 7 day) then
a.car_number
end) as recentExpcarNumTotal]]>
FROM
order_vipcard_detail a
where 1=1
and a.data_state=1
<if test="plNos != null and plNos.size >0">
and a.pl_no in
<foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
#{plNo}
</foreach>
</if>
<if test="carType != null ">
and a.car_type =#{carType}
</if>
<if test="cardType != null ">
and a.card_type =#{cardType}
</if>
<if test="carNumber != null">
and a.car_number like CONCAT('%',#{carNumber},'%')
</if>
<if test="beginTime != null ">
<![CDATA[and a.create_date >= #{beginTime}]]>
</if>
<if test="endTime !=null ">
<![CDATA[and a.create_date <= #{endTime}]]>
</if>
group by a.card_type,
a.car_number) aa
group by aa.card_type
</select>
<!-- 按照终端来源、卡类型 查询会员卡汇总信息 -->
<select id="queryVipCardOrderDetailTotalByPlNosAndCreateDate" parameterType="com.zteits.clouds.api.dto.bill.vipcard.param.QueryVipCardOrderDetailTotalReq"
resultType="com.zteits.order.domain.sdo.OrderVipcardDetailTotalDO">
SELECT
a.order_type as orderType,
a.card_type as cardType,
a.terminal_source as terminalSource ,
IFNULL(a.card_act_amount,0) as cardActAmount
FROM
order_vipcard_detail a,pay_order b
WHERE
1 = 1
AND a.data_state = 1
AND a.data_state = b.data_state
and a.order_id=b.rlt_order_id
and b.order_big_type=300
and b.pay_order_state=40
<if test="plNos != null and plNos.size >0">
and a.pl_no in
<foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
#{plNo}
</foreach>
</if>
<if test="carNumber != null and carNumber != '' ">
and a.car_number = #{carNumber}
</if>
<if test="orderTypes != null and orderTypes.size > 0">
and a.order_type in
<foreach collection="orderTypes" item="orderType" open="(" close=")" separator=",">
#{orderType}
</foreach>
</if>
<![CDATA[AND a.create_date >= #{beginTime}]]>
<![CDATA[AND a.create_date <= #{endTime}]]>
</select>
<!--分页查询会员卡订单明细-->
<select id="queryVipCardOrderDetailForPage" resultType="com.zteits.order.domain.sdo.OrderVipcardDetailDO" parameterType="com.zteits.clouds.api.dto.bill.vipcard.param.QueryVipCardOrderDetailTotalReq">
select a.id as id,
a.detail_order_id as detailOrderId,
a.order_id as orderId,
a.vip_card_no as vipCardNo,
a.order_type as orderType,
a.person_card_no as personCardNo,
a.card_type as cardType,
a.car_type as carType,
a.terminal_source as terminalSource,
a.card_act_amount as cardActAmount,
a.order_dicount_fee as orderDicountFee,
a.price as price,
a.buy_num as buyNum,
a.use_type as useType,
a.pl_no as plNo,
a.pl_name as plName,
a.person_cust_id as personCustId,
a.car_number as carNumber,
a.eff_date as effDate,
a.exp_date as expDate,
a.invoice_state as invoiceState ,
a.remark as remark,
a.create_emp_id as createEmpId,
a.create_name as createName,
a.create_date as createDate,
a.modify_emp_id as modifyEmpId,
a.modify_name as modifyName,
a.modify_date as modifyDate,
b.pay_type as payType,
b.pay_finish_time as payFinishTime
from
order_vipcard_detail a,pay_order b
WHERE
1 = 1
AND a.data_state = 1
AND a.data_state = b.data_state
and a.order_id=b.rlt_order_id
and b.order_big_type=300
and b.pay_order_state=40
<if test="plNos != null and plNos.size >0">
and a.pl_no in
<foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
#{plNo}
</foreach>
</if>
<if test="cardNo != null and cardNo != ''">
and a.vip_card_no = #{cardNo}
</if>
<if test="carNumber != null and carNumber != ''">
and a.car_number = #{carNumber}
</if>
<if test="orderTypes != null and orderTypes.size > 0">
and a.order_type in
<foreach collection="orderTypes" item="orderType" open="(" close=")" separator=",">
#{orderType}
</foreach>
</if>
<![CDATA[AND a.create_date >= #{beginTime}]]>
<![CDATA[AND a.create_date <= #{endTime}]]>
order by a.create_date desc
</select>
</mapper>