public Paginator<DepositRespVO> getDepositQuota(DepositReqVO depositReqVO) throws ExecutionException, InterruptedException {
Page<DepositRespVO> page = new Page<>(depositReqVO.getPageNum(), depositReqVO.getPageSize());
Page<DepositRespVO> depositRespVOPage = baseMapper.pageDeposit(page, depositReqVO);
List<CompletableFuture<DepositRespVO>> futureList = new ArrayList<>();
List<DepositRespVO> list = new ArrayList<>();
List<DepositRespVO> records = depositRespVOPage.getRecords();
if (CollectionUtil.isNotEmpty(records)) {
for (DepositRespVO record : records) {
CompletableFuture<DepositRespVO> future = CompletableFuture.supplyAsync(() -> cal(record), threadPoolTaskExecutor);
futureList.add(future);
}
CompletableFuture<Void> futures = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0]));
// 等待所有任务完成,并获取它们的结果
try {
futures.join();
} catch (Exception e) {
e.printStackTrace();
}
for (CompletableFuture<DepositRespVO> depositRespVOCompletableFuture : futureList) {
DepositRespVO depositRespVO = depositRespVOCompletableFuture.get();
list.add(depositRespVO);
}
depositRespVOPage.setRecords(list);
}
return Paginator.fromPage(depositRespVOPage);
}
private DepositRespVO cal(DepositRespVO record) {
String contractCode = record.getContractCode();
String companyAmount = record.getCompanyAmount(); //保证金
String standardRate = record.getStandardRate(); // 标准比例
record.setContractId(contractCode);
// 计算金额
String ralRate = "";
String recommAmount = "";
String contractAmount = "";
if (StringUtils.isNotBlank(contractCode)) {
ContractRespVO contractInfo = getContractInfo(contractCode);
if (null != contractInfo) {
// 合同金额
contractAmount = StringUtils.isNotBlank(contractInfo.getContractamount()) ? contractInfo.getContractamount() : "";
if (StringUtils.isNotBlank(companyAmount) && StringUtils.isNotBlank(contractAmount)) { // 交了保证金且有合同额
BigDecimal rate = new BigDecimal(companyAmount).divide(new BigDecimal(contractAmount), 4, RoundingMode.HALF_UP);
BigDecimal multiply = rate.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
ralRate = multiply.toString();
if (StringUtils.isNotBlank(standardRate) && multiply.compareTo(new BigDecimal(standardRate)) < 0) { // 实际保证金比例比标准低
BigDecimal differRate = new BigDecimal(standardRate).subtract(multiply);
BigDecimal recommAmountDiffer = differRate.multiply(new BigDecimal(contractAmount));
BigDecimal divide = recommAmountDiffer.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
recommAmount = divide.toString();
}
}
}
}
record.setRalRate(StringUtils.isNotBlank(ralRate) ? ralRate : "-");
record.setRecommAmount(StringUtils.isNotBlank(recommAmount) ? recommAmount : "-");
record.setContractAmount(StringUtils.isNotBlank(contractAmount) ? contractAmount : "-");
return record;
}