TdBVipCardContractSmapper.xml
8.86 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
<?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.TdBVipCardContractSMapper">
<resultMap id="BaseResultMap" type="com.zteits.order.domain.TdBVipCardContract">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="contract_no" jdbcType="VARCHAR" property="contractNo" />
<result column="detail_id" jdbcType="BIGINT" property="detailId" />
<result column="order_id" jdbcType="VARCHAR" property="orderId" />
<result column="pl_no" jdbcType="VARCHAR" property="plNo" />
<result column="pl_name" jdbcType="VARCHAR" property="plName" />
<result column="car_number" jdbcType="VARCHAR" property="carNumber" />
<result column="cust_name" jdbcType="VARCHAR" property="custName" />
<result column="cust_phone" jdbcType="VARCHAR" property="custPhone" />
<result column="cust_address" jdbcType="VARCHAR" property="custAddress" />
<result column="price" jdbcType="BIGINT" property="price" />
<result column="total_fee" jdbcType="BIGINT" property="totalFee" />
<result column="eff_date" jdbcType="TIMESTAMP" property="effDate" />
<result column="exp_date" jdbcType="TIMESTAMP" property="expDate" />
<result column="detail_create_date" jdbcType="TIMESTAMP" property="detailCreateDate" />
<result column="contract_year" jdbcType="INTEGER" property="contractYear" />
<result column="file_name" jdbcType="VARCHAR" property="fileName" />
<result column="file_key" jdbcType="VARCHAR" property="fileKey" />
<result column="file_url" jdbcType="VARCHAR" property="fileUrl" />
<result column="file_size" jdbcType="BIGINT" property="fileSize" />
<result column="data_state" jdbcType="INTEGER" property="dataState" />
<result column="create_op" jdbcType="INTEGER" property="createOp" />
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
<result column="modify_op" jdbcType="INTEGER" property="modifyOp" />
<result column="modify_date" jdbcType="TIMESTAMP" property="modifyDate" />
</resultMap>
<!--
待归档月卡购买明细:条件与 OrderVipcardDetailSmapper.queryVipCardOrderInfoForPage 完全一致
(a.data_state=1 and b.data_state=1 and a.order_id=b.order_id and b.order_state in(40,50)),
只额外投影 a.id / a.order_id / a.pl_no / a.pl_name,并排除已在合同表建档的明细。
-->
<select id="selectPendingContractDetails"
parameterType="com.zteits.clouds.api.dto.order.vipcardcontract.param.QueryPendingContractDetailReq"
resultType="com.zteits.order.domain.TdBVipCardContract">
select
a.id as detailId,
a.order_id as orderId,
a.pl_no as plNo,
a.pl_name as plName,
a.car_number as carNumber,
a.price as price,
a.card_act_amount as totalFee,
a.eff_date as effDate,
a.exp_date as expDate,
a.create_date as detailCreateDate
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:已完成*/
and not exists (select 1 from td_b_vip_card_contract c where c.detail_id = a.id)
<if test="plNo != null and plNo != ''">
and a.pl_no = #{plNo}
</if>
order by a.id asc
limit #{limit}
</select>
<insert id="insertIgnoreBatch">
insert ignore into td_b_vip_card_contract
(contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
data_state, create_op, create_date)
values
<foreach collection="list" item="item" separator=",">
(#{item.contractNo}, #{item.detailId}, #{item.orderId}, #{item.plNo}, #{item.plName},
#{item.carNumber}, #{item.custName}, #{item.custPhone}, #{item.custAddress},
#{item.price}, #{item.totalFee}, #{item.effDate}, #{item.expDate},
#{item.detailCreateDate}, #{item.contractYear}, 1, #{item.createOp}, now())
</foreach>
</insert>
<select id="selectUnarchivedContracts"
parameterType="com.zteits.clouds.api.dto.order.vipcardcontract.param.QueryPendingContractDetailReq"
resultMap="BaseResultMap">
select
id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
modify_date
from td_b_vip_card_contract
where data_state = 1
and (file_key is null or file_key = '')
<if test="plNo != null and plNo != ''">
and pl_no = #{plNo}
</if>
order by id asc
limit #{limit}
</select>
<select id="selectByYear" resultMap="BaseResultMap">
select
id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
modify_date
from td_b_vip_card_contract
where data_state = 1
and contract_year = #{contractYear}
<if test="plNo != null and plNo != ''">
and pl_no = #{plNo}
</if>
order by detail_create_date asc, id asc
</select>
<select id="selectContractForPage"
parameterType="com.zteits.clouds.api.dto.order.vipcardcontract.param.QueryVipCardContractPageReq"
resultMap="BaseResultMap">
select
id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
modify_date
from td_b_vip_card_contract
where data_state = 1
<if test="plNo != null and plNo != ''">
and pl_no = #{plNo}
</if>
<if test="carNumber != null and carNumber != ''">
and car_number like concat('%', #{carNumber}, '%')
</if>
<if test="contractNo != null and contractNo != ''">
and contract_no like concat('%', #{contractNo}, '%')
</if>
<if test="custName != null and custName != ''">
and cust_name like concat('%', #{custName}, '%')
</if>
<if test="contractYear != null">
and contract_year = #{contractYear}
</if>
<if test="beginDate != null and beginDate != ''">
<![CDATA[ and eff_date >= #{beginDate} ]]>
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[ and eff_date <= #{endDate} ]]>
</if>
order by id desc
</select>
<select id="selectByIds" resultMap="BaseResultMap">
select
id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
modify_date
from td_b_vip_card_contract
where data_state = 1
and id in
<foreach collection="ids" open="(" close=")" item="id" separator=",">
#{id}
</foreach>
order by detail_create_date asc, id asc
</select>
<select id="selectLedgerYears" resultType="java.lang.String">
select distinct contract_year
from td_b_vip_card_contract
where data_state = 1
and contract_year is not null
<if test="plNo != null and plNo != ''">
and pl_no = #{plNo}
</if>
order by contract_year desc
</select>
<!-- 单条 SQL 批量回写,避免循环操作数据库 -->
<update id="batchUpdateArchive">
update td_b_vip_card_contract
set modify_date = now(),
file_name = case id
<foreach collection="list" item="item">
when #{item.id} then #{item.fileName}
</foreach>
end,
file_key = case id
<foreach collection="list" item="item">
when #{item.id} then #{item.fileKey}
</foreach>
end,
file_url = case id
<foreach collection="list" item="item">
when #{item.id} then #{item.fileUrl}
</foreach>
end,
file_size = case id
<foreach collection="list" item="item">
when #{item.id} then #{item.fileSize}
</foreach>
end,
modify_op = case id
<foreach collection="list" item="item">
when #{item.id} then #{item.opId}
</foreach>
end
where id in
<foreach collection="list" open="(" close=")" item="item" separator=",">
#{item.id}
</foreach>
</update>
</mapper>