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

私有协议应收-开票记录保险公司展示层级关系

lipf 4 месяцев назад
Родитель
Сommit
0acf54d1dd

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

@@ -23,6 +23,11 @@ public class InvoiceRecordResult extends PageRequest {
      */
     private String companyName;
 
+    /**
+     * 保险公司名称及父级的名称,例如
+     */
+    private String companyALlName;
+
     /**
      * 开票方
      */

+ 4 - 0
commons/src/main/java/com/jzg/commons/entity/po/EsmInsCompany.java

@@ -6,11 +6,15 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.jzg.commons.core.base.BaseModel;
 import lombok.Data;
+
+import java.io.Serial;
 import java.util.List;
 @TableName(value = "esm_ins_company")
 @Data
 public class EsmInsCompany extends BaseModel {
 
+    @Serial
+    private static final long serialVersionUID = 3082765270221772930L;
     @TableId(type = IdType.ASSIGN_ID)
     private String id;
 

+ 10 - 0
platform/src/main/java/com/jzg/controller/EsmInsCompanyController.java

@@ -455,4 +455,14 @@ public class EsmInsCompanyController extends BaseController {
         return HttpResult.ok(esmInsCompanyService.getTopCompanyId(companyId));
     }
 
+    /**
+     * 获取所有保险公司的全路径名称
+     * Key: 公司ID
+     * Value: 总公司/分公司/支公司
+     */
+    @Operation(summary = "获取所有保险公司的全路径名称")
+    @GetMapping("getAllCompanyHierarchyPaths")
+    public Map<String, String> getAllCompanyHierarchyPaths(){
+        return esmInsCompanyService.getAllCompanyHierarchyPaths();
+    }
 }

+ 8 - 0
platform/src/main/java/com/jzg/service/EsmInsCompanyService.java

@@ -9,6 +9,7 @@ import com.jzg.commons.entity.vo.EsmInsCompanyVo;
 
 
 import java.util.List;
+import java.util.Map;
 
 public interface EsmInsCompanyService extends IService<EsmInsCompany> {
 
@@ -144,6 +145,13 @@ public interface EsmInsCompanyService extends IService<EsmInsCompany> {
      * @return
      */
     String getTopCompanyId(String companyId);
+
+    /**
+     * 获取所有保险公司的全路径名称
+     * Key: 公司ID
+     * Value: 总公司/分公司/支公司
+     */
+    public Map<String, String> getAllCompanyHierarchyPaths();
 }
 
 

+ 71 - 0
platform/src/main/java/com/jzg/service/impl/EsmInsCompanyServiceImpl.java

@@ -359,6 +359,77 @@ public class EsmInsCompanyServiceImpl extends ServiceImpl<EsmInsCompanyMapper, E
     public String getTopCompanyId(String companyId) {
         return baseMapper.getTopCompanyId(companyId);
     }
+
+    /**
+     * 获取所有保险公司的全路径名称
+     * Key: 公司ID
+     * Value: 总公司/分公司/支公司
+     */
+    public Map<String, String> getAllCompanyHierarchyPaths() {
+        log.info("获取所有保险公司的全路径名称");
+        // 1. 查询所有未删除的保险公司(一次性加载,避免循环查库)
+        List<EsmInsCompany> allCompanies = baseMapper.selectList(null);
+        allCompanies = allCompanies.stream().filter(action->action.getIsDelete()==0).toList();
+
+        // 2. 将列表转换为 Map,以便通过 ID 快速查找对象 (ID -> Company Object)
+        Map<String, EsmInsCompany> companyMap = allCompanies.stream()
+                .collect(Collectors.toMap(EsmInsCompany::getId, c -> c));
+
+        // 3. 结果缓存 Map (ID -> "A/B/C" Path)
+        // 使用 ConcurrentHashMap 或者普通 HashMap 均可,视并发需求而定
+        Map<String, String> pathCache = new HashMap<>();
+
+        // 4. 遍历所有公司,构建路径
+        for (EsmInsCompany company : allCompanies) {
+            buildPath(company.getId(), companyMap, pathCache);
+        }
+        log.info("构建得到的公司的层级结构如下: [{}]", JSONUtil.toJsonStr(pathCache));
+        return pathCache;
+    }
+
+    /**
+     * 递归构建单个公司的路径(带缓存优化,防止重复计算)
+     */
+    private String buildPath(String currentId, Map<String, EsmInsCompany> companyMap, Map<String, String> pathCache) {
+        // 如果已经计算过,直接返回(记忆化搜索,防止重复递归)
+        if (pathCache.containsKey(currentId)) {
+            return pathCache.get(currentId);
+        }
+
+        EsmInsCompany currentCompany = companyMap.get(currentId);
+        if (currentCompany == null) {
+            return "";
+        }
+
+        // 获取父级 ID
+        String parentId = currentCompany.getParentId();
+
+        String fullPath;
+
+        // 判断是否有父级 (根据数据库设计,根节点的 parent_id 通常为 0 或 null)
+        if (parentId == null || parentId.equals("0")) {
+            // 如果是根节点,路径就是它自己的名字
+            //fullPath = currentCompany.getName();
+            fullPath = currentCompany.getNameSimple();
+        } else {
+            // 如果有父级,递归获取父级的路径,然后拼接当前名字
+            // 注意:这里递归调用 buildPath,利用缓存避免死循环和重复计算
+            String parentPath = buildPath(parentId, companyMap, pathCache);
+
+            if (parentPath.isEmpty()) {
+                //fullPath = currentCompany.getName();
+                fullPath = currentCompany.getNameSimple();
+            } else {
+                //fullPath = parentPath + "/" + currentCompany.getName();
+                fullPath = parentPath + "/" + currentCompany.getNameSimple();
+            }
+        }
+
+        // 存入缓存
+        pathCache.put(currentId, fullPath);
+        return fullPath;
+    }
+
 }
 
 

+ 9 - 0
tenant/organization/src/main/java/com/jzg/organization/client/EsmInsCompanyClient.java

@@ -9,11 +9,20 @@ import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Map;
 
 @FeignClient(name = "jzg-platform")
 public interface EsmInsCompanyClient {
 
 
+    /**
+     * 获取所有保险公司的全路径名称
+     * Key: 公司ID
+     * Value: 总公司/分公司/支公司
+     */
+    @GetMapping("esmInsCompany/getAllCompanyHierarchyPaths")
+    public Map<String, String> getAllCompanyHierarchyPaths();
+
     /**
      * 根据id获取保险公司信息
      *

+ 2 - 0
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -1194,6 +1194,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         Page<InvoiceRecordResult> invoiceRecordList = baseMapper.getInvoiceRecordList(invoiceRecordQueryVo.getPage(), invoiceRecordQueryVo);
         List<InvoiceRecordResult> records = invoiceRecordList.getRecords();
         if(CollUtil.isNotEmpty(records)){
+            Map<String, String> allCompanyHierarchyPaths = esmInsCompanyClient.getAllCompanyHierarchyPaths();
             records = records.stream().peek(action->{
                 String settlementStatusName = Constant.settlementStatusMap.get(Objects.toString(action.getStatus(),""));
                 action.setSettlementStatusName(settlementStatusName);
@@ -1212,6 +1213,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 action.setSettlementAmount(settlementAmount);
                 // 设置待结算金额
                 action.setRemainSettlementAmount(remainSettlementAmount);
+                action.setCompanyALlName(allCompanyHierarchyPaths.get(Objects.toString(action.getCompanyId(),"")));
             }).toList();
             invoiceRecordList.setRecords(records);
         }