浏览代码

Merge branch 'dev_jzg_lipf_v20260622'

lipf 1 月之前
父节点
当前提交
8e32192b07

+ 28 - 13
commons/src/main/java/com/jzg/commons/entity/finance/dto/CompanySuperviseSettlementReportDto.java

@@ -2,7 +2,6 @@ package com.jzg.commons.entity.finance.dto;
 
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
-import lombok.NoArgsConstructor;
 
 import java.io.Serial;
 import java.io.Serializable;
@@ -14,22 +13,44 @@ import java.util.List;
  */
 
 @Data
-@NoArgsConstructor
 public class CompanySuperviseSettlementReportDto implements Serializable {
 
 
+    public CompanySuperviseSettlementReportDto(){
+
+    }
+
+    public CompanySuperviseSettlementReportDto(String companyId,String secondCompanyId,String partnerCompanyId) {
+        this.companyId = companyId;
+        this.secondCompanyId = secondCompanyId;
+        this.partnerCompanyId = partnerCompanyId;
+    }
+
+    @Schema(description = "支公司保险公司Id")
+    private String id;
+
+    @Schema(description = "上级公司ID")
+    private String parentId; // 必须加!构建树形结构需要
+
+
     @Serial
     private static final long serialVersionUID = -2428003756552348627L;
-    @Schema(description = "保险公司Id")
+    @Schema(description = "总公司保险公司Id")
     private String companyId;
+
+    @Schema(description = "二级保险公司Id")
+    private String secondCompanyId;
+
+    @Schema(description = "支公司保险公司Id(三级)")
+    private String partnerCompanyId;
+
+    @Schema(description = "支公司保险公司名称")
+    private String partnerCompanyName;
+
     @Schema(description = "对接人手机号")
     private String contactPersonPhone;
 
-    @Schema(description = "保险公司Id")
-    private String id;
 
-    @Schema(description = "上级公司ID")
-    private String parentId; // 必须加!构建树形结构需要
 
     @Schema(description = "保险公司")
     private String companyName;
@@ -87,10 +108,4 @@ public class CompanySuperviseSettlementReportDto implements Serializable {
     private List<CompanySuperviseSettlementReportDto> children;
 
 
-    public CompanySuperviseSettlementReportDto(String companyId, String companyName, String parentId) {
-        this.companyId = companyId;
-        this.id = companyId;
-        this.parentId= parentId;
-        this.companyName  =  companyName;
-    }
 }

+ 19 - 0
commons/src/main/java/com/jzg/commons/entity/finance/dto/TreeKeyVO.java

@@ -0,0 +1,19 @@
+package com.jzg.commons.entity.finance.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+public class TreeKeyVO implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1740250395933872139L;
+    private String id;
+
+    private String parentId;
+
+}

+ 109 - 74
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -404,12 +404,11 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         if("5".equals(incomeDataVO.getInvoiceType()) || "6".equals(incomeDataVO.getInvoiceType())){
             incomeDataVO.setAgreementType("1");
         }
+
         List<InsPlyIncome> incomes =  baseMapper.queryIncomeDatasByOrderIds(orderNos,companyId,incomeDataVO.getInvoiceType(),incomeDataVO.getAgreementType());
-        log.info("根据订单号和保司id查询出[{}]条记录。 orderNos =[{}],companyId=[{}]",CollUtil.size(incomes), JSONUtil.toJsonStr(orderNos), companyId);
+        log.info("根据订单号查询出[{}]条记录。 orderNos =[{}]",CollUtil.size(incomes), JSONUtil.toJsonStr(orderNos));
         // 需要查询未结算的数据 modify by lipf 2026年6月4日11:06:50
-        incomes = incomes.stream().filter(action->{
-            return "0".equals(action.getSettlementStatus());
-        }).toList();
+        incomes = incomes.stream().filter(action-> "0".equals(action.getSettlementStatus())).toList();
         List<InsPlyIncome> filterIncomes = new ArrayList<>();
         if(CollUtil.isEmpty(incomeDataVO.getSearchList())){
             filterIncomes = incomes;
@@ -5726,14 +5725,12 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         // 1. 先将有数据的保险公司进行汇总
         // 累计应收金额, 应收手续费(手续费)
         List<CompanySuperviseSettlementReportDto> allCompaniesIncomeDatas = baseMapper.queryCumulativeAccountsReceivable(systemCode, queryVo);
+
+//        allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().filter(action->{
+//            return "1738811735599312496".equals(action.getPartnerCompanyId());
+//        }).toList();
         // 结算状态在上面的sql进行过筛选了,后面就不再筛选了
         queryVo.setStatus(null);
-//        if("20".equals(queryVo.getAccountsReceivable())){
-//            allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action->{
-//                // 统计非车的手续费
-//                action.setSuperviseFee(action.getSuperviseFee4Other());
-//            }).toList();
-//        }
 
         // 车险
         if("10".equals(queryVo.getAccountsReceivable())){
@@ -5750,11 +5747,6 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 action.setSuperviseFee(BigDecimalUtil.add(action.getSuperviseFee(), action.getSuperviseFee4Other()));
             }).toList();
         }
