Ver código fonte

个人用户画像处理

wangxx 1 semana atrás
pai
commit
8f8fc8b6b8

+ 1 - 1
airport-admin/src/main/java/com/sundot/airport/web/controller/score/DeptPortraitController.java

@@ -195,7 +195,7 @@ public class DeptPortraitController extends BaseController {
195 195
      */
196 196
     @ApiOperation("清空所有画像缓存")
197 197
     @PostMapping("/clear-cache")
198
-    @CacheEvict(value = {"dept:members", "dept:distribution", "dept:position", "portrait", "station:stats", "team:stats"}, allEntries = true)
198
+    @CacheEvict(value = {"dept:members", "dept:distribution", "dept:position", "portrait", "station:stats", "team:stats","dept_user_tree"}, allEntries = true)
199 199
     public AjaxResult clearPortraitCache() {
200 200
         return success("缓存已清空");
201 201
     }

+ 3 - 2
airport-common/src/main/java/com/sundot/airport/common/utils/DateUtils.java

@@ -35,7 +35,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
35 35
     private static String[] parsePatterns = {
36 36
             "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
37 37
             "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
38
-            "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
38
+            "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM",
39
+            "yyyy"};
39 40
 
40 41
     /**
41 42
      * 获取当前Date型日期
@@ -207,4 +208,4 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
207 208
                 cal.get(Calendar.MONTH) + 1,
208 209
                 cal.get(Calendar.DAY_OF_MONTH));
209 210
     }
210
-}
211
+}

+ 40 - 8
airport-ledger/src/main/java/com/sundot/airport/ledger/service/impl/EmployeePortraitServiceImpl.java

@@ -2,6 +2,7 @@ package com.sundot.airport.ledger.service.impl;
2 2
 
3 3
 import com.sundot.airport.common.core.domain.entity.SysDept;
4 4
 import com.sundot.airport.common.core.domain.entity.SysUser;
5
+import com.sundot.airport.common.enums.DeptTypeEnum;
5 6
 import com.sundot.airport.common.enums.ScoreLevelEnum;
6 7
 import com.sundot.airport.ledger.domain.LedgerExamScore;
7 8
 import com.sundot.airport.ledger.domain.ScoreDimension;
@@ -206,6 +207,7 @@ public class EmployeePortraitServiceImpl implements IEmployeePortraitService {
206 207
         vo.setSecurityInspectionPosition(user.getSecurityInspectionPosition());
207 208
         vo.setUserTags(user.getTags());
208 209
 
210
+
209 211
         // 司龄、工龄、开机年限
210 212
         long nowMs = System.currentTimeMillis();
211 213
         if (user.getStartWorkingDate() != null) {
@@ -251,15 +253,45 @@ public class EmployeePortraitServiceImpl implements IEmployeePortraitService {
251 253
         // 部门路径
252 254
         if (user.getDept() != null) {
253 255
             String deptName = user.getDept().getDeptName();
254
-            String parentDeptName = "";
255
-            Long parentId = user.getDept().getParentId();
256
-            if (parentId != null && parentId > 0) {
257
-                SysDept parent = sysDeptMapper.selectDeptById(parentId);
258
-                if (parent != null) parentDeptName = parent.getDeptName();
256
+            //根据名称查询部门
257
+            SysDept dept = sysDeptMapper.selectDeptById(user.getDept().getDeptId());
258
+            // 祖先ID批量查询
259
+            List<Long> ancestorIds = new ArrayList<>();
260
+            if (dept.getAncestors() != null) {
261
+                for (String id : dept.getAncestors().split(",")) {
262
+                    Long deptId = Long.parseLong(id.trim());
263
+                    if (deptId > 0) ancestorIds.add(deptId);
264
+                }
265
+            }
266
+            
267
+            // 一次查询所有祖先部门
268
+            Map<Long, SysDept> deptMap = ancestorIds.isEmpty() ? new HashMap<>() 
269
+                : sysDeptMapper.selectDeptByIdList(ancestorIds).stream()
270
+                    .collect(Collectors.toMap(SysDept::getDeptId, d -> d));
271
+            
272
+            // 构建路径(从BRIGADE到当前部门)
273
+            List<String> path = new ArrayList<>();
274
+            String currentDeptType = dept.getDeptType();
275
+            if (!DeptTypeEnum.MANAGER.getCode().equals(currentDeptType) && !DeptTypeEnum.TEAMS.getCode().equals(currentDeptType)) {
276
+                path.add(deptName);
277
+            } else {
278
+                // 从BRIGADE级别开始构建路径
279
+                for (Long id : ancestorIds) {
280
+                    SysDept d = deptMap.get(id);
281
+                    if (d != null) {
282
+                        if (DeptTypeEnum.BRIGADE.getCode().equals(d.getDeptType())) path.clear();
283
+                        path.add(d.getDeptName());
284
+                    }
285
+                }
286
+                path.add(deptName);
259 287
             }
288
+            
260 289
             vo.setDeptName(deptName);
261
-            vo.setParentDeptName(parentDeptName);
262
-            vo.setDeptPath(parentDeptName.isEmpty() ? deptName : parentDeptName + "/" + deptName);
290
+            vo.setParentDeptName(ancestorIds.isEmpty() ? "" : 
291
+                Optional.ofNullable(deptMap.get(dept.getParentId()))
292
+                    .orElseGet(() -> sysDeptMapper.selectDeptById(dept.getParentId()))
293
+                    .getDeptName());
294
+            vo.setDeptPath(String.join("/", path));
263 295
         }
264 296
     }
265 297
 
@@ -507,4 +539,4 @@ public class EmployeePortraitServiceImpl implements IEmployeePortraitService {
507 539
         });
508 540
         return result;
509 541
     }
510
-}
542
+}