Commit ff3a5dfc by Jony.L

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

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