update 优化汇付结算账户一致性

This commit is contained in:
jsowell
2026-07-16 13:32:43 +08:00
parent b4731d3e85
commit 345a6efb37
10 changed files with 138 additions and 68 deletions

View File

@@ -59,5 +59,8 @@ public class QueryMemberResponse extends AdapayBaseResponse{
private String bank_acct_type;
private String prov_code;
private String card_id;
private String min_amt;
private String remained_amt;
private String channel_remark;
}
}

View File

@@ -327,8 +327,11 @@ public class AdapayService {
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
SettleAccountDTO request = buildSettleAccountDTO(dto);
Map<String, Object> settleCount = createSettleAccountRequest(request, adapayMemberAccount.getAdapayMemberId(), wechatAppId);
if (settleCount == null || StringUtils.equals((String) settleCount.get("status"), "failed")) {
String errorMsg = settleCount == null ? "创建汇付结算账户失败" : (String) settleCount.get("error_msg");
if (settleCount == null
|| !AdapayStatusEnum.SUCCEEDED.getValue().equals(settleCount.get("status"))
|| StringUtils.isBlank((String) settleCount.get("id"))) {
String errorMsg = settleCount == null ? null : (String) settleCount.get("error_msg");
errorMsg = StringUtils.isNotBlank(errorMsg) ? errorMsg : "创建汇付结算账户失败";
throw new BusinessException("00500001", errorMsg);
}
@@ -348,13 +351,7 @@ public class AdapayService {
return Lists.newArrayList();
}
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
String settleAccountId = adapayMemberAccount.getSettleAccountId();
if (StringUtils.isBlank(settleAccountId) && isCorpMember(adapayMemberAccount.getAdapayMemberId())) {
AdapayCorpMemberVO corpMemberVO = queryCorpAdapayMemberInfo(adapayMemberAccount.getAdapayMemberId(), wechatAppId);
if (corpMemberVO != null) {
settleAccountId = corpMemberVO.getSettleAccountId();
}
}
String settleAccountId = resolveSettleAccountId(adapayMemberAccount, wechatAppId);
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount(adapayMemberAccount.getAdapayMemberId(), settleAccountId, wechatAppId);
if (adapaySettleAccountVO == null) {
return Lists.newArrayList();
@@ -363,6 +360,35 @@ public class AdapayService {
return Lists.newArrayList(adapaySettleAccountVO);
}
private String resolveSettleAccountId(AdapayMemberAccount account, String wechatAppId) throws BaseAdaPayException {
if (StringUtils.isNotBlank(account.getSettleAccountId())) {
return account.getSettleAccountId();
}
String settleAccountId = null;
if (isPersonalMember(account.getAdapayMemberId())) {
AdapayMemberInfoVO memberInfo = queryAdapayMemberInfo(account.getAdapayMemberId(), wechatAppId);
if (memberInfo != null) {
settleAccountId = memberInfo.getSettleAccountId();
}
} else {
AdapayCorpMemberVO corpMember = queryCorpAdapayMemberInfo(account.getAdapayMemberId(), wechatAppId);
if (corpMember != null) {
settleAccountId = corpMember.getSettleAccountId();
}
}
if (StringUtils.isNotBlank(settleAccountId)) {
AdapayMemberAccount updateRecord = new AdapayMemberAccount();
updateRecord.setMerchantId(account.getMerchantId());
updateRecord.setAdapayMemberId(account.getAdapayMemberId());
updateRecord.setSettleAccountId(settleAccountId);
adapayMemberAccountService.updateAdapayMemberAccountByMemberId(updateRecord);
account.setSettleAccountId(settleAccountId);
}
return settleAccountId;
}
/**
* 创建汇付会员
*
@@ -501,12 +527,21 @@ public class AdapayService {
}
QueryMemberResponse queryMemberResponse = JSON.parseObject(JSON.toJSONString(member), QueryMemberResponse.class);
String settleAccountId = null;
if (CollectionUtils.isNotEmpty(queryMemberResponse.getSettle_accounts())) {
settleAccountId = queryMemberResponse.getSettle_accounts().stream()
.map(QueryMemberResponse.SettleAccount::getId)
.filter(StringUtils::isNotBlank)
.findFirst()
.orElse(null);
}
AdapayMemberInfoVO resultVO = AdapayMemberInfoVO.builder()
.memberId(adapayMemberId)
.nickname(queryMemberResponse.getNickname())
.gender(queryMemberResponse.getGender())
.email(queryMemberResponse.getEmail())
.location(queryMemberResponse.getLocation())
.settleAccountId(settleAccountId)
.build();
return resultVO;
}
@@ -686,6 +721,9 @@ public class AdapayService {
.bankAcctType(accountInfo.getBank_acct_type())
.provCode(accountInfo.getProv_code())
.areaCode(accountInfo.getArea_code())
.minAmt(accountInfo.getMin_amt())
.remainedAmt(accountInfo.getRemained_amt())
.channelRemark(accountInfo.getChannel_remark())
.build();
return resultVO;
}
@@ -776,6 +814,7 @@ public class AdapayService {
* @throws BaseAdaPayException
*/
public void updateSettleAccountConfig(UpdateAccountConfigDTO dto) throws BaseAdaPayException {
assertActionAllowed(dto.getMerchantId(), AdapayOpenActionEnum.UPDATE_SETTLE_ACCOUNT_CONFIG);
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
@@ -784,16 +823,19 @@ public class AdapayService {
}
// 通过merchantId 查询出汇付会员id 和 结算账户id用来查询余额
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(dto.getMerchantId());
if (adapayMemberAccount == null) {
log.error("通过merchantId:{}, 没有查询到结算账户配置", dto.getMerchantId());
return;
AdapayMemberAccount adapayMemberAccount = requireCurrentMemberAccount(dto.getMerchantId());
String settleAccountId = resolveSettleAccountId(adapayMemberAccount, wechatAppId);
if (StringUtils.isBlank(settleAccountId)) {
throw new BusinessException("", "未查询到结算账户");
}
if (StringUtils.isAllBlank(dto.getMinAmt(), dto.getRemainedAmt(), dto.getChannelRemark())) {
throw new BusinessException("", "结算起始金额、结算留存金额和结算摘要至少填写一项");
}
// 修改账户配置
Map<String, Object> params = Maps.newHashMap();
params.put("app_id", config.getAdapayAppId());
params.put("member_id", adapayMemberAccount.getAdapayMemberId());
params.put("settle_account_id", adapayMemberAccount.getSettleAccountId());
params.put("settle_account_id", settleAccountId);
if (StringUtils.isNotBlank(dto.getMinAmt())) {
params.put("min_amt", dto.getMinAmt());
}
@@ -803,8 +845,13 @@ public class AdapayService {
if (StringUtils.isNotBlank(dto.getChannelRemark())) {
params.put("channel_remark", dto.getChannelRemark());
}
Map<String, Object> settleCount = SettleAccount.update(params);
Map<String, Object> settleCount = SettleAccount.modify(params, config.getWechatAppId());
log.info("更新结算账户设置 param:{}, result:{}", JSON.toJSONString(params), JSON.toJSONString(settleCount));
if (settleCount == null
|| !AdapayStatusEnum.SUCCEEDED.getValue().equals(settleCount.get("status"))) {
String errorMsg = settleCount == null ? null : (String) settleCount.get("error_msg");
throw new BusinessException("", StringUtils.isNotBlank(errorMsg) ? errorMsg : "修改汇付结算配置失败");
}
}
/**
@@ -1683,38 +1730,20 @@ public class AdapayService {
* 用户需要换绑银行卡 1-删除结算账户信息2-使用新账户信息创建结算账户】
*/
public void changeBankCard(ChangeBankCardDTO dto) throws BaseAdaPayException {
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
// 获取汇付支会员信息
AdapayMemberAccount account = adapayMemberAccountService.selectByMerchantId(dto.getMerchantId());
if (account == null) {
return;
}
// 1-删除结算账户信息
String adapayMemberId = account.getAdapayMemberId();
String settleAccountId = null;
AdapayCorpMemberVO adapayCorpMemberVO = this.queryCorpAdapayMemberInfo(adapayMemberId, wechatAppId);
if (adapayCorpMemberVO != null) {
settleAccountId = adapayCorpMemberVO.getSettleAccountId();
}
this.createDeleteSettleAccountRequest(adapayMemberId, settleAccountId, wechatAppId);
// 2-使用新账户信息创建结算账户
SettleAccountDTO settleAccountDTO = new SettleAccountDTO();
settleAccountDTO.setCardId(dto.getCardId());
settleAccountDTO.setCardName(dto.getCardName());
settleAccountDTO.setTelNo(dto.getTelNo());
settleAccountDTO.setBankCode(dto.getBankCode());
settleAccountDTO.setBankAcctType(dto.getBankAcctType());
settleAccountDTO.setProvCode(dto.getProvCode());
settleAccountDTO.setAreaCode(dto.getAreaCode());
Map<String, Object> settleAccount = this.createSettleAccountRequest(settleAccountDTO, adapayMemberId, wechatAppId);
if (settleAccount != null && !StringUtils.equals((String) settleAccount.get("status"), "failed")) {
AdapayMemberAccount updateRecord = new AdapayMemberAccount();
updateRecord.setAdapayMemberId(adapayMemberId);
updateRecord.setMerchantId(dto.getMerchantId());
updateRecord.setSettleAccountId((String) settleAccount.get("id"));
adapayMemberAccountService.updateAdapayMemberAccountByMemberId(updateRecord);
}
deleteSettleAccount(AdapayMemberInfoDTO.builder().merchantId(dto.getMerchantId()).build());
CreateSettleAccountDTO createRequest = CreateSettleAccountDTO.builder()
.merchantId(dto.getMerchantId())
.bankAcctType(dto.getBankAcctType())
.cardId(dto.getCardId())
.cardName(dto.getCardName())
.certId(dto.getCertId())
.certType(dto.getCertType())
.telNo(dto.getTelNo())
.bankCode(dto.getBankCode())
.provCode(dto.getProvCode())
.areaCode(dto.getAreaCode())
.build();
createSettleAccount(createRequest);
}
/**
@@ -1805,21 +1834,27 @@ public class AdapayService {
assertActionAllowed(dto.getMerchantId(), AdapayOpenActionEnum.DELETE_SETTLE_ACCOUNT);
AdapayMemberAccount adapayMemberAccount = requireCurrentMemberAccount(dto.getMerchantId());
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(dto.getMerchantId());
String adapayMemberId = StringUtils.isNotBlank(dto.getAdapayMemberId()) ? dto.getAdapayMemberId() : adapayMemberAccount.getAdapayMemberId();
String settleAccountId = StringUtils.isNotBlank(dto.getSettleAccountId()) ? dto.getSettleAccountId() : adapayMemberAccount.getSettleAccountId();
if (StringUtils.isBlank(settleAccountId) && isCorpMember(adapayMemberId)) {
AdapayCorpMemberVO corpMemberVO = queryCorpAdapayMemberInfo(adapayMemberId, wechatAppId);
if (corpMemberVO != null) {
settleAccountId = corpMemberVO.getSettleAccountId();
}
String adapayMemberId = adapayMemberAccount.getAdapayMemberId();
if (StringUtils.isNotBlank(dto.getAdapayMemberId())
&& !StringUtils.equals(dto.getAdapayMemberId(), adapayMemberId)) {
throw new BusinessException("", "汇付用户信息不匹配");
}
String settleAccountId = resolveSettleAccountId(adapayMemberAccount, wechatAppId);
if (StringUtils.isBlank(settleAccountId)) {
throw new BusinessException("", "未查询到结算账户");
}
if (StringUtils.isNotBlank(dto.getSettleAccountId())
&& !StringUtils.equals(dto.getSettleAccountId(), settleAccountId)) {
throw new BusinessException("", "结算账户信息不匹配");
}
assertSettleAccountCanDelete(dto.getMerchantId());
this.createDeleteSettleAccountRequest(adapayMemberId, settleAccountId, wechatAppId);
adapayMemberAccountService.clearSettleAccountByMerchantId(dto.getMerchantId());
int cleared = adapayMemberAccountService.clearCurrentSettleAccount(
adapayMemberAccount.getId(), dto.getMerchantId(), adapayMemberId, settleAccountId);
if (cleared != 1) {
throw new BusinessException("", "汇付结算账户已删除,但本地账户状态更新失败,请联系管理员处理");
}
}
public void deleteAdapayMember(DeleteAdapayMemberDTO dto) throws BaseAdaPayException {
@@ -2018,6 +2053,7 @@ public class AdapayService {
break;
case PERSONAL_COMPLETED:
actions.add(AdapayOpenActionEnum.UPDATE_PERSONAL_MEMBER.getValue());
actions.add(AdapayOpenActionEnum.UPDATE_SETTLE_ACCOUNT_CONFIG.getValue());
actions.add(AdapayOpenActionEnum.DELETE_SETTLE_ACCOUNT.getValue());
break;
case CORP_AUDITING:
@@ -2035,6 +2071,7 @@ public class AdapayService {
break;
case CORP_COMPLETED:
actions.add(AdapayOpenActionEnum.UPDATE_CORP_MEMBER.getValue());
actions.add(AdapayOpenActionEnum.UPDATE_SETTLE_ACCOUNT_CONFIG.getValue());
actions.add(AdapayOpenActionEnum.DELETE_SETTLE_ACCOUNT.getValue());
break;
default:

View File

@@ -20,4 +20,6 @@ public class AdapayMemberInfoVO {
private String gender;
// 昵称
private String nickname;
// 结算账户id
private String settleAccountId;
}

View File

@@ -73,4 +73,10 @@ public class AdapaySettleAccountVO {
* 银行账户开户银行所在地区编码(省市编码),银行账户类型为对公时,必填
*/
private String areaCode;
private String minAmt;
private String remainedAmt;
private String channelRemark;
}

View File

@@ -124,7 +124,10 @@ public interface AdapayMemberAccountMapper {
@Param("merchantId") String merchantId,
@Param("adapayMemberId") String adapayMemberId);
void clearSettleAccountByMerchantId(String merchantId);
int clearCurrentSettleAccount(@Param("id") Integer id,
@Param("merchantId") String merchantId,
@Param("adapayMemberId") String adapayMemberId,
@Param("settleAccountId") String settleAccountId);
/**
* 根据运营商id查询最近一条的信息

View File

@@ -115,7 +115,7 @@ public interface AdapayMemberAccountService {
*/
int deleteCurrentAccount(Integer id, String merchantId, String adapayMemberId);
void clearSettleAccountByMerchantId(String merchantId);
int clearCurrentSettleAccount(Integer id, String merchantId, String adapayMemberId, String settleAccountId);
/**
* 根据运营商Id查询最近一条的信息

View File

@@ -279,9 +279,12 @@ public class AdapayMemberAccountServiceImpl implements AdapayMemberAccountServic
}
@Override
public void clearSettleAccountByMerchantId(String merchantId) {
adapayMemberAccountMapper.clearSettleAccountByMerchantId(merchantId);
redisCache.deleteObject(CacheConstants.ADAPAY_MEMBER_ACCOUNT + merchantId);
public int clearCurrentSettleAccount(Integer id, String merchantId, String adapayMemberId, String settleAccountId) {
int result = adapayMemberAccountMapper.clearCurrentSettleAccount(id, merchantId, adapayMemberId, settleAccountId);
if (result > 0) {
redisCache.deleteObject(CacheConstants.ADAPAY_MEMBER_ACCOUNT + merchantId);
}
return result;
}
/**

View File

@@ -583,12 +583,15 @@
and del_flag = '0'
</update>
<update id="clearSettleAccountByMerchantId">
<update id="clearCurrentSettleAccount">
update
adapay_member_account
set settle_account_id = null,
update_time = now()
where merchant_id = #{merchantId,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
and merchant_id = #{merchantId,jdbcType=VARCHAR}
and adapay_member_id = #{adapayMemberId,jdbcType=VARCHAR}
and settle_account_id = #{settleAccountId,jdbcType=VARCHAR}
and del_flag = '0'
</update>