|
|
@@ -60,6 +60,14 @@ public class AlipayBatchPayService {
|
|
|
public Map<String, String> authorizeApply(String enterpriseId, String participantId) {
|
|
|
if (participantId == null || participantId.isBlank())
|
|
|
throw new BusinessException(400, "付款方支付宝账号不能为空");
|
|
|
+ // 重复新增防护: 同付款方已有非 UNBIND 状态的授权记录时不允许重复申请(设计文档 2.4)
|
|
|
+ BatchAuthorizeEntity existing = batchAuthorizeMapper.selectOne(
|
|
|
+ new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<BatchAuthorizeEntity>()
|
|
|
+ .eq(BatchAuthorizeEntity::getEnterpriseId, enterpriseId)
|
|
|
+ .eq(BatchAuthorizeEntity::getParticipantId, participantId)
|
|
|
+ .ne(BatchAuthorizeEntity::getStatus, "UNBIND"));
|
|
|
+ if (existing != null)
|
|
|
+ throw new BusinessException(400, "该付款方已存在制单授权申请,无需重复授权");
|
|
|
String outBizNo = SnowflakeIdGenerator.nextIdStr();
|
|
|
try {
|
|
|
AlipayFundAuthorizeUniApplyModel model = new AlipayFundAuthorizeUniApplyModel();
|
|
|
@@ -89,7 +97,8 @@ public class AlipayBatchPayService {
|
|
|
entity.setAuthorizeLink(response.getAuthorizeLink());
|
|
|
batchAuthorizeMapper.insert(entity);
|
|
|
|
|
|
- return Map.of("authorize_link", response.getAuthorizeLink(),
|
|
|
+ return Map.of("authorize_link",
|
|
|
+ response.getAuthorizeLink() != null ? response.getAuthorizeLink() : "",
|
|
|
"out_biz_no", outBizNo, "status", "AUTHING");
|
|
|
} catch (AlipayApiException e) {
|
|
|
throw new BusinessException(400, "生成授权链接失败: " + e.getMessage());
|
|
|
@@ -111,7 +120,9 @@ public class AlipayBatchPayService {
|
|
|
if (!response.isSuccess())
|
|
|
throw new BusinessException(400, "查询授权状态失败: " + response.getMsg());
|
|
|
|
|
|
- if (response.getAgreementNo() != null && !response.getAgreementNo().isBlank()) {
|
|
|
+ // 仅 AUTHED 才回写: UNBIND 也返回协议号, 直接回写会破坏本地状态机(UNBIND 由异步通知回写)
|
|
|
+ if ("AUTHED".equals(response.getStatus())
|
|
|
+ && response.getAgreementNo() != null && !response.getAgreementNo().isBlank()) {
|
|
|
BatchAuthorizeEntity entity = batchAuthorizeMapper.selectOne(
|
|
|
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<BatchAuthorizeEntity>()
|
|
|
.eq(BatchAuthorizeEntity::getOutBizNo, outBizNo));
|
|
|
@@ -119,6 +130,9 @@ public class AlipayBatchPayService {
|
|
|
entity.setAgreementNo(response.getAgreementNo());
|
|
|
entity.setStatus("AUTHED");
|
|
|
batchAuthorizeMapper.updateById(entity);
|
|
|
+ } else {
|
|
|
+ log.warn("制单授权查询成功但本地记录不存在, enterpriseId={}, outBizNo={}, agreementNo={}",
|
|
|
+ enterpriseId, outBizNo, response.getAgreementNo());
|
|
|
}
|
|
|
}
|
|
|
return Map.of("agreement_no", response.getAgreementNo() != null ? response.getAgreementNo() : "",
|