Bläddra i källkod

考核指标分类表

chenshudong 1 månad sedan
förälder
incheckning
8aa9150fea

+ 12 - 0
airport-admin/src/main/java/com/sundot/airport/web/controller/system/BasePerformanceIndicatorCategoryController.java

@@ -3,6 +3,8 @@ package com.sundot.airport.web.controller.system;
3 3
 import java.util.List;
4 4
 import javax.servlet.http.HttpServletResponse;
5 5
 
6
+import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeDTO;
7
+import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeRequestDTO;
6 8
 import org.springframework.security.access.prepost.PreAuthorize;
7 9
 import org.springframework.beans.factory.annotation.Autowired;
8 10
 import org.springframework.web.bind.annotation.GetMapping;
@@ -105,4 +107,14 @@ public class BasePerformanceIndicatorCategoryController extends BaseController {
105 107
         List<BasePerformanceIndicatorCategory> list = basePerformanceIndicatorCategoryService.selectBasePerformanceIndicatorCategoryList(basePerformanceIndicatorCategory);
106 108
         return success(list);
107 109
     }
110
+
111
+    /**
112
+     * 获取分类树及关联指标(支持模糊查询)
113
+     */
114
+    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:list')")
115
+    @PostMapping("/getCategoryTreeWithIndicatorList")
116
+    public AjaxResult getCategoryTreeWithIndicatorList(@RequestBody BasePerformanceIndicatorCategoryTreeRequestDTO requestDTO) {
117
+        List<BasePerformanceIndicatorCategoryTreeDTO> tree = basePerformanceIndicatorCategoryService.getCategoryTreeWithIndicatorList(requestDTO);
118
+        return AjaxResult.success(tree);
119
+    }
108 120
 }

+ 107 - 0
airport-system/src/main/java/com/sundot/airport/system/domain/BasePerformanceIndicatorCategoryTreeDTO.java

@@ -0,0 +1,107 @@
1
+package com.sundot.airport.system.domain;
2
+
3
+import com.fasterxml.jackson.annotation.JsonFormat;
4
+import lombok.Data;
5
+import org.springframework.format.annotation.DateTimeFormat;
6
+
7
+import java.util.ArrayList;
8
+import java.util.Date;
9
+import java.util.List;
10
+
11
+/**
12
+ * 考核指标分类树及关联指标对象
13
+ *
14
+ * @author ruoyi
15
+ * @date 2026-04-28
16
+ */
17
+@Data
18
+public class BasePerformanceIndicatorCategoryTreeDTO {
19
+
20
+    /**
21
+     * 主键
22
+     */
23
+    private Long id;
24
+    /**
25
+     * 编码
26
+     */
27
+    private String code;
28
+    /**
29
+     * 名称
30
+     */
31
+    private String name;
32
+    /**
33
+     * 父分类ID
34
+     */
35
+    private Long parentId;
36
+    /**
37
+     * 祖级列表
38
+     */
39
+    private String ancestors;
40
+    /**
41
+     * 排序
42
+     */
43
+    private Integer orderNum;
44
+    /**
45
+     * 层级
46
+     */
47
+    private Integer level;
48
+    /**
49
+     * 创建者
50
+     */
51
+    private String createBy;
52
+    /**
53
+     * 创建时间
54
+     */
55
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
56
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
57
+    private Date createTime;
58
+    /**
59
+     * 更新者
60
+     */
61
+    private String updateBy;
62
+    /**
63
+     * 更新时间
64
+     */
65
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
66
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
67
+    private Date updateTime;
68
+    /**
69
+     * 备注
70
+     */
71
+    private String remark;
72
+    /**
73
+     * 子分类列表
74
+     */
75
+    private List<BasePerformanceIndicatorCategoryTreeDTO> children = new ArrayList<>();
76
+    /**
77
+     * 当前分类下的指标列表
78
+     */
79
+    private List<BasePerformanceIndicator> indicatorList = new ArrayList<>();
80
+
81
+    /**
82
+     * 转换为DTO
83
+     *
84
+     * @param entity
85
+     * @return
86
+     */
87
+    public static BasePerformanceIndicatorCategoryTreeDTO fromEntity(BasePerformanceIndicatorCategory entity) {
88
+        if (entity == null) {
89
+            return null;
90
+        }
91
+        BasePerformanceIndicatorCategoryTreeDTO dto = new BasePerformanceIndicatorCategoryTreeDTO();
92
+        dto.setId(entity.getId());
93
+        dto.setCode(entity.getCode());
94
+        dto.setName(entity.getName());
95
+        dto.setParentId(entity.getParentId());
96
+        dto.setAncestors(entity.getAncestors());
97
+        dto.setOrderNum(entity.getOrderNum());
98
+        dto.setLevel(entity.getLevel());
99
+        dto.setCreateBy(entity.getCreateBy());
100
+        dto.setCreateTime(entity.getCreateTime());
101
+        dto.setUpdateBy(entity.getUpdateBy());
102
+        dto.setUpdateTime(entity.getUpdateTime());
103
+        dto.setRemark(entity.getRemark());
104
+        return dto;
105
+    }
106
+
107
+}

