mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
优化批量查询汇付分账信息
This commit is contained in:
@@ -8,9 +8,9 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||
import com.huifu.adapay.model.*;
|
||||
import com.huifu.adapay.model.CorpMember;
|
||||
import com.huifu.adapay.model.SettleAccount;
|
||||
import com.huifu.adapay.model.*;
|
||||
import com.jsowell.adapay.common.*;
|
||||
import com.jsowell.adapay.config.AbstractAdapayConfig;
|
||||
import com.jsowell.adapay.dto.*;
|
||||
@@ -52,6 +52,7 @@ import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -1657,6 +1658,99 @@ public class AdapayService {
|
||||
/**
|
||||
* 根据paymentIdList查询分账信息
|
||||
*/
|
||||
// public Map<String, List<String>> getSplitInfoMapByPaymentIdList(List<String> paymentIdList) throws BaseAdaPayException {
|
||||
// Map<String, List<String>> resultMap = Maps.newHashMap();
|
||||
// if (CollectionUtils.isEmpty(paymentIdList)) {
|
||||
// return resultMap;
|
||||
// }
|
||||
// List<String> unSplitList = Lists.newArrayList(); // 未分帐
|
||||
// List<String> splitList = Lists.newArrayList(); // 已分帐
|
||||
// List<String> selfList = Lists.newArrayList(); // 自己分帐
|
||||
//
|
||||
// BigDecimal total = BigDecimal.ZERO; // 总分账金额
|
||||
// BigDecimal totalWithdrawalAmt = BigDecimal.ZERO; // 实际到账金额汇总
|
||||
// BigDecimal totalFeeAmt = BigDecimal.ZERO; // 手续费金额汇总
|
||||
//
|
||||
// Map<String, BigDecimal> amountDetailMap = Maps.newHashMap();
|
||||
// for (String paymentId : paymentIdList) {
|
||||
// if (StringUtils.isBlank(paymentId)) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // 根据paymentId查询支付确认情况
|
||||
// QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
||||
// dto.setPaymentId(paymentId);
|
||||
// dto.setWechatAppId(wechatAppId1);
|
||||
// QueryPaymentConfirmDetailResponse response = this.queryPaymentConfirmList(dto);
|
||||
//
|
||||
// if (response == null) {
|
||||
// // 未查询到分账信息,add to unSplitList
|
||||
// unSplitList.add(paymentId);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
||||
// if (CollectionUtils.isEmpty(confirms)) {
|
||||
// // confirms为空,add to unSplitList
|
||||
// unSplitList.add(paymentId);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // 添加到已分帐list
|
||||
// splitList.add(paymentId);
|
||||
// for (PaymentConfirmInfo confirm : confirms) {
|
||||
// if (this.queryConfirmReverseStatus(confirm)) {
|
||||
// log.info("支付确认id:" + confirm.getId() + "撤销了。。。");
|
||||
// continue;
|
||||
// }
|
||||
// JSONObject jsonObject = JSON.parseObject(confirm.getDescription());
|
||||
// String adapayMemberId = jsonObject.getString("adapayMemberId");
|
||||
// if (StringUtils.isBlank(adapayMemberId)) {
|
||||
// adapayMemberId = jsonObject.getString("adapayMemberIds");
|
||||
// }
|
||||
//
|
||||
// BigDecimal confirmAmt = new BigDecimal(confirm.getConfirmAmt()); // 本次确认金额
|
||||
// BigDecimal confirmedAmt = new BigDecimal(confirm.getConfirmedAmt()); // 已确认金额
|
||||
// BigDecimal feeAmt = new BigDecimal(confirm.getFeeAmt()); // 手续费
|
||||
//
|
||||
// // 汇总已确认金额
|
||||
// total = total.add(confirmedAmt);
|
||||
//
|
||||
// // 汇总手续费金额
|
||||
// totalFeeAmt = totalFeeAmt.add(feeAmt);
|
||||
//
|
||||
// // 汇总可提现金额
|
||||
// totalWithdrawalAmt = totalWithdrawalAmt.add(confirmAmt).subtract(feeAmt);
|
||||
//
|
||||
// // confirm
|
||||
// List<DivMember> divMembers = confirm.getDivMembers();
|
||||
// // System.out.println("confirm:" + JSON.toJSONString(divMembers));
|
||||
// for (DivMember divMember : divMembers) {
|
||||
// // 放map
|
||||
// amountDetailMap.merge(divMember.getMemberId(), new BigDecimal(divMember.getAmount()), BigDecimal::add);
|
||||
// }
|
||||
//
|
||||
// if (StringUtils.equals(adapayMemberId, "0")
|
||||
// || StringUtils.equals(adapayMemberId, "AM29102732")) {
|
||||
// // 0为默认平台id, AM29102732为罗总账户
|
||||
// selfList.add(paymentId);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// log.info("\n入参paymentId数量:{}, 已分帐数量:{}, 未分帐数量:{}, 未分帐id:{} " +
|
||||
// "\n已分帐:{}, 总分账:{}, 数量:{}" +
|
||||
// "\n金额明细:[总到账金额:{}, 总手续费:{}] " +
|
||||
// "\n自己:{}, 数量:{}",
|
||||
// paymentIdList.size(), splitList.size(), unSplitList.size(), unSplitList,
|
||||
// JSON.toJSONString(amountDetailMap), total, splitList.size(),
|
||||
// totalWithdrawalAmt, totalFeeAmt,
|
||||
// selfList, selfList.size());
|
||||
//
|
||||
// resultMap.put("unSplitList", unSplitList);
|
||||
// resultMap.put("splitList", splitList);
|
||||
// return resultMap;
|
||||
// }
|
||||
|
||||
public Map<String, List<String>> getSplitInfoMapByPaymentIdList(List<String> paymentIdList) throws BaseAdaPayException {
|
||||
Map<String, List<String>> resultMap = Maps.newHashMap();
|
||||
if (CollectionUtils.isEmpty(paymentIdList)) {
|
||||
@@ -1666,76 +1760,93 @@ public class AdapayService {
|
||||
List<String> splitList = Lists.newArrayList(); // 已分帐
|
||||
List<String> selfList = Lists.newArrayList(); // 自己分帐
|
||||
|
||||
BigDecimal total = BigDecimal.ZERO; // 总分账金额
|
||||
BigDecimal totalWithdrawalAmt = BigDecimal.ZERO; // 实际到账金额汇总
|
||||
BigDecimal totalFeeAmt = BigDecimal.ZERO; // 手续费金额汇总
|
||||
// 使用原子引用包装可变对象
|
||||
AtomicReference<BigDecimal> total = new AtomicReference<>(BigDecimal.ZERO);
|
||||
AtomicReference<BigDecimal> totalWithdrawalAmt = new AtomicReference<>(BigDecimal.ZERO);
|
||||
AtomicReference<BigDecimal> totalFeeAmt = new AtomicReference<>(BigDecimal.ZERO);
|
||||
|
||||
Map<String, BigDecimal> amountDetailMap = Maps.newHashMap();
|
||||
for (String paymentId : paymentIdList) {
|
||||
if (StringUtils.isBlank(paymentId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 根据paymentId查询支付确认情况
|
||||
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
||||
dto.setPaymentId(paymentId);
|
||||
dto.setWechatAppId(wechatAppId1);
|
||||
QueryPaymentConfirmDetailResponse response = this.queryPaymentConfirmList(dto);
|
||||
paymentIdList.parallelStream()
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.forEach(paymentId -> {
|
||||
// 根据paymentId查询支付确认情况
|
||||
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
||||
dto.setPaymentId(paymentId);
|
||||
dto.setWechatAppId(wechatAppId1);
|
||||
QueryPaymentConfirmDetailResponse response = this.queryPaymentConfirmList(dto);
|
||||
|
||||
if (response == null) {
|
||||
// 未查询到分账信息,add to unSplitList
|
||||
unSplitList.add(paymentId);
|
||||
continue;
|
||||
}
|
||||
if (response == null) {
|
||||
// 未查询到分账信息,add to unSplitList
|
||||
synchronized (unSplitList) {
|
||||
unSplitList.add(paymentId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
||||
if (CollectionUtils.isEmpty(confirms)) {
|
||||
// confirms为空,add to unSplitList
|
||||
unSplitList.add(paymentId);
|
||||
continue;
|
||||
}
|
||||
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
||||
if (CollectionUtils.isEmpty(confirms)) {
|
||||
// confirms为空,add to unSplitList
|
||||
synchronized (unSplitList) {
|
||||
unSplitList.add(paymentId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加到已分帐list
|
||||
splitList.add(paymentId);
|
||||
for (PaymentConfirmInfo confirm : confirms) {
|
||||
if (this.queryConfirmReverseStatus(confirm)) {
|
||||
log.info("支付确认id:" + confirm.getId() + "撤销了。。。");
|
||||
continue;
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(confirm.getDescription());
|
||||
String adapayMemberId = jsonObject.getString("adapayMemberId");
|
||||
if (StringUtils.isBlank(adapayMemberId)) {
|
||||
adapayMemberId = jsonObject.getString("adapayMemberIds");
|
||||
// 添加到已分帐list
|
||||
synchronized (splitList) {
|
||||
splitList.add(paymentId);
|
||||
}
|
||||
for (PaymentConfirmInfo confirm : confirms) {
|
||||
try {
|
||||
if (queryConfirmReverseStatus(confirm)) {
|
||||
log.info("支付确认id:" + confirm.getId() + "撤销了。。。");
|
||||
continue;
|
||||
}
|
||||
} catch (BaseAdaPayException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(confirm.getDescription());
|
||||
String adapayMemberId = jsonObject.getString("adapayMemberId");
|
||||
if (StringUtils.isBlank(adapayMemberId)) {
|
||||
adapayMemberId = jsonObject.getString("adapayMemberIds");
|
||||
}
|
||||
|
||||
BigDecimal confirmAmt = new BigDecimal(confirm.getConfirmAmt()); // 本次确认金额
|
||||
BigDecimal confirmedAmt = new BigDecimal(confirm.getConfirmedAmt()); // 已确认金额
|
||||
BigDecimal feeAmt = new BigDecimal(confirm.getFeeAmt()); // 手续费
|
||||
|
||||
// 汇总已确认金额
|
||||
total.getAndUpdate(current -> current.add(confirmedAmt));
|
||||
|
||||
// 汇总手续费金额
|
||||
totalFeeAmt.getAndUpdate(current -> current.add(feeAmt));
|
||||
|
||||
// 汇总可提现金额
|
||||
totalWithdrawalAmt.getAndUpdate(current -> current.add(confirmAmt).subtract(feeAmt));
|
||||
|
||||
// confirm
|
||||
List<DivMember> divMembers = confirm.getDivMembers();
|
||||
// System.out.println("confirm:" + JSON.toJSONString(divMembers));
|
||||
for (DivMember divMember : divMembers) {
|
||||
synchronized (amountDetailMap) {
|
||||
// 放map
|
||||
amountDetailMap.merge(divMember.getMemberId(), new BigDecimal(divMember.getAmount()), BigDecimal::add);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.equals(adapayMemberId, "0")
|
||||
|| StringUtils.equals(adapayMemberId, "AM29102732")) {
|
||||
// 0为默认平台id, AM29102732为罗总账户
|
||||
synchronized (selfList) {
|
||||
selfList.add(paymentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
BigDecimal confirmAmt = new BigDecimal(confirm.getConfirmAmt()); // 本次确认金额
|
||||
BigDecimal confirmedAmt = new BigDecimal(confirm.getConfirmedAmt()); // 已确认金额
|
||||
BigDecimal feeAmt = new BigDecimal(confirm.getFeeAmt()); // 手续费
|
||||
|
||||
// 汇总已确认金额
|
||||
total = total.add(confirmedAmt);
|
||||
|
||||
// 汇总手续费金额
|
||||
totalFeeAmt = totalFeeAmt.add(feeAmt);
|
||||
|
||||
// 汇总可提现金额
|
||||
totalWithdrawalAmt = totalWithdrawalAmt.add(confirmAmt).subtract(feeAmt);
|
||||
|
||||
// confirm
|
||||
List<DivMember> divMembers = confirm.getDivMembers();
|
||||
// System.out.println("confirm:" + JSON.toJSONString(divMembers));
|
||||
for (DivMember divMember : divMembers) {
|
||||
// 放map
|
||||
amountDetailMap.merge(divMember.getMemberId(), new BigDecimal(divMember.getAmount()), BigDecimal::add);
|
||||
}
|
||||
|
||||
if (StringUtils.equals(adapayMemberId, "0")
|
||||
|| StringUtils.equals(adapayMemberId, "AM29102732")) {
|
||||
// 0为默认平台id, AM29102732为罗总账户
|
||||
selfList.add(paymentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("\n入参paymentId数量:{}, 已分帐数量:{}, 未分帐数量:{}, 未分帐id:{} " +
|
||||
"\n已分帐:{}, 总分账:{}, 数量:{}" +
|
||||
"\n金额明细:[总到账金额:{}, 总手续费:{}] " +
|
||||
|
||||
Reference in New Issue
Block a user