Просмотр исходного кода

Merge remote-tracking branch 'origin/dev_jzg_lipf_v20260622' into dev_jzg_lipf_v20260622

lipf 1 месяц назад
Родитель
Сommit
cefc38b8cf

+ 30 - 3
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -906,15 +906,19 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         // 提前收集所有需要查询的ID,批量查询,彻底解决循环N+1
         Set<String> allFollowIds = new HashSet<>();
         Set<String> allSettlementIds = new HashSet<>();
+        Set<String> allInvoiceIds = new HashSet<>();
         followGroupMap.values().forEach(list -> {
             list.forEach(vo -> {
                 allFollowIds.add(vo.getFollowId());
                 allSettlementIds.add(vo.getSettlementId());
+                allInvoiceIds.add(vo.getInvoiceId());
             });
         });
 
         // 批量查询跟单订单
         Map<String, InsFeeFollowOrder> followOrderMap = batchQueryFollowOrder(allFollowIds);
+        // 批量查询未结算的开票信息
+        Map<String, InsPlyIncomeInvoice> invoiceMap = batchQueryInvoice(allInvoiceIds);
         // 批量查询结算单
         Map<String, InsPlyIncomeInvoiceSettlement> settlementMap = batchQuerySettlement(allSettlementIds);
 
@@ -937,6 +941,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
 
             // 汇总当前分组所有followId、settlementId
             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();
 
             // 应收金额(取第任意一条就行了)
@@ -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()){
                 vo.setTotalUnSettlementAmount(BigDecimal.ZERO);
             }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);
@@ -1005,6 +1016,21 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 .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
      */
@@ -1191,7 +1217,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 newVo.setTotalReceivable(totalOtherReceivable);
                 newVo.setInvoiceType(invoiceType);
                 newVo.setTotalInvoiced(BigDecimal.ZERO);
-                newVo.setTotalUnInvoiced(BigDecimal.ZERO);
+                newVo.setTotalUnInvoiced(totalOtherReceivable);
                 newVo.setTotalSettlementAmount(BigDecimal.ZERO);
                 newVo.setTotalUnSettlementAmount(BigDecimal.ZERO);
 
@@ -1205,6 +1231,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 if (CollUtil.isNotEmpty(insFeeFollowOrderReconciliations)){
                     InsFeeFollowOrderReconciliation insFeeFollowOrderReconciliation = CollUtil.getFirst(insFeeFollowOrderReconciliations);
                     newVo.setTotalReconciliationAmount(insFeeFollowOrderReconciliation.getReconciliationAmount());
+                    newVo.setTotalUnInvoiced(insFeeFollowOrderReconciliation.getReconciliationAmount());
                 }
 
                 newVo.setCompanyName(getCompanyName(partnerCompanyId, companyMap));
@@ -4601,7 +4628,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         vo.setPartnerCompanyId(partnerCompanyId);
         vo.setReceivablePremium(receivable);
         vo.setInvoiced(invoiced);
-        vo.setUninvoiced(BigDecimal.ZERO);
+        vo.setUninvoiced(receivable);
 
         // --- 查询数据库获取对账信息 ---
         // 构造查询条件:年、月、合作方ID