OrderMapper.xml
7.77 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
<?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.b2c.orders.dao.impl.OrderDaoBean">
<resultMap id="OrderRM" type="com.b2c.orders.domain.Order">
<id property="id" column="id" />
<result property="buyerId" column="buyer_id" />
<result property="buyerName" column="buyer_name" />
<result property="sellerId" column="seller_id" />
<result property="sellerName" column="seller_name" />
<result property="deliveryType" column="delivery_type" />
<result property="orderStatus" column="order_status"
typeHandler="com.b2c.orders.dao.utils.OrderStatusTypeHandler" />
<result property="payStatus" column="pay_status" />
<result property="buyerMemo" column="buyer_memo" />
<result property="payTime" column="pay_time" />
<result property="deliveryTime" column="delivery_time" />
<result property="buyerConfirmTime" column="buyer_confirm_time" />
<result property="sellerConfirmTime" column="seller_confirm_time" />
<result property="reservationTime" column="reservation_time" />
<result property="submitTime" column="submit_time" />
<result property="payType" column="pay_type" />
<result property="totalPrice" column="total_price" />
<result property="realTotalPrice" column="real_total_price" />
<result property="versionNum" column="version_num" />
<result property="delete" column="delete_flag" />
<result property="statusInReason" column="status_in_reason" />
<collection property="orderItems" column="id"
select="com.b2c.orders.dao.impl.OrderItemDaoBean.findByOrderId" />
</resultMap>
<sql id="selectColumn">
t1.id
,t1.buyer_id
,t1.buyer_name
,t1.seller_id
,t1.seller_name
,t1.delivery_type
,t1.order_status
,t1.pay_status
,t1.buyer_memo
,t1.pay_time
,t1.delivery_time
,t1.reservation_time
,t1.buyer_confirm_time
,t1.seller_confirm_time
,t1.submit_time
,t1.pay_type
,t1.total_price
,t1.real_total_price
,t1.version_num
,t1.status_in_reason
</sql>
<sql id="selectCondition">
<if test="param != null">
<if test="param.id != null and param.id != ''">
and t1.id = #{param.id}
</if>
<if test="param.buyerId != null and param.buyerId != ''">
and t1.buyer_id = #{param.buyerId}
</if>
<if test="param.buyerName != null and param.buyerName != ''">
and t1.buyer_name = #{param.buyerName}
</if>
<if test="param.sellerId != null and param.sellerId != ''">
and t1.seller_id = #{param.sellerId}
</if>
<if test="param.sellerName != null and param.sellerName != ''">
and t1.seller_name = #{param.sellerName}
</if>
<if test="param.deliveryType != null and param.deliveryType != ''">
and t1.delivery_type = #{param.deliveryType}
</if>
<if test="param.orderStatus != null and param.orderStatus != ''">
and t1.order_status = #{param.orderStatus}
</if>
<if test="param.payStatus != null and param.payStatus != ''">
and t1.pay_status = #{param.payStatus}
</if>
<if test="param.buyerMemo != null and param.buyerMemo != ''">
and t1.buyer_memo = #{param.buyerMemo}
</if>
<if test="param.payBeginTime != null and param.payBeginTime != ''">
<![CDATA[and t1.pay_time >= #{param.payBeginTime}]]>
</if>
<if test="param.payEndTime != null and param.payEndTime != ''">
<![CDATA[and t1.pay_time <= #{param.payEndTime}]]>
</if>
<if
test="param.deliveryBeginTime != null and param.deliveryBeginTime != ''">
<![CDATA[and t1.delivery_time >= #{param.deliveryBeginTime}]]>
</if>
<if test="param.deliveryEndTime != null and param.deliveryEndTime != ''">
<![CDATA[and t1.delivery_time <= #{param.deliveryEndTime}]]>
</if>
<if
test="param.buyerConfirmEndTime != null and param.buyerConfirmBeginTime != ''">
<![CDATA[and t1.buyer_confirm_time >= #{param.buyerConfirmBeginTime}]]>
</if>
<if
test="param.buyerConfirmEndTime != null and param.buyerConfirmEndTime != ''">
<![CDATA[and t1.buyer_confirm_time <= #{param.buyerConfirmEndTime}]]>
</if>
<if
test="param.sellerConfirmBeginTime != null and param.sellerConfirmBeginTime != ''">
<![CDATA[and t1.seller_confirm_time >= #{param.sellerConfirmBeginTime}]]>
</if>
<if
test="param.sellerConfirmEndTime != null and param.sellerConfirmEndTime != ''">
<![CDATA[and t1.seller_confirm_time <= #{param.sellerConfirmEndTime}]]>
</if>
<if
test="param.reservationBeginTime != null and param.reservationBeginTime != ''">
<![CDATA[and t1.reservation_time >= #{param.reservationBeginTime}]]>
</if>
<if
test="param.reservationEndTime != null and param.reservationEndTime != ''">
<![CDATA[and t1.reservation_time <= #{param.reservationEndTime}]]>
</if>
<if test="param.submitBeginTime != null and param.submitBeginTime != ''">
<![CDATA[and t1.submit_time >= #{param.submitBeginTime}]]>
</if>
<if test="param.submitEndTime != null and param.submitEndTime != ''">
<![CDATA[and t1.submit_time <= #{param.submitEndTime}]]>
</if>
<if test="param.buyerMemo != null and param.buyerMemo != ''">
and t1.pay_type = #{param.payType}
</if>
<if test="param.buyerMemo != null and param.buyerMemo != ''">
and t1.total_price = #{param.totalPrice}
</if>
<if test="param.productName != null and param.productName != ''">
<![CDATA[and t2.product_name like CONCAT('%',#{param.productName},'%')]]>
</if>
</if>
and delete_flag = 0
</sql>
<sql id="joinOrderItem">
<if test="param.productName != null and param.productName != ''">
RIGHT JOIN t_order_item t2 ON t2.order_id = t1.id
</if>
</sql>
<select id="getById" parameterType="Long" resultMap="OrderRM">
SELECT
<include refid="selectColumn" />
FROM t_order t1
WHERE delete_flag = 0 AND id = #{id}
</select>
<insert id="save" parameterType="com.b2c.orders.domain.Order">
<![CDATA[
INSERT INTO t_order(
id,
buyer_id,
seller_id,
delivery_type,
order_status,
pay_status,
buyer_memo,
delivery_time,
pay_type,
total_price
) VALUES(
#{id},
#{buyerId},
#{sellerId},
#{deliveryType},
#{orderStatus},
#{payStatus},
#{buyerMemo},
#{deliveryTime},
#{payType},
#{totalPrice}
)
]]>
</insert>
<update id="update" parameterType="com.b2c.orders.domain.Order">
<![CDATA[
UPDATE t_order set
order_status=#{orderStatus},
pay_status=#{payStatus},
buyer_memo=#{buyerMemo},
pay_time=#{payTime},
delivery_time=#{deliveryTime},
buyer_confirm_time=#{buyerConfirmTime},
seller_confirm_time=#{sellerConfirmTime},
real_total_price=#{realTotalPrice},
status_in_reason=#{statusInReason}
version_num=version_num + 1
where 1=1
and version_num=#{versionNum} and id = #{id}
]]>
</update>
<select id="countByCondition" parameterType="Query" resultType="Integer">
SELECT count(1) FROM t_order
<include refid="joinOrderItem" />
where 1=1
<include refid="selectCondition" />
</select>
<select id="listByCondition" parameterType="Query" resultMap="OrderRM">
SELECT
<include refid="selectColumn" />
FROM t_order t1
<include refid="joinOrderItem" />
where 1=1
<include refid="selectCondition" />
order by t1.id desc
<![CDATA[
limit #{startRow},#{pageSize}
]]>
</select>
<update id="deleteById" parameterType="Long">
<![CDATA[
update t_order set delete_flag = 1,version_num=version_num + 1
where 1 = 1
and id = #{id} and version_num=#{versionNum}
]]>
</update>
</mapper>