|
@@ -906,15 +906,19 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
// 提前收集所有需要查询的ID,批量查询,彻底解决循环N+1
|
|
// 提前收集所有需要查询的ID,批量查询,彻底解决循环N+1
|
|
|
Set<String> allFollowIds = new HashSet<>();
|
|
Set<String> allFollowIds = new HashSet<>();
|
|
|
Set<String> allSettlementIds = new HashSet<>();
|
|
Set<String> allSettlementIds = new HashSet<>();
|
|
|
|
|
+ Set<String> allInvoiceIds = new HashSet<>();
|
|
|
followGroupMap.values().forEach(list -> {
|
|
followGroupMap.values().forEach(list -> {
|
|
|
list.forEach(vo -> {
|
|
list.forEach(vo -> {
|
|
|
allFollowIds.add(vo.getFollowId());
|
|
allFollowIds.add(vo.getFollowId());
|
|
|
allSettlementIds.add(vo.getSettlementId());
|
|
allSettlementIds.add(vo.getSettlementId());
|
|
|
|
|
+ allInvoiceIds.add(vo.getInvoiceId());
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 批量查询跟单订单
|
|
// 批量查询跟单订单
|
|
|
Map<String, InsFeeFollowOrder> followOrderMap = batchQueryFollowOrder(allFollowIds);
|
|
Map<String, InsFeeFollowOrder> followOrderMap = batchQueryFollowOrder(allFollowIds);
|
|
|
|
|
+ // 批量查询未结算的开票信息
|
|
|
|
|
+ Map<String, InsPlyIncomeInvoice> invoiceMap = batchQueryInvoice(allInvoiceIds);
|
|
|
// 批量查询结算单
|
|
// 批量查询结算单
|
|
|
Map<String, InsPlyIncomeInvoiceSettlement> settlementMap = batchQuerySettlement(allSettlementIds);
|
|
Map<String, InsPlyIncomeInvoiceSettlement> settlementMap = batchQuerySettlement(allSettlementIds);
|
|
|
|
|
|
|
@@ -937,6 +941,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
|
|
|
|
|
// 汇总当前分组所有followId、settlementId
|
|
// 汇总当前分组所有followId、settlementId
|
|
|
List<String> followIds = voList.stream().map(FollowCompanyFeeVO::getFollowId).distinct().toList();
|
|
List<String> followIds = voList.stream().map(FollowCompanyFeeVO::getFollowId).distinct().toList();
|
|
|
|
|
+ List<String> invoiceIds = voList.stream().map(FollowCompanyFeeVO::getInvoiceId).distinct().toList();
|
|
|
List<String> settlementIds = voList.stream().map(FollowCompanyFeeVO::getSettlementId).distinct().toList();
|
|
List<String> settlementIds = voList.stream().map(FollowCompanyFeeVO::getSettlementId).distinct().toList();
|
|
|
|
|
|
|
|
// 应收金额(取第任意一条就行了)
|
|
// 应收金额(取第任意一条就行了)
|
|
@@ -983,7 +988,13 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
if (insFeeFollowOrderList.size() == insFeeFollowOrderList.stream().filter(insFeeFollowOrder -> SettlementIdentificationEnum.SETTLED.getCode().equals(insFeeFollowOrder.getSettlementIdentification())).count()){
|
|
if (insFeeFollowOrderList.size() == insFeeFollowOrderList.stream().filter(insFeeFollowOrder -> SettlementIdentificationEnum.SETTLED.getCode().equals(insFeeFollowOrder.getSettlementIdentification())).count()){
|
|
|
vo.setTotalUnSettlementAmount(BigDecimal.ZERO);
|
|
vo.setTotalUnSettlementAmount(BigDecimal.ZERO);
|
|
|
}else{
|
|
}else{
|
|
|
- vo.setTotalUnSettlementAmount(totalInvoiced.subtract(totalSettlementAmount));
|
|
|
|
|
|
|
+ // 和wwq讨论过了,这个就是统计已开票未结算的数据
|
|
|
|
|
+ BigDecimal invoiceNoSettlement = invoiceIds.stream()
|
|
|
|
|
+ .map(invoiceMap::get)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .map(InsPlyIncomeInvoice::getReceivableSupervisePremium)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ vo.setTotalUnSettlementAmount(invoiceNoSettlement);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
aggResult.add(vo);
|
|
aggResult.add(vo);
|
|
@@ -1005,6 +1016,21 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
.collect(Collectors.toMap(InsFeeFollowOrder::getId, Function.identity(), (k1, k2) -> k1));
|
|
.collect(Collectors.toMap(InsFeeFollowOrder::getId, Function.identity(), (k1, k2) -> k1));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 批量查询未结算的开票信息
|
|
|
|
|
+ */
|
|
|
|
|
+ private Map<String, InsPlyIncomeInvoice> batchQueryInvoice(Set<String> invoiceIdSet) {
|
|
|
|
|
+ if (CollUtil.isEmpty(invoiceIdSet)) {
|
|
|
|
|
+ return new HashMap<>(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ LambdaQueryWrapper<InsPlyIncomeInvoice> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.in(InsPlyIncomeInvoice::getId, invoiceIdSet);
|
|
|
|
|
+ wrapper.eq(InsPlyIncomeInvoice::getStatus, "0");
|
|
|
|
|
+ List<InsPlyIncomeInvoice> insPlyIncomeInvoices = insPlyIncomeInvoiceMapper.selectList(wrapper);
|
|
|
|
|
+ return insPlyIncomeInvoices.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(InsPlyIncomeInvoice::getId, Function.identity(), (k1, k2) -> k1));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 批量查询结算单,返回ID->实体Map
|
|
* 批量查询结算单,返回ID->实体Map
|
|
|
*/
|
|
*/
|
|
@@ -1191,7 +1217,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
newVo.setTotalReceivable(totalOtherReceivable);
|
|
newVo.setTotalReceivable(totalOtherReceivable);
|
|
|
newVo.setInvoiceType(invoiceType);
|
|
newVo.setInvoiceType(invoiceType);
|
|
|
newVo.setTotalInvoiced(BigDecimal.ZERO);
|
|
newVo.setTotalInvoiced(BigDecimal.ZERO);
|
|
|
- newVo.setTotalUnInvoiced(BigDecimal.ZERO);
|
|
|
|
|
|
|
+ newVo.setTotalUnInvoiced(totalOtherReceivable);
|
|
|
newVo.setTotalSettlementAmount(BigDecimal.ZERO);
|
|
newVo.setTotalSettlementAmount(BigDecimal.ZERO);
|
|
|
newVo.setTotalUnSettlementAmount(BigDecimal.ZERO);
|
|
newVo.setTotalUnSettlementAmount(BigDecimal.ZERO);
|
|
|
|
|
|
|
@@ -1205,6 +1231,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
if (CollUtil.isNotEmpty(insFeeFollowOrderReconciliations)){
|
|
if (CollUtil.isNotEmpty(insFeeFollowOrderReconciliations)){
|
|
|
InsFeeFollowOrderReconciliation insFeeFollowOrderReconciliation = CollUtil.getFirst(insFeeFollowOrderReconciliations);
|
|
InsFeeFollowOrderReconciliation insFeeFollowOrderReconciliation = CollUtil.getFirst(insFeeFollowOrderReconciliations);
|
|
|
newVo.setTotalReconciliationAmount(insFeeFollowOrderReconciliation.getReconciliationAmount());
|
|
newVo.setTotalReconciliationAmount(insFeeFollowOrderReconciliation.getReconciliationAmount());
|
|
|
|
|
+ newVo.setTotalUnInvoiced(insFeeFollowOrderReconciliation.getReconciliationAmount());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
newVo.setCompanyName(getCompanyName(partnerCompanyId, companyMap));
|
|
newVo.setCompanyName(getCompanyName(partnerCompanyId, companyMap));
|
|
@@ -1789,9 +1816,11 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
// String incomeId = invoicingVo.getIncomeIds().get(0);
|
|
// String incomeId = invoicingVo.getIncomeIds().get(0);
|
|
|
|
|
|
|
|
// 这里的公司应该是支公司的公司
|
|
// 这里的公司应该是支公司的公司
|
|
|
- invoice.setCompanyId(invoicingVo.getCompanyId());
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ List<String> parternerCompanyId = baseMapper.queryDistinctParternerCompanyId(invoicingVo.getIncomeIds());
|
|
|
|
|
+ if(CollUtil.size(parternerCompanyId) >1 || CollUtil.size(parternerCompanyId) == 0){
|
|
|
|
|
+ throw new ServiceException("勾选的应收订单对应的保险机构不唯一");
|
|
|
|
|
+ }
|
|
|
|
|
+ invoice.setCompanyId(parternerCompanyId.get(0));
|
|
|
invoice.setInvoiceType(invoicingVo.getInvoiceType());
|
|
invoice.setInvoiceType(invoicingVo.getInvoiceType());
|
|
|
// 开票类型 1、手续费 2、跟单费 3、驾意险手续费 4、驾意险跟单费 5、平台应收-车险 6、平台应收-非车险
|
|
// 开票类型 1、手续费 2、跟单费 3、驾意险手续费 4、驾意险跟单费 5、平台应收-车险 6、平台应收-非车险
|
|
|
if("1".equals(invoicingVo.getInvoiceType()) || "2".equals(invoicingVo.getInvoiceType())){
|
|
if("1".equals(invoicingVo.getInvoiceType()) || "2".equals(invoicingVo.getInvoiceType())){
|
|
@@ -1840,6 +1869,9 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
if(invoicingVo == null){
|
|
if(invoicingVo == null){
|
|
|
throw new ServiceException("无法开票,开票参数为空");
|
|
throw new ServiceException("无法开票,开票参数为空");
|
|
|
}
|
|
}
|
|
|
|
|
+ if(CollUtil.isEmpty(invoicingVo.getIncomeIds())){
|
|
|
|
|
+ throw new SystemException("只选择要开票的应收数据");
|
|
|
|
|
+ }
|
|
|
// if(StrUtil.isEmpty(invoicingVo.getInvoiceNo())){
|
|
// if(StrUtil.isEmpty(invoicingVo.getInvoiceNo())){
|
|
|
// throw new ServiceException("发票号不能为空");
|
|
// throw new ServiceException("发票号不能为空");
|
|
|
// }
|
|
// }
|
|
@@ -4596,7 +4628,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
vo.setPartnerCompanyId(partnerCompanyId);
|
|
vo.setPartnerCompanyId(partnerCompanyId);
|
|
|
vo.setReceivablePremium(receivable);
|
|
vo.setReceivablePremium(receivable);
|
|
|
vo.setInvoiced(invoiced);
|
|
vo.setInvoiced(invoiced);
|
|
|
- vo.setUninvoiced(BigDecimal.ZERO);
|
|
|
|
|
|
|
+ vo.setUninvoiced(receivable);
|
|
|
|
|
|
|
|
// --- 查询数据库获取对账信息 ---
|
|
// --- 查询数据库获取对账信息 ---
|
|
|
// 构造查询条件:年、月、合作方ID
|
|
// 构造查询条件:年、月、合作方ID
|