-
-        // for test, 查看一家公司的数据,将不可变对象变成 可变对象
-//        allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().filter(action-> "1738811735599338932".equals(action.getCompanyId())).toList();
-//        allCompaniesIncomeDatas = new ArrayList<>(allCompaniesIncomeDatas);
-
         // 直接从allCompaniesIncomeDatas获取到incomeId,然后过滤数据
         List<InsPlyIncomeDto> dtoList = allCompaniesIncomeDatas.stream()
                 .map(CompanySuperviseSettlementReportDto::getId)
@@ -5768,20 +5760,16 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         List<InsPlyIncomeDto> filterIncomeList = filterIncomeByInvoiceAndSettleCondition(dtoList, queryVo);
         allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().filter(all -> filterIncomeList.stream().anyMatch(x -> x.getId().equals(all.getId()))).toList();
 
-        // 将allCompaniesIncomeDatas中相同的companyId的totalReceivable、totalFollowFee、superviseFee、followFee数据相加,并只保留一条
         // 按公司ID分组聚合求和
         Map<String, List<CompanySuperviseSettlementReportDto>> groupByCompany = allCompaniesIncomeDatas.stream()
-                .collect(Collectors.groupingBy(CompanySuperviseSettlementReportDto::getCompanyId));
+                .collect(Collectors.groupingBy(CompanySuperviseSettlementReportDto::getPartnerCompanyId));
 
         // 聚合结果集合
         List<CompanySuperviseSettlementReportDto> resultList = new ArrayList<>();
         for (Map.Entry<String, List<CompanySuperviseSettlementReportDto>> entry : groupByCompany.entrySet()) {
             List<CompanySuperviseSettlementReportDto> groupList = entry.getValue();
-            CompanySuperviseSettlementReportDto sumDto = new CompanySuperviseSettlementReportDto();
-            // 赋值固定字段(取第一条即可)
-            sumDto.setCompanyId(entry.getKey());
-            CompanySuperviseSettlementReportDto first = groupList.get(0);
-            sumDto.setCompanyName(first.getCompanyName());
+            CompanySuperviseSettlementReportDto firstReportDto = groupList.get(0);
+            CompanySuperviseSettlementReportDto sumDto = new CompanySuperviseSettlementReportDto(firstReportDto.getCompanyId(), firstReportDto.getSecondCompanyId(),firstReportDto.getPartnerCompanyId());
             // 数值累加
             BigDecimal totalReceivable = groupList.stream()
                     .map(x -> new BigDecimal(x.getTotalReceivable()))
@@ -5792,13 +5780,12 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
             sumDto.setTotalReceivable(totalReceivable.toString());
             sumDto.setSuperviseFee(superviseFee.toString());
-            sumDto.setParentId(first.getParentId());
             resultList.add(sumDto);
         }
         // 最终聚合完成的数据
         allCompaniesIncomeDatas = resultList;
 
-        allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action-> action.setId(action.getCompanyId())).toList();
+        allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action-> action.setId(action.getPartnerCompanyId())).toList();
 
         if (CollUtil.isEmpty(allCompaniesIncomeDatas)) {
             String msg = String.format("租户%s下暂时没有手续费",systemCode);
@@ -5806,9 +5793,10 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             return HttpResult.ok(msg, Collections.emptyList());
         }
         // add by lipf, 前端保险公司的查询条件未生效,进行bug修复
+        // TODO 这里需要都支持
         if(StrUtil.isNotEmpty(queryVo.getCompanyId())){
             allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream()
-                    .filter(action-> queryVo.getCompanyId().equals(action.getCompanyId())).toList();
+                    .filter(action-> queryVo.getCompanyId().equals(action.getPartnerCompanyId())).toList();
         }
         // 2. 汇总后,计算得到已开票,未开票,已结算,未结算的数据
         allCompaniesIncomeDatas = this.calStatisAmount(allCompaniesIncomeDatas, queryVo, systemCode);
