|
|
@@ -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
|
}
|