将支付成功、退款成功的 MQ 消费逻辑进行迁移
This commit is contained in:
parent
63b4c27c8f
commit
04f53da686
@ -1,45 +0,0 @@
|
|||||||
package cn.iocoder.mall.pay.api.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支付退款状态枚举
|
|
||||||
*/
|
|
||||||
public enum PayRefundStatus {
|
|
||||||
|
|
||||||
WAITING(1, "处理中"),
|
|
||||||
SUCCESS(2, "成功"),
|
|
||||||
FAILURE(3, "失败"), // 例如说,支付单超时
|
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态
|
|
||||||
*/
|
|
||||||
private Integer value;
|
|
||||||
/**
|
|
||||||
* 名字
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
PayRefundStatus(Integer value, String name) {
|
|
||||||
this.value = value;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PayRefundStatus setValue(Integer value) {
|
|
||||||
this.value = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PayRefundStatus setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package cn.iocoder.mall.pay.biz.dao;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.pay.biz.dataobject.PayRefundDO;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface PayRefundMapper {
|
|
||||||
|
|
||||||
void insert(PayRefundDO entity);
|
|
||||||
|
|
||||||
int update(@Param("entity") PayRefundDO entity,
|
|
||||||
@Param("whereStatus") Integer whereStatus);
|
|
||||||
|
|
||||||
PayRefundDO selectById(@Param("id") Integer id);
|
|
||||||
|
|
||||||
PayRefundDO selectByRefundCode(@Param("refundCode") String refundCode);
|
|
||||||
|
|
||||||
List<PayRefundDO> selectListByPage(@Param("createBeginTime") Date createBeginTime,
|
|
||||||
@Param("createEndTime") Date createEndTime,
|
|
||||||
@Param("finishBeginTime") Date finishBeginTime,
|
|
||||||
@Param("finishEndTime") Date finishEndTime,
|
|
||||||
@Param("status") Integer status,
|
|
||||||
@Param("payChannel") Integer payChannel,
|
|
||||||
@Param("offset") Integer offset,
|
|
||||||
@Param("limit") Integer limit);
|
|
||||||
|
|
||||||
Integer selectCountByPage(@Param("createBeginTime") Date createBeginTime,
|
|
||||||
@Param("createEndTime") Date createEndTime,
|
|
||||||
@Param("finishBeginTime") Date finishBeginTime,
|
|
||||||
@Param("finishEndTime") Date finishEndTime,
|
|
||||||
@Param("status") Integer status,
|
|
||||||
@Param("payChannel") Integer payChannel);
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package cn.iocoder.mall.pay.biz.dao;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionDO;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface PayTransactionMapper {
|
|
||||||
|
|
||||||
int updateForRefundTotal(@Param("id") Integer id,
|
|
||||||
@Param("refundTotalIncr") Integer refundTotalIncr);
|
|
||||||
|
|
||||||
|
|
||||||
List<PayTransactionDO> selectListByPage(@Param("createBeginTime") Date createBeginTime,
|
|
||||||
@Param("createEndTime") Date createEndTime,
|
|
||||||
@Param("paymentBeginTime") Date paymentBeginTime,
|
|
||||||
@Param("paymentEndTime") Date paymentEndTime,
|
|
||||||
@Param("status") Integer status,
|
|
||||||
@Param("hasRefund") Boolean hasRefund,
|
|
||||||
@Param("payChannel") Integer payChannel,
|
|
||||||
@Param("orderSubject") String orderSubject,
|
|
||||||
@Param("offset") Integer offset,
|
|
||||||
@Param("limit") Integer limit);
|
|
||||||
|
|
||||||
Integer selectCountByPage(@Param("createBeginTime") Date createBeginTime,
|
|
||||||
@Param("createEndTime") Date createEndTime,
|
|
||||||
@Param("paymentBeginTime") Date paymentBeginTime,
|
|
||||||
@Param("paymentEndTime") Date paymentEndTime,
|
|
||||||
@Param("status") Integer status,
|
|
||||||
@Param("hasRefund") Boolean hasRefund,
|
|
||||||
@Param("payChannel") Integer payChannel,
|
|
||||||
@Param("orderSubject") String orderSubject);
|
|
||||||
|
|
||||||
}
|
|
@ -1,122 +0,0 @@
|
|||||||
<?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="cn.iocoder.mall.pay.biz.dao.PayRefundMapper">
|
|
||||||
|
|
||||||
<sql id="FIELDS">
|
|
||||||
id, transaction_id, refund_code, app_id, create_ip, order_id,
|
|
||||||
order_description, price, status,
|
|
||||||
finish_time, notify_url, extension_data, refund_channel, refund_time, notify_time,
|
|
||||||
trade_no, create_time
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<insert id="insert" parameterType="PayRefundDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
|
||||||
INSERT INTO refund (
|
|
||||||
transaction_id, refund_code, app_id, create_ip, order_id,
|
|
||||||
order_description, price, status,
|
|
||||||
finish_time, notify_url, extension_data, refund_channel, refund_time, notify_time,
|
|
||||||
trade_no, create_time
|
|
||||||
) VALUES (
|
|
||||||
#{transactionId}, #{refundCode}, #{appId}, #{createIp}, #{orderId},
|
|
||||||
#{orderDescription}, #{price}, #{status},
|
|
||||||
#{finishTime}, #{notifyUrl}, #{extensionData}, #{refundChannel}, #{refundTime}, #{notifyTime},
|
|
||||||
#{tradeNo}, #{createTime}
|
|
||||||
)
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<update id="update">
|
|
||||||
UPDATE refund
|
|
||||||
<set>
|
|
||||||
<if test="entity.status != null">
|
|
||||||
, status = #{entity.status}
|
|
||||||
</if>
|
|
||||||
<if test="entity.finishTime != null">
|
|
||||||
, finish_time = #{entity.finishTime}
|
|
||||||
</if>
|
|
||||||
<if test="entity.extensionData != null">
|
|
||||||
, extension_data = #{entity.extensionData}
|
|
||||||
</if>
|
|
||||||
<if test="entity.refundTime != null">
|
|
||||||
, refund_time = #{entity.refundTime}
|
|
||||||
</if>
|
|
||||||
<if test="entity.notifyTime != null">
|
|
||||||
, notify_time = #{entity.notifyTime}
|
|
||||||
</if>
|
|
||||||
<if test="entity.tradeNo != null">
|
|
||||||
, trade_no = #{entity.tradeNo}
|
|
||||||
</if>
|
|
||||||
</set>
|
|
||||||
WHERE id = #{entity.id}
|
|
||||||
<if test="whereStatus != null">
|
|
||||||
AND status = #{whereStatus}
|
|
||||||
</if>
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<select id="selectByRefundCode" parameterType="String" resultType="PayRefundDO">
|
|
||||||
SELECT
|
|
||||||
<include refid="FIELDS"/>
|
|
||||||
FROM refund
|
|
||||||
WHERE refund_code = #{refundCode}
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectById" parameterType="Integer" resultType="PayRefundDO">
|
|
||||||
SELECT
|
|
||||||
<include refid="FIELDS"/>
|
|
||||||
FROM refund
|
|
||||||
WHERE id = #{id}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectListByPage" resultType="PayRefundDO">
|
|
||||||
SELECT
|
|
||||||
<include refid="FIELDS"/>
|
|
||||||
FROM refund
|
|
||||||
<where>
|
|
||||||
<if test="createBeginTime != null">
|
|
||||||
AND create_time >= #{createBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="createEndTime != null">
|
|
||||||
AND #{createEndTime} >= create_time
|
|
||||||
</if>
|
|
||||||
<if test="finishBeginTime != null">
|
|
||||||
AND finish_time >= #{finishBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="finishEndTime != null">
|
|
||||||
AND #{finishEndTime} >= finish_time
|
|
||||||
</if>
|
|
||||||
<if test="status != null">
|
|
||||||
AND status = #{status}
|
|
||||||
</if>
|
|
||||||
<if test="payChannel != null">
|
|
||||||
AND pay_channel = #{payChannel}
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
LIMIT #{offset}, #{limit}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectCountByPage" resultType="Integer">
|
|
||||||
SELECT
|
|
||||||
COUNT(1)
|
|
||||||
FROM refund
|
|
||||||
<where>
|
|
||||||
<if test="createBeginTime != null">
|
|
||||||
AND create_time >= #{createBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="createEndTime != null">
|
|
||||||
AND #{createEndTime} >= create_time
|
|
||||||
</if>
|
|
||||||
<if test="finishBeginTime != null">
|
|
||||||
AND finish_time >= #{finishBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="finishEndTime != null">
|
|
||||||
AND #{finishEndTime} >= finish_time
|
|
||||||
</if>
|
|
||||||
<if test="status != null">
|
|
||||||
AND status = #{status}
|
|
||||||
</if>
|
|
||||||
<if test="payChannel != null">
|
|
||||||
AND pay_channel = #{payChannel}
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
@ -1,25 +0,0 @@
|
|||||||
<?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="cn.iocoder.mall.pay.biz.dao.PayTransactionExtensionMapper">
|
|
||||||
|
|
||||||
<sql id="FIELDS">
|
|
||||||
id, transaction_id, pay_channel, transaction_code, extension_data,
|
|
||||||
create_ip, status, create_time
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<select id="selectByTransactionCode" parameterType="String" resultType="PayTransactionExtensionDO">
|
|
||||||
SELECT
|
|
||||||
<include refid="FIELDS"/>
|
|
||||||
FROM transaction_extension
|
|
||||||
WHERE transaction_code = #{transactionCode}
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectById" parameterType="Integer" resultType="PayTransactionExtensionDO">
|
|
||||||
SELECT
|
|
||||||
<include refid="FIELDS"/>
|
|
||||||
FROM transaction_extension
|
|
||||||
WHERE id = #{id}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
@ -1,128 +0,0 @@
|
|||||||
<?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="cn.iocoder.mall.pay.biz.dao.PayTransactionMapper">
|
|
||||||
|
|
||||||
<sql id="FIELDS">
|
|
||||||
id, app_id, create_ip, order_id, order_subject,
|
|
||||||
order_description, order_memo, price, status, expire_time,
|
|
||||||
finish_time, notify_url, extension_id, pay_channel, payment_time,
|
|
||||||
notify_time, trade_no, refund_total, create_time
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<update id="update">
|
|
||||||
UPDATE transaction
|
|
||||||
<set>
|
|
||||||
<if test="entity.status != null">
|
|
||||||
, status = #{entity.status}
|
|
||||||
</if>
|
|
||||||
<if test="entity.extensionId != null">
|
|
||||||
, extension_id = #{entity.extensionId}
|
|
||||||
</if>
|
|
||||||
<if test="entity.payChannel != null">
|
|
||||||
, pay_channel = #{entity.payChannel}
|
|
||||||
</if>
|
|
||||||
<if test="entity.paymentTime != null">
|
|
||||||
, payment_time = #{entity.paymentTime}
|
|
||||||
</if>
|
|
||||||
<if test="entity.finishTime != null">
|
|
||||||
, finish_time = #{entity.finishTime}
|
|
||||||
</if>
|
|
||||||
<if test="entity.notifyTime != null">
|
|
||||||
, notify_time = #{entity.notifyTime}
|
|
||||||
</if>
|
|
||||||
<if test="entity.tradeNo != null">
|
|
||||||
, trade_no = #{entity.tradeNo}
|
|
||||||
</if>
|
|
||||||
</set>
|
|
||||||
WHERE id = #{entity.id}
|
|
||||||
<if test="whereStatus != null">
|
|
||||||
AND status = #{whereStatus}
|
|
||||||
</if>
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="updateForRefundTotal">
|
|
||||||
UPDATE `transaction`
|
|
||||||
SET refund_total = refund_total + ${refundTotalIncr}
|
|
||||||
WHERE price >= refund_total + ${refundTotalIncr}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<select id="selectByAppIdAndOrderId" resultType="PayTransactionDO">
|
|
||||||
SELECT
|
|
||||||
<include refid="FIELDS"/>
|
|
||||||
FROM transaction
|
|
||||||
WHERE app_id = #{appId}
|
|
||||||
AND order_id = #{orderId}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectListByPage" resultType="PayTransactionDO">
|
|
||||||
SELECT
|
|
||||||
<include refid="FIELDS"/>
|
|
||||||
FROM transaction
|
|
||||||
<where>
|
|
||||||
<if test="createBeginTime != null">
|
|
||||||
AND create_time >= #{createBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="createEndTime != null">
|
|
||||||
AND #{createEndTime} >= create_time
|
|
||||||
</if>
|
|
||||||
<if test="paymentBeginTime != null">
|
|
||||||
AND payment_time >= #{paymentBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="paymentEndTime != null">
|
|
||||||
AND #{paymentEndTime} >= payment_time
|
|
||||||
</if>
|
|
||||||
<if test="status != null">
|
|
||||||
AND status = #{status}
|
|
||||||
</if>
|
|
||||||
<if test="hasRefund == true">
|
|
||||||
AND refund_total > 0
|
|
||||||
</if>
|
|
||||||
<if test="hasRefund == false">
|
|
||||||
AND refund_total = 0
|
|
||||||
</if>
|
|
||||||
<if test="payChannel != null">
|
|
||||||
AND pay_channel = #{payChannel}
|
|
||||||
</if>
|
|
||||||
<if test="orderSubject != null">
|
|
||||||
order_subject LIKE "%"#{orderSubject}"%"
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
LIMIT #{offset}, #{limit}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectCountByPage" resultType="Integer">
|
|
||||||
SELECT
|
|
||||||
COUNT(1)
|
|
||||||
FROM transaction
|
|
||||||
<where>
|
|
||||||
<if test="createBeginTime != null">
|
|
||||||
AND create_time >= #{createBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="createEndTime != null">
|
|
||||||
AND #{createEndTime} >= create_time
|
|
||||||
</if>
|
|
||||||
<if test="paymentBeginTime != null">
|
|
||||||
AND payment_time >= #{paymentBeginTime}
|
|
||||||
</if>
|
|
||||||
<if test="paymentEndTime != null">
|
|
||||||
AND #{paymentEndTime} >= payment_time
|
|
||||||
</if>
|
|
||||||
<if test="status != null">
|
|
||||||
AND status = #{status}
|
|
||||||
</if>
|
|
||||||
<if test="hasRefund == true">
|
|
||||||
AND refund_total > 0
|
|
||||||
</if>
|
|
||||||
<if test="hasRefund == false">
|
|
||||||
AND refund_total = 0
|
|
||||||
</if>
|
|
||||||
<if test="payChannel != null">
|
|
||||||
AND pay_channel = #{payChannel}
|
|
||||||
</if>
|
|
||||||
<if test="orderSubject != null">
|
|
||||||
order_subject LIKE "%"#{orderSubject}"%"
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
@ -0,0 +1,30 @@
|
|||||||
|
package cn.iocoder.mall.payservice.enums.refund;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付退款状态枚举
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum PayRefundStatus {
|
||||||
|
|
||||||
|
WAITING(1, "处理中"),
|
||||||
|
SUCCESS(2, "成功"),
|
||||||
|
FAILURE(3, "失败"), // 例如说,支付单超时
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private final Integer value;
|
||||||
|
/**
|
||||||
|
* 名字
|
||||||
|
*/
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
PayRefundStatus(Integer value, String name) {
|
||||||
|
this.value = value;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.mall.pay.biz.component;
|
package cn.iocoder.mall.payservice.common.dubbo;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.util.StringUtil;
|
import cn.iocoder.common.framework.util.StringUtils;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
@ -48,7 +48,7 @@ public class DubboReferencePool {
|
|||||||
|
|
||||||
private ReferenceMeta createGenericService(String notifyUrl) {
|
private ReferenceMeta createGenericService(String notifyUrl) {
|
||||||
// 使用 # 号分隔,格式为 服务名#方法名#版本号
|
// 使用 # 号分隔,格式为 服务名#方法名#版本号
|
||||||
List<String> notifyUrlParts = StringUtil.split(notifyUrl, "#");
|
List<String> notifyUrlParts = StringUtils.split(notifyUrl, "#");
|
||||||
// 创建 ApplicationConfig 对象
|
// 创建 ApplicationConfig 对象
|
||||||
ApplicationConfig application = new ApplicationConfig();
|
ApplicationConfig application = new ApplicationConfig();
|
||||||
application.setName(dubboApplicationName);
|
application.setName(dubboApplicationName);
|
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.mall.payservice.common;
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.mall.payservice.dal.mysql.dataobject.refund;
|
package cn.iocoder.mall.payservice.dal.mysql.dataobject.refund;
|
||||||
|
|
||||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||||
|
import cn.iocoder.mall.payservice.enums.refund.PayRefundStatus;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@ -68,7 +69,7 @@ public class PayRefundDO extends DeletableDO {
|
|||||||
/**
|
/**
|
||||||
* 退款状态
|
* 退款状态
|
||||||
*
|
*
|
||||||
* @see cn.iocoder.mall.pay.api.constant.PayRefundStatus
|
* 外键 {@link PayRefundStatus}
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package cn.iocoder.mall.payservice.dal.mysql.mapper.refund;
|
||||||
|
|
||||||
|
import cn.iocoder.mall.payservice.dal.mysql.dataobject.refund.PayRefundDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface PayRefundMapper extends BaseMapper<PayRefundDO> {
|
||||||
|
|
||||||
|
default int update(PayRefundDO entity, Integer whereStatus) {
|
||||||
|
return update(entity, new QueryWrapper<PayRefundDO>()
|
||||||
|
.eq("id", entity.getId()).eq("status", whereStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
default PayRefundDO selectByRefundCode(String refundCode) {
|
||||||
|
return selectOne(new QueryWrapper<PayRefundDO>()
|
||||||
|
.eq("refund_code", refundCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// <if test="createBeginTime != null">
|
||||||
|
// AND create_time >= #{createBeginTime}
|
||||||
|
// </if>
|
||||||
|
// <if test="createEndTime != null">
|
||||||
|
// AND #{createEndTime} >= create_time
|
||||||
|
// </if>
|
||||||
|
// <if test="finishBeginTime != null">
|
||||||
|
// AND finish_time >= #{finishBeginTime}
|
||||||
|
// </if>
|
||||||
|
// <if test="finishEndTime != null">
|
||||||
|
// AND #{finishEndTime} >= finish_time
|
||||||
|
// </if>
|
||||||
|
// <if test="status != null">
|
||||||
|
// AND status = #{status}
|
||||||
|
// </if>
|
||||||
|
// <if test="payChannel != null">
|
||||||
|
// AND pay_channel = #{payChannel}
|
||||||
|
// </if>
|
||||||
|
|
||||||
|
// List<PayRefundDO> selectListByPage(@Param("createBeginTime") Date createBeginTime,
|
||||||
|
// @Param("createEndTime") Date createEndTime,
|
||||||
|
// @Param("finishBeginTime") Date finishBeginTime,
|
||||||
|
// @Param("finishEndTime") Date finishEndTime,
|
||||||
|
// @Param("status") Integer status,
|
||||||
|
// @Param("payChannel") Integer payChannel,
|
||||||
|
// @Param("offset") Integer offset,
|
||||||
|
// @Param("limit") Integer limit);
|
||||||
|
//
|
||||||
|
// Integer selectCountByPage(@Param("createBeginTime") Date createBeginTime,
|
||||||
|
// @Param("createEndTime") Date createEndTime,
|
||||||
|
// @Param("finishBeginTime") Date finishBeginTime,
|
||||||
|
// @Param("finishEndTime") Date finishEndTime,
|
||||||
|
// @Param("status") Integer status,
|
||||||
|
// @Param("payChannel") Integer payChannel);
|
||||||
|
|
||||||
|
}
|
@ -7,6 +7,42 @@ import org.springframework.stereotype.Repository;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface PayTransactionMapper extends BaseMapper<PayTransactionDO> {
|
public interface PayTransactionMapper extends BaseMapper<PayTransactionDO> {
|
||||||
|
//
|
||||||
|
// UPDATE `transaction`
|
||||||
|
// SET refund_total = refund_total + ${refundTotalIncr}
|
||||||
|
// WHERE price >= refund_total + ${refundTotalIncr}
|
||||||
|
//
|
||||||
|
|
||||||
|
// int updateForRefundTotal(@Param("id") Integer id,
|
||||||
|
// @Param("refundTotalIncr") Integer refundTotalIncr);
|
||||||
|
|
||||||
|
// <if test="createBeginTime != null">
|
||||||
|
// AND create_time >= #{createBeginTime}
|
||||||
|
// </if>
|
||||||
|
// <if test="createEndTime != null">
|
||||||
|
// AND #{createEndTime} >= create_time
|
||||||
|
// </if>
|
||||||
|
// <if test="paymentBeginTime != null">
|
||||||
|
// AND payment_time >= #{paymentBeginTime}
|
||||||
|
// </if>
|
||||||
|
// <if test="paymentEndTime != null">
|
||||||
|
// AND #{paymentEndTime} >= payment_time
|
||||||
|
// </if>
|
||||||
|
// <if test="status != null">
|
||||||
|
// AND status = #{status}
|
||||||
|
// </if>
|
||||||
|
// <if test="hasRefund == true">
|
||||||
|
// AND refund_total > 0
|
||||||
|
// </if>
|
||||||
|
// <if test="hasRefund == false">
|
||||||
|
// AND refund_total = 0
|
||||||
|
// </if>
|
||||||
|
// <if test="payChannel != null">
|
||||||
|
// AND pay_channel = #{payChannel}
|
||||||
|
// </if>
|
||||||
|
// <if test="orderSubject != null">
|
||||||
|
// order_subject LIKE "%"#{orderSubject}"%"
|
||||||
|
// </if>
|
||||||
|
|
||||||
// default IPage<PayTransactionDO> selectPage(TransactionPageBO pageBO) {
|
// default IPage<PayTransactionDO> selectPage(TransactionPageBO pageBO) {
|
||||||
// return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
// return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package cn.iocoder.mall.pay.biz.mq;
|
package cn.iocoder.mall.payservice.mq.consumer;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.util.DateUtil;
|
import cn.iocoder.common.framework.util.DateUtil;
|
||||||
import cn.iocoder.common.framework.util.ExceptionUtil;
|
import cn.iocoder.common.framework.util.ExceptionUtil;
|
||||||
import cn.iocoder.mall.pay.api.constant.PayTransactionNotifyStatusEnum;
|
import cn.iocoder.mall.payservice.common.dubbo.DubboReferencePool;
|
||||||
import cn.iocoder.mall.pay.api.message.AbstractPayNotifySuccessMessage;
|
import cn.iocoder.mall.payservice.dal.mysql.dataobject.notify.PayNotifyLogDO;
|
||||||
import cn.iocoder.mall.pay.biz.component.DubboReferencePool;
|
import cn.iocoder.mall.payservice.dal.mysql.dataobject.notify.PayNotifyTaskDO;
|
||||||
import cn.iocoder.mall.pay.biz.dao.PayNotifyLogMapper;
|
import cn.iocoder.mall.payservice.dal.mysql.mapper.notify.PayNotifyLogMapper;
|
||||||
import cn.iocoder.mall.pay.biz.dao.PayNotifyTaskMapper;
|
import cn.iocoder.mall.payservice.dal.mysql.mapper.notify.PayNotifyTaskMapper;
|
||||||
import cn.iocoder.mall.pay.biz.dataobject.PayNotifyLogDO;
|
import cn.iocoder.mall.payservice.enums.notify.PayNotifyStatusEnum;
|
||||||
import cn.iocoder.mall.pay.biz.dataobject.PayNotifyTaskDO;
|
import cn.iocoder.mall.payservice.mq.producer.message.AbstractPayNotifySuccessMessage;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -17,13 +17,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public abstract class AbstractPayNotifySuccessConsumer<T extends AbstractPayNotifySuccessMessage> implements RocketMQListener<T> {
|
public abstract class AbstractPayNotifySuccessMQConsumer<T extends AbstractPayNotifySuccessMessage> implements RocketMQListener<T> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DubboReferencePool dubboReferencePool;
|
private DubboReferencePool dubboReferencePool;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PayNotifyTaskMapper payTransactionNotifyTaskMapper;
|
private PayNotifyTaskMapper payNotifyTaskMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PayNotifyLogMapper payTransactionNotifyLogMapper;
|
private PayNotifyLogMapper payTransactionNotifyLogMapper;
|
||||||
|
|
||||||
@ -39,25 +39,27 @@ public abstract class AbstractPayNotifySuccessConsumer<T extends AbstractPayNoti
|
|||||||
.setLastExecuteTime(new Date())
|
.setLastExecuteTime(new Date())
|
||||||
.setNotifyTimes(message.getNotifyTimes() + 1);
|
.setNotifyTimes(message.getNotifyTimes() + 1);
|
||||||
try {
|
try {
|
||||||
|
// TODO 芋艿,这里要优化下,不要在事务里,进行 RPC 调用
|
||||||
response = invoke(message, referenceMeta);
|
response = invoke(message, referenceMeta);
|
||||||
if ("success".equals(response)) { // 情况一,请求成功且返回成功
|
if ("success".equals(response)) { // 情况一,请求成功且返回成功
|
||||||
// 更新通知成功
|
// 更新通知成功
|
||||||
updateTask.setStatus(PayTransactionNotifyStatusEnum.SUCCESS.getValue());
|
updateTask.setStatus(PayNotifyStatusEnum.SUCCESS.getStatus());
|
||||||
payTransactionNotifyTaskMapper.update(updateTask);
|
payNotifyTaskMapper.updateById(updateTask);
|
||||||
// 需要更新支付交易单通知应用成功
|
// 需要更新支付交易单通知应用成功
|
||||||
afterInvokeSuccess(message);
|
afterInvokeSuccess(message);
|
||||||
} else { // 情况二,请求成功且返回失败
|
} else { // 情况二,请求成功且返回失败
|
||||||
// 更新通知请求成功,但是结果失败
|
// 更新通知请求成功,但是结果失败
|
||||||
handleFailure(updateTask, PayTransactionNotifyStatusEnum.REQUEST_SUCCESS.getValue());
|
handleFailure(updateTask, PayNotifyStatusEnum.REQUEST_SUCCESS.getStatus());
|
||||||
payTransactionNotifyTaskMapper.update(updateTask);
|
payNotifyTaskMapper.updateById(updateTask);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) { // 请求失败
|
} catch (Throwable e) { // 请求失败
|
||||||
// 更新通知请求失败
|
// 更新通知请求失败
|
||||||
response = ExceptionUtil.getRootCauseMessage(e);
|
response = ExceptionUtil.getRootCauseMessage(e);
|
||||||
handleFailure(updateTask, PayTransactionNotifyStatusEnum.REQUEST_FAILURE.getValue());
|
handleFailure(updateTask, PayNotifyStatusEnum.REQUEST_FAILURE.getStatus());
|
||||||
payTransactionNotifyTaskMapper.update(updateTask);
|
payNotifyTaskMapper.updateById(updateTask);
|
||||||
// 抛出异常,回滚事务
|
// 抛出异常,回滚事务
|
||||||
throw e; // TODO 芋艿,此处不能抛出异常。因为,会导致 MQ + 定时任务多重试。此处的目标是,事务回滚 + 吃掉事务。另外,最后的 finally 的日志,要插入成功。
|
// TODO 芋艿,此处不能抛出异常。因为,会导致 MQ + 定时任务多重试。此处的目标是,事务回滚 + 吃掉事务。另外,最后的 finally 的日志,要插入成功。
|
||||||
|
// throw e;
|
||||||
} finally {
|
} finally {
|
||||||
// 插入 PayTransactionNotifyLogDO 日志
|
// 插入 PayTransactionNotifyLogDO 日志
|
||||||
PayNotifyLogDO notifyLog = new PayNotifyLogDO().setNotifyId(message.getId())
|
PayNotifyLogDO notifyLog = new PayNotifyLogDO().setNotifyId(message.getId())
|
||||||
@ -68,7 +70,7 @@ public abstract class AbstractPayNotifySuccessConsumer<T extends AbstractPayNoti
|
|||||||
|
|
||||||
private void handleFailure(PayNotifyTaskDO updateTask, Integer defaultStatus) {
|
private void handleFailure(PayNotifyTaskDO updateTask, Integer defaultStatus) {
|
||||||
if (updateTask.getNotifyTimes() >= PayNotifyTaskDO.NOTIFY_FREQUENCY.length) {
|
if (updateTask.getNotifyTimes() >= PayNotifyTaskDO.NOTIFY_FREQUENCY.length) {
|
||||||
updateTask.setStatus(PayTransactionNotifyStatusEnum.FAILURE.getValue());
|
updateTask.setStatus(PayNotifyStatusEnum.FAILURE.getStatus());
|
||||||
} else {
|
} else {
|
||||||
updateTask.setNextNotifyTime(DateUtil.addDate(Calendar.SECOND, PayNotifyTaskDO.NOTIFY_FREQUENCY[updateTask.getNotifyTimes()]));
|
updateTask.setNextNotifyTime(DateUtil.addDate(Calendar.SECOND, PayNotifyTaskDO.NOTIFY_FREQUENCY[updateTask.getNotifyTimes()]));
|
||||||
updateTask.setStatus(defaultStatus);
|
updateTask.setStatus(defaultStatus);
|
@ -1,9 +1,9 @@
|
|||||||
package cn.iocoder.mall.pay.biz.mq;
|
package cn.iocoder.mall.payservice.mq.consumer;
|
||||||
|
|
||||||
import cn.iocoder.mall.pay.api.message.PayRefundSuccessMessage;
|
import cn.iocoder.mall.payservice.common.dubbo.DubboReferencePool;
|
||||||
import cn.iocoder.mall.pay.biz.component.DubboReferencePool;
|
import cn.iocoder.mall.payservice.dal.mysql.dataobject.refund.PayRefundDO;
|
||||||
import cn.iocoder.mall.pay.biz.dao.PayRefundMapper;
|
import cn.iocoder.mall.payservice.dal.mysql.mapper.refund.PayRefundMapper;
|
||||||
import cn.iocoder.mall.pay.biz.dataobject.PayRefundDO;
|
import cn.iocoder.mall.payservice.mq.producer.message.PayRefundSuccessMessage;
|
||||||
import org.apache.dubbo.rpc.service.GenericService;
|
import org.apache.dubbo.rpc.service.GenericService;
|
||||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||||
@ -18,8 +18,7 @@ import java.util.Date;
|
|||||||
topic = PayRefundSuccessMessage.TOPIC,
|
topic = PayRefundSuccessMessage.TOPIC,
|
||||||
consumerGroup = "pay-consumer-group-" + PayRefundSuccessMessage.TOPIC
|
consumerGroup = "pay-consumer-group-" + PayRefundSuccessMessage.TOPIC
|
||||||
)
|
)
|
||||||
@Deprecated // 艿艿:突然发现,业务方实际无需回调。参考了 https://help.youzan.com/displaylist/detail_4_998 的文章。业务方,只要记录下退款单号,进行关联即可。
|
public class PayRefundSuccessMQConsumer extends AbstractPayNotifySuccessMQConsumer<PayRefundSuccessMessage>
|
||||||
public class PayRefundSuccessConsumer extends AbstractPayNotifySuccessConsumer<PayRefundSuccessMessage>
|
|
||||||
implements RocketMQListener<PayRefundSuccessMessage> {
|
implements RocketMQListener<PayRefundSuccessMessage> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -40,7 +39,7 @@ public class PayRefundSuccessConsumer extends AbstractPayNotifySuccessConsumer<P
|
|||||||
@Override
|
@Override
|
||||||
protected void afterInvokeSuccess(PayRefundSuccessMessage message) {
|
protected void afterInvokeSuccess(PayRefundSuccessMessage message) {
|
||||||
PayRefundDO updateRefund = new PayRefundDO().setId(message.getRefundId()).setFinishTime(new Date());
|
PayRefundDO updateRefund = new PayRefundDO().setId(message.getRefundId()).setFinishTime(new Date());
|
||||||
payRefundMapper.update(updateRefund, null);
|
payRefundMapper.updateById(updateRefund);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package cn.iocoder.mall.pay.biz.mq;
|
package cn.iocoder.mall.payservice.mq.consumer;
|
||||||
|
|
||||||
import cn.iocoder.mall.pay.api.message.PayTransactionSuccessMessage;
|
import cn.iocoder.mall.payservice.common.dubbo.DubboReferencePool;
|
||||||
import cn.iocoder.mall.pay.biz.component.DubboReferencePool;
|
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionDO;
|
||||||
import cn.iocoder.mall.pay.biz.dao.PayTransactionMapper;
|
import cn.iocoder.mall.payservice.dal.mysql.mapper.transaction.PayTransactionMapper;
|
||||||
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionDO;
|
import cn.iocoder.mall.payservice.mq.producer.message.PayTransactionSuccessMessage;
|
||||||
import org.apache.dubbo.rpc.service.GenericService;
|
import org.apache.dubbo.rpc.service.GenericService;
|
||||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||||
@ -18,7 +18,7 @@ import java.util.Date;
|
|||||||
topic = PayTransactionSuccessMessage.TOPIC,
|
topic = PayTransactionSuccessMessage.TOPIC,
|
||||||
consumerGroup = "pay-consumer-group-" + PayTransactionSuccessMessage.TOPIC
|
consumerGroup = "pay-consumer-group-" + PayTransactionSuccessMessage.TOPIC
|
||||||
)
|
)
|
||||||
public class PayTransactionSuccessConsumer extends AbstractPayNotifySuccessConsumer<PayTransactionSuccessMessage>
|
public class PayTransactionSuccessMQConsumer extends AbstractPayNotifySuccessMQConsumer<PayTransactionSuccessMessage>
|
||||||
implements RocketMQListener<PayTransactionSuccessMessage> {
|
implements RocketMQListener<PayTransactionSuccessMessage> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -39,7 +39,7 @@ public class PayTransactionSuccessConsumer extends AbstractPayNotifySuccessConsu
|
|||||||
@Override
|
@Override
|
||||||
protected void afterInvokeSuccess(PayTransactionSuccessMessage message) {
|
protected void afterInvokeSuccess(PayTransactionSuccessMessage message) {
|
||||||
PayTransactionDO updateTransaction = new PayTransactionDO().setId(message.getTransactionId()).setFinishTime(new Date());
|
PayTransactionDO updateTransaction = new PayTransactionDO().setId(message.getTransactionId()).setFinishTime(new Date());
|
||||||
payTransactionMapper.update(updateTransaction, null);
|
payTransactionMapper.updateById(updateTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user