ref 同步接口调整

This commit is contained in:
bootx
2024-05-12 21:42:15 +08:00
parent 8b46b56bff
commit e9e44deb42
22 changed files with 104 additions and 139 deletions

View File

@@ -68,7 +68,7 @@ public @interface QueryParam {
IS_NULL,
/** 排序 */
SORT;
SORT
}
/**
@@ -81,7 +81,7 @@ public @interface QueryParam {
/** 转换为下划线 */
UNDER_LINE,
/** 不进行处理 */
NONE;
NONE
}

View File

@@ -43,7 +43,7 @@ public @interface Translate {
/** 字典 */
DICT,
/** 数据表 暂未实现 */
TABLE;
TABLE
}

View File

@@ -1,10 +1,13 @@
package cn.bootx.platform.common.core.exception;
import lombok.Getter;
import java.io.Serializable;
/**
* 错误码异常基类
*/
@Getter
public abstract class ErrorCodeRuntimeException extends RuntimeException implements Serializable {
private static final long serialVersionUID = 1724988277326336635L;
@@ -20,10 +23,6 @@ public abstract class ErrorCodeRuntimeException extends RuntimeException impleme
super();
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}

View File

@@ -1,5 +1,7 @@
package cn.bootx.platform.common.core.rest;
import lombok.Getter;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
@@ -10,6 +12,7 @@ import java.util.List;
* @author xxm
* @since 2020/4/21 14:37
*/
@Getter
public class PageResult<T> implements Serializable {
private static final long serialVersionUID = -739437195275623607L;
@@ -34,37 +37,21 @@ public class PageResult<T> implements Serializable {
*/
private long current = 1;
public List<T> getRecords() {
return records;
}
public PageResult<T> setRecords(List<T> records) {
this.records = records;
return this;
}
public long getTotal() {
return total;
}
public PageResult<T> setTotal(long total) {
this.total = total;
return this;
}
public long getSize() {
return size;
}
public PageResult<T> setSize(long size) {
this.size = size;
return this;
}
public long getCurrent() {
return current;
}
public PageResult<T> setCurrent(long current) {
this.current = current;
return this;

View File

@@ -125,7 +125,7 @@ public class IpToRegionService {
searcher.close();
} catch (IOException e) {
// 这句不会执行, finally中try无效
throw new BizException("IP查询器关闭失败");
log.error("关闭Ip地址库失败");
}
}
}

View File

@@ -57,7 +57,7 @@ public class SaTokenRedisConfiguration {
// 获取自定义Redis对象
RedisProperties aloneRedis = saTokenDaoRedisProperties.getAloneRedis();
if (alone) {
RedisConfiguration redisConfig = new RedisStandaloneConfiguration();
RedisConfiguration redisConfig;
// 单机模式/集群模式
if (aloneRedis.getCluster() == null || CollUtil.isEmpty(aloneRedis.getCluster().getNodes())) {

View File

@@ -86,7 +86,7 @@ public class DataChangeRecorderInnerInterceptor implements InnerInterceptor {
long startTs = System.currentTimeMillis();
DataVersionLog dataVersion;
try {
Statement statement = null;
Statement statement;
try {
statement = CCJSqlParserUtil.parse(mpBs.sql());
} catch (JSQLParserException e) {

View File

@@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper;
import com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import lombok.Getter;
import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
@@ -45,14 +46,11 @@ public class BaseManager<M extends BaseMapper<T>, T> {
protected Log log = LogFactory.getLog(getClass());
@Getter
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Autowired
protected M baseMapper;
public M getBaseMapper() {
return baseMapper;
}
public Class<T> getEntityClass() {
return currentModelClass();
}

View File

@@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* 认证支撑服务
*
@@ -36,7 +38,7 @@ public class AuthAssistService {
// 判断用户是否存在
UserInfo userInfo = userInfoManager.findByPhone(phone).orElseThrow(UserInfoNotExistsException::new);
if (userInfo.getStatus() != UserStatusCode.NORMAL) {
if (!Objects.equals(userInfo.getStatus(), UserStatusCode.NORMAL)) {
throw new BizException("用户状态异常");
}
// 有效期5分钟

View File

@@ -8,6 +8,7 @@ import cn.bootx.platform.iam.core.third.entity.UserThird;
import cn.bootx.platform.iam.core.third.entity.UserThirdInfo;
import cn.bootx.platform.iam.core.user.dao.UserInfoManager;
import cn.bootx.platform.iam.core.user.entity.UserInfo;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -73,7 +74,7 @@ public class UserTiredOperateService {
.setNickname(authUser.getNickname())
.setAvatar(authUser.getAvatar())
.setThirdUserId(authUser.getUuid());
this.bindOpenInfo(userThirdInfo);
SpringUtil.getBean(this.getClass()).bindOpenInfo(userThirdInfo);
}
/**

View File

@@ -1,32 +0,0 @@
package cn.daxpay.single.sdk.model.sync;
import cn.daxpay.single.sdk.code.RefundSyncStatusEnum;
import cn.daxpay.single.sdk.net.DaxPayResponseModel;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* 退款信息同步结果
* @author xxm
* @since 2024/2/7
*/
@Getter
@Setter
@ToString
public class RefundSyncModel extends DaxPayResponseModel {
/**
* 支付网关同步结果
* @see RefundSyncStatusEnum
*
*/
private String status;
/** 是否进行了修复 */
private boolean repair;
/** 修复号 */
private String repairOrderNo;
}

View File

@@ -7,25 +7,19 @@ import lombok.Setter;
import lombok.ToString;
/**
* 支付订单同步结果
* 交易同步结果
* @author xxm
* @since 2023/12/27
*/
@Getter
@Setter
@ToString
public class PaySyncModel extends DaxPayResponseModel {
public class SyncModel extends DaxPayResponseModel {
/**
* 支付订单同步结果
* @see PaySyncStatusEnum
*/
private String status;
/** 是否进行了修复 */
private boolean repair;
/** 修复号 */
private String repairOrderNo;
private Boolean status;
}

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.sdk.param.sync;
import cn.daxpay.single.sdk.model.sync.PaySyncModel;
import cn.daxpay.single.sdk.model.sync.SyncModel;
import cn.daxpay.single.sdk.net.DaxPayRequest;
import cn.daxpay.single.sdk.response.DaxPayResult;
import cn.hutool.core.lang.TypeReference;
@@ -15,8 +15,7 @@ import lombok.Setter;
*/
@Getter
@Setter
public class PaySyncParam extends DaxPayRequest<PaySyncModel> {
public class PaySyncParam extends DaxPayRequest<SyncModel> {
/** 订单号 */
private String orderNo;
@@ -36,7 +35,7 @@ public class PaySyncParam extends DaxPayRequest<PaySyncModel> {
* 将请求返回结果反序列化为实体类
*/
@Override
public DaxPayResult<PaySyncModel> toModel(String json) {
return JSONUtil.toBean(json, new TypeReference<DaxPayResult<PaySyncModel>>() {}, false);
public DaxPayResult<SyncModel> toModel(String json) {
return JSONUtil.toBean(json, new TypeReference<DaxPayResult<SyncModel>>() {}, false);
}
}

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.sdk.param.sync;
import cn.daxpay.single.sdk.model.sync.RefundSyncModel;
import cn.daxpay.single.sdk.model.sync.SyncModel;
import cn.daxpay.single.sdk.net.DaxPayRequest;
import cn.daxpay.single.sdk.response.DaxPayResult;
import cn.hutool.core.lang.TypeReference;
@@ -15,7 +15,7 @@ import lombok.Setter;
*/
@Getter
@Setter
public class RefundSyncParam extends DaxPayRequest<RefundSyncModel> {
public class RefundSyncParam extends DaxPayRequest<SyncModel> {
/** 退款号 */
private String refundNo;
@@ -35,7 +35,7 @@ public class RefundSyncParam extends DaxPayRequest<RefundSyncModel> {
* 将请求返回结果反序列化为实体类
*/
@Override
public DaxPayResult<RefundSyncModel> toModel(String json) {
return JSONUtil.toBean(json, new TypeReference<DaxPayResult<RefundSyncModel>>() {}, false);
public DaxPayResult<SyncModel> toModel(String json) {
return JSONUtil.toBean(json, new TypeReference<DaxPayResult<SyncModel>>() {}, false);
}
}

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.sdk.payment;
import cn.daxpay.single.sdk.code.SignTypeEnum;
import cn.daxpay.single.sdk.model.sync.PaySyncModel;
import cn.daxpay.single.sdk.model.sync.SyncModel;
import cn.daxpay.single.sdk.net.DaxPayConfig;
import cn.daxpay.single.sdk.net.DaxPayKit;
import cn.daxpay.single.sdk.param.sync.PaySyncParam;
@@ -31,10 +31,8 @@ public class PayOrderSyncTest {
@Test
public void testPay() {
PaySyncParam param = new PaySyncParam();
param.setBizOrderNo("P0001");
DaxPayResult<PaySyncModel> execute = DaxPayKit.execute(param);
param.setBizOrderNo("SDK_1715341621498");
DaxPayResult<SyncModel> execute = DaxPayKit.execute(param);
System.out.println(execute);
System.out.println(execute.getData());
}

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.sdk.payment;
import cn.daxpay.single.sdk.code.SignTypeEnum;
import cn.daxpay.single.sdk.model.sync.RefundSyncModel;
import cn.daxpay.single.sdk.model.sync.SyncModel;
import cn.daxpay.single.sdk.net.DaxPayConfig;
import cn.daxpay.single.sdk.net.DaxPayKit;
import cn.daxpay.single.sdk.param.sync.RefundSyncParam;
@@ -34,7 +34,7 @@ public class RefundOrderSyncTest {
param.setRefundNo("R0001");
DaxPayResult<RefundSyncModel> execute = DaxPayKit.execute(param);
DaxPayResult<SyncModel> execute = DaxPayKit.execute(param);
System.out.println(execute);
System.out.println(execute.getData());
}

View File

@@ -31,10 +31,4 @@ public class SyncResult extends PaymentCommonResult {
@Schema(description = "支付网关同步状态")
private String status = FAIL.getCode();
@Schema(description = "是否进行了修复")
private Boolean repair;
@Schema(description = "修复号")
private String repairNo;
}

View File

@@ -176,7 +176,7 @@ public class ClientNoticeService {
throw new RepetitiveOperationException("支付同步处理中,请勿重复操作");
}
// 查询任务, 进行发送
ClientNoticeTask task = null;
ClientNoticeTask task;
try {
task = taskManager.findById(taskId).orElse(null);
// 不存在任务直接跳过

View File

@@ -1,6 +1,5 @@
package cn.daxpay.single.service.core.payment.sync.service;
import cn.bootx.platform.common.core.exception.BizException;
import cn.bootx.platform.common.core.exception.RepetitiveOperationException;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.code.PayChannelEnum;
@@ -65,7 +64,7 @@ public class PaySyncService {
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public SyncResult sync(PaySyncParam param) {
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNo())
.orElseThrow(() -> new BizException("支付订单不存在"));
.orElseThrow(() -> new PayFailureException("支付订单不存在"));
// 钱包支付钱包不需要
if (PayChannelEnum.WALLET.getCode().equals(payOrder.getChannel())){
throw new PayFailureException("订单没有异步支付方式,不需要同步");
@@ -92,20 +91,20 @@ public class PaySyncService {
AbsPaySyncStrategy syncPayStrategy = PaySyncStrategyFactory.create(payOrder.getChannel());
syncPayStrategy.initPayParam(payOrder);
// 执行操作, 获取支付网关同步的结果
PaySyncResult syncResult = syncPayStrategy.doSyncStatus();
PaySyncResult paySyncResult = syncPayStrategy.doSyncStatus();
// 判断是否同步成功
if (Objects.equals(syncResult.getSyncStatus(), PaySyncStatusEnum.FAIL)){
if (Objects.equals(paySyncResult.getSyncStatus(), PaySyncStatusEnum.FAIL)){
// 同步失败, 返回失败响应, 同时记录失败的日志
this.saveRecord(payOrder, syncResult, false, null, syncResult.getErrorMsg());
throw new PayFailureException(syncResult.getErrorMsg());
this.saveRecord(payOrder, paySyncResult, false, null, paySyncResult.getErrorMsg());
throw new PayFailureException(paySyncResult.getErrorMsg());
}
// 支付订单的网关订单号是否一致, 不一致进行更新
if (!Objects.equals(syncResult.getOutOrderNo(), payOrder.getOutOrderNo())){
payOrder.setOutOrderNo(syncResult.getOutOrderNo());
if (!Objects.equals(paySyncResult.getOutOrderNo(), payOrder.getOutOrderNo())){
payOrder.setOutOrderNo(paySyncResult.getOutOrderNo());
payOrderService.updateById(payOrder);
}
// 判断网关状态是否和支付单一致, 同时特定情况下更新网关同步状态
boolean statusSync = this.checkAndAdjustSyncStatus(syncResult,payOrder);
boolean statusSync = this.checkAndAdjustSyncStatus(paySyncResult,payOrder);
PayRepairResult repairResult = new PayRepairResult();
try {
// 状态不一致,执行支付单修复逻辑
@@ -116,22 +115,19 @@ public class PaySyncService {
repairInfo.setSource(PayRepairSourceEnum.SYNC);
}
// 设置支付单完成时间
repairInfo.setFinishTime(syncResult.getPayTime());
repairResult = this.repairHandler(syncResult, payOrder);
repairInfo.setFinishTime(paySyncResult.getPayTime());
repairResult = this.repairHandler(paySyncResult, payOrder);
}
} catch (PayFailureException e) {
// 同步失败, 返回失败响应, 同时记录失败的日志
syncResult.setSyncStatus(PaySyncStatusEnum.FAIL);
this.saveRecord(payOrder, syncResult, false, null, e.getMessage());
paySyncResult.setSyncStatus(PaySyncStatusEnum.FAIL);
this.saveRecord(payOrder, paySyncResult, false, null, e.getMessage());
throw e;
}
// 同步成功记录日志
this.saveRecord( payOrder, syncResult, !statusSync, repairResult.getRepairNo(), null);
return new SyncResult()
.setStatus(syncResult.getSyncStatus().getCode())
.setRepair(!statusSync)
.setRepairNo(repairResult.getRepairNo());
this.saveRecord( payOrder, paySyncResult, !statusSync, repairResult.getRepairNo(), null);
return new SyncResult().setStatus(paySyncResult.getSyncStatus().getCode());
} finally {
lockTemplate.releaseLock(lock);
}
@@ -223,7 +219,7 @@ public class PaySyncService {
break;
}
default: {
throw new BizException("代码有问题");
throw new PayFailureException("代码有问题");
}
}
return repair;

View File

@@ -83,21 +83,21 @@ public class RefundSyncService {
// 同步前处理, 主要预防请求过于迅速
syncPayStrategy.doBeforeHandler();
// 执行操作, 获取支付网关同步的结果
RefundSyncResult syncResult = syncPayStrategy.doSyncStatus();
RefundSyncResult refundSyncResult = syncPayStrategy.doSyncStatus();
// 判断是否同步成功
if (Objects.equals(syncResult.getSyncStatus(), RefundSyncStatusEnum.FAIL)) {
if (Objects.equals(refundSyncResult.getSyncStatus(), RefundSyncStatusEnum.FAIL)) {
// 同步失败, 返回失败响应, 同时记录失败的日志
this.saveRecord(refundOrder, syncResult, false, null, syncResult.getErrorMsg());
throw new PayFailureException(syncResult.getErrorMsg());
this.saveRecord(refundOrder, refundSyncResult, false, null, refundSyncResult.getErrorMsg());
throw new PayFailureException(refundSyncResult.getErrorMsg());
}
// 订单的通道交易号是否一致, 不一致进行更新
if (Objects.nonNull(syncResult.getOutRefundNo()) && !Objects.equals(syncResult.getOutRefundNo(), refundOrder.getOutRefundNo())){
refundOrder.setOutRefundNo(syncResult.getOutRefundNo());
if (Objects.nonNull(refundSyncResult.getOutRefundNo()) && !Objects.equals(refundSyncResult.getOutRefundNo(), refundOrder.getOutRefundNo())){
refundOrder.setOutRefundNo(refundSyncResult.getOutRefundNo());
refundOrderManager.updateById(refundOrder);
}
// 判断网关状态是否和支付单一致
boolean statusSync = this.checkSyncStatus(syncResult, refundOrder);
boolean statusSync = this.checkSyncStatus(refundSyncResult, refundOrder);
RefundRepairResult repairResult = new RefundRepairResult();
try {
// 状态不一致,执行退款单修复逻辑
@@ -107,21 +107,18 @@ public class RefundSyncService {
if (Objects.isNull(repairInfo.getSource())){
repairInfo.setSource(PayRepairSourceEnum.SYNC);
}
repairInfo.setFinishTime(syncResult.getFinishTime());
repairResult = this.repairHandler(syncResult, refundOrder);
repairInfo.setFinishTime(refundSyncResult.getFinishTime());
repairResult = this.repairHandler(refundSyncResult, refundOrder);
}
} catch (PayFailureException e) {
// 同步失败, 返回失败响应, 同时记录失败的日志
syncResult.setSyncStatus(RefundSyncStatusEnum.FAIL);
this.saveRecord(refundOrder, syncResult, false, null, e.getMessage());
refundSyncResult.setSyncStatus(RefundSyncStatusEnum.FAIL);
this.saveRecord(refundOrder, refundSyncResult, false, null, e.getMessage());
throw e;
}
// 同步成功记录日志
this.saveRecord(refundOrder, syncResult, !statusSync, repairResult.getRepairNo(), null);
return new SyncResult()
.setStatus(syncResult.getSyncStatus().getCode())
.setRepair(!statusSync)
.setRepairNo(repairResult.getRepairNo());
this.saveRecord(refundOrder, refundSyncResult, !statusSync, repairResult.getRepairNo(), null);
return new SyncResult().setStatus(refundSyncResult.getSyncStatus().getCode());
} finally {
lockTemplate.releaseLock(lock);
}

View File

@@ -366,11 +366,11 @@ public class UnionPayKit extends UnionPayService {
X509CertSelector selector = new X509CertSelector();
selector.setCertificate(cert);
Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
Set<TrustAnchor> trustAnchors = new HashSet<>();
trustAnchors.add(new TrustAnchor(rootCert, null));
PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(trustAnchors, selector);
Set<X509Certificate> intermediateCerts = new HashSet<X509Certificate>();
Set<X509Certificate> intermediateCerts = new HashSet<>();
intermediateCerts.add(rootCert);
intermediateCerts.add(middleCert);
intermediateCerts.add(cert);
@@ -389,9 +389,6 @@ public class UnionPayKit extends UnionPayService {
catch (java.security.cert.CertPathBuilderException e) {
LOG.error("verify certificate chain fail.", e);
}
catch (CertificateExpiredException e) {
LOG.error("", e);
}
catch (GeneralSecurityException e) {
LOG.error("", e);
}
@@ -516,9 +513,13 @@ public class UnionPayKit extends UnionPayService {
@Override
public String buildRequest(Map<String, Object> orderInfo, MethodType method) {
StringBuffer sf = new StringBuffer();
sf.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + payConfigStorage.getInputCharset() + "\"/></head><body>");
sf.append("<form id = \"pay_form\" action=\"" + getFrontTransUrl() + "\" method=\"post\">");
if (null != orderInfo && 0 != orderInfo.size()) {
sf.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=")
.append(payConfigStorage.getInputCharset())
.append("\"/></head><body>");
sf.append("<form id = \"pay_form\" action=\"")
.append(getFrontTransUrl())
.append("\" method=\"post\">");
if (null != orderInfo && !orderInfo.isEmpty()) {
for (Map.Entry<String, Object> entry : orderInfo.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();

31
qodana.yaml Normal file
View File

@@ -0,0 +1,31 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"
#Specify inspection profile for code analysis
profile:
name: qodana.starter
#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>
#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>
projectJDK: 8 #(Applied in CI/CD pipeline)
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-jvm:latest