Commit ea4fa68579a915fda88bfeb78ec3a07ddd452fb5

Authored by YunaiV
1 parent 1cc3483a

feat(pay): 新增支付渠道列表接口

- 新增 GET /pay/channel/list 按 appId 返回渠道列表
- Service/Mapper 补充按应用查询全部支付渠道
- 列表转换时清空 config,避免密钥和证书配置下发到列表页
- 保持 /pay/channel/get 返回完整配置用于编辑详情
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/channel/PayChannelController.java
@@ -71,6 +71,15 @@ public class PayChannelController { @@ -71,6 +71,15 @@ public class PayChannelController {
71 return success(PayChannelConvert.INSTANCE.convert(channel)); 71 return success(PayChannelConvert.INSTANCE.convert(channel));
72 } 72 }
73 73
  74 + @GetMapping("/list")
  75 + @Operation(summary = "获得指定应用的支付渠道列表")
  76 + @Parameter(name = "appId", description = "应用编号", required = true, example = "1")
  77 + @PreAuthorize("@ss.hasPermission('pay:channel:query')")
  78 + public CommonResult<List<PayChannelRespVO>> getChannelList(@RequestParam("appId") Long appId) {
  79 + List<PayChannelDO> list = channelService.getChannelListByAppId(appId);
  80 + return success(PayChannelConvert.INSTANCE.convertList(list));
  81 + }
  82 +
74 @GetMapping("/get-enable-code-list") 83 @GetMapping("/get-enable-code-list")
75 @Operation(summary = "获得指定应用的开启的支付渠道编码列表") 84 @Operation(summary = "获得指定应用的开启的支付渠道编码列表")
76 @Parameter(name = "appId", description = "应用编号", required = true, example = "1") 85 @Parameter(name = "appId", description = "应用编号", required = true, example = "1")
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/convert/channel/PayChannelConvert.java
1 package cn.iocoder.yudao.module.pay.convert.channel; 1 package cn.iocoder.yudao.module.pay.convert.channel;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
4 import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelCreateReqVO; 5 import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelCreateReqVO;
5 import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelRespVO; 6 import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelRespVO;
6 import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelUpdateReqVO; 7 import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelUpdateReqVO;
@@ -9,6 +10,8 @@ import org.mapstruct.Mapper; @@ -9,6 +10,8 @@ import org.mapstruct.Mapper;
9 import org.mapstruct.Mapping; 10 import org.mapstruct.Mapping;
10 import org.mapstruct.factory.Mappers; 11 import org.mapstruct.factory.Mappers;
11 12
  13 +import java.util.List;
  14 +
12 @Mapper 15 @Mapper
13 public interface PayChannelConvert { 16 public interface PayChannelConvert {
14 17
@@ -23,6 +26,15 @@ public interface PayChannelConvert { @@ -23,6 +26,15 @@ public interface PayChannelConvert {
23 @Mapping(target = "config",expression = "java(cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString(bean.getConfig()))") 26 @Mapping(target = "config",expression = "java(cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString(bean.getConfig()))")
24 PayChannelRespVO convert(PayChannelDO bean); 27 PayChannelRespVO convert(PayChannelDO bean);
25 28
  29 + default List<PayChannelRespVO> convertList(List<PayChannelDO> list) {
  30 + // 列表不下发 config(密钥/证书),详情接口再返回完整配置
  31 + return CollectionUtils.convertList(list, channel -> {
  32 + PayChannelRespVO vo = convert(channel);
  33 + vo.setConfig(null);
  34 + return vo;
  35 + });
  36 + }
  37 +
26 PageResult<PayChannelRespVO> convertPage(PageResult<PayChannelDO> page); 38 PageResult<PayChannelRespVO> convertPage(PageResult<PayChannelDO> page);
27 39
28 } 40 }
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/channel/PayChannelMapper.java
@@ -28,4 +28,8 @@ public interface PayChannelMapper extends BaseMapperX&lt;PayChannelDO&gt; { @@ -28,4 +28,8 @@ public interface PayChannelMapper extends BaseMapperX&lt;PayChannelDO&gt; {
28 .eq(PayChannelDO::getStatus, status)); 28 .eq(PayChannelDO::getStatus, status));
29 } 29 }
30 30
  31 + default List<PayChannelDO> selectListByAppId(Long appId) {
  32 + return selectList(PayChannelDO::getAppId, appId);
  33 + }
  34 +
31 } 35 }
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelService.java
@@ -94,6 +94,14 @@ public interface PayChannelService { @@ -94,6 +94,14 @@ public interface PayChannelService {
94 List<PayChannelDO> getEnableChannelList(Long appId); 94 List<PayChannelDO> getEnableChannelList(Long appId);
95 95
96 /** 96 /**
  97 + * 获得指定应用的渠道列表
  98 + *
  99 + * @param appId 应用编号
  100 + * @return 渠道列表
  101 + */
  102 + List<PayChannelDO> getChannelListByAppId(Long appId);
  103 +
  104 + /**
97 * 获得指定编号的支付客户端 105 * 获得指定编号的支付客户端
98 * 106 *
99 * @param id 编号 107 * @param id 编号
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java
@@ -157,6 +157,11 @@ public class PayChannelServiceImpl implements PayChannelService { @@ -157,6 +157,11 @@ public class PayChannelServiceImpl implements PayChannelService {
157 } 157 }
158 158
159 @Override 159 @Override
  160 + public List<PayChannelDO> getChannelListByAppId(Long appId) {
  161 + return payChannelMapper.selectListByAppId(appId);
  162 + }
  163 +
  164 + @Override
160 public PayClient getPayClient(Long id) { 165 public PayClient getPayClient(Long id) {
161 PayChannelDO channel = validPayChannel(id); 166 PayChannelDO channel = validPayChannel(id);
162 return payClientFactory.createOrUpdatePayClient(id, channel.getCode(), channel.getConfig()); 167 return payClientFactory.createOrUpdatePayClient(id, channel.getCode(), channel.getConfig());