Bläddra i källkod

首页-能力对比-查获上报

chenshudong 2 månader sedan
förälder
incheckning
2af3751a19

+ 154 - 0
airport-admin/src/main/java/com/sundot/airport/web/controller/system/SysHomePageController.java

@@ -2,6 +2,7 @@ package com.sundot.airport.web.controller.system;
2 2
 
3 3
 import cn.hutool.core.util.ObjectUtil;
4 4
 import cn.hutool.core.util.StrUtil;
5
+import com.sundot.airport.attendance.service.IAttendancePostRecordService;
5 6
 import com.sundot.airport.check.service.ICheckLargeScreenService;
6 7
 import com.sundot.airport.common.core.controller.BaseController;
7 8
 import com.sundot.airport.common.core.domain.AjaxResult;
@@ -11,14 +12,18 @@ import com.sundot.airport.common.core.domain.SysHomePageDetailDto;
11 12
 import com.sundot.airport.common.core.domain.SysHomePageDetailQueryParamDto;
12 13
 import com.sundot.airport.common.core.domain.SysHomePageRankingDto;
13 14
 import com.sundot.airport.common.core.domain.entity.SysDept;
15
+import com.sundot.airport.common.core.domain.entity.SysUser;
14 16
 import com.sundot.airport.common.enums.DataPermissionType;
15 17
 import com.sundot.airport.common.enums.DeptType;
16 18
 import com.sundot.airport.common.enums.DeptTypeEnum;
17 19
 import com.sundot.airport.common.enums.HomePageQueryEnum;
18 20
 import com.sundot.airport.common.enums.SourceTypeEnum;
19 21
 import com.sundot.airport.common.exception.ServiceException;
22
+import com.sundot.airport.common.utils.DateUtils;
23
+import com.sundot.airport.item.mapper.SeizureReportMapper;
20 24
 import com.sundot.airport.system.service.ISysDeptService;
21 25
 import com.sundot.airport.system.service.ISysLearningGrowthService;
26
+import com.sundot.airport.system.service.ISysUserService;
22 27
 import com.sundot.airport.web.core.utils.DataPermissionUtils;
23 28
 import org.springframework.beans.factory.annotation.Autowired;
24 29
 import org.springframework.web.bind.annotation.GetMapping;
@@ -31,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
31 36
 import java.math.BigDecimal;
32 37
 import java.math.RoundingMode;
33 38
 import java.util.ArrayList;
39
+import java.util.Calendar;
34 40
 import java.util.Collections;
35 41
 import java.util.List;
36 42
 import java.util.stream.Collectors;
