3 Ревизии 7409ed5129 ... ae3ef3212f

Автор SHA1 Съобщение Дата
  simonlll ae3ef3212f 优化首页报表抽问抽答接口性能:批量调用时统一初始化部门缓存,避免重复查询数据库 преди 1 месец
  simonlll 414f971b93 Merge branch 'master' of http://git.sundot.cn/haikou/meilan-server преди 1 месец
  simonlll 1141624ee2 抽问抽答如果未作答,仍返回题目的正确选项 преди 2 месеца

+ 8 - 2
airport-admin/src/main/java/com/sundot/airport/web/controller/system/SysHomeReportController.java

@@ -450,8 +450,14 @@ public class SysHomeReportController extends BaseController {
450 450
      */
451 451
     private List<SysHomeReportDetailDto> getAnswerList(List<SysHomePageDetailQueryParamDto> dtoList) {
452 452
         List<SysHomeReportDetailDto> result = new ArrayList<>();
453
-        for (SysHomePageDetailQueryParamDto item : dtoList) {
454
-            result.add(getAnswer(item));
453
+        // 批量调用前统一初始化部门缓存,避免每次 answerData 都重复查询数据库
454
+        accuracyStatisticsService.initDeptCache();
455
+        try {
456
+            for (SysHomePageDetailQueryParamDto item : dtoList) {
457
+                result.add(getAnswer(item));
458
+            }
459
+        } finally {
460
+            accuracyStatisticsService.clearDeptCache();
455 461
         }
456 462
         return result;
457 463
     }

+ 10 - 0
airport-exam/src/main/java/com/sundot/airport/exam/service/IAccuracyStatisticsService.java

@@ -69,4 +69,14 @@ public interface IAccuracyStatisticsService {
69 69
      * @return 首页报表-抽问抽答正确率数据
70 70
      */
71 71
     com.sundot.airport.common.core.domain.SysHomeReportDetailDto answerData(BaseLargeScreenQueryParamDto dto);
72
+
73
+    /**
74
+     * 初始化部门缓存(批量调用 answerData 前调用,避免重复查询数据库)
75
+     */
76
+    void initDeptCache();
77
+
78
+    /**
79
+     * 清理部门缓存
80
+     */
81
+    void clearDeptCache();
72 82
 }

+ 9 - 6
airport-exam/src/main/java/com/sundot/airport/exam/service/impl/AccuracyStatisticsServiceImpl.java

@@ -159,7 +159,8 @@ public class AccuracyStatisticsServiceImpl implements IAccuracyStatisticsService
159 159
     /**
160 160
      * 初始化部门缓存
161 161
      */
162
-    private DeptCache initDeptCache() {
162
+    @Override
163
+    public void initDeptCache() {
163 164
         DeptCache cache = DEPT_CACHE.get();
164 165
         if (cache == null) {
165 166
             long start = System.currentTimeMillis();
@@ -168,13 +169,13 @@ public class AccuracyStatisticsServiceImpl implements IAccuracyStatisticsService
168 169
             DEPT_CACHE.set(cache);
169 170
             log.info("initDeptCache: loaded {} depts in {}ms", allDepts.size(), System.currentTimeMillis() - start);
170 171
         }
171
-        return cache;
172 172
     }
173 173
 
174 174
     /**
175 175
      * 清理缓存
176 176
      */
177
-    private void clearDeptCache() {
177
+    @Override
178
+    public void clearDeptCache() {
178 179
         DEPT_CACHE.remove();
179 180
     }
180 181
 
@@ -1253,7 +1254,8 @@ public class AccuracyStatisticsServiceImpl implements IAccuracyStatisticsService
1253 1254
             result.setName(sysUser.getNickName());
1254 1255
             result.setType(HomePageQueryEnum.USER.getCode());
1255 1256
         } else {
1256
-            SysDept sysDept = deptService.selectDeptById(dto.getDeptId());
1257
+            DeptCache cache = getDeptCache();
1258
+            SysDept sysDept = cache != null ? cache.deptMap.get(dto.getDeptId()) : deptService.selectDeptById(dto.getDeptId());
1257 1259
             if (ObjectUtil.isNull(sysDept)) {
1258 1260
                 throw new ServiceException("【" + dto.getDeptId() + "】部门不存在");
1259 1261
             }
@@ -1332,12 +1334,13 @@ public class AccuracyStatisticsServiceImpl implements IAccuracyStatisticsService
1332 1334
             }
1333 1335
         } else if (ObjectUtil.isNotNull(dto.getDeptId())) {
1334 1336
             // 部门维度:获取部门下所有用户的正确率
1335
-            SysDept sysDept = deptService.selectDeptById(dto.getDeptId());
1337
+            DeptCache cache = getDeptCache();
1338
+            SysDept sysDept = cache != null ? cache.deptMap.get(dto.getDeptId()) : deptService.selectDeptById(dto.getDeptId());
1336 1339
             if (sysDept == null) {
1337 1340
                 return result;
1338 1341
             }
1339 1342
 
1340
-            DeptHierarchy hierarchy = getDeptHierarchy(dto.getDeptId());
1343
+            DeptHierarchy hierarchy = getDeptHierarchyCached(dto.getDeptId());
1341 1344
             List<Long> teamIds = getTeamIdsUnderDept(dto.getDeptId(), hierarchy);
1342 1345
 
1343 1346
             if (teamIds.isEmpty()) {