+ 25 - 0
airport-system/src/main/java/com/sundot/airport/system/domain/BasePerformanceIndicatorCategoryTreeRequestDTO.java

@@ -0,0 +1,25 @@
1
+package com.sundot.airport.system.domain;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 考核指标分类树及关联指标查询请求参数
7
+ *
8
+ * @author ruoyi
9
+ * @date 2026-04-28
10
+ */
11
+@Data
12
+public class BasePerformanceIndicatorCategoryTreeRequestDTO {
13
+    /**
14
+     * 分类编码
15
+     */
16
+    private String categoryCode;
17
+    /**
18
+     * 分类名称
19
+     */
20
+    private String categoryName;
21
+    /**
22
+     * 指标名称
23
+     */
24
+    private String indicatorName;
25
+}

+ 10 - 0
airport-system/src/main/java/com/sundot/airport/system/service/IBasePerformanceIndicatorCategoryService.java

@@ -3,6 +3,8 @@ package com.sundot.airport.system.service;
3 3
 import java.util.List;
4 4
 
5 5
 import com.sundot.airport.system.domain.BasePerformanceIndicatorCategory;
6
+import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeDTO;
7
+import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeRequestDTO;
6 8
 
7 9
 /**
8 10
  * 考核指标分类Service接口
@@ -74,4 +76,12 @@ public interface IBasePerformanceIndicatorCategoryService {
74 76
      * @return 树结构列表
75 77
      */
76 78
     public List<BasePerformanceIndicatorCategory> buildTree(List<BasePerformanceIndicatorCategory> list);
79
+
80
+    /**
81
+     * 获取分类树及关联指标(支持模糊查询)
82
+     *
83
+     * @param requestDTO 入参
84
+     * @return 树结构列表
85
+     */
86
+    public List<BasePerformanceIndicatorCategoryTreeDTO> getCategoryTreeWithIndicatorList(BasePerformanceIndicatorCategoryTreeRequestDTO requestDTO);
77 87
 }

+ 107 - 0
airport-system/src/main/java/com/sundot/airport/system/service/impl/BasePerformanceIndicatorCategoryServiceImpl.java

@@ -1,14 +1,22 @@
1 1
 package com.sundot.airport.system.service.impl;
2 2
 
3 3
 import java.util.ArrayList;
4
+import java.util.Collections;
5
+import java.util.Comparator;
4 6
 import java.util.HashMap;
5 7
 import java.util.List;
6 8
 import java.util.Map;
9
+import java.util.stream.Collectors;
7 10
 
8 11
 import cn.hutool.core.util.ObjectUtil;
12
+import cn.hutool.core.util.StrUtil;
9 13
 import com.sundot.airport.common.config.LevelConfig;
10 14
 import com.sundot.airport.common.exception.ServiceException;
11 15
 import com.sundot.airport.common.utils.DateUtils;
16
+import com.sundot.airport.system.domain.BasePerformanceIndicator;
17
+import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeDTO;
18
+import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeRequestDTO;
19
+import com.sundot.airport.system.service.IBasePerformanceIndicatorService;
12 20
 import com.sundot.airport.system.utils.CodeGeneratorUtil;
13 21
 import org.apache.commons.lang3.ObjectUtils;
14 22
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +41,8 @@ public class BasePerformanceIndicatorCategoryServiceImpl implements IBasePerform
33 41
     private LevelConfig levelConfig;
34 42
     @Autowired
35 43
     private CodeGeneratorUtil codeGeneratorUtil;
44
+    @Autowired
45
+    private IBasePerformanceIndicatorService basePerformanceIndicatorService;
36 46
 
