| 1946 |
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.PaymentMapper">
|
|
|
6 |
|
|
|
7 |
<resultMap type="payment" id="paymentResult">
|
|
|
8 |
<id property="id" column="id"/>
|
|
|
9 |
<collection property="attributes" javaType="ArrayList" column="id" ofType="paymentAttribute" select="getAttributesForPayment"/>
|
|
|
10 |
</resultMap>
|
|
|
11 |
|
|
|
12 |
<insert id="insertPayment" parameterType="payment" useGeneratedKeys="true" keyProperty="id">
|
|
|
13 |
INSERT INTO payment
|
|
|
14 |
(gatewayId, userId, merchantTxnId, amount, status, initTimestamp)
|
|
|
15 |
VALUES
|
|
|
16 |
(#{gatewayId}, #{userId}, #{merchantTxnId}, #{amount}, #{status}, now())
|
|
|
17 |
</insert>
|
|
|
18 |
|
|
|
19 |
<insert id="insertPaymentAttribute" parameterType="map">
|
|
|
20 |
INSERT INTO paymentattribute
|
|
|
21 |
(payment_id, name, value)
|
|
|
22 |
VALUES(#{paymentId}, #{name}, #{value})
|
|
|
23 |
ON DUPLICATE KEY UPDATE value=values(value);
|
|
|
24 |
</insert>
|
|
|
25 |
|
|
|
26 |
<update id="updatePayment" parameterType="payment">
|
|
|
27 |
UPDATE payment
|
|
|
28 |
SET gatewayPaymentId = #{gatewayPaymentId},
|
|
|
29 |
sessionId = #{sessionId},
|
|
|
30 |
gatewayTxnStatus = #{gatewayTxnStatus},
|
|
|
31 |
description = #{description},
|
|
|
32 |
gatewayTxnId = #{gatewayTxnId},
|
|
|
33 |
authCode = #{authCode},
|
|
|
34 |
referenceCode = #{referenceCode},
|
|
|
35 |
errorCode = #{errorCode},
|
|
|
36 |
status = #{status},
|
|
|
37 |
gatewayTxnDate = #{gatewayTxnDate},
|
|
|
38 |
successTimestamp = #{successTimestamp},
|
|
|
39 |
errorTimestamp = #{errorTimestamp}
|
|
|
40 |
WHERE id=#{id}
|
|
|
41 |
</update>
|
|
|
42 |
|
|
|
43 |
<sql id="selectAllPaymentFields">
|
|
|
44 |
SELECT * FROM payment
|
|
|
45 |
</sql>
|
|
|
46 |
|
|
|
47 |
<select id="getPayment" parameterType="int" resultMap="paymentResult">
|
|
|
48 |
<include refid="selectAllPaymentFields"/>
|
|
|
49 |
WHERE id=#{id}
|
|
|
50 |
</select>
|
|
|
51 |
|
|
|
52 |
<select id="getPaymentForTxn" parameterType="int" resultMap="paymentResult">
|
|
|
53 |
SELECT * FROM payment
|
|
|
54 |
WHERE merchantTxnId=#{merchantTxnId}
|
|
|
55 |
</select>
|
|
|
56 |
|
| 2288 |
chandransh |
57 |
<sql id="getPaymentsWhereClause">
|
|
|
58 |
<if test="fromTime != ''">
|
|
|
59 |
initTimestamp >= #{fromTime}
|
|
|
60 |
</if>
|
|
|
61 |
<if test="toTime != '' && status == 0">
|
|
|
62 |
AND initTimestamp <= #{toTime}
|
|
|
63 |
</if>
|
|
|
64 |
<if test="toTime != '' && status != 0">
|
|
|
65 |
AND (errorTimestamp <= #{toTime} OR successTimestamp <= #{toTime})
|
|
|
66 |
</if>
|
|
|
67 |
<if test="status != -1">
|
|
|
68 |
AND status=#{status}
|
|
|
69 |
</if>
|
|
|
70 |
<if test="gatewayId != 0">
|
|
|
71 |
AND gatewayId = #{gatewayId}
|
|
|
72 |
</if>
|
|
|
73 |
</sql>
|
|
|
74 |
|
| 1946 |
chandransh |
75 |
<select id="getPayments" parameterType="map" resultMap="paymentResult">
|
|
|
76 |
SELECT * FROM payment
|
|
|
77 |
<where>
|
| 2288 |
chandransh |
78 |
<include refid="getPaymentsWhereClause"/>
|
| 1946 |
chandransh |
79 |
</where>
|
|
|
80 |
ORDER BY id
|
|
|
81 |
</select>
|
|
|
82 |
|
|
|
83 |
<select id="getPaymentsForUser" parameterType="map" resultMap="paymentResult">
|
|
|
84 |
SELECT * FROM payment
|
|
|
85 |
<where>
|
| 2288 |
chandransh |
86 |
<include refid="getPaymentsWhereClause"/>
|
|
|
87 |
AND userId=#{userId}
|
| 1946 |
chandransh |
88 |
</where>
|
|
|
89 |
ORDER BY id
|
|
|
90 |
</select>
|
|
|
91 |
|
|
|
92 |
<select id="getMinMaxPaymentAmount" resultType="hashmap">
|
|
|
93 |
SELECT MIN(AMOUNT) MIN, MAX(AMOUNT) MAX from payment
|
|
|
94 |
</select>
|
|
|
95 |
|
|
|
96 |
<select id="getAttributesForPayment" parameterType="int" resultType="paymentAttribute">
|
|
|
97 |
SELECT * FROM paymentattribute where payment_id = #{id}
|
|
|
98 |
</select>
|
|
|
99 |
</mapper>
|