Ver código fonte

Merge remote-tracking branch 'origin/master'

lixiaolong 3 meses atrás
pai
commit
f171b30bbd

+ 19 - 0
commons/src/main/java/com/jzg/commons/entity/finance/vo/FollowCompanyFeeVO.java

@@ -15,6 +15,10 @@ public class FollowCompanyFeeVO {
 
 
     private String companyId;
     private String companyId;
 
 
+    private String year;
+
+    private String month;
+
     @Schema(description = "对接人")
     @Schema(description = "对接人")
     private String contactPerson;
     private String contactPerson;
 
 
@@ -47,4 +51,19 @@ public class FollowCompanyFeeVO {
     /** 累计应收  totalReceivable */
     /** 累计应收  totalReceivable */
     private BigDecimal totalReceivable;
     private BigDecimal totalReceivable;
 
 
+    /**
+     * 开票记录id
+     */
+    private String invoiceId;
+
+    /**
+     * 结算记录id
+     */
+    private String settlementId;
+
+    /**
+     * 跟单id
+     */
+    private String followId;
+
 }
 }

+ 5 - 0
commons/src/main/java/com/jzg/commons/entity/finance/vo/InvoiceRecordResult.java

@@ -148,4 +148,9 @@ public class InvoiceRecordResult extends PageRequest {
      * 分支公司名称
      * 分支公司名称
      */
      */
     private String partnerCompanyName;
     private String partnerCompanyName;
+
+    /**
+     * 回款差额
+     */
+    private BigDecimal settlementPaymentDifference;
 }
 }

+ 12 - 0
commons/src/main/java/com/jzg/commons/entity/po/InsFeeOrders.java

@@ -165,12 +165,24 @@ public class InsFeeOrders {
     @Schema(description = "交强出口比例")
     @Schema(description = "交强出口比例")
     private BigDecimal jqExportRatio;
     private BigDecimal jqExportRatio;
 
 
+    @TableField(exist = false)
+    @Schema(description = "交强出口比例(含分销比例)")
+    private BigDecimal jqExportRatioContainDistribution;
+
     @Schema(description = "商业险出口比例")
     @Schema(description = "商业险出口比例")
     private BigDecimal syExportRatio;
     private BigDecimal syExportRatio;
 
 
+    @TableField(exist = false)
+    @Schema(description = "商业险出口比例(含分销比例)")
+    private BigDecimal syExportRatioContainDistribution;
+
     @Schema(description = "驾意险出口比例")
     @Schema(description = "驾意险出口比例")
     private BigDecimal jyExportRatio;
     private BigDecimal jyExportRatio;
 
 
+    @TableField(exist = false)
+    @Schema(description = "驾意险出口比例(含分销比例)")
+    private BigDecimal jyExportRatioContainDistribution;
+
     @Schema(description = "交强出口费用")
     @Schema(description = "交强出口费用")
     private BigDecimal jqExportPremium;
     private BigDecimal jqExportPremium;
 
 

+ 19 - 0
commons/src/main/java/com/jzg/commons/util/BigDecimalUtil.java

@@ -36,6 +36,25 @@ public class BigDecimalUtil {
         return val.negate();
         return val.negate();
     }
     }
 
 