37 47
     /**
38 48
      * 查询考核指标分类
@@ -208,4 +218,101 @@ public class BasePerformanceIndicatorCategoryServiceImpl implements IBasePerform
208 218
             throw new ServiceException("操作失败,层级超过限制" + levelConfig.getPerformanceIndicatorCategoryLevel() + "级");
209 219
         }
210 220
     }
221
+
222
+    /**
223
+     * 获取分类树及关联指标(支持模糊查询)
224
+     *
225
+     * @param requestDTO 入参
226
+     * @return 树结构列表
227
+     */
228
+    @Override
229
+    public List<BasePerformanceIndicatorCategoryTreeDTO> getCategoryTreeWithIndicatorList(BasePerformanceIndicatorCategoryTreeRequestDTO requestDTO) {
230
+
231
+        // 1. 查询所有分类
232
+        List<BasePerformanceIndicatorCategory> allCategorieList = basePerformanceIndicatorCategoryMapper.selectBasePerformanceIndicatorCategoryList(new BasePerformanceIndicatorCategory());
233
+
234
+        // 2. 查询指标(支持指标名称模糊匹配)
235
+        BasePerformanceIndicator indicator = new BasePerformanceIndicator();
236
+        indicator.setName(requestDTO.getIndicatorName());
237
+        List<BasePerformanceIndicator> indicatorList = basePerformanceIndicatorService.selectBasePerformanceIndicatorList(indicator);
238
+
239
+        // 3. 按分类编码分组指标
240
+        Map<String, List<BasePerformanceIndicator>> indicatorMap = indicatorList.stream().collect(Collectors.groupingBy(BasePerformanceIndicator::getCategoryCode));
241
+
242
+        // 4. 转换为DTO并绑定指标
243
+        Map<Long, BasePerformanceIndicatorCategoryTreeDTO> dtoMap = new HashMap<>();
244
+        for (BasePerformanceIndicatorCategory category : allCategorieList) {
245
+            BasePerformanceIndicatorCategoryTreeDTO dto = BasePerformanceIndicatorCategoryTreeDTO.fromEntity(category);
246
+            List<BasePerformanceIndicator> list = indicatorMap.get(category.getCode());
247
+            dto.setIndicatorList(list != null ? list : Collections.emptyList());
248
+            dtoMap.put(dto.getId(), dto);
249
+        }
250
+
251
+        // 5. 构建树形结构
252
+        List<BasePerformanceIndicatorCategoryTreeDTO> rootList = new ArrayList<>();
253
+        for (BasePerformanceIndicatorCategoryTreeDTO dto : dtoMap.values()) {
254
+            Long parentId = dto.getParentId();
255
+            if (parentId == null || parentId == 0) {
256
+                rootList.add(dto);
257
+            } else {
258
+                BasePerformanceIndicatorCategoryTreeDTO parent = dtoMap.get(parentId);
259
+                if (parent != null) {
260
+                    parent.getChildren().add(dto);
261
+                }
262
+            }
263
+        }
264
+
265
+        // 6. 递归过滤(分类条件 + 指标条件)
266
+        List<BasePerformanceIndicatorCategoryTreeDTO> filteredRootList = filterTree(rootList, requestDTO);
267
+
268
+        // 7. 排序
269
+        sortChildren(filteredRootList);
270
+
271
+        return filteredRootList;
272
+    }
273
+
274
+    /**
275
+     * 递归过滤树节点
276
+     */
277
+    private List<BasePerformanceIndicatorCategoryTreeDTO> filterTree(List<BasePerformanceIndicatorCategoryTreeDTO> nodeList, BasePerformanceIndicatorCategoryTreeRequestDTO requestDTO) {
278
+        List<BasePerformanceIndicatorCategoryTreeDTO> result = new ArrayList<>();
279
+        for (BasePerformanceIndicatorCategoryTreeDTO node : nodeList) {
280
+            boolean selfMatch = matchesCategory(node, requestDTO);
281
+            List<BasePerformanceIndicatorCategoryTreeDTO> filteredChildren = filterTree(node.getChildren(), requestDTO);
282
+
283
+            // 保留条件:自身匹配 或 子节点有匹配
284
+            if (selfMatch || !filteredChildren.isEmpty()) {
285
+                node.setChildren(filteredChildren);
286
+                result.add(node);
287
+            }
288
+        }
289
+        return result;
290
+    }
291
+
292
+    /**
293
+     * 匹配分类
294
+     */
295
+    private boolean matchesCategory(BasePerformanceIndicatorCategoryTreeDTO dto, BasePerformanceIndicatorCategoryTreeRequestDTO requestDTO) {
296
+        boolean match = true;
297
+        if (StrUtil.isNotBlank(requestDTO.getCategoryCode())) {
298
+            match = match && requestDTO.getCategoryCode().equals(dto.getCode());
299
+        }
300
+        if (StrUtil.isNotBlank(requestDTO.getCategoryName())) {
301
+            match = match && StrUtil.containsIgnoreCase(dto.getName(), requestDTO.getCategoryName());
302
+        }
303
+        return match;
304
+    }
305
+
306
+    /**
307
+     * 排序子节点
308
+     */
309
+    private void sortChildren(List<BasePerformanceIndicatorCategoryTreeDTO> list) {
310
+        if (list == null) {
311
+            return;
312
+        }
313
+        list.sort(Comparator.comparing(BasePerformanceIndicatorCategoryTreeDTO::getOrderNum, Comparator.nullsLast(Integer::compareTo)));
314
+        for (BasePerformanceIndicatorCategoryTreeDTO dto : list) {
315
+            sortChildren(dto.getChildren());
316
+        }
317
+    }
211 318
 }