重构支付流水逻辑

This commit is contained in:
kuang.yife 2023-05-31 09:38:56 +08:00
parent 82a9d1cdbc
commit d28e6a1b90
6 changed files with 480 additions and 0 deletions

View File

@ -133,6 +133,7 @@ public class PayCallbackService implements CallBackService {
// 保存一条支付记录 // 保存一条支付记录
PaymentDTO payment = response.toJavaObject(PaymentDTO.class); PaymentDTO payment = response.toJavaObject(PaymentDTO.class);
String status = payment.getStatus(); String status = payment.getStatus();
financialMasterService.insertPayment(payment); financialMasterService.insertPayment(payment);
if (!AdapayStatusEnum.succeeded.code.equals(status)) { if (!AdapayStatusEnum.succeeded.code.equals(status)) {

View File

@ -0,0 +1,101 @@
package com.ghy.system.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
/**
* 支付流水对象 adapy_payment
*
* @author clunt
* @date 2023-05-31
*/
@Data
public class AdapyPayment extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 支付流水 */
private String paymentId;
/** 分公司id */
@Excel(name = "分公司id")
private Long deptId;
/** 支付状态: 01.初始 02.进行中 03.结束 */
@Excel(name = "支付状态: 01.初始 02.进行中 03.结束")
private String payStatus;
/** 处理中 pedding 成功successed 失败 failed */
@Excel(name = "处理中 pedding 成功successed 失败 failed")
private String status;
/** 付款总额 */
@Excel(name = "付款总额")
private BigDecimal payAmt;
/** 优惠金额 */
@Excel(name = "优惠金额")
private BigDecimal discountAmt;
/** 手续费 */
@Excel(name = "手续费")
private BigDecimal feeAmt;
/** 已分账金额 */
@Excel(name = "已分账金额")
private BigDecimal confirmAmt;
/** 退款金额 */
@Excel(name = "退款金额")
private BigDecimal reservedAmt;
/** 退款金额 */
@Excel(name = "退款金额")
private BigDecimal refundAmt;
/** 剩余金额 */
@Excel(name = "剩余金额")
private BigDecimal balanceAmt;
/** 订单号 1.master_ 主单 2.com_ 合并支付 3.add_加价支付 4.balance_ 充值 */
@Excel(name = "订单号 1.master_ 主单 2.com_ 合并支付 3.add_加价支付 4.balance_ 充值")
private String orderNo;
/** 生产 true 测试 false */
@Excel(name = "生产 true 测试 false")
private String prodMode;
/** 应用id */
@Excel(name = "应用id")
private String appId;
/** 微信唯一流水 */
@Excel(name = "微信唯一流水")
private String openId;
/** 支付宝唯一id */
@Excel(name = "支付宝唯一id")
private String buyerId;
/** 支付渠道 */
@Excel(name = "支付渠道")
private String payChannel;
/** 第三方支付流水 */
@Excel(name = "第三方支付流水")
private String partyOrderId;
/** 支付结果查询接口 */
@Excel(name = "支付结果查询接口")
private String queryUrl;
/** 付款时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "付款时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date payTime;
}

View File

@ -0,0 +1,62 @@
package com.ghy.system.mapper;
import com.ghy.system.domain.AdapyPayment;
import java.util.List;
/**
* 支付流水Mapper接口
*
* @author clunt
* @date 2023-05-31
*/
public interface AdapyPaymentMapper
{
/**
* 查询支付流水
*
* @param paymentId 支付流水主键
* @return 支付流水
*/
public AdapyPayment selectAdapyPaymentByPaymentId(String paymentId);
/**
* 查询支付流水列表
*
* @param adapyPayment 支付流水
* @return 支付流水集合
*/
public List<AdapyPayment> selectAdapyPaymentList(AdapyPayment adapyPayment);
/**
* 新增支付流水
*
* @param adapyPayment 支付流水
* @return 结果
*/
public int insertAdapyPayment(AdapyPayment adapyPayment);
/**
* 修改支付流水
*
* @param adapyPayment 支付流水
* @return 结果
*/
public int updateAdapyPayment(AdapyPayment adapyPayment);
/**
* 删除支付流水
*
* @param paymentId 支付流水主键
* @return 结果
*/
public int deleteAdapyPaymentByPaymentId(String paymentId);
/**
* 批量删除支付流水
*
* @param paymentIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteAdapyPaymentByPaymentIds(String[] paymentIds);
}

View File

@ -0,0 +1,62 @@
package com.ghy.system.service;
import java.util.List;
import com.ghy.system.domain.AdapyPayment;
/**
* 支付流水Service接口
*
* @author clunt
* @date 2023-05-31
*/
public interface IAdapyPaymentService
{
/**
* 查询支付流水
*
* @param paymentId 支付流水主键
* @return 支付流水
*/
public AdapyPayment selectAdapyPaymentByPaymentId(String paymentId);
/**
* 查询支付流水列表
*
* @param adapyPayment 支付流水
* @return 支付流水集合
*/
public List<AdapyPayment> selectAdapyPaymentList(AdapyPayment adapyPayment);
/**
* 新增支付流水
*
* @param adapyPayment 支付流水
* @return 结果
*/
public int insertAdapyPayment(AdapyPayment adapyPayment);
/**
* 修改支付流水
*
* @param adapyPayment 支付流水
* @return 结果
*/
public int updateAdapyPayment(AdapyPayment adapyPayment);
/**
* 批量删除支付流水
*
* @param paymentIds 需要删除的支付流水主键集合
* @return 结果
*/
public int deleteAdapyPaymentByPaymentIds(String paymentIds);
/**
* 删除支付流水信息
*
* @param paymentId 支付流水主键
* @return 结果
*/
public int deleteAdapyPaymentByPaymentId(String paymentId);
}

View File

@ -0,0 +1,97 @@
package com.ghy.system.service.impl;
import java.util.List;
import com.ghy.common.utils.DateUtils;
import com.ghy.system.domain.AdapyPayment;
import com.ghy.system.mapper.AdapyPaymentMapper;
import com.ghy.system.service.IAdapyPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ghy.common.core.text.Convert;
/**
* 支付流水Service业务层处理
*
* @author clunt
* @date 2023-05-31
*/
@Service
public class AdapyPaymentServiceImpl implements IAdapyPaymentService
{
@Autowired
private AdapyPaymentMapper adapyPaymentMapper;
/**
* 查询支付流水
*
* @param paymentId 支付流水主键
* @return 支付流水
*/
@Override
public AdapyPayment selectAdapyPaymentByPaymentId(String paymentId)
{
return adapyPaymentMapper.selectAdapyPaymentByPaymentId(paymentId);
}
/**
* 查询支付流水列表
*
* @param adapyPayment 支付流水
* @return 支付流水
*/
@Override
public List<AdapyPayment> selectAdapyPaymentList(AdapyPayment adapyPayment)
{
return adapyPaymentMapper.selectAdapyPaymentList(adapyPayment);
}
/**
* 新增支付流水
*
* @param adapyPayment 支付流水
* @return 结果
*/
@Override
public int insertAdapyPayment(AdapyPayment adapyPayment)
{
adapyPayment.setCreateTime(DateUtils.getNowDate());
return adapyPaymentMapper.insertAdapyPayment(adapyPayment);
}
/**
* 修改支付流水
*
* @param adapyPayment 支付流水
* @return 结果
*/
@Override
public int updateAdapyPayment(AdapyPayment adapyPayment)
{
adapyPayment.setUpdateTime(DateUtils.getNowDate());
return adapyPaymentMapper.updateAdapyPayment(adapyPayment);
}
/**
* 批量删除支付流水
*
* @param paymentIds 需要删除的支付流水主键
* @return 结果
*/
@Override
public int deleteAdapyPaymentByPaymentIds(String paymentIds)
{
return adapyPaymentMapper.deleteAdapyPaymentByPaymentIds(Convert.toStrArray(paymentIds));
}
/**
* 删除支付流水信息
*
* @param paymentId 支付流水主键
* @return 结果
*/
@Override
public int deleteAdapyPaymentByPaymentId(String paymentId)
{
return adapyPaymentMapper.deleteAdapyPaymentByPaymentId(paymentId);
}
}

View File

@ -0,0 +1,157 @@
<?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.ghy.system.mapper.AdapyPaymentMapper">
<resultMap type="AdapyPayment" id="AdapyPaymentResult">
<result property="paymentId" column="payment_id" />
<result property="deptId" column="dept_id" />
<result property="payStatus" column="pay_status" />
<result property="status" column="status" />
<result property="payAmt" column="pay_amt" />
<result property="discountAmt" column="discount_amt" />
<result property="feeAmt" column="fee_amt" />
<result property="confirmAmt" column="confirm_amt" />
<result property="reservedAmt" column="reserved_amt" />
<result property="refundAmt" column="refund_amt" />
<result property="balanceAmt" column="balance_amt" />
<result property="orderNo" column="order_no" />
<result property="prodMode" column="prod_mode" />
<result property="appId" column="app_id" />
<result property="openId" column="open_id" />
<result property="buyerId" column="buyer_id" />
<result property="payChannel" column="pay_channel" />
<result property="partyOrderId" column="party_order_id" />
<result property="queryUrl" column="query_url" />
<result property="payTime" column="pay_time" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectAdapyPaymentVo">
select payment_id, dept_id, pay_status, status, pay_amt, discount_amt, fee_amt, confirm_amt, reserved_amt, refund_amt, balance_amt, order_no, prod_mode, app_id, open_id, buyer_id, pay_channel, party_order_id, query_url, pay_time, create_time, update_time from adapy_payment
</sql>
<select id="selectAdapyPaymentList" parameterType="AdapyPayment" resultMap="AdapyPaymentResult">
<include refid="selectAdapyPaymentVo"/>
<where>
<if test="deptId != null "> and dept_id = #{deptId}</if>
<if test="payStatus != null and payStatus != ''"> and pay_status = #{payStatus}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="payAmt != null "> and pay_amt = #{payAmt}</if>
<if test="discountAmt != null "> and discount_amt = #{discountAmt}</if>
<if test="feeAmt != null "> and fee_amt = #{feeAmt}</if>
<if test="confirmAmt != null "> and confirm_amt = #{confirmAmt}</if>
<if test="reservedAmt != null "> and reserved_amt = #{reservedAmt}</if>
<if test="refundAmt != null "> and refund_amt = #{refundAmt}</if>
<if test="balanceAmt != null "> and balance_amt = #{balanceAmt}</if>
<if test="orderNo != null and orderNo != ''"> and order_no = #{orderNo}</if>
<if test="prodMode != null and prodMode != ''"> and prod_mode = #{prodMode}</if>
<if test="appId != null and appId != ''"> and app_id = #{appId}</if>
<if test="openId != null and openId != ''"> and open_id = #{openId}</if>
<if test="buyerId != null and buyerId != ''"> and buyer_id = #{buyerId}</if>
<if test="payChannel != null and payChannel != ''"> and pay_channel = #{payChannel}</if>
<if test="partyOrderId != null and partyOrderId != ''"> and party_order_id = #{partyOrderId}</if>
<if test="queryUrl != null and queryUrl != ''"> and query_url = #{queryUrl}</if>
<if test="payTime != null "> and pay_time = #{payTime}</if>
</where>
</select>
<select id="selectAdapyPaymentByPaymentId" parameterType="String" resultMap="AdapyPaymentResult">
<include refid="selectAdapyPaymentVo"/>
where payment_id = #{paymentId}
</select>
<insert id="insertAdapyPayment" parameterType="AdapyPayment">
insert into adapy_payment
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="paymentId != null">payment_id,</if>
<if test="deptId != null">dept_id,</if>
<if test="payStatus != null and payStatus != ''">pay_status,</if>
<if test="status != null">status,</if>
<if test="payAmt != null">pay_amt,</if>
<if test="discountAmt != null">discount_amt,</if>
<if test="feeAmt != null">fee_amt,</if>
<if test="confirmAmt != null">confirm_amt,</if>
<if test="reservedAmt != null">reserved_amt,</if>
<if test="refundAmt != null">refund_amt,</if>
<if test="balanceAmt != null">balance_amt,</if>
<if test="orderNo != null">order_no,</if>
<if test="prodMode != null">prod_mode,</if>
<if test="appId != null">app_id,</if>
<if test="openId != null">open_id,</if>
<if test="buyerId != null">buyer_id,</if>
<if test="payChannel != null">pay_channel,</if>
<if test="partyOrderId != null">party_order_id,</if>
<if test="queryUrl != null">query_url,</if>
<if test="payTime != null">pay_time,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="paymentId != null">#{paymentId},</if>
<if test="deptId != null">#{deptId},</if>
<if test="payStatus != null and payStatus != ''">#{payStatus},</if>
<if test="status != null">#{status},</if>
<if test="payAmt != null">#{payAmt},</if>
<if test="discountAmt != null">#{discountAmt},</if>
<if test="feeAmt != null">#{feeAmt},</if>
<if test="confirmAmt != null">#{confirmAmt},</if>
<if test="reservedAmt != null">#{reservedAmt},</if>
<if test="refundAmt != null">#{refundAmt},</if>
<if test="balanceAmt != null">#{balanceAmt},</if>
<if test="orderNo != null">#{orderNo},</if>
<if test="prodMode != null">#{prodMode},</if>
<if test="appId != null">#{appId},</if>
<if test="openId != null">#{openId},</if>
<if test="buyerId != null">#{buyerId},</if>
<if test="payChannel != null">#{payChannel},</if>
<if test="partyOrderId != null">#{partyOrderId},</if>
<if test="queryUrl != null">#{queryUrl},</if>
<if test="payTime != null">#{payTime},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateAdapyPayment" parameterType="AdapyPayment">
update adapy_payment
<trim prefix="SET" suffixOverrides=",">
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="payStatus != null and payStatus != ''">pay_status = #{payStatus},</if>
<if test="status != null">status = #{status},</if>
<if test="payAmt != null">pay_amt = #{payAmt},</if>
<if test="discountAmt != null">discount_amt = #{discountAmt},</if>
<if test="feeAmt != null">fee_amt = #{feeAmt},</if>
<if test="confirmAmt != null">confirm_amt = #{confirmAmt},</if>
<if test="reservedAmt != null">reserved_amt = #{reservedAmt},</if>
<if test="refundAmt != null">refund_amt = #{refundAmt},</if>
<if test="balanceAmt != null">balance_amt = #{balanceAmt},</if>
<if test="orderNo != null">order_no = #{orderNo},</if>
<if test="prodMode != null">prod_mode = #{prodMode},</if>
<if test="appId != null">app_id = #{appId},</if>
<if test="openId != null">open_id = #{openId},</if>
<if test="buyerId != null">buyer_id = #{buyerId},</if>
<if test="payChannel != null">pay_channel = #{payChannel},</if>
<if test="partyOrderId != null">party_order_id = #{partyOrderId},</if>
<if test="queryUrl != null">query_url = #{queryUrl},</if>
<if test="payTime != null">pay_time = #{payTime},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where payment_id = #{paymentId}
</update>
<delete id="deleteAdapyPaymentByPaymentId" parameterType="String">
delete from adapy_payment where payment_id = #{paymentId}
</delete>
<delete id="deleteAdapyPaymentByPaymentIds" parameterType="String">
delete from adapy_payment where payment_id in
<foreach item="paymentId" collection="array" open="(" separator="," close=")">
#{paymentId}
</foreach>
</delete>
</mapper>