| 2747 |
chandransh |
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
2 |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
3 |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
4 |
|
|
|
5 |
<mapper namespace="in.shop2020.payment.persistence.RefundMapper">
|
|
|
6 |
|
|
|
7 |
<resultMap type="refund" id="refundResult">
|
|
|
8 |
<id property="id" column="id"/>
|
|
|
9 |
<collection property="attributes" javaType="ArrayList" column="id" ofType="refundAttribute" select="getAttributesForRefund"/>
|
|
|
10 |
</resultMap>
|
|
|
11 |
|
|
|
12 |
<insert id="insertRefund" parameterType="refund" useGeneratedKeys="true" keyProperty="id">
|
|
|
13 |
INSERT INTO refund
|
|
|
14 |
(gatewayId, paymentId, orderId, amount, attempts, createdAt)
|
|
|
15 |
VALUES
|
|
|
16 |
(#{gatewayId}, #{paymentId}, #{orderId}, #{amount}, 0, now())
|
|
|
17 |
</insert>
|
|
|
18 |
|
|
|
19 |
<insert id="insertRefundAttribute" parameterType="map">
|
|
|
20 |
INSERT INTO refundattribute
|
|
|
21 |
(refund_id, name, value)
|
|
|
22 |
VALUES(#{refundId}, #{name}, #{value})
|
|
|
23 |
ON DUPLICATE KEY UPDATE value=values(value);
|
|
|
24 |
</insert>
|
|
|
25 |
|
|
|
26 |
<update id="updateRefund" parameterType="refund">
|
|
|
27 |
UPDATE refund
|
|
|
28 |
SET
|
|
|
29 |
<if test="processedAt != null">
|
|
|
30 |
processedAt = #{processedAt},
|
|
|
31 |
</if>
|
|
|
32 |
attempts = #{attempts}
|
|
|
33 |
WHERE id=#{id}
|
|
|
34 |
</update>
|
|
|
35 |
|
|
|
36 |
<sql id="selectAllRefundFields">
|
|
|
37 |
SELECT * FROM refund
|
|
|
38 |
</sql>
|
|
|
39 |
|
|
|
40 |
<sql id="batchSizeLimit">
|
|
|
41 |
<if test="batchSize !=0">
|
|
|
42 |
LIMIT #{batchSize}
|
|
|
43 |
</if>
|
|
|
44 |
</sql>
|
|
|
45 |
|
|
|
46 |
<select id="getRefund" parameterType="int" resultMap="refundResult">
|
|
|
47 |
<include refid="selectAllRefundFields"/>
|
|
|
48 |
WHERE id=#{id}
|
|
|
49 |
</select>
|
|
|
50 |
|
|
|
51 |
<select id="getRefunds" parameterType="int" resultMap="refundResult">
|
|
|
52 |
<include refid="selectAllRefundFields"/>
|
|
|
53 |
ORDER BY id
|
|
|
54 |
<include refid="batchSizeLimit"/>
|
|
|
55 |
</select>
|
|
|
56 |
|
|
|
57 |
<select id="getPendingRefunds" parameterType="int" resultMap="refundResult">
|
|
|
58 |
<include refid="selectAllRefundFields"/>
|
|
|
59 |
WHERE processedAt is null and attempts < 5
|
|
|
60 |
ORDER BY id
|
|
|
61 |
<include refid="batchSizeLimit"/>
|
|
|
62 |
</select>
|
|
|
63 |
|
|
|
64 |
<select id="getFailedRefunds" parameterType="int" resultMap="refundResult">
|
|
|
65 |
<include refid="selectAllRefundFields"/>
|
|
|
66 |
WHERE processedAt is null and attempts >= 5
|
|
|
67 |
ORDER BY id
|
|
|
68 |
<include refid="batchSizeLimit"/>
|
|
|
69 |
</select>
|
|
|
70 |
|
|
|
71 |
<select id="getAttributesForRefund" parameterType="int" resultType="refundAttribute">
|
|
|
72 |
SELECT * FROM refundattribute where refund_id = #{id}
|
|
|
73 |
</select>
|
|
|
74 |
</mapper>
|