mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-19 18:45:03 +08:00
优化批量查询汇付分账信息
This commit is contained in:
@@ -44,6 +44,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
@@ -85,9 +86,13 @@ public class PaymentTestController {
|
||||
*/
|
||||
@Test
|
||||
public void queryCreateConfirmReverseNew() throws BaseAdaPayException {
|
||||
StopWatch stopWatch = new StopWatch("批量查询分账信息");
|
||||
List<String> paymentIdList = getPaymentIdList(); // 查询分账信息
|
||||
Map<String, List<String>> splitInfoMap = adapayService.getSplitInfoMapByPaymentIdList(paymentIdList);
|
||||
System.out.println("splitInfoMap:" + JSON.toJSONString(splitInfoMap));
|
||||
stopWatch.start();
|
||||
// Map<String, List<String>> splitInfoMap = adapayService.getSplitInfoMapByPaymentIdList(paymentIdList);
|
||||
Map<String, List<String>> splitInfoMap = adapayService.getSplitInfoMapByPaymentIdListNew(paymentIdList);
|
||||
stopWatch.stop();
|
||||
System.out.println("耗时:" + stopWatch.getLastTaskTimeMillis() + ", splitInfoMap:" + JSON.toJSONString(splitInfoMap));
|
||||
}
|
||||
|
||||
public List<String> getPaymentIdList() {
|
||||
|
||||
@@ -1,6 +1,98 @@
|
||||
002212025092621413910817645268435312640
|
||||
002212025092621444910817646066690895872
|
||||
002212025092622084610817652092584701952
|
||||
002212025092622254910817656386289655808
|
||||
002212025092622443210817661095251091456
|
||||
002212025092622525010817663181866991616
|
||||
002212025092422460010816936686655008768
|
||||
002212025092423313610816948163185098752
|
||||
002212025092501082510816972528182263808
|
||||
002212025092501252510816976807009886208
|
||||
002212025092501464410816982171293986816
|
||||
002212025092502170410816989806579834880
|
||||
002212025092502403710816995731088748544
|
||||
002212025092502411410816995887678930944
|
||||
002212025092502540810816999135018131456
|
||||
002212025092503480810817012722704990208
|
||||
002212025092504090010817017974938329088
|
||||
002212025092504190510817020509719789568
|
||||
002212025092504364510817024957774991360
|
||||
002212025092505500610817043417150136320
|
||||
002212025092505565510817045134101094400
|
||||
002212025092505591510817045717755256832
|
||||
002212025092506582610817060614635433984
|
||||
002212025092507221910817066622455824384
|
||||
002212025092508142210817079724068978688
|
||||
002212025092508192110817080976538488832
|
||||
002212025092509183810817095895002562560
|
||||
002212025092509215610817096726900793344
|
||||
002212025092509393410817101165929836544
|
||||
002212025092510060210817107826073583616
|
||||
002212025092510063410817107958991036416
|
||||
002212025092510171910817110666091339776
|
||||
002212025092510185910817111081763618816
|
||||
002212025092510320510817114382286594048
|
||||
002212025092510533310817119780993421312
|
||||
002212025092511060510817122937530109952
|
||||
002212025092511150510817125201909002241
|
||||
002212025092511312310817129305276334080
|
||||
002212025092511462110817133071241203712
|
||||
002212025092511475310817133457243004928
|
||||
002212025092512015410817136983100764160
|
||||
002212025092512105510817139253880188928
|
||||
002212025092512110510817139294275547136
|
||||
002212025092512410110817146826213728256
|
||||
002212025092512450310817147844448133120
|
||||
002212025092512515910817149589274382336
|
||||
002212025092512575510817151082027180032
|
||||
002212025092513020610817152133404975104
|
||||
002212025092513090810817153902570786816
|
||||
002212025092513151310817155432434790400
|
||||
002212025092513194110817156560174104576
|
||||
002212025092513215710817157130469396480
|
||||
002212025092513444510817162865626505217
|
||||
002212025092513491610817164004430344192
|
||||
002212025092513581810817166278347071488
|
||||
002212025092514051210817168011202826240
|
||||
002212025092514053010817168088931676160
|
||||
002212025092514113710817169629604356096
|
||||
002212025092514153710817170635994087424
|
||||
002212025092514380410817176284538744832
|
||||
002212025092514382710817176381662056448
|
||||
002212025092514425910817177521917186048
|
||||
002212025092514484810817178983015522304
|
||||
002212025092514543910817180455715393536
|
||||
002212025092515012210817182146405781504
|
||||
002212025092515045210817183029668458496
|
||||
002212025092515083410817183960518725632
|
||||
002212025092515190610817186609028628480
|
||||
002212025092515214010817187257849995264
|
||||
002212025092515305110817189569078820864
|
||||
002212025092515524910817195096169058304
|
||||
002212025092516062610817198524236935168
|
||||
002212025092516223210817202575871541248
|
||||
002212025092516344610817205651571425280
|
||||
002212025092517073110817213893408296960
|
||||
002212025092517130410817215290598068224
|
||||
002212025092517155410817216005877596160
|
||||
002212025092517254910817218498380660736
|
||||
002212025092517342210817220650008264704
|
||||
002212025092517452810817223444555431936
|
||||
002212025092518125010817230330155720704
|
||||
002212025092518183610817231781762244608
|
||||
002212025092518384710817236864210415616
|
||||
002212025092518441910817238256748548096
|
||||
002212025092518444710817238373555728384
|
||||
002212025092519233010817248117595299840
|
||||
002212025092519312910817250126167498752
|
||||
002212025092519454910817253730513133568
|
||||
002212025092519510810817255070291578880
|
||||
002212025092520075610817259297642340352
|
||||
002212025092520113210817260202106404864
|
||||
002212025092520150510817261096478810112
|
||||
002212025092520353110817266238502416384
|
||||
002212025092520402510817267474022604800
|
||||
002212025092520555210817271361358385152
|
||||
002212025092521124710817275619163992064
|
||||
002212025092521200610817277458341130240
|
||||
002212025092521503310817285120017375232
|
||||
002212025092521512110817285324531789824
|
||||
002212025092521565110817286706165035008
|
||||
002212025092522294710817294996009615360
|
||||
002212025092522320710817295583728062464
|
||||
002212025092522345910817296304284315648
|
||||
002212025092523013710817303007121850368
|
||||
@@ -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