Jelajahi Sumber

1、修改已知bug

rayson 11 bulan lalu
induk
melakukan
9cd78cf818

+ 2 - 1
citu-framework/citu-spring-boot-starter-security/src/main/java/com/citu/framework/security/core/util/SecurityFrameworkUtils.java

@@ -138,7 +138,8 @@ public class SecurityFrameworkUtils {
     @Nullable
     public static <T> T getLoginUserDataId(Class<T> type) {
         LoginUser loginUser = getLoginUser();
-        if (CollUtil.isEmpty(loginUser.getInfo())
+        if (null == loginUser
+                || CollUtil.isEmpty(loginUser.getInfo())
                 || null == loginUser.getInfo()
                 || !loginUser.getInfo().containsKey(LoginUser.INFO_KEY_DATA_ID)) {
             throw exception(FORBIDDEN);

+ 43 - 1
citu-module-pay/citu-module-pay-biz/src/main/java/com/citu/module/pay/controller/admin/currency/PayCurrencyRechargeController.java

@@ -1,13 +1,30 @@
 package com.citu.module.pay.controller.admin.currency;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import com.citu.framework.common.enums.UserTypeEnum;
 import com.citu.framework.common.pojo.CommonResult;
+import com.citu.framework.common.pojo.PageParam;
+import com.citu.framework.common.pojo.PageResult;
 import com.citu.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
 import com.citu.module.pay.api.notify.dto.PayRefundNotifyReqDTO;
+import com.citu.module.pay.controller.admin.currency.vo.recharge.PayCurrencyRechargePageReqVO;
+import com.citu.module.pay.controller.admin.currency.vo.recharge.PayCurrencyRechargeRespVO;
+import com.citu.module.pay.controller.admin.order.vo.PayOrderPageItemRespVO;
+import com.citu.module.pay.controller.admin.order.vo.PayOrderPageReqVO;
+import com.citu.module.pay.controller.app.currency.vo.recharge.AppPayCurrencyRechargeRespVO;
+import com.citu.module.pay.convert.currency.PayCurrencyRechargeConvert;
+import com.citu.module.pay.convert.order.PayOrderConvert;
+import com.citu.module.pay.dal.dataobject.app.PayAppDO;
+import com.citu.module.pay.dal.dataobject.currency.PayCurrencyRechargeDO;
+import com.citu.module.pay.dal.dataobject.order.PayOrderDO;
 import com.citu.module.pay.service.currency.PayCurrencyRechargeService;
+import com.citu.module.pay.service.order.PayOrderService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -15,8 +32,14 @@ import javax.annotation.Resource;
 import javax.annotation.security.PermitAll;
 import javax.validation.Valid;
 
+import java.util.List;
+import java.util.Map;
+
 import static com.citu.framework.common.pojo.CommonResult.success;
+import static com.citu.framework.common.util.collection.CollectionUtils.convertList;
 import static com.citu.framework.common.util.servlet.ServletUtils.getClientIP;
+import static com.citu.framework.security.core.util.SecurityFrameworkUtils.getLoginUserDataId;
+import static com.citu.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
 
 @Tag(name = "管理后台 - 货币账户充值")
 @RestController
@@ -28,6 +51,9 @@ public class PayCurrencyRechargeController {
     @Resource
     private PayCurrencyRechargeService currencyRechargeService;
 
+    @Resource
+    private PayOrderService payOrderService;
+
     @PostMapping("/update-paid")
     @Operation(summary = "更新货币账户充值为已充值") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob
     @PermitAll // 无需登录, 内部校验实现
@@ -38,9 +64,10 @@ public class PayCurrencyRechargeController {
     }
 
     // TODO @jason:发起退款,要 post 操作哈;
-    @GetMapping("/refund")
+    @PutMapping("/refund")
     @Operation(summary = "发起货币账户充值退款")
     @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('pay:currency-recharge:update')")
     public CommonResult<Boolean> refundCurrencyRecharge(@RequestParam("id") Long id) {
         currencyRechargeService.refundCurrencyRecharge(id, getClientIP());
         return success(true);
@@ -55,4 +82,19 @@ public class PayCurrencyRechargeController {
         return success(true);
     }
 
+    @GetMapping("/page")
+    @Operation(summary = "获得货币账户充值记录分页")
+    @PreAuthorize("@ss.hasPermission('pay:currency-recharge:query')")
+    public CommonResult<PageResult<PayCurrencyRechargeRespVO>> getCurrencyRechargePage(
+            @Valid PayCurrencyRechargePageReqVO pageReqVO) {
+        PageResult<PayCurrencyRechargeDO> pageResult = currencyRechargeService
+                .getCurrencyRechargePackagePage(pageReqVO);
+        if (CollUtil.isEmpty(pageResult.getList())) {
+            return success(PageResult.empty(pageResult.getTotal()));
+        }
+        // 拼接数据
+        List<PayOrderDO> payOrderList = payOrderService.getOrderList(
+                convertList(pageResult.getList(), PayCurrencyRechargeDO::getPayOrderId));
+        return success(PayCurrencyRechargeConvert.INSTANCE.convertPage2(pageResult, payOrderList));
+    }
 }

+ 39 - 0
citu-module-pay/citu-module-pay-biz/src/main/java/com/citu/module/pay/controller/admin/currency/vo/recharge/PayCurrencyRechargePageReqVO.java

@@ -0,0 +1,39 @@
+package com.citu.module.pay.controller.admin.currency.vo.recharge;
+
+import com.citu.framework.common.pojo.PageParam;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.time.LocalDateTime;
+
+import static com.citu.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 货币账户充值记录分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class PayCurrencyRechargePageReqVO extends PageParam {
+
+    @Schema(description = "支付成功的支付渠道", requiredMode = Schema.RequiredMode.REQUIRED)
+    private String payChannelCode;
+
+    @Schema(description = "货币账户 id", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Long currencyId;
+
+    @Schema(description = "充值套餐编号", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Long packageId;
+
+    @Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Long payOrderId;
+
+    @Schema(description = "是否已支付", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Boolean payStatus;
+
+    @Schema(description = "支付退款单编号", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Long payRefundId;
+
+
+}

+ 45 - 0
citu-module-pay/citu-module-pay-biz/src/main/java/com/citu/module/pay/controller/admin/currency/vo/recharge/PayCurrencyRechargeRespVO.java

@@ -0,0 +1,45 @@
+package com.citu.module.pay.controller.admin.currency.vo.recharge;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Schema(description = "管理后台 - 货币账户充值记录 Resp VO")
+@Data
+public class PayCurrencyRechargeRespVO {
+
+    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    private Long id;
+
+    @Schema(description = "用户实际到账余额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
+    private Long totalPrice;
+
+    @Schema(description = "实际支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
+    private Long payPrice;
+
+    @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
+    private Long bonusPrice;
+
+    @Schema(description = "支付成功的支付渠道", requiredMode = Schema.RequiredMode.REQUIRED)
+    private String payChannelCode;
+
+    @Schema(description = "支付渠道名", example = "微信小程序支付")
+    private String payChannelName;
+
+    @Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Long payOrderId;
+
+    @Schema(description = "支付成功的外部订单号", requiredMode = Schema.RequiredMode.REQUIRED)
+    private String payOrderChannelOrderNo; // 从 PayOrderDO 的 channelOrderNo 字段
+
+    @Schema(description = "订单支付时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    private LocalDateTime payTime;
+
+    @Schema(description = "是否已支付", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
+    private Boolean payStatus;
+
+    @Schema(description = "退款状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
+    private Integer refundStatus;
+
+}

+ 18 - 1
citu-module-pay/citu-module-pay-biz/src/main/java/com/citu/module/pay/convert/currency/PayCurrencyRechargeConvert.java

@@ -6,6 +6,7 @@ import com.citu.framework.common.util.collection.CollectionUtils;
 import com.citu.framework.common.util.collection.MapUtils;
 import com.citu.framework.common.util.object.BeanUtils;
 import com.citu.framework.dict.core.DictFrameworkUtils;
+import com.citu.module.pay.controller.admin.currency.vo.recharge.PayCurrencyRechargeRespVO;
 import com.citu.module.pay.controller.app.currency.vo.recharge.AppPayCurrencyRechargeCreateRespVO;
 import com.citu.module.pay.controller.app.currency.vo.recharge.AppPayCurrencyRechargeRespVO;
 import com.citu.module.pay.dal.dataobject.currency.PayCurrencyRechargeDO;
@@ -14,6 +15,7 @@ import com.citu.module.pay.enums.DictTypeConstants;
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 import org.mapstruct.factory.Mappers;
+import org.springframework.util.StringUtils;
 
 import java.util.List;
 import java.util.Map;
@@ -24,7 +26,7 @@ public interface PayCurrencyRechargeConvert {
     PayCurrencyRechargeConvert INSTANCE = Mappers.getMapper(PayCurrencyRechargeConvert.class);
 
     @Mapping(target = "totalPrice", expression = "java( payPrice + bonusPrice)")
-    PayCurrencyRechargeDO convert(Long walletId, Long payPrice, Long bonusPrice, Long packageId);
+    PayCurrencyRechargeDO convert(Long currencyId, Long payPrice, Long bonusPrice, Long packageId);
 
     AppPayCurrencyRechargeCreateRespVO convert(PayCurrencyRechargeDO bean);
 
@@ -41,4 +43,19 @@ public interface PayCurrencyRechargeConvert {
         return voPageResult;
     }
 
+    default PageResult<PayCurrencyRechargeRespVO> convertPage2(PageResult<PayCurrencyRechargeDO> pageResult,
+                                                               List<PayOrderDO> payOrderList) {
+        PageResult<PayCurrencyRechargeRespVO> voPageResult = BeanUtils.toBean(pageResult, PayCurrencyRechargeRespVO.class);
+        Map<Long, PayOrderDO> payOrderMap = CollectionUtils.convertMap(payOrderList, PayOrderDO::getId);
+        voPageResult.getList().forEach(recharge -> {
+            if (StringUtils.hasText(recharge.getPayChannelCode())) {
+                recharge.setPayChannelName(DictFrameworkUtils.getDictDataLabel(
+                        DictTypeConstants.CHANNEL_CODE, recharge.getPayChannelCode()));
+            }
+            MapUtils.findAndThen(payOrderMap, recharge.getPayOrderId(),
+                    order -> recharge.setPayOrderChannelOrderNo(order.getChannelOrderNo()));
+        });
+        return voPageResult;
+    }
+
 }

+ 14 - 2
citu-module-pay/citu-module-pay-biz/src/main/java/com/citu/module/pay/dal/mysql/currency/PayCurrencyRechargeMapper.java

@@ -4,6 +4,7 @@ import com.citu.framework.common.pojo.PageParam;
 import com.citu.framework.common.pojo.PageResult;
 import com.citu.framework.mybatis.core.mapper.BaseMapperX;
 import com.citu.framework.mybatis.core.query.LambdaQueryWrapperX;
+import com.citu.module.pay.controller.admin.currency.vo.recharge.PayCurrencyRechargePageReqVO;
 import com.citu.module.pay.dal.dataobject.currency.PayCurrencyRechargeDO;
 import org.apache.ibatis.annotations.Mapper;
 
@@ -20,11 +21,22 @@ public interface PayCurrencyRechargeMapper extends BaseMapperX<PayCurrencyRechar
                 .eq(PayCurrencyRechargeDO::getId, id).eq(PayCurrencyRechargeDO::getRefundStatus, whereRefundStatus));
     }
 
-    default PageResult<PayCurrencyRechargeDO> selectPage(PageParam pageReqVO, Long walletId, Boolean payStatus) {
+    default PageResult<PayCurrencyRechargeDO> selectPage(PageParam pageReqVO, Long currencyId, Boolean payStatus) {
         return selectPage(pageReqVO, new LambdaQueryWrapperX<PayCurrencyRechargeDO>()
-                .eq(PayCurrencyRechargeDO::getCurrencyId, walletId)
+                .eq(PayCurrencyRechargeDO::getCurrencyId, currencyId)
                 .eq(PayCurrencyRechargeDO::getPayStatus, payStatus)
                 .orderByDesc(PayCurrencyRechargeDO::getId));
     }
 
+    default PageResult<PayCurrencyRechargeDO> selectPage(PayCurrencyRechargePageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<PayCurrencyRechargeDO>()
+                .eqIfPresent(PayCurrencyRechargeDO::getCurrencyId, reqVO.getCurrencyId())
+                .eqIfPresent(PayCurrencyRechargeDO::getPayStatus, reqVO.getPayStatus())
+                .eqIfPresent(PayCurrencyRechargeDO::getPayChannelCode, reqVO.getPayChannelCode())
+                .eqIfPresent(PayCurrencyRechargeDO::getPackageId, reqVO.getPackageId())
+                .eqIfPresent(PayCurrencyRechargeDO::getPayOrderId, reqVO.getPayOrderId())
+                .eqIfPresent(PayCurrencyRechargeDO::getPayRefundId, reqVO.getPayRefundId())
+                .orderByDesc(PayCurrencyRechargeDO::getCreateTime));
+    }
+
 }

+ 10 - 0
citu-module-pay/citu-module-pay-biz/src/main/java/com/citu/module/pay/service/currency/PayCurrencyRechargeService.java

@@ -2,6 +2,7 @@ package com.citu.module.pay.service.currency;
 
 import com.citu.framework.common.pojo.PageParam;
 import com.citu.framework.common.pojo.PageResult;
+import com.citu.module.pay.controller.admin.currency.vo.recharge.PayCurrencyRechargePageReqVO;
 import com.citu.module.pay.controller.app.currency.vo.recharge.AppPayCurrencyRechargeCreateReqVO;
 import com.citu.module.pay.dal.dataobject.currency.PayCurrencyRechargeDO;
 
@@ -38,6 +39,15 @@ public interface PayCurrencyRechargeService {
     PageResult<PayCurrencyRechargeDO> getCurrencyRechargePackagePage(Long dataId, Long userId, Integer userType,
                                                                      PageParam pageReqVO, Boolean payStatus);
 
+
+    /**
+     * 获得货币账户充值记录分页
+     *
+     * @param reqVO    查询条件
+     * @return 货币账户充值记录分页
+     */
+    PageResult<PayCurrencyRechargeDO> getCurrencyRechargePackagePage(PayCurrencyRechargePageReqVO reqVO);
+
     /**
      * 更新货币账户充值成功
      *

+ 13 - 5
citu-module-pay/citu-module-pay-biz/src/main/java/com/citu/module/pay/service/currency/PayCurrencyRechargeServiceImpl.java

@@ -8,6 +8,7 @@ import com.citu.framework.common.pojo.PageResult;
 import com.citu.framework.pay.core.enums.refund.PayRefundStatusRespEnum;
 import com.citu.module.pay.api.order.dto.PayOrderCreateReqDTO;
 import com.citu.module.pay.api.refund.dto.PayRefundCreateReqDTO;
+import com.citu.module.pay.controller.admin.currency.vo.recharge.PayCurrencyRechargePageReqVO;
 import com.citu.module.pay.controller.app.currency.vo.recharge.AppPayCurrencyRechargeCreateReqVO;
 import com.citu.module.pay.convert.currency.PayCurrencyRechargeConvert;
 import com.citu.module.pay.dal.dataobject.currency.PayCurrencyDO;
@@ -54,9 +55,11 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
     /**
      * TODO 芋艿:放到 payconfig
      */
-    private static final Long WALLET_PAY_APP_ID = 8L;
+    private static final Long WALLET_PAY_APP_ID = 11L;
 
-    private static final String WALLET_RECHARGE_ORDER_SUBJECT = "货币账户余额充值";
+    private static final String RECHARGE_ORDER_SUBJECT = "账户充值";
+    /** 比例倍数 1:10 **/
+    private static final Integer RATIO_MULTIPLE = 10;
     @Resource
     public SocialClientApi socialClientApi;
     @Resource
@@ -93,7 +96,7 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
         Long payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO()
                 .setAppId(WALLET_PAY_APP_ID).setUserIp(userIp)
                 .setMerchantOrderId(recharge.getId().toString()) // 业务的订单编号
-                .setSubject(WALLET_RECHARGE_ORDER_SUBJECT).setBody("")
+                .setSubject(RECHARGE_ORDER_SUBJECT).setBody("")
                 .setPrice(Math.toIntExact(recharge.getPayPrice()))
                 .setExpireTime(addTime(Duration.ofHours(2L)))); // TODO @芋艿:支付超时时间
         // 2.2 更新货币账户充值记录中支付订单
@@ -109,6 +112,11 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
         return currencyRechargeMapper.selectPage(pageReqVO, currency.getId(), payStatus);
     }
 
+    @Override
+    public PageResult<PayCurrencyRechargeDO> getCurrencyRechargePackagePage(PayCurrencyRechargePageReqVO reqVO) {
+        return currencyRechargeMapper.selectPage(reqVO);
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void updateCurrencyRechargerPaid(Long id, Long payOrderId) {
@@ -233,7 +241,7 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
             throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND);
         }
         // 2.2 校验退款金额一致
-        if (notEqual(payRefund.getRefundPrice(), currencyRecharge.getPayPrice())) {
+        if (notEqual(Long.valueOf(payRefund.getRefundPrice()), currencyRecharge.getPayPrice())) {
             log.error("[validateCurrencyRechargeCanRefunded][货币账户({}) payRefund({}) 退款金额不匹配,请进行处理!货币账户数据是:{},payRefund 数据是:{}]",
                     currencyRecharge.getId(), payRefundId, toJsonString(currencyRecharge), toJsonString(payRefund));
             throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH);
@@ -294,7 +302,7 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
             throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS);
         }
         // 2.3 校验支付金额一致
-        if (notEqual(payOrder.getPrice(), currencyRecharge.getPayPrice())) {
+        if (notEqual(Long.valueOf(payOrder.getPrice()), currencyRecharge.getPayPrice())) {
             log.error("[validateDemoOrderCanPaid][货币账户({}) payOrder({}) 支付金额不匹配,请进行处理!货币账户 数据是:{},payOrder 数据是:{}]",
                     currencyRecharge.getId(), payOrderId, toJsonString(currencyRecharge), toJsonString(payOrder));
             throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH);