Ver código fonte

feat:【PAY 支付】转账单,支持导出功能

YunaiV 6 meses atrás
pai
commit
0e7ce63719

+ 2 - 0
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/DictTypeConstants.java

@@ -15,4 +15,6 @@ public interface DictTypeConstants {
 
     String NOTIFY_STATUS = "pay_notify_status"; // 回调状态
 
+    String TRANSFER_STATUS = "pay_transfer_status"; // 转账状态
+
 }

+ 1 - 7
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/refund/PayRefundController.java

@@ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -78,13 +77,8 @@ public class PayRefundController {
     @PreAuthorize("@ss.hasPermission('pay:refund:export')")
     @ApiAccessLog(operateType = EXPORT)
     public void exportRefundExcel(@Valid PayRefundExportReqVO exportReqVO,
-            HttpServletResponse response) throws IOException {
+                                  HttpServletResponse response) throws IOException {
         List<PayRefundDO> list = refundService.getRefundList(exportReqVO);
-        if (CollectionUtil.isEmpty(list)) {
-            ExcelUtils.write(response, "退款订单.xls", "数据",
-                    PayRefundExcelVO.class, new ArrayList<>());
-            return;
-        }
 
         // 拼接返回
         Map<Long, PayAppDO> appMap = appService.getAppMap(convertList(list, PayRefundDO::getAppId));

+ 46 - 5
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/transfer/PayTransferController.java

@@ -1,16 +1,20 @@
 package cn.iocoder.yudao.module.pay.controller.admin.transfer;
 
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageItemRespVO;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
 import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferPageReqVO;
 import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferRespVO;
+import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
 import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
+import cn.iocoder.yudao.module.pay.service.app.PayAppService;
 import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.Valid;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -19,7 +23,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.io.IOException;
+import java.util.Map;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
 
 @Tag(name = "管理后台 - 转账单")
 @RestController
@@ -29,22 +39,53 @@ public class PayTransferController {
 
     @Resource
     private PayTransferService payTransferService;
+    @Resource
+    private PayAppService payAppService;
 
     @GetMapping("/get")
     @Operation(summary = "获得转账订单")
     @PreAuthorize("@ss.hasPermission('pay:transfer:query')")
     public CommonResult<PayTransferRespVO> getTransfer(@RequestParam("id") Long id) {
         PayTransferDO transfer = payTransferService.getTransfer(id);
-        return success(BeanUtils.toBean(transfer, PayTransferRespVO.class));
+        if (transfer == null) {
+            return success(new PayTransferRespVO());
+        }
+
+        // 拼接数据
+        PayAppDO app = payAppService.getApp(transfer.getAppId());
+        return success(BeanUtils.toBean(transfer, PayTransferRespVO.class, transferVO -> {
+            if (app != null) {
+                transferVO.setAppName(app.getName());
+            }
+        }));
     }
 
-    // TODO @芋艿:get 和 page 的返回,是不是统一融合
     @GetMapping("/page")
     @Operation(summary = "获得转账订单分页")
     @PreAuthorize("@ss.hasPermission('pay:transfer:query')")
-    public CommonResult<PageResult<PayTransferPageItemRespVO>> getTransferPage(@Valid PayTransferPageReqVO pageVO) {
+    public CommonResult<PageResult<PayTransferRespVO>> getTransferPage(@Valid PayTransferPageReqVO pageVO) {
         PageResult<PayTransferDO> pageResult = payTransferService.getTransferPage(pageVO);
-        return success(BeanUtils.toBean(pageResult, PayTransferPageItemRespVO.class));
+
+        // 拼接数据
+        Map<Long, PayAppDO> apps = payAppService.getAppMap(convertList(pageResult.getList(), PayTransferDO::getAppId));
+        return success(BeanUtils.toBean(pageResult, PayTransferRespVO.class, transferVO -> {
+            if (apps.containsKey(transferVO.getAppId())) {
+                transferVO.setAppName(apps.get(transferVO.getAppId()).getName());
+            }
+        }));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出转账订单 Excel")
+    @PreAuthorize("@ss.hasPermission('pay:transfer:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportTransfer(PayTransferPageReqVO pageReqVO,
+                               HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PAGE_SIZE_NONE);
+        PageResult<PayTransferRespVO> pageResult = getTransferPage(pageReqVO).getData();
+
+        // 导出 Excel
+        ExcelUtils.write(response, "转账订单.xls", "数据", PayTransferRespVO.class, pageResult.getList());
     }
 
 }

+ 0 - 62
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/transfer/vo/PayTransferPageItemRespVO.java

@@ -1,62 +0,0 @@
-package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-import java.time.LocalDateTime;
-
-/**
- * @author jason
- */
-@Schema(description = "管理后台 - 转账单分页项 Response VO")
-@Data
-public class PayTransferPageItemRespVO {
-
-    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2931")
-    private Long id;
-
-    @Schema(description = "转账单号", requiredMode = Schema.RequiredMode.REQUIRED)
-    private String no;
-
-    @Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12831")
-    private Long appId;
-
-    @Schema(description = "转账渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24833")
-    private Long channelId;
-
-    @Schema(description = "转账渠道编码", requiredMode = Schema.RequiredMode.REQUIRED)
-    private String channelCode;
-
-    @Schema(description = "商户转账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17481")
-    private String merchantOrderId;
-
-    @Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
-    private Integer type;
-
-    @Schema(description = "转账状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
-    private Integer status;
-
-    @Schema(description = "转账成功时间")
-    private LocalDateTime successTime;
-
-    @Schema(description = "转账金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "964")
-    private Integer price;
-
-    @Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED)
-    private String subject;
-
-    @Schema(description = "收款人姓名", example = "王五")
-    private String userName;
-
-    @Schema(description = "支付宝登录号", example = "29245")
-    private String alipayLogonId;
-
-    @Schema(description = "微信 openId", example = "26589")
-    private String openid;
-
-    @Schema(description = "渠道转账单号")
-    private String channelTransferNo;
-
-    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
-    private LocalDateTime createTime;
-}

+ 3 - 0
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/transfer/vo/PayTransferPageReqVO.java

@@ -32,6 +32,9 @@ public class PayTransferPageReqVO extends PageParam {
     @Schema(description = "收款人姓名", example = "王五")
     private String userName;
 
+    @Schema(description = "收款人账号", example = "26589")
+    private String userAccount;
+
     @Schema(description = "渠道转账单号")
     private String channelTransferNo;
 

+ 32 - 10
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/transfer/vo/PayTransferRespVO.java

@@ -1,5 +1,12 @@
 package cn.iocoder.yudao.module.pay.controller.admin.transfer.vo;
 
+import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
+import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
+import cn.iocoder.yudao.framework.excel.core.convert.MoneyConvert;
+import cn.iocoder.yudao.module.pay.enums.DictTypeConstants;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.*;
 import java.time.LocalDateTime;
@@ -7,53 +14,65 @@ import java.util.Map;
 
 @Schema(description = "管理后台 - 转账单 Response VO")
 @Data
+@ExcelIgnoreUnannotated
 public class PayTransferRespVO {
 
+    @ExcelProperty("转账单编号")
     @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2931")
     private Long id;
 
+    @ExcelProperty("转账单号")
     @Schema(description = "转账单号", requiredMode = Schema.RequiredMode.REQUIRED)
     private String no;
 
     @Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12831")
     private Long appId;
 
+    @ExcelProperty("应用名称")
+    @Schema(description = "应用名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
+    private String appName;
+
     @Schema(description = "转账渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24833")
     private Long channelId;
 
+    @ExcelProperty(value = "转账渠道", converter = DictConvert.class)
+    @DictFormat(DictTypeConstants.CHANNEL_CODE)
     @Schema(description = "转账渠道编码", requiredMode = Schema.RequiredMode.REQUIRED)
     private String channelCode;
 
+    @ExcelProperty("商户转账单编号")
     @Schema(description = "商户转账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17481")
-    private String merchantOrderId;
-
-    @Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
-    private Integer type;
+    private String merchantTransferId;
 
+    @ExcelProperty(value = "转账状态", converter = DictConvert.class)
+    @DictFormat(DictTypeConstants.TRANSFER_STATUS)
     @Schema(description = "转账状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
     private Integer status;
 
+    @ExcelProperty("转账成功时间")
     @Schema(description = "转账成功时间")
     private LocalDateTime successTime;
 
     @Schema(description = "转账金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "964")
+    @ExcelProperty(value = "转账金额", converter = MoneyConvert.class)
     private Integer price;
 
-    @Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("转账标题")
+    @Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "冲冲冲!")
     private String subject;
 
     @Schema(description = "收款人姓名", example = "王五")
+    @ExcelProperty("收款人姓名")
     private String userName;
 
-    @Schema(description = "支付宝登录号", example = "29245")
-    private String alipayLogonId;
-
-    @Schema(description = "微信 openId", example = "26589")
-    private String openid;
+    @Schema(description = "收款人账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "26589")
+    @ExcelProperty("收款人账号")
+    private String userAccount;
 
     @Schema(description = "异步通知商户地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn")
     private String notifyUrl;
 
+    @ExcelProperty("用户 IP")
     @Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED)
     private String userIp;
 
@@ -61,11 +80,13 @@ public class PayTransferRespVO {
     private Map<String, String> channelExtras;
 
     @Schema(description = "渠道转账单号")
+    @ExcelProperty("渠道转账单号")
     private String channelTransferNo;
 
     @Schema(description = "调用渠道的错误码")
     private String channelErrorCode;
 
+    @ExcelProperty("渠道错误提示")
     @Schema(description = "调用渠道的错误提示")
     private String channelErrorMsg;
 
@@ -73,6 +94,7 @@ public class PayTransferRespVO {
     private String channelNotifyData;
 
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
 }

+ 1 - 0
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/transfer/PayTransferMapper.java

@@ -39,6 +39,7 @@ public interface PayTransferMapper extends BaseMapperX<PayTransferDO> {
                 .eqIfPresent(PayTransferDO::getMerchantTransferId, reqVO.getMerchantOrderId())
                 .eqIfPresent(PayTransferDO::getStatus, reqVO.getStatus())
                 .likeIfPresent(PayTransferDO::getUserName, reqVO.getUserName())
+                .likeIfPresent(PayTransferDO::getUserAccount, reqVO.getUserAccount())
                 .eqIfPresent(PayTransferDO::getChannelTransferNo, reqVO.getChannelTransferNo())
                 .betweenIfPresent(PayTransferDO::getCreateTime, reqVO.getCreateTime())
                 .orderByDesc(PayTransferDO::getId));

+ 5 - 0
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/app/PayAppServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pay.service.app;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.module.pay.controller.admin.app.vo.PayAppCreateReqVO;
@@ -17,6 +18,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -116,6 +118,9 @@ public class PayAppServiceImpl implements PayAppService {
 
     @Override
     public List<PayAppDO> getAppList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return Collections.emptyList();
+        }
         return appMapper.selectBatchIds(ids);
     }