@@ -5822,9 +5810,9 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
 
         // 3. 填充保险公司的父级保险公司
         allCompaniesIncomeDatas = this.fillParentCompany(allCompaniesIncomeDatas);
-        log.info("构建树形结构之前的数据:allCompaniesIncomeDatas=[{}]", JSONUtil.toJsonStr(allCompaniesIncomeDatas));
+        log.info("构建树形结构之前的数据:allCompaniesIncomeDatas.size=[{}]", CollUtil.size(allCompaniesIncomeDatas));
         // 4. 构建树型结构
-        List<Tree<String>> roots = buildTree(allCompaniesIncomeDatas);
+        List<Tree<String>> roots = this.buildTree(allCompaniesIncomeDatas);
         return HttpResult.ok(roots);
     }
 
@@ -5875,14 +5863,14 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         Map<String, CompanySuperviseSettlementReportDto> companyMap;
         companyMap = allCompaniesIncomeDatas.stream()
                                     .peek(action->{
-                                        EsmInsCompany esmInsCompany = bsMap.get(action.getCompanyId());
+                                        EsmInsCompany esmInsCompany = bsMap.get(action.getPartnerCompanyId());
                                         if(esmInsCompany != null){
                                             action.setCompanyName(esmInsCompany.getNameSimple());
                                         }else{
-                                            action.setCompanyName(action.getCompanyId());
+                                            action.setCompanyName(action.getPartnerCompanyId());
                                         }
                                     }).collect(Collectors.toMap(
-                                            CompanySuperviseSettlementReportDto::getCompanyId,
+                                            CompanySuperviseSettlementReportDto::getPartnerCompanyId,
                                             Function.identity(),
                                             (a, b) -> a
                                     ));
@@ -5929,7 +5917,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             BigDecimal sxfS = sxfSettledAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
             BigDecimal overinflatedAmount = sxfOverinflatedAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
             companySuperviseSettlementReportDto.setSxfSettledAmount(Objects.toString(sxfS, BigDecimal.ZERO+""));
-            companySuperviseSettlementReportDto.setSxfUnSettledAmount(BigDecimalUtil.subtract(sxf,BigDecimalUtil.add(sxfS,sxfSettledDiffAmountMap.getOrDefault(companyId, BigDecimal.ZERO))).toString());
+            companySuperviseSettlementReportDto.setSxfUnSettledAmount(BigDecimalUtil.subtract(sxf,BigDecimalUtil.subtract(sxfS,sxfSettledDiffAmountMap.getOrDefault(companyId, BigDecimal.ZERO))).toString());
             companySuperviseSettlementReportDto.setTotalOverinflatedAmount(Objects.toString(overinflatedAmount, BigDecimal.ZERO+""));
             companySuperviseSettlementReportDto.setSettlementPaymentDifference(Objects.toString(sxfSettledDiffAmountMap.getOrDefault(companyId, BigDecimal.ZERO)) );
             // 当起始日期有值的时候,计算的没有意义
@@ -5944,6 +5932,21 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         return new ArrayList<>(companyMap.values().stream().toList());
     }
 
