mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	优化 支付配置校验方式,优化业务层异常抛出类型,优化支付应用渲染逻辑,添加删除支付商户 支付应用的校验,退款订单去除reqNo字段,支付订单去除 channelExtras 参数展示
This commit is contained in:
		| @@ -1,7 +1,6 @@ | ||||
| package cn.iocoder.yudao.adminserver.modules.pay.controller.app; | ||||
|  | ||||
| import cn.hutool.core.collection.CollUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.controller.app.vo.*; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.convert.app.PayAppConvert; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.service.app.PayAppService; | ||||
| @@ -10,12 +9,12 @@ import cn.iocoder.yudao.adminserver.modules.pay.service.merchant.PayMerchantServ | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; | ||||
| import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||||
| import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||||
| import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||||
| import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| @@ -28,20 +27,11 @@ import javax.annotation.Resource; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.validation.Valid; | ||||
| import java.io.IOException; | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.*; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||
| import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||||
|  | ||||
| /** | ||||
|  * 支付应用信息 controller 组件 | ||||
|  * | ||||
|  * @author aquan | ||||
|  */ // TODO @aquan:一般 controller 上就不写注释了,因为有 swagger 注解,不然就重复啦 | ||||
| @Slf4j | ||||
| @Api(tags = "支付应用信息") | ||||
| @RestController | ||||
| @@ -119,6 +109,7 @@ public class PayAppController { | ||||
|         // 得到所有的应用编号,查出所有的通道 | ||||
|         Collection<Long> payAppIds = CollectionUtils.convertList(pageResult.getList(), PayAppDO::getId); | ||||
|         List<PayChannelDO> channels = channelService.getChannelListByAppIds(payAppIds); | ||||
|         Iterator<PayChannelDO> iterator = channels.iterator(); | ||||
|  | ||||
|         // 得到所有的商户信息 | ||||
|         Collection<Long> merchantIds = CollectionUtils.convertList(pageResult.getList(), PayAppDO::getMerchantId); | ||||
| @@ -132,22 +123,15 @@ public class PayAppController { | ||||
|             // 写入商户的数据 | ||||
|             respVO.setPayMerchant(PayAppConvert.INSTANCE.convert(deptMap.get(app.getMerchantId()))); | ||||
|             // 写入支付渠道信息的数据 | ||||
|             // TODO @aquan:VO 里返回的 payChannel,是不是用一个 Set 集合就好了,里面是渠道的枚举值 | ||||
|             PayAppPageItemRespVO.PayChannel payChannel = new PayAppPageItemRespVO.PayChannel(); | ||||
|             channels.forEach(c -> { | ||||
|                 if (c.getAppId().equals(app.getId())) { | ||||
|                     // 获取 set 方法 | ||||
|                     String methodName = StrUtil.toCamelCase("set_" + c.getCode()); | ||||
|                     try { | ||||
|                         // 根据 set 方法将值写入 | ||||
|                         payChannel.getClass().getMethod(methodName, Integer.class) | ||||
|                                 .invoke(payChannel, CommonStatusEnum.ENABLE.getStatus()); | ||||
|                     } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { | ||||
|                         log.error("[getAppPage]调用方法[{}]设置参数[{}]异常", c.getCode(), methodName); | ||||
|                     } | ||||
|             Set<String> channelCodes = new HashSet<>(PayChannelEnum.values().length); | ||||
|             while (iterator.hasNext()) { | ||||
|                 PayChannelDO channelDO = iterator.next(); | ||||
|                 if (channelDO.getAppId().equals(app.getId())) { | ||||
|                     channelCodes.add(channelDO.getCode()); | ||||
|                     iterator.remove(); | ||||
|                 } | ||||
|             }); | ||||
|             respVO.setPayChannel(payChannel); | ||||
|             } | ||||
|             respVO.setChannelCodes(channelCodes); | ||||
|             appList.add(respVO); | ||||
|         }); | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| package cn.iocoder.yudao.adminserver.modules.pay.controller.app.vo; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| @@ -8,7 +7,13 @@ import lombok.EqualsAndHashCode; | ||||
| import lombok.ToString; | ||||
|  | ||||
| import java.util.Date; | ||||
| import java.util.Set; | ||||
|  | ||||
| /** | ||||
|  * 支付应用信息分页查询 Response VO | ||||
|  * | ||||
|  * @author aquan | ||||
|  */ | ||||
| @ApiModel(value = "支付应用信息分页查询 Response VO", description = "相比于支付信息,还会多出应用渠道的开关信息") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @@ -38,39 +43,8 @@ public class PayAppPageItemRespVO extends PayAppBaseVO { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 支付渠道 | ||||
|      */ | ||||
|     private PayChannel payChannel; | ||||
|     @ApiModelProperty(value = "渠道编码集合", required = true, example = "alipay_pc,alipay_wap...") | ||||
|     private Set<String> channelCodes; | ||||
|  | ||||
|     /** | ||||
|      * 支付渠道开通情况 | ||||
|      * 1默认为未开通当前支付渠道,0为已开通支付渠道 | ||||
|      */ | ||||
|     @Data | ||||
|     @ApiModel("支付渠道") | ||||
|     public static class PayChannel { | ||||
|  | ||||
|         @ApiModelProperty(value = "微信 JSAPI 支付", required = true, example = "1") | ||||
|         private Integer wxPub = CommonStatusEnum.DISABLE.getStatus(); | ||||
|  | ||||
|         @ApiModelProperty(value = "微信小程序支付", required = true, example = "1") | ||||
|         private Integer wxLite = CommonStatusEnum.DISABLE.getStatus(); | ||||
|  | ||||
|         @ApiModelProperty(value = "微信 App 支付", required = true, example = "1") | ||||
|         private Integer wxApp = CommonStatusEnum.DISABLE.getStatus(); | ||||
|  | ||||
|         @ApiModelProperty(value = "支付宝 PC 网站支付", required = true, example = "1") | ||||
|         private Integer alipayPc = CommonStatusEnum.DISABLE.getStatus(); | ||||
|  | ||||
|         @ApiModelProperty(value = "支付宝 Wap 网站支付", required = true, example = "1") | ||||
|         private Integer alipayWap = CommonStatusEnum.DISABLE.getStatus(); | ||||
|  | ||||
|         @ApiModelProperty(value = "支付宝App 支付", required = true, example = "1") | ||||
|         private Integer alipayApp = CommonStatusEnum.DISABLE.getStatus(); | ||||
|  | ||||
|         @ApiModelProperty(value = "支付宝扫码支付", required = true, example = "1") | ||||
|         private Integer alipayQr = CommonStatusEnum.DISABLE.getStatus(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -75,7 +75,7 @@ public class PayMerchantController { | ||||
|         return success(PayMerchantConvert.INSTANCE.convert(merchant)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/list-name") // TODO @aquan:/list-name =》/list-by-name | ||||
|     @GetMapping("/list-by-name") | ||||
|     @ApiOperation("根据商户名称获得支付商户信息列表") | ||||
|     @ApiImplicitParam(name = "name", value = "商户名称", example = "芋道", dataTypeClass = Long.class) | ||||
|     @PreAuthorize("@ss.hasPermission('pay:merchant:query')") | ||||
|   | ||||
| @@ -2,11 +2,10 @@ package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||||
| import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import io.swagger.annotations.*; | ||||
|  | ||||
| import com.alibaba.excel.annotation.ExcelProperty; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| /** | ||||
|  * 支付商户信息 Excel VO | ||||
| @@ -29,7 +28,7 @@ public class PayMerchantExcelVO { | ||||
|     private String shortName; | ||||
|  | ||||
|     @ExcelProperty(value = "开启状态",converter = DictConvert.class) | ||||
|     @DictFormat("pay_merchant_status") | ||||
|     @DictFormat("sys_common_status") | ||||
|     private Integer status; | ||||
|  | ||||
|     @ExcelProperty("备注") | ||||
|   | ||||
| @@ -46,9 +46,6 @@ public class PayOrderDetailsRespVO extends PayOrderBaseVO { | ||||
|         @ApiModelProperty(value = "支付订单号") | ||||
|         private String no; | ||||
|  | ||||
|         @ApiModelProperty(value = "支付渠道的额外参数") | ||||
|         private String channelExtras; | ||||
|  | ||||
|         @ApiModelProperty(value = "支付异步通知的内容") | ||||
|         private String channelNotifyData; | ||||
|     } | ||||
|   | ||||
| @@ -16,10 +16,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | ||||
| @Data | ||||
| public class PayRefundBaseVO { | ||||
|  | ||||
|     @ApiModelProperty(value = "退款单请求号", required = true) | ||||
|     @NotNull(message = "退款单请求号不能为空") | ||||
|     private String reqNo; | ||||
|  | ||||
|     @ApiModelProperty(value = "商户编号", required = true) | ||||
|     @NotNull(message = "商户编号不能为空") | ||||
|     private Long merchantId; | ||||
|   | ||||
| @@ -22,9 +22,6 @@ public class PayRefundExcelVO { | ||||
|     @ExcelProperty("商品名称") | ||||
|     private String subject; | ||||
|  | ||||
|     @ExcelProperty("退款单请求号") | ||||
|     private String reqNo; | ||||
|  | ||||
|     @ExcelProperty(value = "商户名称") | ||||
|     private String merchantName; | ||||
|  | ||||
|   | ||||
| @@ -13,9 +13,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | ||||
| @Data | ||||
| public class PayRefundExportReqVO { | ||||
|  | ||||
|     @ApiModelProperty(value = "退款单请求号") | ||||
|     private String reqNo; | ||||
|  | ||||
|     @ApiModelProperty(value = "商户编号") | ||||
|     private Long merchantId; | ||||
|  | ||||
|   | ||||
| @@ -18,9 +18,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ | ||||
| @ToString(callSuper = true) | ||||
| public class PayRefundPageReqVO extends PageParam { | ||||
|  | ||||
|     @ApiModelProperty(value = "退款单请求号") | ||||
|     private String reqNo; | ||||
|  | ||||
|     @ApiModelProperty(value = "商户编号") | ||||
|     private Long merchantId; | ||||
|  | ||||
|   | ||||
| @@ -8,8 +8,6 @@ import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderExtensionDO; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.Mapping; | ||||
| import org.mapstruct.Mappings; | ||||
| import org.mapstruct.factory.Mappers; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| @@ -44,10 +42,6 @@ public interface PayOrderConvert { | ||||
|      * @param bean 订单扩展DO | ||||
|      * @return 详细订单扩展 RespVO | ||||
|      */ | ||||
|     @Mappings({ | ||||
|             @Mapping(target = "channelExtras" | ||||
|                     , expression = "java(bean.getChannelExtras() != null ? bean.getChannelExtras().toString():null)") | ||||
|     }) | ||||
|     PayOrderDetailsRespVO.PayOrderExtension orderDetailExtensionConvert(PayOrderExtensionDO bean); | ||||
|  | ||||
|     List<PayOrderRespVO> convertList(List<PayOrderDO> list); | ||||
|   | ||||
| @@ -62,7 +62,6 @@ public interface PayRefundConvert { | ||||
|         PayRefundExcelVO payRefundExcelVO = new PayRefundExcelVO(); | ||||
|  | ||||
|         payRefundExcelVO.setId(bean.getId()); | ||||
|         payRefundExcelVO.setReqNo(bean.getReqNo()); | ||||
|         payRefundExcelVO.setTradeNo(bean.getTradeNo()); | ||||
|         payRefundExcelVO.setMerchantOrderId(bean.getMerchantOrderId()); | ||||
|         payRefundExcelVO.setMerchantRefundNo(bean.getMerchantRefundNo()); | ||||
|   | ||||
| @@ -60,12 +60,24 @@ public interface PayAppMapper extends BaseMapperX<PayAppDO> { | ||||
|  | ||||
|     /** | ||||
|      * 根据 商户 ID 查询支付应用信息 | ||||
|      * | ||||
|      * @param merchantId 商户 ID | ||||
|      * @return 支付应用信息列表 | ||||
|      */ | ||||
|     default List<PayAppDO> getListByMerchantId(String merchantId){ | ||||
|     default List<PayAppDO> getListByMerchantId(String merchantId) { | ||||
|         return selectList(new LambdaQueryWrapper<PayAppDO>() | ||||
|                 .select(PayAppDO::getId, PayAppDO::getName) | ||||
|                 .eq(PayAppDO::getMerchantId, merchantId)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据商户号统计存在的支付应用数量 | ||||
|      * | ||||
|      * @param merchantId 商户 ID | ||||
|      * @return 支付应用数量 | ||||
|      */ | ||||
|     default Long selectCount(Long merchantId) { | ||||
|         return selectCount(new LambdaQueryWrapper<PayAppDO>().eq(PayAppDO::getMerchantId, merchantId)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -55,8 +55,7 @@ public interface PayChannelMapper extends BaseMapperX<PayChannelDO> { | ||||
|      * @param code       通道编码 | ||||
|      * @return 数量 | ||||
|      */ | ||||
|     // TODO @aquan:Mapper 的操作,和 db 保持一致 | ||||
|     default Integer getChannelCountByConditions(Long merchantId, Long appid, String code) { | ||||
|     default Integer selectCount(Long merchantId, Long appid, String code) { | ||||
|         return this.selectCount(new QueryWrapper<PayChannelDO>().lambda() | ||||
|                 .eq(PayChannelDO::getMerchantId, merchantId) | ||||
|                 .eq(PayChannelDO::getAppId, appid) | ||||
| @@ -71,7 +70,7 @@ public interface PayChannelMapper extends BaseMapperX<PayChannelDO> { | ||||
|      * @param code       通道编码 | ||||
|      * @return 数量 | ||||
|      */ | ||||
|     default PayChannelDO getChannelByConditions(Long merchantId, Long appid, String code) { | ||||
|     default PayChannelDO selectOne(Long merchantId, Long appid, String code) { | ||||
|         return this.selectOne((new QueryWrapper<PayChannelDO>().lambda() | ||||
|                 .eq(PayChannelDO::getMerchantId, merchantId) | ||||
|                 .eq(PayChannelDO::getAppId, appid) | ||||
|   | ||||
| @@ -62,4 +62,18 @@ public interface PayOrderMapper extends BaseMapperX<PayOrderDO> { | ||||
|                 .in(PayOrderDO::getId, idList)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询符合的订单数量 | ||||
|      * | ||||
|      * @param appId 应用编号 | ||||
|      * @param status 订单状态 | ||||
|      * @return 条数 | ||||
|      */ | ||||
|     default Long selectCount(Long appId, Integer status) { | ||||
|  | ||||
|         return selectCount(new LambdaQueryWrapper<PayOrderDO>() | ||||
|                 .eq(PayOrderDO::getAppId, appId) | ||||
|                 .in(PayOrderDO::getStatus, status)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayRefundDO | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| import java.util.List; | ||||
| @@ -20,7 +21,6 @@ public interface PayRefundMapper extends BaseMapperX<PayRefundDO> { | ||||
|  | ||||
|     default PageResult<PayRefundDO> selectPage(PayRefundPageReqVO reqVO) { | ||||
|         return selectPage(reqVO, new QueryWrapperX<PayRefundDO>() | ||||
|                 .likeIfPresent("req_no", reqVO.getReqNo()) | ||||
|                 .eqIfPresent("merchant_id", reqVO.getMerchantId()) | ||||
|                 .eqIfPresent("app_id", reqVO.getAppId()) | ||||
|                 .eqIfPresent("channel_code", reqVO.getChannelCode()) | ||||
| @@ -37,7 +37,6 @@ public interface PayRefundMapper extends BaseMapperX<PayRefundDO> { | ||||
|                 .eqIfPresent("merchant_id", reqVO.getMerchantId()) | ||||
|                 .eqIfPresent("app_id", reqVO.getAppId()) | ||||
|                 .eqIfPresent("channel_code", reqVO.getChannelCode()) | ||||
|                 .likeIfPresent("req_no", reqVO.getReqNo()) | ||||
|                 .likeIfPresent("merchant_refund_no", reqVO.getMerchantRefundNo()) | ||||
|                 .eqIfPresent("type", reqVO.getType()) | ||||
|                 .eqIfPresent("status", reqVO.getStatus()) | ||||
| @@ -46,4 +45,17 @@ public interface PayRefundMapper extends BaseMapperX<PayRefundDO> { | ||||
|                 .orderByDesc("id")); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询符合的订单数量 | ||||
|      * | ||||
|      * @param appId 应用编号 | ||||
|      * @param status 订单状态 | ||||
|      * @return 条数 | ||||
|      */ | ||||
|     default Long selectCount(Long appId, Integer status) { | ||||
|  | ||||
|         return selectCount(new LambdaQueryWrapper<PayRefundDO>() | ||||
|                 .eq(PayRefundDO::getAppId, appId) | ||||
|                 .eq(PayRefundDO::getStatus, status)); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -9,9 +9,13 @@ import cn.iocoder.yudao.adminserver.modules.pay.controller.app.vo.PayAppUpdateRe | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.convert.app.PayAppConvert; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.app.PayAppMapper; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant.PayMerchantMapper; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.order.PayOrderMapper; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.order.PayRefundMapper; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.service.app.PayAppService; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderStatusEnum; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum; | ||||
| import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import com.google.common.annotations.VisibleForTesting; | ||||
| @@ -21,7 +25,7 @@ import org.springframework.validation.annotation.Validated; | ||||
| import javax.annotation.Resource; | ||||
| import java.util.*; | ||||
|  | ||||
| import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_APP_NOT_FOUND; | ||||
| import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.*; | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
| import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||||
|  | ||||
| @@ -36,9 +40,17 @@ public class PayAppServiceImpl implements PayAppService { | ||||
|  | ||||
|     @Resource | ||||
|     private PayAppMapper appMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private PayMerchantMapper merchantMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private PayOrderMapper orderMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private PayRefundMapper refundMapper; | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     public Long createApp(PayAppCreateReqVO createReqVO) { | ||||
|         // 插入 | ||||
| @@ -61,7 +73,8 @@ public class PayAppServiceImpl implements PayAppService { | ||||
|     public void deleteApp(Long id) { | ||||
|         // 校验存在 | ||||
|         this.validateAppExists(id); | ||||
|         // TODO aquan:校验是否存在进行中的支付单、退款单,如果是,则不允许删除。 | ||||
|         this.validateOrderTransactionExist(id); | ||||
|  | ||||
|         // 删除 | ||||
|         appMapper.deleteById(id); | ||||
|     } | ||||
| @@ -157,4 +170,21 @@ public class PayAppServiceImpl implements PayAppService { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 验证是否存在交易中或者退款中等处理中状态的订单 | ||||
|      * | ||||
|      * @param appId 应用 ID | ||||
|      */ | ||||
|     private void validateOrderTransactionExist(Long appId) { | ||||
|         // 查看交易订单 | ||||
|         if (orderMapper.selectCount(appId, PayOrderStatusEnum.WAITING.getStatus()) > 0) { | ||||
|             throw exception(PAY_APP_EXIST_TRANSACTION_ORDER_CANT_DELETE); | ||||
|         } | ||||
|         // 查看退款订单 | ||||
|         if (refundMapper.selectCount(appId,   PayRefundStatusEnum.CREATE.getStatus()) > 0) { | ||||
|             throw exception(PAY_APP_EXIST_TRANSACTION_ORDER_CANT_DELETE); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package cn.iocoder.yudao.adminserver.modules.pay.service.channel.impl; | ||||
|  | ||||
| import cn.hutool.core.util.ObjectUtil; | ||||
| import cn.hutool.json.JSONUtil; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelCreateReqVO; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelExportReqVO; | ||||
| @@ -14,7 +15,6 @@ import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; | ||||
| import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.util.Assert; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| @@ -46,8 +46,9 @@ public class PayChannelServiceImpl implements PayChannelService { | ||||
|     public Long createChannel(PayChannelCreateReqVO reqVO) { | ||||
|         // 断言是否有重复的 | ||||
|         PayChannelDO channelDO = this.getChannelByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode()); | ||||
|         // TODO @aquan:这里会抛出系统异常,不会抛出 ServiceException | ||||
|         Assert.isNull(channelDO, CHANNEL_EXIST_SAME_CHANNEL_ERROR.getMsg()); | ||||
|         if (ObjectUtil.isNotNull(channelDO)) { | ||||
|             throw exception(CHANNEL_EXIST_SAME_CHANNEL_ERROR); | ||||
|         } | ||||
|  | ||||
|         // 新增渠道 | ||||
|         PayChannelDO channel = PayChannelConvert.INSTANCE.convert(reqVO); | ||||
| @@ -122,7 +123,7 @@ public class PayChannelServiceImpl implements PayChannelService { | ||||
|      */ | ||||
|     @Override | ||||
|     public Integer getChannelCountByConditions(Long merchantId, Long appid, String code) { | ||||
|         return this.channelMapper.getChannelCountByConditions(merchantId, appid, code); | ||||
|         return this.channelMapper.selectCount(merchantId, appid, code); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -135,7 +136,7 @@ public class PayChannelServiceImpl implements PayChannelService { | ||||
|      */ | ||||
|     @Override | ||||
|     public PayChannelDO getChannelByConditions(Long merchantId, Long appid, String code) { | ||||
|         return this.channelMapper.getChannelByConditions(merchantId, appid, code); | ||||
|         return this.channelMapper.selectOne(merchantId, appid, code); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -146,11 +147,14 @@ public class PayChannelServiceImpl implements PayChannelService { | ||||
|      */ | ||||
|     private void settingConfigAndCheckParam(PayChannelDO channel, String configStr) { | ||||
|         // 得到这个渠道是微信的还是支付宝的 | ||||
|         Class<? extends PayClientConfig> payClass = PayChannelEnum.findByCodeGetClass(channel.getCode()); | ||||
|         Assert.notNull(payClass, CHANNEL_NOT_EXISTS.getMsg()); | ||||
|         Class<? extends PayClientConfig> payClass = PayChannelEnum.getByCode(channel.getCode()).getConfigClass(); | ||||
|         if (ObjectUtil.isNull(payClass)) { | ||||
|             throw exception(CHANNEL_NOT_EXISTS); | ||||
|         } | ||||
|         PayClientConfig config = JSONUtil.toBean(configStr, payClass); | ||||
|  | ||||
|         // 验证参数 | ||||
|         config.verifyParam(validator); | ||||
|         config.validate(validator); | ||||
|         channel.setConfig(config); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -16,7 +16,7 @@ import java.util.Map; | ||||
| /** | ||||
|  * 支付商户信息 Service 接口 | ||||
|  * | ||||
|  * @author 芋艿 TODO @aquan:作者是你哈 | ||||
|  * @author aquan | ||||
|  */ | ||||
| public interface PayMerchantService { | ||||
|  | ||||
|   | ||||
| @@ -1,11 +1,13 @@ | ||||
| package cn.iocoder.yudao.adminserver.modules.pay.service.merchant.impl; | ||||
|  | ||||
| import cn.hutool.core.date.DateUtil; | ||||
| import cn.hutool.core.util.ObjectUtil; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantCreateReqVO; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantExportReqVO; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantPageReqVO; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantUpdateReqVO; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.convert.merchant.PayMerchantConvert; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.app.PayAppMapper; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant.PayMerchantMapper; | ||||
| import cn.iocoder.yudao.adminserver.modules.pay.service.merchant.PayMerchantService; | ||||
| import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; | ||||
| @@ -19,6 +21,7 @@ import java.time.LocalDateTime; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_MERCHANT_EXIST_APP_CANT_DELETE; | ||||
| import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_MERCHANT_NOT_EXISTS; | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
|  | ||||
| @@ -34,6 +37,9 @@ public class PayMerchantServiceImpl implements PayMerchantService { | ||||
|     @Resource | ||||
|     private PayMerchantMapper merchantMapper; | ||||
|  | ||||
|     @Resource | ||||
|     private PayAppMapper appMapper; | ||||
|  | ||||
|     @Override | ||||
|     public Long createMerchant(PayMerchantCreateReqVO createReqVO) { | ||||
|         // 插入 | ||||
| @@ -55,19 +61,13 @@ public class PayMerchantServiceImpl implements PayMerchantService { | ||||
|  | ||||
|     @Override | ||||
|     public void deleteMerchant(Long id) { | ||||
|         // 校验存在 | ||||
|         // 校验 | ||||
|         this.validateMerchantExists(id); | ||||
|         // TODO @aquan:需要校验 PayApp 是否都在。如果在的情况下,不允许删除 | ||||
|         this.validateAppExists(id); | ||||
|         // 删除 | ||||
|         merchantMapper.deleteById(id); | ||||
|     } | ||||
|  | ||||
|     private void validateMerchantExists(Long id) { | ||||
|         if (merchantMapper.selectById(id) == null) { | ||||
|             throw exception(PAY_MERCHANT_NOT_EXISTS); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public PayMerchantDO getMerchant(Long id) { | ||||
|         return merchantMapper.selectById(id); | ||||
| @@ -88,13 +88,6 @@ public class PayMerchantServiceImpl implements PayMerchantService { | ||||
|         return merchantMapper.selectList(exportReqVO); | ||||
|     } | ||||
|  | ||||
|     // TODO @aquan:接口上已经有注释,这里不用在有啦 | ||||
|     /** | ||||
|      * 修改商户状态 | ||||
|      * | ||||
|      * @param id     商户编号 | ||||
|      * @param status 状态 | ||||
|      */ | ||||
|     @Override | ||||
|     public void updateMerchantStatus(Long id, Integer status) { | ||||
|         // 校验商户存在 | ||||
| @@ -106,21 +99,11 @@ public class PayMerchantServiceImpl implements PayMerchantService { | ||||
|         merchantMapper.updateById(merchant); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据商户名称模糊查询商户集合 | ||||
|      * | ||||
|      * @param merchantName 商户名称 | ||||
|      * @return 商户集合 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<PayMerchantDO> getMerchantListByName(String merchantName) { | ||||
|         return this.merchantMapper.getMerchantListByName(merchantName); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 检查商户是否存在 | ||||
|      * @param id 商户编号 | ||||
|      */ | ||||
|     @VisibleForTesting | ||||
|     public void checkMerchantExists(Long id) { | ||||
|         if (id == null) { | ||||
| @@ -132,6 +115,27 @@ public class PayMerchantServiceImpl implements PayMerchantService { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 校验商户是否存在 | ||||
|      * | ||||
|      * @param id 商户 ID | ||||
|      */ | ||||
|     private void validateMerchantExists(Long id) { | ||||
|         if (ObjectUtil.isNull(merchantMapper.selectById(id))) { | ||||
|             throw exception(PAY_MERCHANT_NOT_EXISTS); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 校验商户是否还存在支付应用 | ||||
|      * | ||||
|      * @param id 商户ID | ||||
|      */ | ||||
|     private void validateAppExists(Long id) { | ||||
|         if (appMapper.selectCount(id) > 0) { | ||||
|             throw exception(PAY_MERCHANT_EXIST_APP_CANT_DELETE); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // TODO @芋艿:后续增加下合适的算法 | ||||
|     /** | ||||
| @@ -139,8 +143,8 @@ public class PayMerchantServiceImpl implements PayMerchantService { | ||||
|      * | ||||
|      * @return 商户号 | ||||
|      */ | ||||
|     private String generateMerchantNo(){ | ||||
|        return  "M" + DateUtil.format(LocalDateTime.now(),"yyyyMMddHHmmssSSS"); | ||||
|     private String generateMerchantNo() { | ||||
|         return "M" + DateUtil.format(LocalDateTime.now(), "yyyyMMddHHmmssSSS"); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -75,6 +75,4 @@ yudao: | ||||
|       - cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants | ||||
|   tenant: # 多租户相关配置项 | ||||
|     tables: # 配置需要开启多租户的表;如果实体已经继承 TenantBaseDO 类,则无需重复配置 | ||||
|   pay: | ||||
|     payReturnUrl: http://127.0.0.1 # TODO @aquan:这个变量,配置到 dev 或者 local 里,不同环境有差别哈 | ||||
| debug: false | ||||
|   | ||||
| @@ -72,8 +72,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { | ||||
|             o.setUpdateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 35)); | ||||
|         }); | ||||
|         refundMapper.insert(dbRefund); | ||||
|         // 测试 reqNo 不匹配 | ||||
|         refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setReqNo("RF1111112"))); | ||||
|         // 测试 merchantId 不匹配 | ||||
|         refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantId(2L))); | ||||
|         // 测试 appId 不匹配 | ||||
| @@ -94,7 +92,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { | ||||
|                 o.setCreateTime(DateUtils.buildTime(2022, 1, 1, 10, 10, 10)))); | ||||
|         // 准备参数 | ||||
|         PayRefundPageReqVO reqVO = new PayRefundPageReqVO(); | ||||
|         reqVO.setReqNo("RF0000001"); | ||||
|         reqVO.setMerchantId(1L); | ||||
|         reqVO.setAppId(1L); | ||||
|         reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode()); | ||||
| @@ -147,8 +144,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { | ||||
|             o.setUpdateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 35)); | ||||
|         }); | ||||
|         refundMapper.insert(dbRefund); | ||||
|         // 测试 reqNo 不匹配 | ||||
|         refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setReqNo("RF1111112"))); | ||||
|         // 测试 merchantId 不匹配 | ||||
|         refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantId(2L))); | ||||
|         // 测试 appId 不匹配 | ||||
| @@ -170,7 +165,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { | ||||
|  | ||||
|         // 准备参数 | ||||
|         PayRefundExportReqVO reqVO = new PayRefundExportReqVO(); | ||||
|         reqVO.setReqNo("RF0000001"); | ||||
|         reqVO.setMerchantId(1L); | ||||
|         reqVO.setAppId(1L); | ||||
|         reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 chen quan
					chen quan