+    /**
+     *
+     * @author lipf
+     * @date 2026/7/1 14:58
+     */
+    public static BigDecimal add(BigDecimal ... v1s){
+        if (v1s == null || v1s.length == 0) {
+            return BigDecimal.ZERO;
+        }
+        BigDecimal sum = BigDecimal.ZERO;
+        for (BigDecimal v1 : v1s) {
+            if(v1 == null){
+                v1 = BigDecimal.ZERO;
+            }
+            sum = BigDecimalUtil.add(sum,v1);
+        }
+        return sum;
+    }
+
     /**
     /**
      * 提供精确的加法运算
      * 提供精确的加法运算
      * @param v1 被加数
      * @param v1 被加数

+ 2 - 0
tenant/insurance/quotation-hengbang/src/main/java/com/jzg/quotation/hengbang/crawler/service/Impl/HengBangCrawlerRequestImpl.java

@@ -189,6 +189,8 @@ public class HengBangCrawlerRequestImpl implements HengBangCrawlerRequest {
         if (errorMsg.contains("该车是转保车,请输入对应的转保验证码")) {
         if (errorMsg.contains("该车是转保车,请输入对应的转保验证码")) {
             String responseBody = resJsonObj.getString("responseBody");
             String responseBody = resJsonObj.getString("responseBody");
             HbCrawlerRecordResponse recordResponse = JSONObject.parseObject(responseBody, HbCrawlerRecordResponse.class);
             HbCrawlerRecordResponse recordResponse = JSONObject.parseObject(responseBody, HbCrawlerRecordResponse.class);
+            recordResponse.getCheckcodeJq().replace("0","o");
+            recordResponse.getCheckcodeSy().replace("0","o");
             calculationRequest.setTransferVehicle(recordResponse);
             calculationRequest.setTransferVehicle(recordResponse);
 
 
             resJson = hbCrawlerRequestComponent.getCalculationResult(calculationRequest, headers);
             resJson = hbCrawlerRequestComponent.getCalculationResult(calculationRequest, headers);

+ 22 - 9
tenant/insurance/quotation-summary/src/main/java/com/jzg/quotation/summary/service/impl/InsFeeOrdersServiceImpl.java

@@ -153,19 +153,19 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
         // 1. 交强险
         // 1. 交强险
         calculatePremiumByRule(insFeeOrders, "jq", jqPremium,
         calculatePremiumByRule(insFeeOrders, "jq", jqPremium,
                 insFeeOrders.getJqCommissionRatio(), insFeeOrders.getJqInletRatio(), insFeeOrders.getJqFollowRatio(),
                 insFeeOrders.getJqCommissionRatio(), insFeeOrders.getJqInletRatio(), insFeeOrders.getJqFollowRatio(),
-                insFeeOrders.getJqAdditionalRatio(), insFeeOrders.getJqKeepPointRatio(), insFeeOrders.getJqExportRatio(), insFeeOrders.getJqExportKeepPointRatio(),
+                insFeeOrders.getJqAdditionalRatio(), insFeeOrders.getJqKeepPointRatio(), insFeeOrders.getJqExportRatio(), insFeeOrders.getJqExportKeepPointRatio(),insFeeOrders.getJqExportRatioContainDistribution(),
                 withTax, taxRate, SCALE);
                 withTax, taxRate, SCALE);
 
 
         // 2. 商业险
         // 2. 商业险
         calculatePremiumByRule(insFeeOrders, "sy", syPremium,
         calculatePremiumByRule(insFeeOrders, "sy", syPremium,
                 insFeeOrders.getSyCommissionRatio(), insFeeOrders.getSyInletRatio(), insFeeOrders.getSyFollowRatio(),
                 insFeeOrders.getSyCommissionRatio(), insFeeOrders.getSyInletRatio(), insFeeOrders.getSyFollowRatio(),
-                insFeeOrders.getSyAdditionalRatio(), insFeeOrders.getSyKeepPointRatio(), insFeeOrders.getSyExportRatio(), insFeeOrders.getSyExportKeepPointRatio(),
+                insFeeOrders.getSyAdditionalRatio(), insFeeOrders.getSyKeepPointRatio(), insFeeOrders.getSyExportRatio(), insFeeOrders.getSyExportKeepPointRatio(),insFeeOrders.getSyExportRatioContainDistribution(),
                 withTax, taxRate, SCALE);
                 withTax, taxRate, SCALE);
 
 
         // 3. 驾乘险
         // 3. 驾乘险
         calculatePremiumByRule(insFeeOrders, "jy", jyPremium,
         calculatePremiumByRule(insFeeOrders, "jy", jyPremium,
                 insFeeOrders.getJyCommissionRatio(), insFeeOrders.getJyInletRatio(), insFeeOrders.getJyFollowRatio(),
                 insFeeOrders.getJyCommissionRatio(), insFeeOrders.getJyInletRatio(), insFeeOrders.getJyFollowRatio(),
-                insFeeOrders.getJyAdditionalRatio(), insFeeOrders.getJyKeepPointRatio(), insFeeOrders.getJyExportRatio(), insFeeOrders.getJyExportKeepPointRatio(),
+                insFeeOrders.getJyAdditionalRatio(), insFeeOrders.getJyKeepPointRatio(), insFeeOrders.getJyExportRatio(), insFeeOrders.getJyExportKeepPointRatio(),insFeeOrders.getJyExportRatioContainDistribution(),
                 withTax, taxRate, SCALE);
                 withTax, taxRate, SCALE);
 
 
         // 重新统计总应收、总应付
         // 重新统计总应收、总应付
@@ -203,7 +203,7 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
             InsFeeOrders insFeeOrders, String type,
             InsFeeOrders insFeeOrders, String type,
             BigDecimal premium,
             BigDecimal premium,
             BigDecimal commissionRatio, BigDecimal inletRatio, BigDecimal followRatio,
             BigDecimal commissionRatio, BigDecimal inletRatio, BigDecimal followRatio,
-            BigDecimal addThrowRatio, BigDecimal keepPointRatio, BigDecimal exportRatio, BigDecimal exportKeepPointRatio,
+            BigDecimal addThrowRatio, BigDecimal keepPointRatio, BigDecimal exportRatio, BigDecimal exportKeepPointRatio, BigDecimal exportRatioContainDistribution,
             Integer withTax, BigDecimal taxRate, int scale) {
             Integer withTax, BigDecimal taxRate, int scale) {
 
 
         // 计算基数
         // 计算基数
@@ -228,8 +228,15 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
         BigDecimal exportKeepPoint = premium.multiply(exportKeepPointRatio).setScale(scale, RoundingMode.DOWN);
         BigDecimal exportKeepPoint = premium.multiply(exportKeepPointRatio).setScale(scale, RoundingMode.DOWN);
         // 留点比例直接乘, modify by lipf ,留点比例在infFeeOrder中计算得到。这里直接使用 2026年6月16日17:32:09, 为了保持金额一致,留点比例不适用百分比乘积,而是使用金额相减
         // 留点比例直接乘, modify by lipf ,留点比例在infFeeOrder中计算得到。这里直接使用 2026年6月16日17:32:09, 为了保持金额一致,留点比例不适用百分比乘积,而是使用金额相减
         // BigDecimal keepPoint = premium.multiply(keepPointRatio).setScale(scale, RoundingMode.HALF_EVEN);
         // BigDecimal keepPoint = premium.multiply(keepPointRatio).setScale(scale, RoundingMode.HALF_EVEN);
-        BigDecimal keepPoint = BigDecimalUtil.subtract(BigDecimalUtil.add(inlet,addThrow),export);
-        log.info("计算留点:inlet=[{}],addThrow=[{}].export=[{}]", inlet, addThrow, export);
+        //BigDecimal keepPoint = BigDecimalUtil.subtract(BigDecimalUtil.add(inlet,addThrow),export);
+        // modify by lipf 2026年7月1日10:07:18 计算留点的时候,将分销费用移除
+//        BigDecimal distributionFee = BigDecimalUtil.add(insFeeOrders.getFirstDistributionFee(), insFeeOrders.getSecondDistributionFee(), insFeeOrders.getThirdDistributionFee());
+//        log.info("分销总费用:distributionFee=【{}】",distributionFee);
+//        BigDecimal keepPoint = BigDecimalUtil.subtract(BigDecimalUtil.add(inlet,addThrow),BigDecimalUtil.add(export, distributionFee));
+//        log.info("留点费用:inlet=[{}],addThrow=[{}],export=[{}], distributionFee=[{}]mkeepPoint=[{}]", inlet, addThrow, export, distributionFee, keepPoint);
+        BigDecimal exportContainDistribute = premium.multiply(exportRatioContainDistribution).setScale(scale, RoundingMode.HALF_DOWN);
+        BigDecimal keepPoint = BigDecimalUtil.subtract(BigDecimalUtil.add(inlet,addThrow),exportContainDistribute);
+        log.info("计算留点:inlet=[{}],addThrow=[{}].exportContainDistribute=[{}]", inlet, addThrow, exportContainDistribute);
 
 
         // 赋值到实体(自动匹配 jq / sy / jy)
         // 赋值到实体(自动匹配 jq / sy / jy)
         if ("jq".equals(type)) {
         if ("jq".equals(type)) {
@@ -432,9 +439,15 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
         insFeeOrders.setSyExportRatio(syExportRatio);
         insFeeOrders.setSyExportRatio(syExportRatio);
         insFeeOrders.setJyExportRatio(jyExportRatio);
         insFeeOrders.setJyExportRatio(jyExportRatio);
         // 需求:入口 + 加投 - 出口 = 留点
         // 需求:入口 + 加投 - 出口 = 留点
-        BigDecimal jqKeepPointRatio = (jqInletRatio.divide(taxFactor, 5, RoundingMode.HALF_EVEN)).add(jqAdditionalRatio).subtract(jqExportRatio);
-        BigDecimal syKeepPointRatio = (syInletRatio.divide(taxFactor, 5, RoundingMode.HALF_EVEN)).add(syAdditionalRatio).subtract(syExportRatio);
-        BigDecimal jyKeepPointRatio = (jyInletRatio.divide(taxFactor, 5, RoundingMode.HALF_EVEN)).add(jyAdditionalRatio).subtract(jyExportRatio);
+        BigDecimal distributionRatio = BigDecimalUtil.divide(BigDecimalUtil.add(insFeeOrders.getFirstDistributionRatio(), insFeeOrders.getSecondDistributionRatio(), insFeeOrders.getThirdDistributionRatio()),new BigDecimal(100));
+        insFeeOrders.setJqExportRatioContainDistribution(BigDecimalUtil.add(jqExportRatio,distributionRatio));
+        insFeeOrders.setSyExportRatioContainDistribution(BigDecimalUtil.add(syExportRatio,distributionRatio) );
+        insFeeOrders.setJyExportRatioContainDistribution(BigDecimalUtil.add(jyExportRatio,distributionRatio) );
+        BigDecimal jqKeepPointRatio = (jqInletRatio.divide(taxFactor, 5, RoundingMode.HALF_EVEN)).add(jqAdditionalRatio).subtract(BigDecimalUtil.add(jqExportRatio,distributionRatio));
+        log.info("计算留点比例。 distributionRatio=[{}],jqInletRatio=[{}],jqAdditionalRatio=[{}],jqExportRatio=[{}]", distributionRatio,jqInletRatio,jqAdditionalRatio,jqExportRatio);
+
+        BigDecimal syKeepPointRatio = (syInletRatio.divide(taxFactor, 5, RoundingMode.HALF_EVEN)).add(syAdditionalRatio).subtract(BigDecimalUtil.add(jqExportRatio,syExportRatio));
+        BigDecimal jyKeepPointRatio = (jyInletRatio.divide(taxFactor, 5, RoundingMode.HALF_EVEN)).add(jyAdditionalRatio).subtract(BigDecimalUtil.add(jqExportRatio,jyExportRatio));
         // 留点比例
         // 留点比例
         insFeeOrders.setJqKeepPointRatio(jqKeepPointRatio);
         insFeeOrders.setJqKeepPointRatio(jqKeepPointRatio);
         insFeeOrders.setSyKeepPointRatio(syKeepPointRatio);
         insFeeOrders.setSyKeepPointRatio(syKeepPointRatio);

+ 135 - 34
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -729,19 +729,79 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
     public List<FollowCompanyFeeVO> followCompanySuperviseSettlementReport(SettlementReportQueryVo settlementReportQueryVo) {
     public List<FollowCompanyFeeVO> followCompanySuperviseSettlementReport(SettlementReportQueryVo settlementReportQueryVo) {
         log.info("私有协议-跟单结算记录-结算报表: settlementReportQueryVo=[{}]", JSONUtil.toJsonStr(settlementReportQueryVo));
         log.info("私有协议-跟单结算记录-结算报表: settlementReportQueryVo=[{}]", JSONUtil.toJsonStr(settlementReportQueryVo));
 
 
+        // 返回值
+        List<FollowCompanyFeeVO> resultList = CollUtil.newArrayList();
+
         List<FollowCompanyFeeVO> followCompanyFeeVos = insFeeFollowOrderMapper.selectFollowCompanySettlementReport(settlementReportQueryVo);
         List<FollowCompanyFeeVO> followCompanyFeeVos = insFeeFollowOrderMapper.selectFollowCompanySettlementReport(settlementReportQueryVo);
         // 查询所有保险公司,匹配保险公司的id和名称
         // 查询所有保险公司,匹配保险公司的id和名称
         HttpResult<Map<String, EsmInsCompany>> mapHttpResult = esmInsCompanyClient.queryAllCompanyMap();
         HttpResult<Map<String, EsmInsCompany>> mapHttpResult = esmInsCompanyClient.queryAllCompanyMap();
         Map<String, EsmInsCompany> data = mapHttpResult.getData();
         Map<String, EsmInsCompany> data = mapHttpResult.getData();
-        if (CollUtil.isEmpty(data)){
-            return followCompanyFeeVos;
+        if (CollUtil.isEmpty(data) || CollUtil.isEmpty(followCompanyFeeVos)){
+            return resultList;
         }
         }
-        for (FollowCompanyFeeVO followCompanyFeeVo : followCompanyFeeVos) {
-            followCompanyFeeVo.setCompanyName(null != data.get(followCompanyFeeVo.getPartnerCompanyId()) ? data.get(followCompanyFeeVo.getPartnerCompanyId()).getName() : "");
-            followCompanyFeeVo.setTotalUnSettlementAmount(followCompanyFeeVo.getTotalInvoiced().subtract(followCompanyFeeVo.getTotalSettlementAmount()));
-            followCompanyFeeVo.setTotalUnInvoiced(followCompanyFeeVo.getTotalReceivable().subtract(followCompanyFeeVo.getTotalInvoiced()));
+
+        // 根据分支公司分组
+        Map<String, List<FollowCompanyFeeVO>> followMap = followCompanyFeeVos.stream().collect(Collectors.groupingBy(follow -> follow.getPartnerCompanyId() + "_" + follow.getYear() + "_" + follow.getMonth()));
+        for (Map.Entry<String, List<FollowCompanyFeeVO>> entry : followMap.entrySet()) {
+            // key = 合作公司ID
+            String key = entry.getKey();
+
+            // 分组参数
+            String[] arr = key.split("_");
+            String partnerCompanyId = arr[0];
+            String year = arr[1];
+            String month = arr[2];
+
+
+            // value = 当前公司下所有VO集合
+            List<FollowCompanyFeeVO> voList = entry.getValue();
+
+            // 返回值
+            FollowCompanyFeeVO followCompanyFeeVO = new FollowCompanyFeeVO();
+            followCompanyFeeVO.setPartnerCompanyId(partnerCompanyId);
+
+            List<String> followIds = voList.stream().map(FollowCompanyFeeVO::getFollowId).toList();
+            List<String> invoiceIds = voList.stream().map(FollowCompanyFeeVO::getInvoiceId).toList();
+            List<String> settlementIds = voList.stream().map(FollowCompanyFeeVO::getSettlementId).toList();
+
+            // 根据所有followCompanyFeeVos的followId统计出已开票
+            LambdaQueryWrapper<InsFeeFollowOrder> insFeeFollowOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            insFeeFollowOrderLambdaQueryWrapper.in(InsFeeFollowOrder::getId, followIds);
+            List<InsFeeFollowOrder> insFeeFollowOrders = insFeeFollowOrderMapper.selectList(insFeeFollowOrderLambdaQueryWrapper);
+            // 总金额
+            InsFeeFollowOrder feeFollowOrder = CollUtil.getFirst(insFeeFollowOrders);
+            // 取对账金额
+            BigDecimal receivablePremium = feeFollowOrder.getReconciliationAmount();
+            followCompanyFeeVO.setTotalReceivable(receivablePremium);
+
+            BigDecimal totalInvoiced = insFeeFollowOrders.stream().map(InsFeeFollowOrder::getInvoiced).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
+            // 已开票总金额
+            followCompanyFeeVO.setTotalInvoiced(totalInvoiced);
+
+            // 未结算金额
+            followCompanyFeeVO.setTotalUnInvoiced(receivablePremium.subtract(totalInvoiced));
+
+            // 统计结算金额
+            LambdaQueryWrapper<InsPlyIncomeInvoiceSettlement> insPlyIncomeInvoiceSettlementLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            insPlyIncomeInvoiceSettlementLambdaQueryWrapper.in(InsPlyIncomeInvoiceSettlement::getId, settlementIds);
+            List<InsPlyIncomeInvoiceSettlement> insPlyIncomeInvoiceSettlements = insPlyIncomeInvoiceSettlementMapper.selectList(insPlyIncomeInvoiceSettlementLambdaQueryWrapper);
+            BigDecimal totalSettlementAmount = insPlyIncomeInvoiceSettlements.stream().map(InsPlyIncomeInvoiceSettlement::getActualReceivedAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
+            // 已结算总金额
+            followCompanyFeeVO.setTotalSettlementAmount(totalSettlementAmount);
+
+            // 未结算金额
+            followCompanyFeeVO.setTotalUnSettlementAmount(totalInvoiced.subtract(totalSettlementAmount));
+            followCompanyFeeVO.setCompanyName(null != data.get(partnerCompanyId) ? data.get(partnerCompanyId).getName() : "");
+
+            resultList.add(followCompanyFeeVO);
         }
         }
-        return followCompanyFeeVos;
+
+//        for (FollowCompanyFeeVO followCompanyFeeVo : followCompanyFeeVos) {
+//            followCompanyFeeVo.setCompanyName(null != data.get(followCompanyFeeVo.getPartnerCompanyId()) ? data.get(followCompanyFeeVo.getPartnerCompanyId()).getName() : "");
+//            followCompanyFeeVo.setTotalUnSettlementAmount(followCompanyFeeVo.getTotalInvoiced().subtract(followCompanyFeeVo.getTotalSettlementAmount()));
+//            followCompanyFeeVo.setTotalUnInvoiced(followCompanyFeeVo.getTotalReceivable().subtract(followCompanyFeeVo.getTotalInvoiced()));
+//        }
+        return resultList;
     }
     }
 
 
     /**
     /**
@@ -4042,6 +4102,10 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                         .map(InsPlyIncomeInvoiceSettlement::getActualReceivedAmount)
                         .map(InsPlyIncomeInvoiceSettlement::getActualReceivedAmount)
                         .filter(Objects::nonNull)
                         .filter(Objects::nonNull)
                         .reduce(BigDecimal.ZERO, BigDecimal::add);
                         .reduce(BigDecimal.ZERO, BigDecimal::add);
+                BigDecimal settlementPaymentDifference = insPlyIncomeInvoiceSettlements.stream()
+                        .map(InsPlyIncomeInvoiceSettlement::getSettlementPaymentDifference)
+                        .filter(Objects::nonNull)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                 BigDecimal receivableSupervisePremium = action.getReceivableSupervisePremium()  != null ? action.getReceivableSupervisePremium(): BigDecimal.ZERO;
                 BigDecimal receivableSupervisePremium = action.getReceivableSupervisePremium()  != null ? action.getReceivableSupervisePremium(): BigDecimal.ZERO;
 //                BigDecimal overinflatedAmount = action.getOverinflatedAmount() != null? action.getOverinflatedAmount(): BigDecimal.ZERO;
 //                BigDecimal overinflatedAmount = action.getOverinflatedAmount() != null? action.getOverinflatedAmount(): BigDecimal.ZERO;
                 // 待结算金额 = 开票金额 - 已收金额
                 // 待结算金额 = 开票金额 - 已收金额
@@ -4052,6 +4116,9 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 action.setRemainSettlementAmount(remainSettlementAmount);
                 action.setRemainSettlementAmount(remainSettlementAmount);
                 action.setCompanyAllName(allCompanyHierarchyPaths.get(Objects.toString(action.getCompanyId(),"")));
                 action.setCompanyAllName(allCompanyHierarchyPaths.get(Objects.toString(action.getCompanyId(),"")));
                 action.setSettlementStatus(settlementStatusName);
                 action.setSettlementStatus(settlementStatusName);
+                // 回款差额
+                action.setSettlementPaymentDifference(settlementPaymentDifference);
+
                 if ("2".equals(invoiceRecordQueryVo.getInvoiceType())) {
                 if ("2".equals(invoiceRecordQueryVo.getInvoiceType())) {
                     LambdaQueryWrapper<InsFeeFollowOrder> insFeeFollowOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
                     LambdaQueryWrapper<InsFeeFollowOrder> insFeeFollowOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
                     insFeeFollowOrderLambdaQueryWrapper.eq(InsFeeFollowOrder::getYear, action.getYear());
                     insFeeFollowOrderLambdaQueryWrapper.eq(InsFeeFollowOrder::getYear, action.getYear());
@@ -4412,18 +4479,60 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         }else{
         }else{
             exportSuperviseSettlementDetailExcelDtos = baseMapper.getSuperviseSettlementDetailExcelDtos(page, settlementQueryVo);
             exportSuperviseSettlementDetailExcelDtos = baseMapper.getSuperviseSettlementDetailExcelDtos(page, settlementQueryVo);
         }
         }
-        exportSuperviseSettlementDetailExcelDtos.getRecords().forEach(dto -> {
-            if (dto.getInvoiceParty().equals("1")) {
-                dto.setInvoiceParty("我方开票");
-            } else if (dto.getInvoiceParty().equals("2")) {
-                dto.setInvoiceParty("保司开票");
-            }
-            if (dto.getStatus().equals("1")) {
-                dto.setStatus("已结算");
-            } else if (dto.getStatus().equals("0")) {
-                dto.setStatus("未结算");
+        if (CollUtil.isNotEmpty(exportSuperviseSettlementDetailExcelDtos.getRecords())){
+            Map<String, InsPlyIncomeInvoiceSettlement> settlementMap = new HashMap<>();
+            if (!(settlementQueryVo.getInvoiceTypes().contains("5") && settlementQueryVo.getInvoiceTypes().contains("6"))) {
+                // 根据invoiceId关联查询ins_ply_income_invoice_settlement表
+                LambdaQueryWrapper<InsPlyIncomeInvoiceSettlement> insPlyIncomeInvoiceSettlementLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                insPlyIncomeInvoiceSettlementLambdaQueryWrapper.in(InsPlyIncomeInvoiceSettlement::getInvoiceId, exportSuperviseSettlementDetailExcelDtos.getRecords().stream().map(ExportSuperviseSettlementDetailExcelDto::getInvoiceId).toList());
+                insPlyIncomeInvoiceSettlementLambdaQueryWrapper.eq(InsPlyIncomeInvoiceSettlement::getIsDelete, 0);
+                if (StrUtil.isNotBlank(settlementQueryVo.getSettlementPerson())) {
+                    // 结算人
+                    insPlyIncomeInvoiceSettlementLambdaQueryWrapper.eq(InsPlyIncomeInvoiceSettlement::getCreateBy, settlementQueryVo.getSettlementPerson());
+                }
+                if (StrUtil.isNotBlank(settlementQueryVo.getSettlementTimeStart()) && StrUtil.isNotBlank(settlementQueryVo.getSettlementTimeEnd())) {
+                    // 结算时间
+                    insPlyIncomeInvoiceSettlementLambdaQueryWrapper.between(StrUtil.isNotBlank(settlementQueryVo.getSettlementTimeStart()) && StrUtil.isNotBlank(settlementQueryVo.getSettlementTimeEnd()),
+                            InsPlyIncomeInvoiceSettlement::getCreateTime, settlementQueryVo.getSettlementTimeStart(), settlementQueryVo.getSettlementTimeEnd());
+                }
+                List<InsPlyIncomeInvoiceSettlement> insPlyIncomeInvoiceSettlements = insPlyIncomeInvoiceSettlementMapper.selectList(insPlyIncomeInvoiceSettlementLambdaQueryWrapper);
+                // 如果结算记录不为空,且结算人、结算时间不为空,则根据结算记录的invoiceId过滤列表
+                if (CollUtil.isNotEmpty(insPlyIncomeInvoiceSettlements)) {
+                    if (StrUtil.isNotBlank(settlementQueryVo.getSettlementPerson()) || (StrUtil.isNotBlank(settlementQueryVo.getSettlementTimeStart()) && StrUtil.isNotBlank(settlementQueryVo.getSettlementTimeEnd()))) {
+                        List<String> invoiceList = insPlyIncomeInvoiceSettlements.stream().map(InsPlyIncomeInvoiceSettlement::getInvoiceId).toList();
+                        // filter:lambda 返回 true 的元素留下,false 的剔除
+                        exportSuperviseSettlementDetailExcelDtos.setRecords(exportSuperviseSettlementDetailExcelDtos.getRecords().stream().filter(detail -> invoiceList.contains(detail.getInvoiceId())).toList());
+                    }
+
+                    // 冲突时保留旧值(第一条)
+                    settlementMap = insPlyIncomeInvoiceSettlements.stream()
+                            .collect(Collectors.toMap(
+                                    InsPlyIncomeInvoiceSettlement::getInvoiceId,
+                                    Function.identity(),
+                                    (oldVal, newVal) -> oldVal
+                            ));
+                }
             }
             }
-        });
+
+            final Map<String, InsPlyIncomeInvoiceSettlement> finalSettlementMap = settlementMap;
+            exportSuperviseSettlementDetailExcelDtos.getRecords().forEach(dto -> {
+                if (dto.getInvoiceParty().equals("1")) {
+                    dto.setInvoiceParty("我方开票");
+                } else if (dto.getInvoiceParty().equals("2")) {
+                    dto.setInvoiceParty("保司开票");
+                }
+                if (dto.getStatus().equals("1")) {
+                    dto.setStatus("已结算");
+                } else if (dto.getStatus().equals("0")) {
+                    dto.setStatus("未结算");
+                }
+                InsPlyIncomeInvoiceSettlement insPlyIncomeInvoiceSettlement = finalSettlementMap.get(dto.getInvoiceId());
+                if (null != insPlyIncomeInvoiceSettlement){
+                    dto.setSettlementPerson(insPlyIncomeInvoiceSettlement.getCreateBy());
+                    dto.setSettlementTime(insPlyIncomeInvoiceSettlement.getCreateTime());
+                }
+            });
+        }
         return exportSuperviseSettlementDetailExcelDtos;
         return exportSuperviseSettlementDetailExcelDtos;
     }
     }
 
 
@@ -4643,22 +4752,14 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
     public void exportOtherSettlementExcel(Page page, SettlementQueryVo settlementQueryVo) throws IOException {
     public void exportOtherSettlementExcel(Page page, SettlementQueryVo settlementQueryVo) throws IOException {
         verifyUploadPath();
         verifyUploadPath();
         settlementQueryVo.setSystemCode(baseController.getSystemCode());
         settlementQueryVo.setSystemCode(baseController.getSystemCode());
-        Page<ExportOtherSettlementExcelDto> exportOtherSettlementExcelDtos = baseMapper.getOtherSettlementExcelDtos(page, settlementQueryVo);
-        exportOtherSettlementExcelDtos.getRecords().forEach(dto -> {
-            if (dto.getInvoiceParty().equals("1")) {
-                dto.setInvoiceParty("我方开票");
-            } else if (dto.getInvoiceParty().equals("2")) {
-                dto.setInvoiceParty("保司开票");
-            }
-            switch (dto.getInvoiceType()) {
-                case "1" -> dto.setInvoiceType("手续费");
-                case "2" -> dto.setInvoiceType("跟单费");
-                case "3" -> dto.setInvoiceType("驾意险手续费");
-                case "4" -> dto.setInvoiceType("驾意险跟单费");
-            }
-        });
-        List<ExportOtherSettlementExcelDto> list = exportOtherSettlementExcelDtos.getRecords();
-        EasyExcelUtils.exportForWeb(ServletUtils.getResponse(), ExportOtherSettlementExcelDto.class, list, "车险跟单费结算记录");
+        log.info("查询平台结算记录:settlementQueryVo=[{}]", JSONUtil.toJsonStr(settlementQueryVo));
+        // 设置空条件
+        setNoneCondition(settlementQueryVo);
+        settlementQueryVo.setSystemCode(baseController.getSystemCode());
+        Page<ExportSuperviseSettlementExcelDto> exportSuperviseSettlementExcelDtos = baseMapper.followSettlementExcelDtos(page, settlementQueryVo);
+        // 补充、转换列表的数据
+        supplementaryListData(exportSuperviseSettlementExcelDtos);
+        EasyExcelUtils.exportForWeb(ServletUtils.getResponse(), ExportSuperviseSettlementExcelDto.class, exportSuperviseSettlementExcelDtos.getRecords(), "车险跟单费结算记录");
     }
     }
 
 
     /**
     /**

+ 5 - 4
tenant/organization/src/main/resources/mapper/InsFeeFollowOrderMapper.xml

@@ -48,9 +48,11 @@
     <select id="selectFollowCompanySettlementReport" resultType="com.jzg.commons.entity.finance.vo.FollowCompanyFeeVO">
     <select id="selectFollowCompanySettlementReport" resultType="com.jzg.commons.entity.finance.vo.FollowCompanyFeeVO">
         SELECT
         SELECT
         ffo.partner_company_id AS partnerCompanyId,
         ffo.partner_company_id AS partnerCompanyId,
-        SUM(COALESCE(ffo.invoiced, 0.00)) AS totalInvoiced,
-        SUM(COALESCE(sett.actual_received_amount, 0.00)) AS totalSettlementAmount,
-        MAX(COALESCE(ffo.reconciliation_amount, 0.00)) AS totalReceivable
+        ffo.id AS followId,
+        ffo.year,
+        ffo.month,
+        inv.id AS invoiceId,
+        sett.id AS settlementId
         FROM ins_fee_follow_order ffo
         FROM ins_fee_follow_order ffo
         -- 跟单订单关联发票中间表
         -- 跟单订单关联发票中间表
         INNER JOIN ins_ply_follow_invoice_link link
         INNER JOIN ins_ply_follow_invoice_link link
@@ -84,7 +86,6 @@
                 AND sett.create_time BETWEEN #{query.settlementStartTime} AND #{query.settlementEndTime}
                 AND sett.create_time BETWEEN #{query.settlementStartTime} AND #{query.settlementEndTime}
             </if>
             </if>
         </where>
         </where>
-        GROUP BY ffo.partner_company_id
     </select>
     </select>
 
 
 
 

+ 20 - 14
tenant/organization/src/main/resources/mapper/PtlAgreementMapper.xml

@@ -62,6 +62,25 @@
         pa.api_type,pa.jq_entrance_fee_ratio,pa.sy_entrance_fee_ratio,pa.jy_entrance_fee_ratio
         pa.api_type,pa.jq_entrance_fee_ratio,pa.sy_entrance_fee_ratio,pa.jy_entrance_fee_ratio
     </sql>
     </sql>
     <select id="queryPage" resultType="com.jzg.commons.entity.vo.AgreementVo">
     <select id="queryPage" resultType="com.jzg.commons.entity.vo.AgreementVo">
+        WITH RECURSIVE t AS (
+        SELECT
+        id,
+        CAST(id AS CHAR) COLLATE utf8mb4_general_ci AS str_id
+        FROM
+        esm_ins_company
+        WHERE
+        id = #{param.companyId}
+        AND is_delete = 0
+        AND parent_id = 0 UNION ALL
+        SELECT
+        c.id,
+        CAST(c.id AS CHAR) COLLATE utf8mb4_general_ci AS str_id
+        FROM
+        esm_ins_company c
+        JOIN t ON c.parent_id = t.id
+        WHERE
+        c.is_delete = 0
+        )
         select <include refid="Base_Column_List"/>
         select <include refid="Base_Column_List"/>
         FROM ptl_agreement pa
         FROM ptl_agreement pa
         LEFT JOIN ptl_agreement_attribution paa on pa.attribution_id = paa.id AND paa.is_delete = 0
         LEFT JOIN ptl_agreement_attribution paa on pa.attribution_id = paa.id AND paa.is_delete = 0
@@ -80,20 +99,7 @@
                 and pa.system_code = #{param.systemCode}
                 and pa.system_code = #{param.systemCode}
             </if>
             </if>
             <if test="param.companyId != null and param.companyId != ''">
             <if test="param.companyId != null and param.companyId != ''">
-                and pa.company_id in (
-                WITH RECURSIVE t AS (
-                SELECT id
-                FROM esm_ins_company
-                WHERE id = #{param.companyId}
-                AND parent_id = 0
-                AND is_delete = 0
-                UNION ALL
-                SELECT c.id
-                FROM esm_ins_company c
-                JOIN t ON c.parent_id = t.id
-                WHERE c.is_delete = 0
-                )
-                SELECT id FROM t)
+                AND pa.company_id IN (SELECT str_id FROM t)
             </if>
             </if>
             <if test="param.companyIds != null and param.companyIds != ''">
             <if test="param.companyIds != null and param.companyIds != ''">
                 and pa.company_id in
                 and pa.company_id in

+ 7 - 29
tenant/organization/src/main/resources/mapper/ReceivableMapper.xml

@@ -876,10 +876,9 @@
 
 
     <select id="getSuperviseSettlementDetailExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseSettlementDetailExcelDto">
     <select id="getSuperviseSettlementDetailExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseSettlementDetailExcelDto">
         select ipi.contact_person, ipi.contact_person_phone,
         select ipi.contact_person, ipi.contact_person_phone,
-        ipiis.id as settlementId,
-        ipiis.invoice_id as invoiceId,
         io.company_name as companyName,
         io.company_name as companyName,
         io.signing_time as signingTime,
         io.signing_time as signingTime,
+        ipii.id as invoiceId,
         ipii.status as status,
         ipii.status as status,
         ipi.license_no as licenseNo,
         ipi.license_no as licenseNo,
         io.product_name as productName,
         io.product_name as productName,
@@ -896,29 +895,14 @@
         ipi.jy_premium as jyPremium,
         ipi.jy_premium as jyPremium,
         ipi.jy_supervise_costs_proportion as jySuperviseCostsProportion,
         ipi.jy_supervise_costs_proportion as jySuperviseCostsProportion,
         ipi.jy_policy_no as jyPolicyNo,
         ipi.jy_policy_no as jyPolicyNo,
-        ipi.tax_premium as taxPremium,
-        ipii.create_by as invoicePerson,
-        ipii.create_time as invoiceTime,
-        ipiis.create_by as settlementPerson,
-        ipiis.create_time as settlementTime
-        FROM
-        ins_ply_income_invoice ipii
-        LEFT JOIN ins_ply_income_invoice_settlement ipiis ON ipiis.invoice_id = ipii.id AND ipiis.is_delete = 0
-        LEFT JOIN ins_ply_income_invoice_link ipil ON ipil.invoice_id = ipiis.invoice_id AND ipil.is_delete = 0
-        LEFT JOIN ins_ply_income ipi ON ipi.id = ipil.income_id AND ipi.is_delete = 0
-        LEFT JOIN ins_orders io ON ipi.order_no = io.id AND io.is_delete = 0
+        ipi.tax_premium as taxPremium
+        FROM ins_ply_income_invoice ipii
+        LEFT JOIN ins_ply_income_invoice_link ipil ON ipii.id = ipil.invoice_id AND ipil.is_delete = 0
+        LEFT JOIN ins_ply_income ipi ON ipi.id = ipil.income_id  AND ipi.is_delete = 0
+        LEFT JOIN ins_orders io  ON ipi.order_no = io.id  AND io.is_delete = 0
         <where>
         <where>
             ipii.is_delete = 0
             ipii.is_delete = 0
             AND ipii.system_code = #{settlementQueryVo.systemCode}
             AND ipii.system_code = #{settlementQueryVo.systemCode}
-            <if test="settlementQueryVo.settlementId != null and settlementQueryVo.settlementId != ''">
-                AND ipiis.id = #{settlementQueryVo.settlementId}
-            </if>
-            <if test="settlementQueryVo.settlementIds != null and settlementQueryVo.settlementIds != ''">
-                AND ipiis.id IN
-                <foreach collection="settlementQueryVo.settlementIds" item="settlementId" open="(" separator="," close=")">
-                    #{settlementId}
-                </foreach>
-            </if>
             <if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
             <if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
                 AND ipii.invoice_type IN
                 AND ipii.invoice_type IN
                 <foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
                 <foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
@@ -926,7 +910,7 @@
                 </foreach>
                 </foreach>
             </if>
             </if>
             <if test="settlementQueryVo.invoiceId != null and settlementQueryVo.invoiceId != ''">
             <if test="settlementQueryVo.invoiceId != null and settlementQueryVo.invoiceId != ''">
-                AND ipiis.invoice_id = #{settlementQueryVo.invoiceId}
+                AND ipii.id = #{settlementQueryVo.invoiceId}
             </if>
             </if>
             <if test="settlementQueryVo.companyId != null and settlementQueryVo.companyId != ''">
             <if test="settlementQueryVo.companyId != null and settlementQueryVo.companyId != ''">
                 AND ipi.company_id = #{settlementQueryVo.companyId}
                 AND ipi.company_id = #{settlementQueryVo.companyId}
@@ -934,12 +918,6 @@
             <if test="settlementQueryVo.invoiceParty != null and settlementQueryVo.invoiceParty != ''">
             <if test="settlementQueryVo.invoiceParty != null and settlementQueryVo.invoiceParty != ''">
                 AND ipii.invoice_party = #{settlementQueryVo.invoiceParty}
                 AND ipii.invoice_party = #{settlementQueryVo.invoiceParty}
             </if>
             </if>
-            <if test="settlementQueryVo.settlementPerson != null and settlementQueryVo.settlementPerson != ''">
-                AND ipiis.create_by = #{settlementQueryVo.settlementPerson}
-            </if>
-            <if test="settlementQueryVo.settlementTimeStart != null and settlementQueryVo.settlementTimeStart != ''">
-                AND ipiis.create_time between #{settlementQueryVo.signingTimeStart} and #{settlementQueryVo.signingTimeEnd}
-            </if>
             <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
             <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
                 AND ipi.agreement_type = #{settlementQueryVo.agreementType}
                 AND ipi.agreement_type = #{settlementQueryVo.agreementType}
             </if>
             </if>