+    /**
+     * 通用金额汇总方法
+     * @param list 数据列表
+     * @param getter 获取字段值的函数
+     * @return 汇总后的金额字符串
+     */
+    private String sumAmount(List<CompanySuperviseSettlementReportDto> list,
+                             Function<CompanySuperviseSettlementReportDto, String> getter) {
+        return list.stream()
+                .map(getter)
+                .filter(Objects::nonNull)
+                .map(BigDecimal::new)
+                .reduce(BigDecimal.ZERO, BigDecimal::add)
+                .toString();
+    }
 
     /**
      * 填充父级保司信息
@@ -5969,55 +5972,88 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         HttpResult<Map<String, EsmInsCompany>> allCompanyMapRes = esmInsCompanyClient.queryAllCompanyMap();
         Map<String, EsmInsCompany> companys = allCompanyMapRes.getData();
 
-//        // 填充保险公司的, 这里保险公司最多三级
-        List<CompanySuperviseSettlementReportDto> secondCompanyList = new ArrayList<>();
-        Set<String> existCompanyIds = allCompaniesIncomeDatas.stream().map(CompanySuperviseSettlementReportDto::getCompanyId).collect(Collectors.toSet());
-
-        for (CompanySuperviseSettlementReportDto thirdCompany : allCompaniesIncomeDatas) {
-            if(!"0".equals(thirdCompany.getParentId()) && !existCompanyIds.contains(thirdCompany.getParentId()) ){
-                String companyName = thirdCompany.getParentId();
-                EsmInsCompany esmInsCompany = companys.get(thirdCompany.getParentId());
-                if(esmInsCompany != null){
-                    companyName = esmInsCompany.getNameSimple();
-                    secondCompanyList.add(new CompanySuperviseSettlementReportDto(thirdCompany.getParentId(),companyName,esmInsCompany.getParentId()));
-                    log.info("====获取保险公司的名称:[{}]-[{}]",thirdCompany.getParentId(),companyName);
-                }
-
-            }
-        }
-        List<CompanySuperviseSettlementReportDto> firstCompanyList = new ArrayList<>();
-        for (CompanySuperviseSettlementReportDto secondCompany : secondCompanyList) {
-            EsmInsCompany pp = companys.get(secondCompany.getCompanyId());
-            if(pp != null){
-                String parentId = pp.getParentId();
-                String companyName;
-                EsmInsCompany firstCompany = companys.get(parentId);
-                if(firstCompany != null){
-                    companyName = firstCompany.getNameSimple();
-                    firstCompanyList.add(new CompanySuperviseSettlementReportDto(firstCompany.getId(),companyName,firstCompany.getParentId()));
-                    log.info("====获取保险公司的名称:[{}]-[{}]",firstCompany.getId(),companyName);
-                }
-            }
-        }
-        if(CollUtil.isNotEmpty(secondCompanyList)){
-            allCompaniesIncomeDatas.addAll(secondCompanyList);
-        }
-        if(CollUtil.isNotEmpty(firstCompanyList)){
-            allCompaniesIncomeDatas.addAll(firstCompanyList);
+        allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action->{
+            // 第三级别
+            action.setId(action.getPartnerCompanyId());
+            action.setParentId(action.getSecondCompanyId());
+        }).toList();
+        List<CompanySuperviseSettlementReportDto> result = new ArrayList<>(allCompaniesIncomeDatas);
+        Map<String, List<CompanySuperviseSettlementReportDto>> secondCompanys = allCompaniesIncomeDatas.stream().collect(Collectors.groupingBy(CompanySuperviseSettlementReportDto::getSecondCompanyId));
+        for (Map.Entry<String, List<CompanySuperviseSettlementReportDto>> entry : secondCompanys.entrySet()) {
+            String secondCompanyId = entry.getKey(); // 获取 Map 的键
+            List<CompanySuperviseSettlementReportDto> reportList = entry.getValue(); // 获取对应的 List
+            CompanySuperviseSettlementReportDto dto = fillReportDto4Money(reportList);
+            dto.setId(secondCompanyId);
+            dto.setParentId(reportList.get(0).getCompanyId());
+            result.add(dto);
+        }
+
+        Map<String, List<CompanySuperviseSettlementReportDto>> firstCompanys = allCompaniesIncomeDatas.stream().collect(Collectors.groupingBy(CompanySuperviseSettlementReportDto::getCompanyId));
+        for (Map.Entry<String, List<CompanySuperviseSettlementReportDto>> entry : firstCompanys.entrySet()) {
+            List<CompanySuperviseSettlementReportDto> reportList = entry.getValue(); // 获取对应的 List
+            CompanySuperviseSettlementReportDto dto = fillReportDto4Money(reportList);
+            dto.setParentId("0");
+            dto.setId(reportList.get(0).getCompanyId());
+            result.add(dto);
         }
         log.info("填充父级目录后,保险公司级别的数据[{}]条,原先的数据条数是[{}]条", CollUtil.size(allCompaniesIncomeDatas),count);
-        allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream()
+        result = result.stream()
                 .peek(action->{
-                    EsmInsCompany esmInsCompany = companys.get(action.getCompanyId());
+                    EsmInsCompany esmInsCompany = companys.get(action.getId());
                     if(esmInsCompany != null){
                         action.setCompanyName(esmInsCompany.getNameSimple());
                     }else{
                         action.setCompanyName(action.getCompanyId());
                     }
                 }).toList();
-//        var res = allCompaniesIncomeDatas.stream().map(CompanySuperviseSettlementReportDto::getCompanyName).toList();
-//        log.info("res=[{}]", JSONUtil.toJsonStr(res));
-        return allCompaniesIncomeDatas;
+        return result;
+
+    }
+
+    /**
+     * 对金额进行汇总求和
+     *
+     *
+     * @author lipf
+     * @date 2026/8/1 8:44
+     */
+    private CompanySuperviseSettlementReportDto fillReportDto4Money(List<CompanySuperviseSettlementReportDto> reportList) {
+        CompanySuperviseSettlementReportDto dto = new CompanySuperviseSettlementReportDto();
+        // 累计应收金额(手续费页面展示)
+        dto.setTotalReceivable(sumAmount(reportList, CompanySuperviseSettlementReportDto::getTotalReceivable));
+        // 累计应收金额(跟单费页面展示)
+        dto.setTotalFollowFee(sumAmount(reportList, CompanySuperviseSettlementReportDto::getTotalFollowFee));
+        // 应收手续费(车险)
+        dto.setSuperviseFee(sumAmount(reportList, CompanySuperviseSettlementReportDto::getSuperviseFee));
+        // 应收手续费(非车险)
+        dto.setSuperviseFee4Other(sumAmount(reportList, CompanySuperviseSettlementReportDto::getSuperviseFee4Other));
+        // 应收跟单费
+        dto.setFollowFee(sumAmount(reportList, CompanySuperviseSettlementReportDto::getFollowFee));
+        // 手续费已开票金额
+        dto.setSxfInvoicedAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getSxfInvoicedAmount));
+        // 手续费未开票金额
+        dto.setSxfUnInvoicedAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getSxfUnInvoicedAmount));
+        // 跟单费已开票金额
+        dto.setGdfInvoicedAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getGdfInvoicedAmount));
+        // 跟单费未开票金额
+        dto.setGdfUnInvoicedAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getGdfUnInvoicedAmount));
+        // 平台已开票金额
+        dto.setPtInvoicedAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getPtInvoicedAmount));
+        // 平台未开票金额
+        dto.setPtUnInvoicedAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getPtUnInvoicedAmount));
+        // 手续费已结算金额
+        dto.setSxfSettledAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getSxfSettledAmount));
+        // 手续费未结算金额
+        dto.setSxfUnSettledAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getSxfUnSettledAmount));
+        // 跟单费已结算金额
+        dto.setGdfSettledAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getGdfSettledAmount));
+        // 跟单费未结算金额
+        dto.setGdfUnSettledAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getGdfUnSettledAmount));
+        // 虚增金额合计
+        dto.setTotalOverinflatedAmount(sumAmount(reportList, CompanySuperviseSettlementReportDto::getTotalOverinflatedAmount));
+        // 回款差额合计
+        dto.setSettlementPaymentDifference(sumAmount(reportList, CompanySuperviseSettlementReportDto::getSettlementPaymentDifference));
+        return dto;
     }
 
     /**
@@ -6070,6 +6106,8 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             // 将原对象的其他属性放入扩展字段
             tree.putExtra("companyName",dto.getCompanyName());
             tree.putExtra("companyId",dto.getCompanyId());
+            tree.putExtra("partnerCompanyId",dto.getPartnerCompanyId());
+            tree.putExtra("partnerCompanyName",dto.getPartnerCompanyName());
             tree.putExtra("totalReceivable",dto.getTotalReceivable());
             tree.putExtra("totalFollowFee",dto.getTotalFollowFee());
             tree.putExtra("superviseFee",dto.getSuperviseFee());
@@ -6086,9 +6124,6 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             tree.putExtra("gdfUnSettledAmount",dto.getGdfUnSettledAmount());
             tree.putExtra("totalOverinflatedAmount",dto.getTotalOverinflatedAmount());
             tree.putExtra("settlementPaymentDifference",dto.getSettlementPaymentDifference());
-
-
-
         });
         log.info("树形结构构建:一级数据[{}]个", CollUtil.size(build));
         return build;

+ 17 - 23
tenant/organization/src/main/resources/mapper/ReceivableMapper.xml

@@ -256,7 +256,6 @@
         ipi.jq_receivable_premium,
         ipi.sy_receivable_premium,
         ipi.jy_receivable_premium,
-
         ipi.jq_supervise_costs_proportion,
         ipi.sy_supervise_costs_proportion,
         ipi.jy_supervise_costs_proportion,
@@ -272,9 +271,8 @@
         iop.jq_policy_no, -- 交强保单号
         iop.sy_policy_no, -- 商业保单号
         iop.jy_policy_no, -- 非车险保单号
-        io.company_name,
         io.company_id,
-        pa.partner_company_id,
+        ipi.partner_company_id,
         ipi.create_time,
         ipi.create_by,
         ipi.update_time,
@@ -311,7 +309,7 @@
     <select id="queryIncomeDatasByOrderIds" resultType="com.jzg.commons.entity.finance.po.InsPlyIncome">
         <include refid="query"/>
         <if test="companyId != null and companyId != ''">
-            AND io.company_id = #{companyId}
+            AND ipi.partner_company_id = #{companyId}
         </if>
         <if test="agreementType != null and agreementType != ''">
             and ipi.agreement_type = #{agreementType}
@@ -1391,20 +1389,13 @@
 
     <select id="getReceivableCompany" resultType="com.jzg.commons.entity.po.EsmInsCompany">
         SELECT
-        eic.id,
+        distinct eic.id,
         eic.company_code,
         eic.`name`
         FROM
         ins_ply_income ipi
-        left join ins_orders io
-        on
-        ipi.order_no = io.id
-        left join ptl_agreement pa
-        on
-        io.agreement_id = pa.id
         LEFT JOIN esm_ins_company eic
-        ON
-        pa.partner_company_id = eic.id
+        ON ipi.partner_company_id = eic.id
         AND eic.is_delete = 0
         <where>
             ipi.is_delete = 0
@@ -1979,17 +1970,18 @@
     </select>
     <select id="queryCumulativeAccountsReceivable"
             resultType="com.jzg.commons.entity.finance.dto.CompanySuperviseSettlementReportDto">
-        select
-        ipi.id,
-        eic.parent_id,
+        SELECT ipi.id,
         ipi.company_id,
+        eic.parent_id as secondCompanyId,
+        ipi.partner_company_id,
+        eic.name as partner_company_name,
         ipi.system_code,
-        sum(COALESCE(ipi.jq_receivable_premium, 0)+ COALESCE(ipi.sy_receivable_premium ,0)+coalesce(ipi.jy_receivable_premium ,0 )) as totalReceivable,
+        sum(COALESCE(ipi.jq_receivable_premium, 0) + COALESCE(ipi.sy_receivable_premium, 0) + coalesce(ipi.jy_receivable_premium, 0)) AS totalReceivable ,
         sum(coalesce(ipi.jy_supervise_costs_premiums, 0)) AS superviseFee4Other,
-        sum(COALESCE(ipi.jq_supervise_costs_premiums, 0) + COALESCE(ipi.sy_supervise_costs_premiums,0) ) AS superviseFee
+        sum(COALESCE(ipi.jq_supervise_costs_premiums, 0) + COALESCE(ipi.sy_supervise_costs_premiums, 0)) AS superviseFee
         from
         ins_ply_income ipi
-        left join esm_ins_company eic on eic.id = ipi.company_id AND eic.is_delete = 0
+        left join esm_ins_company eic on eic.id = ipi.partner_company_id AND eic.is_delete = 0
         <where>
             ipi.is_delete = 0
             and ipi.system_code = #{systemCode}
@@ -2015,8 +2007,11 @@
         ipi.id,
         eic.parent_id,
         ipi.company_id,
+        ipi.partner_company_id,
+        partner_company_name,
         ipi.system_code
-        having company_id is not null
+        having company_id is not null and partner_company_id is not null
+        order by company_id asc, parent_id asc, partner_company_id asc
     </select>
     <!-- 查询已开票金额 lipf 2026年6月1日17:58:42 -->
     <select id="queryInvoicedAmount" resultType="com.jzg.organization.entity.dto.CalRes">
@@ -2076,9 +2071,8 @@
         a.company_id ,
         sum(COALESCE(a.actual_received_amount, 0)) as settlement,sum(a.overinflatedAmount) overinflatedAmount
         from
-        (
-        select distinct ins.id,
-        ipi.company_id ,
+        ( select distinct ins.id,
+        ipi.partner_company_id as company_id,
         COALESCE(ins.actual_received_amount, 0) as actual_received_amount,
         COALESCE(ins.settlement_payment_difference,0) as overinflatedAmount
         from ins_ply_income_invoice_settlement ins