InviteSettlementItemMapper.xml
6.88 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
<?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.yohoufo.dal.order.InviteSettlementItemMapper" >
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.InviteSettlementItem" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="buyer_uid" property="buyerUid" jdbcType="INTEGER" />
<result column="buyer_order_code" property="buyerOrderCode" jdbcType="BIGINT" />
<result column="seller_uid" property="sellerUid" jdbcType="INTEGER" />
<result column="order_amount" property="orderAmount" jdbcType="DECIMAL" />
<result column="order_create_time" property="orderCreateTime" jdbcType="INTEGER" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="settle_amount" property="settleAmount" jdbcType="DECIMAL" />
<result column="invite_settlement_id" property="inviteSettlementId" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="status_desc" property="statusDesc" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="order_num" property="orderNum" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, buyer_uid, buyer_order_code, seller_uid, order_amount,order_create_time,type,settle_amount, invite_settlement_id,
status, status_desc, create_time
</sql>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteSettlementItem" >
insert into invite_settlement_item (id,
uid,
buyer_uid,
buyer_order_code,
seller_uid,
order_amount,
order_create_time,
type,
settle_amount,
invite_settlement_id,
status,
status_desc,
create_time)
values (#{id,jdbcType=INTEGER},
#{uid,jdbcType=INTEGER},
#{buyerUid,jdbcType=INTEGER},
#{buyerOrderCode,jdbcType=BIGINT},
#{sellerUid,jdbcType=INTEGER},
#{orderAmount,jdbcType=DECIMAL},
#{orderCreateTime,jdbcType=INTEGER},
#{type,jdbcType=INTEGER},
#{settleAmount,jdbcType=DECIMAL},
#{inviteSettlementId,jdbcType=INTEGER},
#{status,jdbcType=INTEGER},
#{statusDesc,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER})
</insert>
<update id="updateToSettled">
update invite_settlement_item
set status = #{tagStatus,jdbcType=INTEGER},
invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status = #{srcStatus,jdbcType=INTEGER}
and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
</update>
<update id="updateToSettledRollback">
update invite_settlement_item
set status = #{tagStatus,jdbcType=INTEGER},
invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status = #{srcStatus,jdbcType=INTEGER}
and id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<update id="updateStatusByUidAndInviteSettlementId">
update invite_settlement_item
set status = #{status,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
</update>
<select id="selectByUidAndBuyerOrderCode" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT}
</select>
<select id="selectOneByUidTypeAndStatus" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status = #{status,jdbcType=INTEGER}
limit 1
</select>
<select id="selectCountByUidTypeAndInviteSettlementId" resultType="java.lang.Integer" >
select
count(1)
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
</select>
<select id="selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
select
seller_uid as 'sellerUid',
count(1) as 'totalElements',
sum(order_amount) as 'totalOrderAmount',
sum(settle_amount) as 'totalSettleAmount'
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
group by seller_uid
</select>
<select id="selectByUidTypeInviteSettlementIdAndSellerUid" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
and seller_uid = #{sellerUid,jdbcType=INTEGER}
</select>
<select id="selectOrderNumByInviterUid" resultMap="BaseResultMap" >
select
seller_uid, count(buyer_order_code) order_num
from invite_settlement_item
where uid = #{inviterUid,jdbcType=INTEGER}
and type = 1
and status in (1,3,4)
GROUP by seller_uid
</select>
<select id="selectStats" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
select
count(1) as 'totalElements',
sum(order_amount) as 'totalOrderAmount',
sum(settle_amount) as 'totalSettleAmount',
sum(if(status=4,settle_amount,0)) as 'totalPaidAmount',
sum(if(status!=4,settle_amount,0)) as 'totalWaitPayAmount'
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status in
<foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER}
</select>
<select id="select" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status in
<foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER}
order by order_create_time desc
limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
</select>
</mapper>