mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-12 07:25:39 +08:00
feat: 添加支付宝直连通道商户创建功能(AlipayChannelMerchant)
- 新增 entity/dao/convert/param/result/service/controller 8 个文件 - POST /admin/alipay/channel-merchant/create-direct 创建直连通道商户 - GET /admin/alipay/channel-merchant/find-by-channel-mch-no 查询配置
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package org.dromara.daxpay.channel.alipay.controller.mch;
|
||||
|
||||
import org.dromara.daxpay.platform.core.annotation.PermCode;
|
||||
import org.dromara.daxpay.platform.core.rest.Res;
|
||||
import org.dromara.daxpay.platform.core.rest.result.Result;
|
||||
import org.dromara.daxpay.channel.alipay.param.mch.AlipayDirectChannelMerchantCreateParam;
|
||||
import org.dromara.daxpay.channel.alipay.result.config.AlipayChannelMerchantResult;
|
||||
import org.dromara.daxpay.channel.alipay.service.mch.AlipayChannelMerchantService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@PermCode(menuCode = "payment:merchant:channelMerchant")
|
||||
@Validated
|
||||
@Tag(name = "支付宝通道商户管理")
|
||||
@RestController
|
||||
@RequestMapping("/admin/alipay/channel-merchant")
|
||||
@RequiredArgsConstructor
|
||||
public class AlipayChannelMerchantController {
|
||||
|
||||
private final AlipayChannelMerchantService alipayChannelMerchantService;
|
||||
|
||||
@PermCode(code = "view", nameCn = "商户通道商户查看", nameEn = "Merchant Channel Merchant View")
|
||||
@Operation(summary = "根据通道商户号查询支付宝通道商户配置")
|
||||
@GetMapping("/find-by-channel-mch-no")
|
||||
public Result<AlipayChannelMerchantResult> findByChannelMchNo(
|
||||
@NotBlank(message = "{validation.field.channelMerchantNo.notBlank}") String channelMchNo) {
|
||||
return Res.ok(alipayChannelMerchantService.findByChannelMchNo(channelMchNo));
|
||||
}
|
||||
|
||||
@PermCode(code = "add", nameCn = "商户通道商户新增", nameEn = "Merchant Channel Merchant Add")
|
||||
@Operation(summary = "创建支付宝直连通道商户")
|
||||
@PostMapping("/create-direct")
|
||||
public Result<Long> createDirect(@RequestBody @Validated AlipayDirectChannelMerchantCreateParam param) {
|
||||
return Res.ok(alipayChannelMerchantService.createDirect(param));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.dromara.daxpay.channel.alipay.convert;
|
||||
|
||||
import org.dromara.daxpay.channel.alipay.entity.config.AlipayChannelMerchant;
|
||||
import org.dromara.daxpay.channel.alipay.result.config.AlipayChannelMerchantResult;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface AlipayChannelMerchantConvert {
|
||||
|
||||
AlipayChannelMerchantConvert CONVERT = Mappers.getMapper(AlipayChannelMerchantConvert.class);
|
||||
|
||||
AlipayChannelMerchantResult toResult(AlipayChannelMerchant entity);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.dromara.daxpay.channel.alipay.dao.config;
|
||||
|
||||
import org.dromara.daxpay.channel.alipay.entity.config.AlipayChannelMerchant;
|
||||
import org.dromara.daxpay.platform.common.mybatisplus.impl.BaseManager;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class AlipayChannelMerchantManager extends BaseManager<AlipayChannelMerchantMapper, AlipayChannelMerchant> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.dromara.daxpay.channel.alipay.dao.config;
|
||||
|
||||
import org.dromara.daxpay.channel.alipay.entity.config.AlipayChannelMerchant;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AlipayChannelMerchantMapper extends MPJBaseMapper<AlipayChannelMerchant> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.dromara.daxpay.channel.alipay.entity.config;
|
||||
|
||||
import org.dromara.daxpay.platform.common.mybatisplus.function.ToResult;
|
||||
import org.dromara.daxpay.channel.alipay.convert.AlipayChannelMerchantConvert;
|
||||
import org.dromara.daxpay.channel.alipay.result.config.AlipayChannelMerchantResult;
|
||||
import org.dromara.daxpay.payment.common.entity.merchant.MchBaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName(value = "mch_alipay_channel_merchant", autoResultMap = true)
|
||||
public class AlipayChannelMerchant extends MchBaseEntity implements ToResult<AlipayChannelMerchantResult> {
|
||||
|
||||
private String channelMchNo;
|
||||
|
||||
private String product;
|
||||
|
||||
private String isvAppId;
|
||||
|
||||
private String alipayUserId;
|
||||
|
||||
private String appAuthToken;
|
||||
|
||||
@Override
|
||||
public AlipayChannelMerchantResult toResult() {
|
||||
return AlipayChannelMerchantConvert.CONVERT.toResult(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.dromara.daxpay.channel.alipay.param.mch;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "支付宝直连通道商户创建参数")
|
||||
public class AlipayDirectChannelMerchantCreateParam {
|
||||
|
||||
@Schema(description = "商户号")
|
||||
@NotBlank(message = "{validation.field.mchNo.notBlank}")
|
||||
private String mchNo;
|
||||
|
||||
@Schema(description = "通道商户名称")
|
||||
@NotBlank(message = "{validation.field.channelMerchantName.notBlank}")
|
||||
private String channelMerchantName;
|
||||
|
||||
@Schema(description = "所属支付产品")
|
||||
@NotBlank(message = "{validation.field.product.notBlank}")
|
||||
private String product;
|
||||
|
||||
@Schema(description = "支付宝商家用户ID(2088开头)")
|
||||
@NotBlank(message = "{validation.field.alipayUserId.notBlank}")
|
||||
private String alipayUserId;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.dromara.daxpay.channel.alipay.result.config;
|
||||
|
||||
import org.dromara.daxpay.payment.common.result.MchTradeBaseResult;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "支付宝通道商户配置结果")
|
||||
public class AlipayChannelMerchantResult extends MchTradeBaseResult {
|
||||
|
||||
@Schema(description = "通道商户号")
|
||||
private String channelMchNo;
|
||||
|
||||
@Schema(description = "所属支付产品")
|
||||
private String product;
|
||||
|
||||
@Schema(description = "支付宝服务商应用ID(aliAppId)")
|
||||
private String isvAppId;
|
||||
|
||||
@Schema(description = "支付宝商家唯一识别码(2088开头的16位数字)")
|
||||
private String alipayUserId;
|
||||
|
||||
@Schema(description = "应用授权令牌")
|
||||
private String appAuthToken;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.dromara.daxpay.channel.alipay.service.mch;
|
||||
|
||||
import org.dromara.daxpay.channel.alipay.dao.config.AlipayChannelMerchantManager;
|
||||
import org.dromara.daxpay.channel.alipay.entity.config.AlipayChannelMerchant;
|
||||
import org.dromara.daxpay.channel.alipay.param.mch.AlipayDirectChannelMerchantCreateParam;
|
||||
import org.dromara.daxpay.channel.alipay.result.config.AlipayChannelMerchantResult;
|
||||
import org.dromara.daxpay.payment.channel.dao.mch.ChannelMerchantManager;
|
||||
import org.dromara.daxpay.payment.channel.entity.mch.ChannelMerchant;
|
||||
import org.dromara.daxpay.platform.core.enums.channel.ChannelMerchantSourceEnum;
|
||||
import org.dromara.daxpay.platform.core.exception.DataNotExistException;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AlipayChannelMerchantService {
|
||||
|
||||
private final ChannelMerchantManager channelMerchantManager;
|
||||
private final AlipayChannelMerchantManager alipayChannelMerchantManager;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createDirect(AlipayDirectChannelMerchantCreateParam param) {
|
||||
String channelMchNo = param.getAlipayUserId();
|
||||
|
||||
ChannelMerchant channelMerchant = new ChannelMerchant();
|
||||
long channelMerchantId = IdUtil.getSnowflakeNextId();
|
||||
channelMerchant.setId(channelMerchantId);
|
||||
channelMerchant.setMchNo(param.getMchNo());
|
||||
channelMerchant.setChannelMchNo(channelMchNo);
|
||||
channelMerchant.setChannelMerchantName(param.getChannelMerchantName());
|
||||
channelMerchant.setProduct(param.getProduct());
|
||||
channelMerchant.setSource(ChannelMerchantSourceEnum.MANUAL.getCode());
|
||||
channelMerchant.setEnable(true);
|
||||
channelMerchantManager.save(channelMerchant);
|
||||
|
||||
AlipayChannelMerchant alipayChannelMerchant = new AlipayChannelMerchant();
|
||||
alipayChannelMerchant.setId(IdUtil.getSnowflakeNextId());
|
||||
alipayChannelMerchant.setMchNo(param.getMchNo());
|
||||
alipayChannelMerchant.setChannelMchNo(channelMchNo);
|
||||
alipayChannelMerchant.setProduct(param.getProduct());
|
||||
alipayChannelMerchant.setAlipayUserId(param.getAlipayUserId());
|
||||
alipayChannelMerchantManager.save(alipayChannelMerchant);
|
||||
return channelMerchantId;
|
||||
}
|
||||
|
||||
public AlipayChannelMerchantResult findByChannelMchNo(String channelMchNo) {
|
||||
return alipayChannelMerchantManager.lambdaQuery()
|
||||
.eq(AlipayChannelMerchant::getChannelMchNo, channelMchNo)
|
||||
.oneOpt()
|
||||
.map(AlipayChannelMerchant::toResult)
|
||||
.orElseThrow(() -> new DataNotExistException("error.payment.channel.channelMerchantNotExist"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user