Commit ff3a5dfc by Jony.L

新支付功能-api模块支付重构补全、支付订单过期定时任务

parent f198f6ea
...@@ -35,10 +35,6 @@ public class ApiOrderRespDTO { ...@@ -35,10 +35,6 @@ public class ApiOrderRespDTO {
private String statusName; private String statusName;
private Integer payStatus;
private String payStatusName;
private Long payOrderId; private Long payOrderId;
private LocalDateTime payTime; private LocalDateTime payTime;
......
...@@ -38,8 +38,6 @@ public class ApiOrderSaveReqDTO { ...@@ -38,8 +38,6 @@ public class ApiOrderSaveReqDTO {
private LocalDateTime cancelTime; private LocalDateTime cancelTime;
private Integer payStatus;
private String remark; private String remark;
} }
\ No newline at end of file
package com.luhu.computility.module.apihub.enums;
/**
* 订单支付状态
*/
public enum ApiOrderPayStatus {
// 请根据实际情况改成对应的值和备注
WAITING(0, "未支付"),
SUCCESS(10, "支付成功"),
REFUND(20, "已退款"),
CLOSED(30, "支付关闭"), // 注意:全部退款后,还是 REFUND 状态
;
private int value;
private String remark;
private ApiOrderPayStatus(int value, String remark) {
this.value = value;
this.remark = remark;
}
public int getValue() {
return value;
}
public String getRemark() {
return remark;
}
public static ApiOrderPayStatus getByValue(int value) {
for (ApiOrderPayStatus o : ApiOrderPayStatus.values()) {
if (o.getValue() == value) {
return o;
}
}
return null;
}
public static String getRemarkByValue(Integer value) {
for (ApiOrderPayStatus status : values()) {
if (status.getValue() == value) {
return status.getRemark();
}
}
return null;
}
}
package com.luhu.computility.module.apihub.enums; //package com.luhu.computility.module.apihub.enums;
//
//
/** ///**
* 订单状态 // * 订单状态
*/ // */
//
//
public enum ApiOrderStatus { //public enum ApiOrderStatus {
// 请根据实际情况改成对应的值和备注 // // 请根据实际情况改成对应的值和备注
//
UNPAID(0, "待支付"), // UNPAID(0, "待支付"),
PAID(10, "已支付"), // PAID(10, "已支付"),
CANCELED(40, "已取消"); // CANCELED(40, "已取消");
private int value; // private int value;
private String remark; // private String remark;
//
private ApiOrderStatus(int value, String remark) { // private ApiOrderStatus(int value, String remark) {
this.value = value; // this.value = value;
this.remark = remark; // this.remark = remark;
} // }
//
public int getValue() { // public int getValue() {
return value; // return value;
} // }
//
public String getRemark() { // public String getRemark() {
return remark; // return remark;
} // }
//
public static ApiOrderStatus getByValue(int value) { // public static ApiOrderStatus getByValue(int value) {
for (ApiOrderStatus o : ApiOrderStatus.values()) { // for (ApiOrderStatus o : ApiOrderStatus.values()) {
if (o.getValue() == value) { // if (o.getValue() == value) {
return o; // return o;
} // }
} // }
return null; // return null;
} // }
//
public static String getRemarkByValue(Integer value) { // public static String getRemarkByValue(Integer value) {
for (ApiOrderStatus status : values()) { // for (ApiOrderStatus status : values()) {
if (status.getValue() == value) { // if (status.getValue() == value) {
return status.getRemark(); // return status.getRemark();
} // }
} // }
return null; // return null;
} // }
} //}
package com.luhu.computility.module.apihub.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* APIHub订单状态枚举
*
* @author jony
*/
@Getter
@AllArgsConstructor
public enum ApihubOrderStatusEnum {
UNPAID(0, "待支付"),
PAID(1, "已支付"),
CANCELED(2, "已取消"),
REFUNDED(3, "已退款");
private final Integer value;
private final String name;
/**
* 判断是否待支付
*/
public static boolean isUnpaid(Integer status) {
return UNPAID.getValue().equals(status);
}
/**
* 判断是否已支付
*/
public static boolean isPaid(Integer status) {
return PAID.getValue().equals(status);
}
/**
* 判断是否已取消
*/
public static boolean isCanceled(Integer status) {
return CANCELED.getValue().equals(status);
}
/**
* 判断是否已退款
*/
public static boolean isRefunded(Integer status) {
return REFUNDED.getValue().equals(status);
}
/**
* 根据值获取枚举
*/
public static ApihubOrderStatusEnum fromValue(Integer value) {
for (ApihubOrderStatusEnum status : values()) {
if (status.getValue().equals(value)) {
return status;
}
}
return null;
}
/**
* 根据值获取名称
*/
public static String getNameByValue(Integer value) {
ApihubOrderStatusEnum statusEnum = fromValue(value);
return statusEnum != null ? statusEnum.getName() : null;
}
}
\ No newline at end of file
...@@ -4,8 +4,7 @@ import cn.hutool.core.date.DateUtil; ...@@ -4,8 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.luhu.computility.framework.common.exception.ServiceException; import com.luhu.computility.framework.common.exception.ServiceException;
import com.luhu.computility.module.apihub.controller.admin.userapiusage.vo.UserApiUsageSaveReqVO; import com.luhu.computility.module.apihub.controller.admin.userapiusage.vo.UserApiUsageSaveReqVO;
import com.luhu.computility.module.apihub.enums.ApiOrderPayStatus; import com.luhu.computility.module.apihub.enums.ApihubOrderStatusEnum;
import com.luhu.computility.module.apihub.enums.ApiOrderStatus;
import com.luhu.computility.module.apihub.service.userapiusage.UserApiUsageService; import com.luhu.computility.module.apihub.service.userapiusage.UserApiUsageService;
import com.luhu.computility.module.pay.api.notify.dto.PayOrderNotifyReqDTO; import com.luhu.computility.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -114,11 +113,7 @@ public class ApiOrderController { ...@@ -114,11 +113,7 @@ public class ApiOrderController {
PageResult<ApiOrderRespVO> pageResult = apiOrderService.getApiOrderPage(pageReqVO); PageResult<ApiOrderRespVO> pageResult = apiOrderService.getApiOrderPage(pageReqVO);
for (ApiOrderRespVO apiOrderRespVO : pageResult.getList()) { for (ApiOrderRespVO apiOrderRespVO : pageResult.getList()) {
apiOrderRespVO.setStatusName(ApiOrderStatus.getByValue(apiOrderRespVO.getStatus()).getRemark()); apiOrderRespVO.setStatusName(ApihubOrderStatusEnum.fromValue(apiOrderRespVO.getStatus()).getName());
if (!ObjectUtil.isEmpty(apiOrderRespVO.getPayStatus())) {
apiOrderRespVO.setPayStatusName(ApiOrderPayStatus.getByValue(apiOrderRespVO.getPayStatus()).getRemark());
}
} }
return success(pageResult); return success(pageResult);
} }
......
...@@ -69,11 +69,6 @@ public class ApiOrderRespVO { ...@@ -69,11 +69,6 @@ public class ApiOrderRespVO {
@Schema(description = "订单状态值:0=待支付,1=已支付,2=已取消", example = "2") @Schema(description = "订单状态值:0=待支付,1=已支付,2=已取消", example = "2")
private String statusName; private String statusName;
@Schema(description = "支付状态", example = "2")
private Integer payStatus;
@Schema(description = "支付状态值", example = "2")
private String payStatusName;
@Schema(description = "支付订单编号", example = "14961") @Schema(description = "支付订单编号", example = "14961")
@ExcelProperty("支付订单编号") @ExcelProperty("支付订单编号")
......
...@@ -53,8 +53,6 @@ public class ApiOrderSaveReqVO { ...@@ -53,8 +53,6 @@ public class ApiOrderSaveReqVO {
@Schema(description = "订单取消时间") @Schema(description = "订单取消时间")
private LocalDateTime cancelTime; private LocalDateTime cancelTime;
@Schema(description = "支付状态", example = "2")
private Integer payStatus;
@Schema(description = "发票链接", example = "www.xxx.com/a1234567.jpg") @Schema(description = "发票链接", example = "www.xxx.com/a1234567.jpg")
private String invoiceUrl; private String invoiceUrl;
......
...@@ -48,49 +48,49 @@ public class ApihubWpgjPayController { ...@@ -48,49 +48,49 @@ public class ApihubWpgjPayController {
@PostMapping("/notify") @PostMapping("/notify")
@PermitAll @PermitAll
@Operation(summary = "WPGJ支付异步回调通知 - APIHub模块") @Operation(summary = "WPGJ支付异步回调通知 - APIHub模块")
public CommonResult<WpgjPayNotifyRespDTO> notifyWpgjPayNew(@RequestBody WpgjPayNotifyDTO notifyDTO) { public WpgjPayNotifyRespDTO notifyWpgjPay(@RequestBody WpgjPayNotifyDTO notifyDTO) {
log.info("[notifyWpgjPayNew][APIHub] 收到WPGJ支付回调(新): {}", JsonUtils.toJsonString(notifyDTO));
WpgjPayNotifyRespDTO response = new WpgjPayNotifyRespDTO(); WpgjPayNotifyRespDTO response = new WpgjPayNotifyRespDTO();
try { try {
log.info("[notifyWpgjPayNew][APIHub] 收到WPGJ支付回调(新): {}", JsonUtils.toJsonString(notifyDTO)); log.info("[notifyWpgjPay][APIHub] 收到WPGJ支付回调(新): {}", JsonUtils.toJsonString(notifyDTO));
// 1. 验证签名(对所有出现的非空字段,按 ASCII 升序拼接,排除 sign) // 1. 验证签名(对所有出现的非空字段,按 ASCII 升序拼接,排除 sign)
if (!verifyWpgjSignature(toPayloadMap(notifyDTO))) { if (!verifyWpgjSignature(toPayloadMap(notifyDTO))) {
log.error("[notifyWpgjPayNew][APIHub] WPGJ回调签名验证失败"); log.error("[notifyWpgjPay][APIHub] WPGJ回调签名验证失败");
response.setCode("99"); response.setCode("99");
response.setMsg("签名验证失败"); response.setMsg("签名验证失败");
response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))); response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
return CommonResult.success(response); return response;
} }
String merOrderId = notifyDTO.getMerOrderId(); String merOrderId = notifyDTO.getMerOrderId();
String orderStatus = notifyDTO.getOrderStatus(); String orderStatus = notifyDTO.getOrderStatus();
log.info("[notifyWpgjPayNew][APIHub] 处理WPGJ支付结果,商户订单号: {}, 订单状态: {}", merOrderId, orderStatus); log.info("[notifyWpgjPay][APIHub] 处理WPGJ支付结果,商户订单号: {}, 订单状态: {}", merOrderId, orderStatus);
// 2. 幂等处理:根据订单状态更新(与算力资源模块保持一致逻辑) // 2. 幂等处理:根据订单状态更新(与算力资源模块保持一致逻辑)
if (WpgjOrderStatusEnum.isSuccess(orderStatus)) { if (WpgjOrderStatusEnum.isSuccess(orderStatus)) {
apiOrderService.updateOrderPaidByWpgj(Long.parseLong(merOrderId), notifyDTO); apiOrderService.updateOrderPaidByWpgj(Long.parseLong(merOrderId), notifyDTO);
log.info("[notifyWpgjPayNew][APIHub] 支付成功处理完成,商户订单号: {}", merOrderId); log.info("[notifyWpgjPay][APIHub] 支付成功处理完成,商户订单号: {}", merOrderId);
} else if (WpgjOrderStatusEnum.isFailedOrClosed(orderStatus)) { } else if (WpgjOrderStatusEnum.isFailedOrClosed(orderStatus)) {
apiOrderService.updateOrderFailedByWpgj(Long.parseLong(merOrderId), notifyDTO); apiOrderService.updateOrderFailedByWpgj(Long.parseLong(merOrderId), notifyDTO);
log.info("[notifyWpgjPayNew][APIHub] 支付失败/关闭处理完成,商户订单号: {}", merOrderId); log.info("[notifyWpgjPay][APIHub] 支付失败/关闭处理完成,商户订单号: {}", merOrderId);
} else { } else {
log.info("[notifyWpgjPayNew][APIHub] 订单状态无需处理,商户订单号: {}, 状态: {}", merOrderId, orderStatus); log.info("[notifyWpgjPay][APIHub] 订单状态无需处理,商户订单号: {}, 状态: {}", merOrderId, orderStatus);
} }
// 3. 返回成功应答 // 3. 返回成功应答
response.setCode("00"); response.setCode("00");
response.setMsg("成功"); response.setMsg("成功");
response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))); response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
return CommonResult.success(response); log.info("[notifyWpgjPay][APIHub] 返回wpgj参数: {}", JsonUtils.toJsonString(response));
return response;
} catch (Exception e) { } catch (Exception e) {
log.error("[notifyWpgjPayNew][APIHub] WPGJ支付回调处理失败", e); log.error("[notifyWpgjPay][APIHub] WPGJ支付回调处理失败", e);
response.setCode("99"); response.setCode("99");
response.setMsg("处理失败"); response.setMsg("处理失败");
response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))); response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
return CommonResult.success(response); return response;
} }
} }
......
...@@ -13,7 +13,7 @@ import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrder ...@@ -13,7 +13,7 @@ import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrder
import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrderPageReqVO; import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrderPageReqVO;
import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrderRespVO; import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrderRespVO;
import com.luhu.computility.module.apihub.dal.dataobject.apiorder.ApiOrderDO; import com.luhu.computility.module.apihub.dal.dataobject.apiorder.ApiOrderDO;
import com.luhu.computility.module.apihub.enums.ApiOrderStatus; import com.luhu.computility.module.apihub.enums.ApihubOrderStatusEnum;
import com.luhu.computility.module.apihub.service.apiorder.ApiOrderService; import com.luhu.computility.module.apihub.service.apiorder.ApiOrderService;
import com.luhu.computility.module.trade.enums.order.TradeOrderInvoiceStatusEnum; import com.luhu.computility.module.trade.enums.order.TradeOrderInvoiceStatusEnum;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
...@@ -72,7 +72,7 @@ public class AppApiOrderController { ...@@ -72,7 +72,7 @@ public class AppApiOrderController {
List<AppApiOrderRespVO> list = pageResult.getList(); List<AppApiOrderRespVO> list = pageResult.getList();
if (!CollectionUtil.isEmpty(list)) { if (!CollectionUtil.isEmpty(list)) {
for (AppApiOrderRespVO vo : list) { for (AppApiOrderRespVO vo : list) {
vo.setStatusName(ApiOrderStatus.getRemarkByValue(vo.getStatus())); vo.setStatusName(ApihubOrderStatusEnum.getNameByValue(vo.getStatus()));
vo.setInvoiceStatusName(TradeOrderInvoiceStatusEnum.getDescriptionByStatus(vo.getInvoiceStatus())); vo.setInvoiceStatusName(TradeOrderInvoiceStatusEnum.getDescriptionByStatus(vo.getInvoiceStatus()));
} }
} }
......
...@@ -77,10 +77,6 @@ public class ApiOrderDO extends BaseDO { ...@@ -77,10 +77,6 @@ public class ApiOrderDO extends BaseDO {
*/ */
private Integer status; private Integer status;
/** /**
* 支付状态:1=已支付,2=未支付
*/
private Integer payStatus;
/**
* 支付订单编号 * 支付订单编号
*/ */
private Long payOrderId; private Long payOrderId;
......
...@@ -19,11 +19,12 @@ import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrder ...@@ -19,11 +19,12 @@ import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrder
import com.luhu.computility.module.apihub.dal.dataobject.api.ApiDO; import com.luhu.computility.module.apihub.dal.dataobject.api.ApiDO;
import com.luhu.computility.module.apihub.dal.dataobject.apicategory.ApiCategoryDO; import com.luhu.computility.module.apihub.dal.dataobject.apicategory.ApiCategoryDO;
import com.luhu.computility.module.apihub.dal.dataobject.apiorder.ApiOrderDO; import com.luhu.computility.module.apihub.dal.dataobject.apiorder.ApiOrderDO;
import com.luhu.computility.module.apihub.enums.ApiOrderStatus;
import com.luhu.computility.module.member.dal.dataobject.user.MemberUserDO; import com.luhu.computility.module.member.dal.dataobject.user.MemberUserDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import com.luhu.computility.module.apihub.controller.admin.apiorder.vo.*; import com.luhu.computility.module.apihub.controller.admin.apiorder.vo.*;
import static com.luhu.computility.module.apihub.enums.ApihubOrderStatusEnum.PAID;
/** /**
* api订单 Mapper * api订单 Mapper
* *
...@@ -48,7 +49,7 @@ public interface ApiOrderMapper extends BaseMapperX<ApiOrderDO> { ...@@ -48,7 +49,7 @@ public interface ApiOrderMapper extends BaseMapperX<ApiOrderDO> {
default List<ApiOrderRespDTO> selectAllPaidList(LocalDateTime[] timePeriod) { default List<ApiOrderRespDTO> selectAllPaidList(LocalDateTime[] timePeriod) {
List<ApiOrderDO> list = selectList(new LambdaQueryWrapperX<ApiOrderDO>() List<ApiOrderDO> list = selectList(new LambdaQueryWrapperX<ApiOrderDO>()
.eq(ApiOrderDO::getStatus, ApiOrderStatus.PAID.getValue()) .eq(ApiOrderDO::getStatus, PAID.getValue())
.betweenIfPresent(ApiOrderDO::getCreateTime, timePeriod)); .betweenIfPresent(ApiOrderDO::getCreateTime, timePeriod));
return BeanUtil.copyToList(list, ApiOrderRespDTO.class); return BeanUtil.copyToList(list, ApiOrderRespDTO.class);
} }
......
...@@ -13,9 +13,8 @@ import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrder ...@@ -13,9 +13,8 @@ import com.luhu.computility.module.apihub.controller.app.apiorder.vo.AppApiOrder
import com.luhu.computility.module.apihub.dal.dataobject.api.ApiDO; import com.luhu.computility.module.apihub.dal.dataobject.api.ApiDO;
import com.luhu.computility.module.apihub.dal.dataobject.apipackage.ApiPackageDO; import com.luhu.computility.module.apihub.dal.dataobject.apipackage.ApiPackageDO;
import com.luhu.computility.module.apihub.dal.redis.no.ApiOrderNoRedisDAO; import com.luhu.computility.module.apihub.dal.redis.no.ApiOrderNoRedisDAO;
import com.luhu.computility.module.apihub.enums.ApiOrderPayStatus;
import com.luhu.computility.module.apihub.enums.ApiOrderRefundStatus; import com.luhu.computility.module.apihub.enums.ApiOrderRefundStatus;
import com.luhu.computility.module.apihub.enums.ApiOrderStatus; import com.luhu.computility.module.apihub.enums.ApihubOrderStatusEnum;
import com.luhu.computility.module.apihub.service.api.ApiService; import com.luhu.computility.module.apihub.service.api.ApiService;
import com.luhu.computility.module.apihub.service.apipackage.ApiPackageService; import com.luhu.computility.module.apihub.service.apipackage.ApiPackageService;
import com.luhu.computility.module.pay.api.order.PayOrderApi; import com.luhu.computility.module.pay.api.order.PayOrderApi;
...@@ -52,12 +51,12 @@ import static com.luhu.computility.framework.common.util.collection.CollectionUt ...@@ -52,12 +51,12 @@ import static com.luhu.computility.framework.common.util.collection.CollectionUt
import static com.luhu.computility.framework.common.util.collection.CollectionUtils.getSumValue; import static com.luhu.computility.framework.common.util.collection.CollectionUtils.getSumValue;
import static com.luhu.computility.framework.common.util.date.LocalDateTimeUtils.addTime; import static com.luhu.computility.framework.common.util.date.LocalDateTimeUtils.addTime;
import static com.luhu.computility.framework.common.util.servlet.ServletUtils.getClientIP; import static com.luhu.computility.framework.common.util.servlet.ServletUtils.getClientIP;
import static com.luhu.computility.module.apihub.enums.ApiOrderStatus.PAID; import static com.luhu.computility.module.apihub.enums.ApihubOrderStatusEnum.PAID;
import static com.luhu.computility.module.apihub.enums.ApihubOrderStatusEnum.CANCELED;
import static com.luhu.computility.module.apihub.enums.ApihubOrderStatusEnum.UNPAID;
import static com.luhu.computility.module.apihub.enums.ErrorCodeConstants.*; import static com.luhu.computility.module.apihub.enums.ErrorCodeConstants.*;
import static com.luhu.computility.module.trade.enums.order.TradeOrderInvoiceStatusEnum.INVOICED; import static com.luhu.computility.module.trade.enums.order.TradeOrderInvoiceStatusEnum.INVOICED;
import static com.luhu.computility.module.trade.enums.order.TradeOrderInvoiceStatusEnum.INVOICING; import static com.luhu.computility.module.trade.enums.order.TradeOrderInvoiceStatusEnum.INVOICING;
import static com.luhu.computility.module.trade.enums.order.TradeOrderStatusEnum.CANCELED;
import static com.luhu.computility.module.trade.enums.order.TradeOrderStatusEnum.UNPAID;
import static org.apache.commons.lang3.ObjectUtils.notEqual; import static org.apache.commons.lang3.ObjectUtils.notEqual;
/** /**
...@@ -195,7 +194,7 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -195,7 +194,7 @@ public class ApiOrderServiceImpl implements ApiOrderService {
createReqVO.setCostPrice(apiPackage.getPrice()); createReqVO.setCostPrice(apiPackage.getPrice());
ApiOrderDO order = BeanUtils.toBean(createReqVO, ApiOrderDO.class); ApiOrderDO order = BeanUtils.toBean(createReqVO, ApiOrderDO.class);
order.setOrderNo(apiOrderNoRedisDAO.generate(ApiOrderNoRedisDAO.API_ORDER_NO_PREFIX)); order.setOrderNo(apiOrderNoRedisDAO.generate(ApiOrderNoRedisDAO.API_ORDER_NO_PREFIX));
order.setStatus(ApiOrderStatus.UNPAID.getValue()); order.setStatus(ApihubOrderStatusEnum.UNPAID.getValue());
order.setUserIp(getClientIP()); order.setUserIp(getClientIP());
order.setRefundStatus(ApiOrderRefundStatus.NONE.getValue()).setRefundPrice(0); order.setRefundStatus(ApiOrderRefundStatus.NONE.getValue()).setRefundPrice(0);
return order; return order;
...@@ -247,7 +246,6 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -247,7 +246,6 @@ public class ApiOrderServiceImpl implements ApiOrderService {
// 3. 更新 apiOrderDO 状态为已支付 // 3. 更新 apiOrderDO 状态为已支付
apiOrderMapper.updateByIdAndStatus(id, order.getStatus(), apiOrderMapper.updateByIdAndStatus(id, order.getStatus(),
new ApiOrderDO().setStatus(PAID.getValue()) new ApiOrderDO().setStatus(PAID.getValue())
.setPayStatus(ApiOrderPayStatus.SUCCESS.getValue())
.setPayTime(LocalDateTime.now()).setPayChannelCode(payOrder.getChannelCode())); .setPayTime(LocalDateTime.now()).setPayChannelCode(payOrder.getChannelCode()));
// 5. 记录订单日志 // 5. 记录订单日志
...@@ -259,7 +257,7 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -259,7 +257,7 @@ public class ApiOrderServiceImpl implements ApiOrderService {
public boolean updateInvoice(ApiOrderSaveReqVO saveVO) { public boolean updateInvoice(ApiOrderSaveReqVO saveVO) {
ApiOrderDO order = apiOrderMapper.selectById(saveVO.getId()); ApiOrderDO order = apiOrderMapper.selectById(saveVO.getId());
if(notEqual(order.getStatus(), PAID.getValue())){ if(notEqual(order.getStatus(), PAID.getValue())){
throw new ServiceException("只有"+PAID.getRemark()+"订单可以开票!"); throw new ServiceException("只有"+PAID.name()+"订单可以开票!");
} }
order.setInvoiceStatus(INVOICED.getStatus()); order.setInvoiceStatus(INVOICED.getStatus());
order.setInvoiceUrl(saveVO.getInvoiceUrl()); order.setInvoiceUrl(saveVO.getInvoiceUrl());
...@@ -309,9 +307,9 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -309,9 +307,9 @@ public class ApiOrderServiceImpl implements ApiOrderService {
public boolean updateRequestInvoice(AppApiOrderInvoiceReqVO reqVO) { public boolean updateRequestInvoice(AppApiOrderInvoiceReqVO reqVO) {
ApiOrderDO apiOrderDO = apiOrderMapper.selectById(reqVO.getId()); ApiOrderDO apiOrderDO = apiOrderMapper.selectById(reqVO.getId());
Integer status = apiOrderDO.getStatus();//订单状态 Integer status = apiOrderDO.getStatus();//订单状态
if(status.equals(UNPAID.getStatus())){ if(status.equals(UNPAID.getValue())){
throw new ServiceException("未支付的订单不能申请开票"); throw new ServiceException("未支付的订单不能申请开票");
} else if (status.equals(CANCELED.getStatus())) { } else if (status.equals(CANCELED.getValue())) {
throw new ServiceException("已取消的订单不能申请开票!"); throw new ServiceException("已取消的订单不能申请开票!");
} }
apiOrderDO.setInvoiceStatus(INVOICING.getStatus()); apiOrderDO.setInvoiceStatus(INVOICING.getStatus());
...@@ -402,7 +400,7 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -402,7 +400,7 @@ public class ApiOrderServiceImpl implements ApiOrderService {
return; return;
} }
if (!(ApiOrderStatus.UNPAID.getValue()==(order.getStatus()))) { if (!(ApihubOrderStatusEnum.UNPAID.getValue()==(order.getStatus()))) {
log.error("[updateOrderPaidByWpgj][APIHub] API订单状态不是待支付,无法更新为已支付,API订单ID: {}, 当前状态: {}", log.error("[updateOrderPaidByWpgj][APIHub] API订单状态不是待支付,无法更新为已支付,API订单ID: {}, 当前状态: {}",
apiOrderId, order.getStatus()); apiOrderId, order.getStatus());
return; return;
...@@ -432,7 +430,6 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -432,7 +430,6 @@ public class ApiOrderServiceImpl implements ApiOrderService {
ApiOrderDO updateApiOrder = new ApiOrderDO(); ApiOrderDO updateApiOrder = new ApiOrderDO();
updateApiOrder.setId(apiOrderId); updateApiOrder.setId(apiOrderId);
updateApiOrder.setStatus(PAID.getValue()); updateApiOrder.setStatus(PAID.getValue());
updateApiOrder.setPayStatus(ApiOrderPayStatus.SUCCESS.getValue());
updateApiOrder.setPayTime(LocalDateTime.now()); updateApiOrder.setPayTime(LocalDateTime.now());
updateApiOrder.setPayChannelCode("WPGJ"); updateApiOrder.setPayChannelCode("WPGJ");
...@@ -466,12 +463,12 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -466,12 +463,12 @@ public class ApiOrderServiceImpl implements ApiOrderService {
ApiOrderDO order = validateApiOrderExists(apiOrderId); ApiOrderDO order = validateApiOrderExists(apiOrderId);
// 2. 校验订单状态,避免重复处理 // 2. 校验订单状态,避免重复处理
if (ApiOrderStatus.CANCELED.getValue() == order.getStatus()) { if (CANCELED.getValue() == order.getStatus()) {
log.warn("[updateOrderFailedByWpgj][APIHub] API订单已经是取消状态,API订单ID: {}", apiOrderId); log.warn("[updateOrderFailedByWpgj][APIHub] API订单已经是取消状态,API订单ID: {}", apiOrderId);
return; return;
} }
if (!(ApiOrderStatus.UNPAID.getValue()==(order.getStatus()))) { if (!(ApihubOrderStatusEnum.UNPAID.getValue()==(order.getStatus()))) {
log.error("[updateOrderFailedByWpgj][APIHub] API订单状态不是待支付,无法更新为已取消,API订单ID: {}, 当前状态: {}", log.error("[updateOrderFailedByWpgj][APIHub] API订单状态不是待支付,无法更新为已取消,API订单ID: {}, 当前状态: {}",
apiOrderId, order.getStatus()); apiOrderId, order.getStatus());
return; return;
...@@ -480,7 +477,7 @@ public class ApiOrderServiceImpl implements ApiOrderService { ...@@ -480,7 +477,7 @@ public class ApiOrderServiceImpl implements ApiOrderService {
// 3. 更新API订单状态为已取消(支付失败) // 3. 更新API订单状态为已取消(支付失败)
ApiOrderDO updateOrder = new ApiOrderDO(); ApiOrderDO updateOrder = new ApiOrderDO();
updateOrder.setId(apiOrderId); updateOrder.setId(apiOrderId);
updateOrder.setStatus(ApiOrderStatus.CANCELED.getValue()); updateOrder.setStatus(ApihubOrderStatusEnum.CANCELED.getValue());
updateOrder.setCancelTime(LocalDateTime.now()); updateOrder.setCancelTime(LocalDateTime.now());
apiOrderMapper.updateById(updateOrder); apiOrderMapper.updateById(updateOrder);
......
...@@ -14,7 +14,8 @@ public enum ResourceOrderStatus { ...@@ -14,7 +14,8 @@ public enum ResourceOrderStatus {
UNPAID(0, "待支付"), UNPAID(0, "待支付"),
PAID(1, "已支付"), PAID(1, "已支付"),
CANCELED(2, "已取消"); CANCELED(2, "已取消"),
REFUNDED(3, "已退款");
private final Integer value; private final Integer value;
private final String label; private final String label;
......
...@@ -48,49 +48,49 @@ public class ComputeWpgjPayController { ...@@ -48,49 +48,49 @@ public class ComputeWpgjPayController {
@PostMapping("/notify") @PostMapping("/notify")
@PermitAll @PermitAll
@Operation(summary = "WPGJ支付异步回调通知(新) - 按文档通用验签") @Operation(summary = "WPGJ支付异步回调通知(新) - 按文档通用验签")
public CommonResult<WpgjPayNotifyRespDTO> notifyWpgjPay(@RequestBody WpgjPayNotifyDTO notifyDTO) { public WpgjPayNotifyRespDTO notifyWpgjPay(@RequestBody WpgjPayNotifyDTO notifyDTO) {
log.info("[notifyWpgjPayNew][Compute] 收到WPGJ支付回调(新): {}", "new-notify进来了进来了————————————————————————————————————————————————————————————————————————————————————————————————");
WpgjPayNotifyRespDTO response = new WpgjPayNotifyRespDTO(); WpgjPayNotifyRespDTO response = new WpgjPayNotifyRespDTO();
try { try {
log.info("[notifyWpgjPayNew][Compute] 收到WPGJ支付回调(新): {}", JsonUtils.toJsonString(notifyDTO)); log.info("[notifyWpgjPay][Compute] 收到WPGJ支付回调(新): {}", JsonUtils.toJsonString(notifyDTO));
// 1. 验证签名(对所有出现的非空字段,按 ASCII 升序拼接,排除 sign) // 1. 验证签名(对所有出现的非空字段,按 ASCII 升序拼接,排除 sign)
if (!verifyWpgjSignature(toPayloadMap(notifyDTO))) { if (!verifyWpgjSignature(toPayloadMap(notifyDTO))) {
log.error("[notifyWpgjPayNew][Compute] WPGJ回调签名验证失败"); log.error("[notifyWpgjPay][Compute] WPGJ回调签名验证失败");
response.setCode("99"); response.setCode("99");
response.setMsg("签名验证失败"); response.setMsg("签名验证失败");
response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))); response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
return CommonResult.success(response); return response;
} }
String merOrderId = notifyDTO.getMerOrderId(); String merOrderId = notifyDTO.getMerOrderId();
String orderStatus = notifyDTO.getOrderStatus(); String orderStatus = notifyDTO.getOrderStatus();
log.info("[notifyWpgjPayNew] 处理WPGJ支付结果,商户订单号: {}, 订单状态: {}", merOrderId, orderStatus); log.info("[notifyWpgjPay] 处理WPGJ支付结果,商户订单号: {}, 订单状态: {}", merOrderId, orderStatus);
// 2. 幂等处理:根据订单状态更新(与老接口保持一致逻辑) // 2. 幂等处理:根据订单状态更新(与老接口保持一致逻辑)
if (WpgjOrderStatusEnum.isSuccess(orderStatus)) { if (WpgjOrderStatusEnum.isSuccess(orderStatus)) {
resourceOrderService.updateOrderPaidByWpgj(Long.parseLong(merOrderId),notifyDTO); resourceOrderService.updateOrderPaidByWpgj(Long.parseLong(merOrderId),notifyDTO);
log.info("[notifyWpgjPayNew] 支付成功处理完成,商户订单号: {}", merOrderId); log.info("[notifyWpgjPay] 支付成功处理完成,商户订单号: {}", merOrderId);
} else if (WpgjOrderStatusEnum.isFailedOrClosed(orderStatus)) { } else if (WpgjOrderStatusEnum.isFailedOrClosed(orderStatus)) {
resourceOrderService.updateOrderFailedByWpgj(Long.parseLong(merOrderId), notifyDTO); resourceOrderService.updateOrderFailedByWpgj(Long.parseLong(merOrderId), notifyDTO);
log.info("[notifyWpgjPayNew] 支付失败/关闭处理完成,商户订单号: {}", merOrderId); log.info("[notifyWpgjPay] 支付失败/关闭处理完成,商户订单号: {}", merOrderId);
} else { } else {
log.info("[notifyWpgjPayNew] 订单状态无需处理,商户订单号: {}, 状态: {}", merOrderId, orderStatus); log.info("[notifyWpgjPay] 订单状态无需处理,商户订单号: {}, 状态: {}", merOrderId, orderStatus);
} }
// 3. 返回成功应答 // 3. 返回成功应答
response.setCode("00"); response.setCode("00");
response.setMsg("成功"); response.setMsg("成功");
response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))); response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
return CommonResult.success(response); log.info("[notifyWpgjPay][Compute] 返回wpgj参数:{}", JsonUtils.toJsonString(response));
return response;
} catch (Exception e) { } catch (Exception e) {
log.error("[notifyWpgjPayNew][Compute] WPGJ支付回调处理失败", e); log.error("[notifyWpgjPay][Compute] WPGJ支付回调处理失败", e);
response.setCode("99"); response.setCode("99");
response.setMsg("处理失败"); response.setMsg("处理失败");
response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))); response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
return CommonResult.success(response); return response;
} }
} }
......
...@@ -24,6 +24,10 @@ public class ResourceOrderRespVO { ...@@ -24,6 +24,10 @@ public class ResourceOrderRespVO {
@ExcelProperty("用户昵称") @ExcelProperty("用户昵称")
private String nickname; private String nickname;
@Schema(description = "用户手机号", example = "13800138000")
@ExcelProperty("用户手机号")
private String mobile;
@Schema(description = "算力资源SKU ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31061") @Schema(description = "算力资源SKU ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31061")
@ExcelProperty("算力资源SKU ID") @ExcelProperty("算力资源SKU ID")
private Long skuId; private Long skuId;
......
...@@ -23,6 +23,7 @@ public interface ResourceOrderMapper extends BaseMapperX<ResourceOrderDO> { ...@@ -23,6 +23,7 @@ public interface ResourceOrderMapper extends BaseMapperX<ResourceOrderDO> {
return selectJoinPage(reqVO, ResourceOrderRespVO.class, new MPJLambdaWrapperX<ResourceOrderDO>() return selectJoinPage(reqVO, ResourceOrderRespVO.class, new MPJLambdaWrapperX<ResourceOrderDO>()
.selectAll(ResourceOrderDO.class) .selectAll(ResourceOrderDO.class)
.selectAs(MemberUserDO::getNickname, ResourceOrderRespVO::getNickname) .selectAs(MemberUserDO::getNickname, ResourceOrderRespVO::getNickname)
.selectAs(MemberUserDO::getMobile, ResourceOrderRespVO::getMobile)
.leftJoin(MemberUserDO.class, MemberUserDO::getId, ResourceOrderDO::getUserId) .leftJoin(MemberUserDO.class, MemberUserDO::getId, ResourceOrderDO::getUserId)
.eqIfPresent(ResourceOrderDO::getUserId, reqVO.getUserId()) .eqIfPresent(ResourceOrderDO::getUserId, reqVO.getUserId())
.eqIfPresent(ResourceOrderDO::getSkuId, reqVO.getSkuId()) .eqIfPresent(ResourceOrderDO::getSkuId, reqVO.getSkuId())
......
...@@ -553,8 +553,6 @@ public class ResourceOrderServiceImpl implements ResourceOrderService { ...@@ -553,8 +553,6 @@ public class ResourceOrderServiceImpl implements ResourceOrderService {
orderId, wpgjOrderAmt, resourceOrderAmt); orderId, wpgjOrderAmt, resourceOrderAmt);
return; return;
} }
log.error("[updateOrderPaidByWpgj] WPGJ金额: {}, 订单金额: {}",
orderId, wpgjOrderAmt, resourceOrderAmt);
// 4. 更新算力资源订单状态为已支付 // 4. 更新算力资源订单状态为已支付
ResourceOrderDO updateResourceOrder = new ResourceOrderDO(); ResourceOrderDO updateResourceOrder = new ResourceOrderDO();
......
...@@ -28,6 +28,8 @@ import java.net.URLEncoder; ...@@ -28,6 +28,8 @@ import java.net.URLEncoder;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import static com.luhu.computility.module.pay.enums.WpgjOrderStatusEnum.WAITING;
/** /**
* 支付单 API 实现类 * 支付单 API 实现类
* *
...@@ -106,7 +108,7 @@ public class PayOrderApiImpl implements PayOrderApi { ...@@ -106,7 +108,7 @@ public class PayOrderApiImpl implements PayOrderApi {
if (WpgjOrderStatusEnum.isSuccess(wpgjOrder.getOrderStatus())) { if (WpgjOrderStatusEnum.isSuccess(wpgjOrder.getOrderStatus())) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PAY_ORDER_STATUS_IS_SUCCESS); throw ServiceExceptionUtil.exception(ErrorCodeConstants.PAY_ORDER_STATUS_IS_SUCCESS);
} }
if (!WpgjOrderStatusEnum.PROCESSING.getStatus().equals(wpgjOrder.getOrderStatus())) { if (!WAITING.getStatus().equals(wpgjOrder.getOrderStatus())) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.PAY_ORDER_STATUS_IS_NOT_WAITING); throw ServiceExceptionUtil.exception(ErrorCodeConstants.PAY_ORDER_STATUS_IS_NOT_WAITING);
} }
return wpgjOrder; return wpgjOrder;
......
...@@ -5,6 +5,9 @@ import com.luhu.computility.framework.mybatis.core.query.LambdaQueryWrapperX; ...@@ -5,6 +5,9 @@ import com.luhu.computility.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.luhu.computility.module.pay.dal.dataobject.wpgj.PayOrderWpgjDO; import com.luhu.computility.module.pay.dal.dataobject.wpgj.PayOrderWpgjDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.List;
/** /**
* 旺铺聚合支付订单 Mapper * 旺铺聚合支付订单 Mapper
* *
...@@ -25,4 +28,17 @@ public interface PayOrderWpgjMapper extends BaseMapperX<PayOrderWpgjDO> { ...@@ -25,4 +28,17 @@ public interface PayOrderWpgjMapper extends BaseMapperX<PayOrderWpgjDO> {
return selectOne(PayOrderWpgjDO::getOrderNo, orderNo); return selectOne(PayOrderWpgjDO::getOrderNo, orderNo);
} }
/**
* 查询过期的处理中订单
*
* @param orderStatus 订单状态
* @param expireTime 过期时间
* @return 过期订单列表
*/
default List<PayOrderWpgjDO> selectListByOrderStatusAndCreateTimeLt(String orderStatus, LocalDateTime expireTime) {
return selectList(new LambdaQueryWrapperX<PayOrderWpgjDO>()
.eq(PayOrderWpgjDO::getOrderStatus, orderStatus)
.lt(PayOrderWpgjDO::getCreateTime, expireTime));
}
} }
\ No newline at end of file
...@@ -13,9 +13,10 @@ import lombok.Getter; ...@@ -13,9 +13,10 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public enum WpgjOrderStatusEnum implements ArrayValuable<String> { public enum WpgjOrderStatusEnum implements ArrayValuable<String> {
PROCESSING("0", "处理中"), WAITING("0", "待支付"),
SUCCESS("1", "支付成功"), SUCCESS("1", "已支付"),
FAILED("2", "支付失败"), CLOSED("2", "已取消"), // 支付关闭
REFUND("3", "已退款"),
; ;
private final String status; private final String status;
...@@ -43,7 +44,7 @@ public enum WpgjOrderStatusEnum implements ArrayValuable<String> { ...@@ -43,7 +44,7 @@ public enum WpgjOrderStatusEnum implements ArrayValuable<String> {
* @return 是否支付失败或关闭 * @return 是否支付失败或关闭
*/ */
public static boolean isFailedOrClosed(String status) { public static boolean isFailedOrClosed(String status) {
return PROCESSING.getStatus().equals(status) || FAILED.getStatus().equals(status); return WAITING.getStatus().equals(status) || CLOSED.getStatus().equals(status);
} }
} }
\ No newline at end of file
...@@ -3,29 +3,29 @@ package com.luhu.computility.module.pay.job.order; ...@@ -3,29 +3,29 @@ package com.luhu.computility.module.pay.job.order;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.luhu.computility.framework.quartz.core.handler.JobHandler; import com.luhu.computility.framework.quartz.core.handler.JobHandler;
import com.luhu.computility.framework.tenant.core.job.TenantJob; import com.luhu.computility.framework.tenant.core.job.TenantJob;
import com.luhu.computility.module.pay.service.order.PayOrderService; import com.luhu.computility.module.pay.service.wpgj.PayOrderWpgjService;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
/** /**
* 支付订单的过期 Job * WPGJ旺铺聚合支付订单的过期 Job
* *
* 支付超过过期时间时,支付渠道是不会通知进行过期,所以需要定时进行过期关闭。 * 支付超过过期时间时,支付渠道是不会通知进行过期,所以需要定时进行过期关闭。
* *
* @author 芋道源码 * @author jonyl
*/ */
@Component @Component
public class PayOrderExpireJob implements JobHandler { public class PayOrderExpireJob implements JobHandler {
@Resource @Resource
private PayOrderService orderService; private PayOrderWpgjService payOrderWpgjService;
@Override @Override
@TenantJob @TenantJob
public String execute(String param) { public String execute(String param) {
int count = orderService.expireOrder(); int count = payOrderWpgjService.expireOrder();
return StrUtil.format("支付过期 {} 个", count); return StrUtil.format("WPGJ支付过期 {} 个", count);
} }
} }
...@@ -42,4 +42,11 @@ public interface PayOrderWpgjService { ...@@ -42,4 +42,11 @@ public interface PayOrderWpgjService {
*/ */
PayOrderWpgjDO getById(Long id); PayOrderWpgjDO getById(Long id);
/**
* 过期处理中的旺铺聚合支付订单
*
* @return 过期的订单数量
*/
int expireOrder();
} }
\ No newline at end of file
package com.luhu.computility.module.pay.service.wpgj; package com.luhu.computility.module.pay.service.wpgj;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.luhu.computility.framework.common.util.object.BeanUtils; import com.luhu.computility.framework.common.util.object.BeanUtils;
import com.luhu.computility.module.pay.controller.admin.notify.vo.WpgjPayNotifyDTO; import com.luhu.computility.module.pay.controller.admin.notify.vo.WpgjPayNotifyDTO;
import com.luhu.computility.module.pay.dal.dataobject.wpgj.PayOrderWpgjDO; import com.luhu.computility.module.pay.dal.dataobject.wpgj.PayOrderWpgjDO;
import com.luhu.computility.module.pay.dal.mysql.wpgj.PayOrderWpgjMapper; import com.luhu.computility.module.pay.dal.mysql.wpgj.PayOrderWpgjMapper;
import com.luhu.computility.module.pay.enums.WpgjOrderStatusEnum;
import com.luhu.computility.module.pay.framework.pay.core.client.impl.wpgj.WpgjPayProperties; import com.luhu.computility.module.pay.framework.pay.core.client.impl.wpgj.WpgjPayProperties;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
/** /**
...@@ -77,4 +81,49 @@ public class PayOrderWpgjServiceImpl implements PayOrderWpgjService { ...@@ -77,4 +81,49 @@ public class PayOrderWpgjServiceImpl implements PayOrderWpgjService {
return payOrderWpgjMapper.selectById(id); return payOrderWpgjMapper.selectById(id);
} }
@Override
public int expireOrder() {
// 1. 查询过期的待支付订单(超过30分钟未支付的订单)
LocalDateTime expireTime = LocalDateTime.now().minusMinutes(30);
List<PayOrderWpgjDO> orders = payOrderWpgjMapper.selectListByOrderStatusAndCreateTimeLt(
WpgjOrderStatusEnum.WAITING.getStatus(), expireTime);
if (CollUtil.isEmpty(orders)) {
return 0;
}
// 2. 遍历执行,将过期的待支付订单标记为已取消
int count = 0;
for (PayOrderWpgjDO order : orders) {
count += expireOrder(order) ? 1 : 0;
}
return count;
}
/**
* 过期单个WPGJ订单
*
* @param order WPGJ订单
* @return 是否过期成功
*/
private boolean expireOrder(PayOrderWpgjDO order) {
try {
// 将待支付的订单更新为已取消状态
PayOrderWpgjDO updateObj = new PayOrderWpgjDO()
.setId(order.getId())
.setOrderStatus(WpgjOrderStatusEnum.CLOSED.getStatus());
int updateCount = payOrderWpgjMapper.updateById(updateObj);
if (updateCount > 0) {
log.info("[expireOrder][WPGJ订单({}) 过期成功,状态更新为已取消]", order.getOrderId());
return true;
} else {
log.error("[expireOrder][WPGJ订单({}) 过期失败,更新状态失败]", order.getOrderId());
return false;
}
} catch (Exception e) {
log.error("[expireOrder][WPGJ订单({}) 过期异常]", order.getOrderId(), e);
return false;
}
}
} }
\ No newline at end of file
...@@ -13,7 +13,7 @@ spring: ...@@ -13,7 +13,7 @@ spring:
# noinspection SpringBootApplicationYaml # noinspection SpringBootApplicationYaml
exclude: exclude:
- com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源 - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
- org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置 # - org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置
- de.codecentric.boot.admin.server.config.AdminServerAutoConfiguration # 禁用 Spring Boot Admin 的 Server 的自动配置 - de.codecentric.boot.admin.server.config.AdminServerAutoConfiguration # 禁用 Spring Boot Admin 的 Server 的自动配置
- de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration # 禁用 Spring Boot Admin 的 Server UI 的自动配置 - de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration # 禁用 Spring Boot Admin 的 Server UI 的自动配置
- de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration # 禁用 Spring Boot Admin 的 Client 的自动配置 - de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration # 禁用 Spring Boot Admin 的 Client 的自动配置
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment