| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?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.ruoyi.system.omgpay.mapper.OmgPaymentAttemptMapper">
- <sql id="attemptColumns">
- id, dd_id AS ddId, merchant_trade_no AS merchantTradeNo,
- store_id AS storeId, merchant_id AS merchantId, amount,
- hash_key_snapshot AS hashKeySnapshot, hash_iv_snapshot AS hashIvSnapshot,
- attempt_status AS attemptStatus, active_dd_id AS activeDdId,
- trade_no AS tradeNo, rtn_code AS rtnCode, rtn_msg AS rtnMsg,
- payment_type AS paymentType, payment_date AS paymentDate, trade_date AS tradeDate,
- payment_type_charge_fee AS paymentTypeChargeFee, simulate_paid AS simulatePaid,
- last_notify_time AS lastNotifyTime,
- create_time AS createTime, update_time AS updateTime
- </sql>
- <!-- FOR UPDATE serializes concurrent endpoint calls before MerchantTradeNo generation/reuse decisions. -->
- <select id="selectOrderForUpdate"
- resultType="com.ruoyi.system.omgpay.domain.OmgPaymentOrderSnapshot">
- SELECT id, dd_id AS ddId, parent_dd_id AS parentDdId, md_id AS storeId,
- user_id AS userId, amount, state, pay_status AS payStatus, pay_type AS payType
- FROM pos_order WHERE dd_id = #{ddId} LIMIT 1 FOR UPDATE
- </select>
- <select id="selectOrder"
- resultType="com.ruoyi.system.omgpay.domain.OmgPaymentOrderSnapshot">
- SELECT id, dd_id AS ddId, parent_dd_id AS parentDdId, md_id AS storeId,
- user_id AS userId, amount, state, pay_status AS payStatus, pay_type AS payType
- FROM pos_order WHERE dd_id = #{ddId} LIMIT 1
- </select>
- <!-- Locking current reads see attempts committed by a transaction that won a unique-key race. -->
- <select id="selectActiveCreatedByDdIdForUpdate"
- resultType="com.ruoyi.system.omgpay.domain.OmgPaymentAttempt">
- SELECT <include refid="attemptColumns"/>
- FROM pos_order_omg_attempt
- WHERE active_dd_id = #{ddId}
- LIMIT 1 FOR UPDATE
- </select>
- <select id="selectActiveCreatedByDdId"
- resultType="com.ruoyi.system.omgpay.domain.OmgPaymentAttempt">
- SELECT <include refid="attemptColumns"/>
- FROM pos_order_omg_attempt
- WHERE active_dd_id = #{ddId}
- LIMIT 1
- </select>
- <select id="selectPaidByDdId"
- resultType="com.ruoyi.system.omgpay.domain.OmgPaymentAttempt">
- SELECT <include refid="attemptColumns"/>
- FROM pos_order_omg_attempt
- WHERE dd_id = #{ddId} AND attempt_status = 1
- ORDER BY payment_date IS NULL, payment_date ASC, id ASC
- LIMIT 1
- </select>
- <select id="selectByMerchantTradeNoForUpdate"
- resultType="com.ruoyi.system.omgpay.domain.OmgPaymentAttempt">
- SELECT <include refid="attemptColumns"/>
- FROM pos_order_omg_attempt
- WHERE merchant_trade_no = #{merchantTradeNo}
- LIMIT 1 FOR UPDATE
- </select>
- <select id="selectByMerchantTradeNo"
- resultType="com.ruoyi.system.omgpay.domain.OmgPaymentAttempt">
- SELECT <include refid="attemptColumns"/>
- FROM pos_order_omg_attempt
- WHERE merchant_trade_no = #{merchantTradeNo}
- LIMIT 1
- </select>
- <!-- active_dd_id is a DB-generated key invariant, so Java inserts only the created facts. -->
- <insert id="insertCreated" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO pos_order_omg_attempt
- (dd_id, merchant_trade_no, store_id, merchant_id, amount,
- hash_key_snapshot, hash_iv_snapshot, attempt_status, create_time, update_time)
- VALUES
- (#{ddId}, #{merchantTradeNo}, #{storeId}, #{merchantId}, #{amount},
- #{hashKeySnapshot}, #{hashIvSnapshot}, #{attemptStatus}, #{createTime}, #{updateTime})
- </insert>
- <!-- PAID is irreversible; a late success may upgrade FAILED or SUPERSEDED. -->
- <update id="markPaid">
- UPDATE pos_order_omg_attempt
- SET attempt_status = 1, trade_no = #{tradeNo}, rtn_code = #{rtnCode}, rtn_msg = #{rtnMsg},
- payment_type = #{paymentType}, payment_date = #{paymentDate}, trade_date = #{tradeDate},
- payment_type_charge_fee = #{paymentTypeChargeFee}, simulate_paid = #{simulatePaid},
- last_notify_time = #{lastNotifyTime}, update_time = #{updateTime}
- WHERE id = #{id} AND attempt_status IN (0, 2, 3)
- </update>
- <update id="markFailed">
- UPDATE pos_order_omg_attempt
- SET attempt_status = 2, trade_no = #{tradeNo}, rtn_code = #{rtnCode}, rtn_msg = #{rtnMsg},
- payment_type = #{paymentType}, payment_date = #{paymentDate}, trade_date = #{tradeDate},
- payment_type_charge_fee = #{paymentTypeChargeFee}, simulate_paid = #{simulatePaid},
- last_notify_time = #{lastNotifyTime}, update_time = #{updateTime}
- WHERE id = #{id} AND attempt_status IN (0, 2)
- </update>
- <update id="supersedeOtherCreated">
- UPDATE pos_order_omg_attempt
- SET attempt_status = 3, update_time = #{updateTime}
- WHERE dd_id = #{ddId} AND id != #{paidAttemptId} AND attempt_status = 0
- </update>
- <!-- Payment notification owns only the payment fact; no order/delivery state is changed here. -->
- <update id="markOrderPaid">
- UPDATE pos_order SET pay_status = 1
- WHERE dd_id = #{ddId} AND pay_status != 1
- </update>
- <select id="countOtherPaidAttempts" resultType="int">
- SELECT COUNT(*) FROM pos_order_omg_attempt
- WHERE dd_id = #{ddId} AND id != #{attemptId} AND attempt_status = 1
- </select>
- </mapper>
|