@@ -45,6 +51,9 @@ import java.util.stream.Collectors;
45 51
 public class SysHomePageController extends BaseController {
46 52
 
47 53
     @Autowired
54
+    private ISysUserService sysUserService;
55
+
56
+    @Autowired
48 57
     private ISysDeptService deptService;
49 58
 
50 59
     @Autowired
@@ -53,6 +62,12 @@ public class SysHomePageController extends BaseController {
53 62
     @Autowired
54 63
     private ISysLearningGrowthService sysLearningGrowthService;
55 64
 
65
+    @Autowired
66
+    private SeizureReportMapper seizureReportMapper;
67
+
68
+    @Autowired
69
+    private IAttendancePostRecordService attendancePostRecordService;
70
+
56 71
     /**
57 72
      * 首页-排名
58 73
      */
@@ -260,6 +275,8 @@ public class SysHomePageController extends BaseController {
260 275
             resultItem.setLearningGrowthScoreGraph(resultItem.getLearningGrowthScore().divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP));
261 276
             resultItem.setCheckPassRate(getCheckPassRate(item));
262 277
             resultItem.setCheckPassRateGraph(resultItem.getCheckPassRate());
278
+            resultItem.setSeizureCount(getSeizureCount(item));
279
+            resultItem.setSeizureCountGraph(getSeizureCountGraph(item));
263 280
             result.add(resultItem);
264 281
         }
265 282
         return result;
@@ -297,4 +314,141 @@ public class SysHomePageController extends BaseController {
297 314
         return sysLearningGrowthService.learningGrowthAverage(dto);
298 315
     }
299 316
 
317
+    /**
318
+     * 部门值计算器函数式接口
319
+     */
320
+    @FunctionalInterface
321
+    private interface DeptValueCalculator {
322
+        BigDecimal calculate(String deptType, SysHomePageDetailQueryParamDto item);
323
+    }
324
+
325
+    /**
326
+     * 获取查获数量
327
+     */
328
+    private BigDecimal getSeizureCount(SysHomePageDetailQueryParamDto item) {
329
+        if (item.getEndDate() != null) {
330
+            item.setEndDate(DateUtils.addSeconds(DateUtils.truncate(item.getEndDate(), Calendar.DAY_OF_MONTH), 86399));
331
+        }
332
+        if (StrUtil.equals(HomePageQueryEnum.USER.getCode(), item.getType())) {
333
+            return seizureReportMapper.selectSelfSeizureCount(item.getId(), item.getStartDate(), item.getEndDate());
334
+        } else {
335
+            return calculateDeptBasedValue(item, this::calculateAverageSeizureCountForDeptType);
336
+        }
337
+    }
338
+
339
+    /**
340
+     * 获取查获数量图形
341
+     */
342
+    private BigDecimal getSeizureCountGraph(SysHomePageDetailQueryParamDto item) {
343
+        if (item.getEndDate() != null) {
344
+            item.setEndDate(DateUtils.addSeconds(DateUtils.truncate(item.getEndDate(), Calendar.DAY_OF_MONTH), 86399));
345
+        }
346
+        if (StrUtil.equals(HomePageQueryEnum.USER.getCode(), item.getType())) {
347
+            BigDecimal totalSeizure = seizureReportMapper.selectSelfSeizureCount(item.getId(), item.getStartDate(), item.getEndDate());
348
+            Long stationId = getStationIdByUserId(item.getId());
349
+            BigDecimal maxSeizureCount = seizureReportMapper.selectMaxSeizureCountInStation(stationId, item.getStartDate(), item.getEndDate());
350
+            return (maxSeizureCount != null && maxSeizureCount.compareTo(BigDecimal.ZERO) > 0) ?
351
+                    totalSeizure.divide(maxSeizureCount, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
352
+        } else {
353
+            return calculateDeptBasedValue(item, this::calculateSeizureCountGraphForDeptType);
354
+        }
355
+    }
356
+
357
+    /**
358
+     * 获取部门相关数值的通用方法
359
+     */
360
+    private BigDecimal calculateDeptBasedValue(SysHomePageDetailQueryParamDto item,
361
+                                               DeptValueCalculator calculator) {
362
+        SysDept sysDept = deptService.selectDeptById(item.getId());
363
+        if (sysDept == null) {
364
+            return BigDecimal.ZERO;
365
+        }
366
+        return calculator.calculate(sysDept.getDeptType(), item);
367
+    }
368
+
369
+    /**
370
+     * 平均查获数量计算
371
+     */
372
+    private BigDecimal calculateAverageSeizureCountForDeptType(String deptType, SysHomePageDetailQueryParamDto item) {
373
+        switch (deptType) {
374
+            case "TEAMS":
375
+                BigDecimal totalTeamSeizure = seizureReportMapper.selectTeamAverage(item.getId(), item.getStartDate(), item.getEndDate());
376
+                Integer teamUserCount = seizureReportMapper.selectUserCountByTeamId(item.getId());
377
+                return (teamUserCount != null && teamUserCount > 0) ?
378
+                        totalTeamSeizure.divide(new BigDecimal(teamUserCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
379
+            case "MANAGER":
380
+                BigDecimal totalDepartmentSeizure = seizureReportMapper.selectDepartmentAverage(item.getId(), item.getStartDate(), item.getEndDate());
381
+                Integer deptUserCount = seizureReportMapper.selectUserCountByDepartmentId(item.getId());
382
+                return (deptUserCount != null && deptUserCount > 0) ?
383
+                        totalDepartmentSeizure.divide(new BigDecimal(deptUserCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
384
+            case "BRIGADE":
385
+                BigDecimal totalBrigadeSeizure = seizureReportMapper.selectBrigadeAverage(item.getId(), item.getStartDate(), item.getEndDate());
386
+                Integer brigadeUserCount = seizureReportMapper.selectUserCountByBrigadeId(item.getId());
387
+                return (brigadeUserCount != null && brigadeUserCount > 0) ?
388
+                        totalBrigadeSeizure.divide(new BigDecimal(brigadeUserCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
389
+            case "STATION":
390
+                BigDecimal totalStationSeizure = seizureReportMapper.selectStationAverage(item.getId(), item.getStartDate(), item.getEndDate());
391
+                Integer stationUserCount = seizureReportMapper.selectUserCountByStationId(item.getId());
392
+                return (stationUserCount != null && stationUserCount > 0) ?
393
+                        totalStationSeizure.divide(new BigDecimal(stationUserCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
394
+            default:
395
+                return BigDecimal.ZERO;
396
+        }
397
+    }
398
+
399
+    /**
400
+     * 查获数量图表计算
401
+     */
402
+    private BigDecimal calculateSeizureCountGraphForDeptType(String deptType, SysHomePageDetailQueryParamDto item) {
403
+        switch (deptType) {
404
+            case "TEAMS":
405
+                Long sectionDeptId = seizureReportMapper.selectSectionDeptIdByTeamId(item.getId());
406
+                Long brigadeDeptId = seizureReportMapper.selectBrigadeDeptIdByDepartmentId(sectionDeptId);
407
+                Long stationId = seizureReportMapper.selectStationDeptIdByDeptId(brigadeDeptId);
408
+                BigDecimal totalTeamSeizure = seizureReportMapper.selectTeamAverage(item.getId(), item.getStartDate(), item.getEndDate());
409
+                //查询班级人数
410
+                Integer teamUserCount = seizureReportMapper.selectUserCountByTeamId(item.getId());
411
+                BigDecimal maxSeizureCount = seizureReportMapper.selectMaxSeizureCountInStation(stationId, item.getStartDate(), item.getEndDate());
412
+                return (maxSeizureCount != null && maxSeizureCount.compareTo(BigDecimal.ZERO) > 0 && teamUserCount != null && teamUserCount > 0) ?
413
+                        totalTeamSeizure.divide(new BigDecimal(teamUserCount), 2, RoundingMode.HALF_UP).divide(maxSeizureCount, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
414
+            case "MANAGER":
415
+                Long brigadeId = seizureReportMapper.selectBrigadeDeptIdByDepartmentId(item.getId());
416
+                Long deptStationId = seizureReportMapper.selectStationDeptIdByDeptId(brigadeId);
417
+                BigDecimal totalDepartmentSeizure = seizureReportMapper.selectDepartmentAverage(item.getId(), item.getStartDate(), item.getEndDate());
418
+                BigDecimal maxSeizureCountForDept = seizureReportMapper.selectMaxSeizureCountInStation(deptStationId, item.getStartDate(), item.getEndDate());
419
+                //查询科室人数
420
+                Integer deptUserCount = seizureReportMapper.selectUserCountByDepartmentId(item.getId());
421
+                return (maxSeizureCountForDept != null && maxSeizureCountForDept.compareTo(BigDecimal.ZERO) > 0 && deptUserCount != null && deptUserCount > 0) ?
422
+                        totalDepartmentSeizure.divide(new BigDecimal(deptUserCount), 2, RoundingMode.HALF_UP).divide(maxSeizureCountForDept, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
423
+            case "BRIGADE":
424
+                Long stationDeptId = seizureReportMapper.selectStationDeptIdByDeptId(item.getId());
425
+                BigDecimal totalBrigadeSeizure = seizureReportMapper.selectBrigadeAverage(item.getId(), item.getStartDate(), item.getEndDate());
426
+                BigDecimal maxSeizureCountFor = seizureReportMapper.selectMaxSeizureCountInStation(stationDeptId, item.getStartDate(), item.getEndDate());
427
+                //查询大队人数
428
+                Integer deptBrigadeUserCount = seizureReportMapper.selectUserCountByBrigadeId(item.getId());
429
+                return (maxSeizureCountFor != null && maxSeizureCountFor.compareTo(BigDecimal.ZERO) > 0 && deptBrigadeUserCount != null && deptBrigadeUserCount > 0) ?
430
+                        totalBrigadeSeizure.divide(new BigDecimal(deptBrigadeUserCount), 2, RoundingMode.HALF_UP).divide(maxSeizureCountFor, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
431
+            case "STATION":
432
+                BigDecimal totalStationSeizure = seizureReportMapper.selectStationAverage(item.getId(), item.getStartDate(), item.getEndDate());
433
+                BigDecimal maxSeizureCountForStation = seizureReportMapper.selectMaxSeizureCountInStation(item.getId(), item.getStartDate(), item.getEndDate());
434
+                //查询站人数
435
+                Integer stationUserCount = seizureReportMapper.selectUserCountByStationId(item.getId());
436
+                return (maxSeizureCountForStation != null && maxSeizureCountForStation.compareTo(BigDecimal.ZERO) > 0 && stationUserCount != null && stationUserCount > 0) ?
437
+                        totalStationSeizure.divide(new BigDecimal(stationUserCount), 2, RoundingMode.HALF_UP).divide(maxSeizureCountForStation, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
438
+            default:
439
+                return BigDecimal.ZERO;
440
+        }
441
+    }
442
+
443
+    /**
444
+     * 根据用户ID获取对应站点ID
445
+     */
446
+    private Long getStationIdByUserId(Long userId) {
447
+        SysUser sysUser = sysUserService.selectUserById(userId);
448
+        List<SysDept> deptList = deptService.selectAllDept(sysUser.getDeptId());
449
+        Collections.reverse(deptList);
450
+        SysDept station = deptList.stream().filter(x -> StrUtil.equals(DeptType.STATION.getCode(), x.getDeptType())).findFirst().orElse(null);
451
+        return station != null ? station.getDeptId() : 0;
452
+    }
453
+
300 454
 }

+ 8 - 0
airport-item/src/main/java/com/sundot/airport/item/mapper/SeizureReportMapper.java

@@ -116,6 +116,14 @@ public interface SeizureReportMapper {
116 116
     public Long selectSectionDeptIdByTeamId(@Param("teamId") Long teamId);
117 117
 
118 118
     /**
119
+     * 查询大队部门ID(根据科室ID)
120
+     *
121
+     * @param departmentId 科室ID
122
+     * @return 大队ID
123
+     */
124
+    public Long selectBrigadeDeptIdByDepartmentId(@Param("departmentId") Long departmentId);
125
+
126
+    /**
119 127
      * 查询站点部门ID(根据部门ID)
120 128
      *
121 129
      * @param deptId 部门ID

+ 7 - 0
airport-item/src/main/resources/mapper/item/SeizureReportMapper.xml

@@ -186,6 +186,13 @@
186 186
         WHERE dept_id = #{teamId}
187 187
     </select>
188 188
 
189
+    <!-- 查询大队部门ID(根据科室ID) -->
190
+    <select id="selectBrigadeDeptIdByDepartmentId" resultType="java.lang.Long">
191
+        SELECT parent_id
192
+        FROM sys_dept
193
+        WHERE dept_id = #{departmentId}
194
+    </select>
195
+
189 196
     <!-- 查询站点部门ID(根据部门ID) -->
190 197
     <select id="selectStationDeptIdByDeptId" resultType="java.lang.Long">
191 198
         SELECT parent_id