chenshudong hace 2 semanas
padre
commit
6f73f98384

+ 43 - 0
airport-admin/src/main/java/com/sundot/airport/web/controller/ledger/LedgerWarningController.java

@@ -0,0 +1,43 @@
1
+package com.sundot.airport.web.controller.ledger;
2
+
3
+import com.sundot.airport.common.core.controller.BaseController;
4
+import com.sundot.airport.common.core.domain.AjaxResult;
5
+import com.sundot.airport.common.dto.LedgerCommonQueryReqVO;
6
+import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailVO;
7
+import com.sundot.airport.ledger.domain.vo.LedgerWarningVO;
8
+import com.sundot.airport.ledger.service.ILedgerWarningService;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.web.bind.annotation.PostMapping;
11
+import org.springframework.web.bind.annotation.RequestBody;
12
+import org.springframework.web.bind.annotation.RequestMapping;
13
+import org.springframework.web.bind.annotation.RestController;
14
+
15
+/**
16
+ * 预警页面控制器
17
+ */
18
+@RestController
19
+@RequestMapping("/ledger/warning")
20
+public class LedgerWarningController extends BaseController {
21
+
22
+    @Autowired
23
+    private ILedgerWarningService ledgerWarningService;
24
+
25
+    /**
26
+     * 台账数据
27
+     */
28
+    @PostMapping("/ledger")
29
+    public AjaxResult ledger(@RequestBody LedgerCommonQueryReqVO queryReq) {
30
+        LedgerWarningVO result = ledgerWarningService.ledger(queryReq);
31
+        return AjaxResult.success(result);
32
+    }
33
+
34
+    /**
35
+     * 员工综合评估预警看板
36
+     */
37
+    @PostMapping("/ledgerDetail")
38
+    public AjaxResult ledgerDetail(@RequestBody LedgerCommonQueryReqVO queryReq) {
39
+        LedgerWarningDetailVO result = ledgerWarningService.ledgerDetail(queryReq);
40
+        return AjaxResult.success(result);
41
+    }
42
+
43
+}

+ 29 - 0
airport-common/src/main/java/com/sundot/airport/common/enums/LedgerAlertLevelEnum.java

@@ -0,0 +1,29 @@
1
+package com.sundot.airport.common.enums;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Getter;
5
+
6
+/**
7
+ * 预警等级枚举
8
+ */
9
+@Getter
10
+@AllArgsConstructor
11
+public enum LedgerAlertLevelEnum {
12
+
13
+    RED_ALERT("1", "红色预警"),
14
+    EXCELLENT_BENCHMARK("2", "优秀标杆"),
15
+    NORMAL_RANGE("3", "正常范围");
16
+
17
+    private final String code;
18
+    private final String desc;
19
+
20
+    public static LedgerAlertLevelEnum getByCode(String code) {
21
+        for (LedgerAlertLevelEnum itemEnum : values()) {
22
+            if (itemEnum.getCode().equals(code)) {
23
+                return itemEnum;
24
+            }
25
+        }
26
+        return null;
27
+    }
28
+
29
+}

+ 29 - 0
airport-common/src/main/java/com/sundot/airport/common/enums/LedgerStatusLabelEnum.java

@@ -0,0 +1,29 @@
1
+package com.sundot.airport.common.enums;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Getter;
5
+
6
+/**
7
+ * 状态标签枚举
8
+ */
9
+@Getter
10
+@AllArgsConstructor
11
+public enum LedgerStatusLabelEnum {
12
+
13
+    EMERGENCY_INTERVENTION("1", "紧急干预"),
14
+    COMMENDATION_AND_MOTIVATION("2", "表彰激励"),
15
+    REGULAR_COACHING("3", "常规辅导");
16
+
17
+    private final String code;
18
+    private final String desc;
19
+
20
+    public static LedgerStatusLabelEnum getByCode(String code) {
21
+        for (LedgerStatusLabelEnum itemEnum : values()) {
22
+            if (itemEnum.getCode().equals(code)) {
23
+                return itemEnum;
24
+            }
25
+        }
26
+        return null;
27
+    }
28
+
29
+}

+ 49 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/domain/vo/LedgerWarningDetailItemVO.java

@@ -0,0 +1,49 @@
1
+package com.sundot.airport.ledger.domain.vo;
2
+
3
+import lombok.Data;
4
+
5
+import java.io.Serializable;
6
+import java.math.BigDecimal;
7
+
8
+/**
9
+ * 预警信息详情明细
10
+ */
11
+@Data
12
+public class LedgerWarningDetailItemVO implements Serializable {
13
+    /**
14
+     * 员工ID
15
+     */
16
+    private Long userId;
17
+    /**
18
+     * 员工账号
19
+     */
20
+    private String userName;
21
+    /**
22
+     * 员工昵称
23
+     */
24
+    private String nickName;
25
+    /**
26
+     * 所属部门ID
27
+     */
28
+    private Long deptId;
29
+    /**
30
+     * 所属部门名称
31
+     */
32
+    private String deptName;
33
+    /**
34
+     * 综合评估得分
35
+     */
36
+    private BigDecimal overallScore;
37
+    /**
38
+     * 预警等级
39
+     */
40
+    private String warningLevel;
41
+    /**
42
+     * 状态标签
43
+     */
44
+    private String statusLabel;
45
+    /**
46
+     * 核心风险/优秀事迹
47
+     */
48
+    private String coreRisksOrOutstandingAchievements;
49
+}

+ 31 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/domain/vo/LedgerWarningDetailVO.java

@@ -0,0 +1,31 @@
1
+package com.sundot.airport.ledger.domain.vo;
2
+
3
+import lombok.Data;
4
+
5
+import java.io.Serializable;
6
+import java.math.BigDecimal;
7
+import java.util.List;
8
+
9
+/**
10
+ * 预警信息详情
11
+ */
12
+@Data
13
+public class LedgerWarningDetailVO implements Serializable {
14
+    /**
15
+     * 红色预警人数
16
+     */
17
+    private Integer redAlertNum;
18
+    /**
19
+     * 优秀标杆人数
20
+     */
21
+    private Integer excellentBenchmarkNum;
22
+    /**
23
+     * 全员平均综合得分
24
+     */
25
+    private BigDecimal averageComprehensiveScore;
26
+    /**
27
+     * 预警信息详情明细列表
28
+     */
29
+    private List<LedgerWarningDetailItemVO> ledgerWarningDetailItemList;
30
+
31
+}

+ 48 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/domain/vo/LedgerWarningVO.java

@@ -0,0 +1,48 @@
1
+package com.sundot.airport.ledger.domain.vo;
2
+
3
+import lombok.Data;
4
+
5
+import java.io.Serializable;
6
+
7
+/**
8
+ * 预警信息
9
+ */
10
+@Data
11
+public class LedgerWarningVO implements Serializable {
12
+    /**
13
+     * 部门监察问题
14
+     */
15
+    private Integer ledgerSupervisionProblem;
16
+    /**
17
+     * 实时质控拦截
18
+     */
19
+    private Integer ledgerRealtimeInterception;
20
+    /**
21
+     * 不安全事件
22
+     */
23
+    private Integer ledgerUnsafeEvent;
24
+    /**
25
+     * 安保测试记录
26
+     */
27
+    private Integer ledgerSecurityTest;
28
+    /**
29
+     * 旅客服务投诉
30
+     */
31
+    private Integer ledgerComplaint;
32
+    /**
33
+     * 服务巡查
34
+     */
35
+    private Integer ledgerServicePatrol;
36
+    /**
37
+     * 航站楼
38
+     */
39
+    private Integer ledgerTerminalBonus;
40
+    /**
41
+     * 小额奖励
42
+     */
43
+    private Integer ledgerRewardApproval;
44
+    /**
45
+     * 考试成绩
46
+     */
47
+    private Integer ledgerExamScore;
48
+}

+ 65 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/mapper/LedgerWarningMapper.java

@@ -0,0 +1,65 @@
1
+package com.sundot.airport.ledger.mapper;
2
+
3
+import com.sundot.airport.common.dto.LedgerCommonQueryReqVO;
4
+import com.sundot.airport.ledger.domain.ScoreEvent;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.util.Date;
8
+import java.util.List;
9
+
10
+/**
11
+ * 预警页面Mapper接口
12
+ */
13
+public interface LedgerWarningMapper {
14
+
15
+    /**
16
+     * 部门监察问题
17
+     */
18
+    Integer selectLedgerSupervisionProblem(LedgerCommonQueryReqVO query);
19
+
20
+    /**
21
+     * 实时质控拦截
22
+     */
23
+    Integer selectLedgerRealtimeInterception(LedgerCommonQueryReqVO query);
24
+
25
+    /**
26
+     * 不安全事件
27
+     */
28
+    Integer selectLedgerUnsafeEvent(LedgerCommonQueryReqVO query);
29
+
30
+    /**
31
+     * 安保测试记录
32
+     */
33
+    Integer selectLedgerSecurityTest(LedgerCommonQueryReqVO query);
34
+
35
+    /**
36
+     * 旅客服务投诉
37
+     */
38
+    Integer selectLedgerComplaint(LedgerCommonQueryReqVO query);
39
+
40
+    /**
41
+     * 服务巡查
42
+     */
43
+    Integer selectLedgerServicePatrol(LedgerCommonQueryReqVO query);
44
+
45
+    /**
46
+     * 航站楼
47
+     */
48
+    Integer selectLedgerTerminalBonus(LedgerCommonQueryReqVO query);
49
+
50
+    /**
51
+     * 小额奖励
52
+     */
53
+    Integer selectLedgerRewardApproval(LedgerCommonQueryReqVO query);
54
+
55
+    /**
56
+     * 考试成绩
57
+     */
58
+    Integer selectLedgerExamScore(LedgerCommonQueryReqVO query);
59
+
60
+    /**
61
+     * 配分事项列表
62
+     */
63
+    List<ScoreEvent> selectScoreEventList(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("scoreIndicatorIdList") List<Long> scoreIndicatorIdList, @Param("userIdList") List<Long> userIdList);
64
+
65
+}

+ 22 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/service/ILedgerWarningService.java

@@ -0,0 +1,22 @@
1
+package com.sundot.airport.ledger.service;
2
+
3
+import com.sundot.airport.common.dto.LedgerCommonQueryReqVO;
4
+import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailVO;
5
+import com.sundot.airport.ledger.domain.vo.LedgerWarningVO;
6
+
7
+/**
8
+ * 预警页面服务
9
+ */
10
+public interface ILedgerWarningService {
11
+
12
+    /**
13
+     * 台账数据
14
+     */
15
+    LedgerWarningVO ledger(LedgerCommonQueryReqVO queryReq);
16
+
17
+    /**
18
+     * 员工综合评估预警看板
19
+     */
20
+    LedgerWarningDetailVO ledgerDetail(LedgerCommonQueryReqVO queryReq);
21
+
22
+}

+ 260 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/service/impl/LedgerWarningServiceImpl.java

@@ -0,0 +1,260 @@
1
+package com.sundot.airport.ledger.service.impl;
2
+
3
+import cn.hutool.core.collection.CollUtil;
4
+import cn.hutool.core.date.DateUtil;
5
+import cn.hutool.core.util.ObjUtil;
6
+import cn.hutool.core.util.StrUtil;
7
+import com.sundot.airport.common.core.domain.entity.SysDept;
8
+import com.sundot.airport.common.core.domain.entity.SysUser;
9
+import com.sundot.airport.common.dto.LedgerCommonQueryReqVO;
10
+import com.sundot.airport.common.enums.DeptTypeEnum;
11
+import com.sundot.airport.common.enums.LedgerAlertLevelEnum;
12
+import com.sundot.airport.common.enums.LedgerStatusLabelEnum;
13
+import com.sundot.airport.common.enums.ScoreLevelEnum;
14
+import com.sundot.airport.common.utils.DeptUtils;
15
+import com.sundot.airport.common.utils.SecurityUtils;
16
+import com.sundot.airport.ledger.domain.ScoreEvent;
17
+import com.sundot.airport.ledger.domain.ScoreIndicator;
18
+import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailItemVO;
19
+import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailVO;
20
+import com.sundot.airport.ledger.domain.vo.LedgerWarningVO;
21
+import com.sundot.airport.ledger.mapper.LedgerWarningMapper;
22
+import com.sundot.airport.ledger.service.IEmployeePortraitService;
23
+import com.sundot.airport.ledger.service.ILedgerWarningService;
24
+import com.sundot.airport.ledger.service.IScoreIndicatorService;
25
+import com.sundot.airport.system.service.ISysDeptService;
26
+import com.sundot.airport.system.service.ISysUserService;
27
+import org.springframework.beans.factory.annotation.Autowired;
28
+import org.springframework.stereotype.Service;
29
+
30
+import java.math.BigDecimal;
31
+import java.math.RoundingMode;
32
+import java.util.ArrayList;
33
+import java.util.Arrays;
34
+import java.util.HashMap;
35
+import java.util.HashSet;
36
+import java.util.List;
37
+import java.util.Map;
38
+import java.util.Set;
39
+import java.util.stream.Collectors;
40
+
41
+/**
42
+ * 预警页面服务
43
+ */
44
+@Service
45
+public class LedgerWarningServiceImpl implements ILedgerWarningService {
46
+
47
+    @Autowired
48
+    private LedgerWarningMapper ledgerWarningMapper;
49
+
50
+    @Autowired
51
+    private IEmployeePortraitService employeePortraitService;
52
+
53
+    @Autowired
54
+    private IScoreIndicatorService scoreIndicatorService;
55
+
56
+    @Autowired
57
+    private ISysDeptService sysDeptService;
58
+
59
+    @Autowired
60
+    private ISysUserService sysUserService;
61
+
62
+    /**
63
+     * 台账数据
64
+     */
65
+    @Override
66
+    public LedgerWarningVO ledger(LedgerCommonQueryReqVO queryReq) {
67
+        LedgerWarningVO result = new LedgerWarningVO();
68
+        result.setLedgerSupervisionProblem(ledgerWarningMapper.selectLedgerSupervisionProblem(queryReq));
69
+        result.setLedgerRealtimeInterception(ledgerWarningMapper.selectLedgerRealtimeInterception(queryReq));
70
+        result.setLedgerUnsafeEvent(ledgerWarningMapper.selectLedgerUnsafeEvent(queryReq));
71
+        result.setLedgerSecurityTest(ledgerWarningMapper.selectLedgerSecurityTest(queryReq));
72
+        result.setLedgerComplaint(ledgerWarningMapper.selectLedgerComplaint(queryReq));
73
+        result.setLedgerServicePatrol(ledgerWarningMapper.selectLedgerServicePatrol(queryReq));
74
+        result.setLedgerTerminalBonus(ledgerWarningMapper.selectLedgerTerminalBonus(queryReq));
75
+        result.setLedgerRewardApproval(ledgerWarningMapper.selectLedgerRewardApproval(queryReq));
76
+        result.setLedgerExamScore(ledgerWarningMapper.selectLedgerExamScore(queryReq));
77
+        return result;
78
+    }
79
+
80
+    /**
81
+     * 台账数据
82
+     */
83
+    @Override
84
+    public LedgerWarningDetailVO ledgerDetail(LedgerCommonQueryReqVO queryReq) {
85
+        List<String> scoreIndicatorNameList = Arrays.asList("员工规范化操作", "后台实时质控拦截", "不安全事件", "安保测试未通过", "旅客服务投诉", "服务监察", "典型服务案例", "典型案例查获", "考试成绩");
86
+        Map<String, String> unitMap = new HashMap<>();
87
+        unitMap.put("员工规范化操作", "项");
88
+        unitMap.put("后台实时质控拦截", "次");
89
+        unitMap.put("不安全事件", "起");
90
+        unitMap.put("安保测试未通过", "项");
91
+        unitMap.put("旅客服务投诉", "件");
92
+        unitMap.put("服务监察", "项");
93
+        unitMap.put("典型服务案例", "次");
94
+        unitMap.put("典型案例查获", "次");
95
+        unitMap.put("考试成绩", "次");
96
+
97
+        Long topSiteId = DeptUtils.getTopSiteId(sysDeptService.selectDeptById(SecurityUtils.getDeptId()));
98
+        // 获取所有部门信息
99
+        Map<Long, SysDept> deptMap = getDeptMap();
100
+        // 构建大队到其所有子部门ID的映射
101
+        Map<Long, Set<Long>> brigadeSubDeptsMap = buildBrigadeSubDeptsMap(getDeptMap());
102
+
103
+        LedgerWarningDetailVO result = new LedgerWarningDetailVO();
104
+        ScoreIndicator scoreIndicatorQuery = new ScoreIndicator();
105
+        scoreIndicatorQuery.setStatus("0");
106
+        scoreIndicatorQuery.setOrg(ScoreLevelEnum.PERSON.getCode());
107
+        scoreIndicatorQuery.setLevel(2);
108
+        List<ScoreIndicator> scoreIndicatorList = scoreIndicatorService.selectList(scoreIndicatorQuery);
109
+        scoreIndicatorList = scoreIndicatorList.stream().filter(scoreIndicator -> scoreIndicatorNameList.contains(scoreIndicator.getName())).collect(Collectors.toList());
110
+        List<Long> scoreIndicatorIdList = scoreIndicatorList.stream().map(ScoreIndicator::getId).collect(Collectors.toList());
111
+        List<Long> userIdList = new ArrayList<>();
112
+        List<String> userNameList = new ArrayList<>();
113
+        Map<Long, SysUser> sysUserMap = new HashMap<>();
114
+        if (ObjUtil.isNotNull(queryReq.getUserId())) {
115
+            userIdList.add(queryReq.getUserId());
116
+            SysUser sysUser = sysUserService.selectUserById(queryReq.getUserId());
117
+            userNameList.add(sysUser.getNickName());
118
+            sysUserMap.put(queryReq.getUserId(), sysUser);
119
+        } else {
120
+            Long targetDeptId = ObjUtil.isNotNull(queryReq.getGroupId()) ? queryReq.getGroupId()
121
+                    : ObjUtil.isNotNull(queryReq.getTeamId()) ? queryReq.getTeamId()
122
+                    : ObjUtil.isNotNull(queryReq.getDeptId()) ? queryReq.getDeptId()
123
+                    : topSiteId;
124
+            List<SysUser> sysUserList = sysUserService.selectUserByDeptId(targetDeptId);
125
+            userIdList.addAll(sysUserList.stream().map(SysUser::getUserId).collect(Collectors.toList()));
126
+            userNameList.addAll(sysUserList.stream().map(SysUser::getNickName).collect(Collectors.toList()));
127
+            sysUserMap.putAll(sysUserList.stream().collect(Collectors.toMap(SysUser::getUserId, user -> user)));
128
+        }
129
+        Map<String, BigDecimal> overallScoreMap = employeePortraitService.getPortraitTotalScore(userNameList, DateUtil.formatDate(queryReq.getStartDate()), DateUtil.formatDate(queryReq.getEndDate()));
130
+        List<ScoreEvent> scoreEventList = ledgerWarningMapper.selectScoreEventList(queryReq.getStartDate(), queryReq.getEndDate(), scoreIndicatorIdList, userIdList);
131
+//        // 由于person_name存在多用户时person_id为空,因此不能根据person_id进行分组处理数据
132
+//        Map<Long, List<ScoreEvent>> scoreEventMap = scoreEventList.stream().collect(Collectors.groupingBy(ScoreEvent::getPersonId));
133
+        List<LedgerWarningDetailItemVO> ledgerWarningDetailItemList = new ArrayList<>();
134
+        userIdList.forEach(userId -> {
135
+            LedgerWarningDetailItemVO ledgerWarningDetailItem = new LedgerWarningDetailItemVO();
136
+            SysUser sysUser = sysUserMap.get(userId);
137
+            ledgerWarningDetailItem.setUserId(sysUser.getUserId());
138
+            ledgerWarningDetailItem.setUserName(sysUser.getUserName());
139
+            ledgerWarningDetailItem.setNickName(sysUser.getNickName());
140
+            ledgerWarningDetailItem.setDeptId(sysUser.getDeptId());
141
+            SysDept dept = deptMap.get(findUserBrigade(sysUser.getDeptId(), brigadeSubDeptsMap));
142
+            if (ObjUtil.isNotNull(dept)) {
143
+                ledgerWarningDetailItem.setDeptName(dept.getDeptName());
144
+            }
145
+            BigDecimal overallScore = overallScoreMap.get(sysUser.getNickName());
146
+            ledgerWarningDetailItem.setOverallScore(overallScore);
147
+            if (ledgerWarningDetailItem.getOverallScore().compareTo(BigDecimal.valueOf(75)) < 0) {
148
+                ledgerWarningDetailItem.setWarningLevel(LedgerAlertLevelEnum.RED_ALERT.getCode());
149
+                ledgerWarningDetailItem.setStatusLabel(LedgerStatusLabelEnum.EMERGENCY_INTERVENTION.getCode());
150
+            } else if (ledgerWarningDetailItem.getOverallScore().compareTo(BigDecimal.valueOf(90)) >= 0) {
151
+                ledgerWarningDetailItem.setWarningLevel(LedgerAlertLevelEnum.EXCELLENT_BENCHMARK.getCode());
152
+                ledgerWarningDetailItem.setStatusLabel(LedgerStatusLabelEnum.COMMENDATION_AND_MOTIVATION.getCode());
153
+            } else {
154
+                ledgerWarningDetailItem.setWarningLevel(LedgerAlertLevelEnum.NORMAL_RANGE.getCode());
155
+                ledgerWarningDetailItem.setStatusLabel(LedgerStatusLabelEnum.REGULAR_COACHING.getCode());
156
+            }
157
+//            // 由于person_name存在多用户时person_id为空,因此不能根据person_id进行分组处理数据
158
+//            List<ScoreEvent> userScoreEventList = scoreEventMap.get(userId);
159
+            List<ScoreEvent> userScoreEventList = scoreEventList.stream()
160
+                    .filter(scoreEvent -> {
161
+                        if (ObjUtil.isNull(scoreEvent.getDimensionId()) || StrUtil.isEmpty(scoreEvent.getPersonName())) {
162
+                            return false;
163
+                        }
164
+                        boolean matched = false;
165
+                        for (String n : scoreEvent.getPersonName().split("[,,]")) {
166
+                            if (sysUser.getNickName().equals(n.trim())) {
167
+                                matched = true;
168
+                                break;
169
+                            }
170
+                        }
171
+                        return matched;
172
+                    })
173
+                    .collect(Collectors.toList());
174
+            if (CollUtil.isNotEmpty(userScoreEventList)) {
175
+                Map<String, Integer> userScoreEventCountMap = userScoreEventList.stream().collect(Collectors.groupingBy(ScoreEvent::getLevel2Name, Collectors.summingInt(e -> 1)));
176
+                String coreRisksOrOutstandingAchievements = userScoreEventCountMap.entrySet().stream()
177
+                        .map(entry -> entry.getKey() + entry.getValue() + unitMap.get(entry.getKey()))
178
+                        .collect(Collectors.joining(","));
179
+                ledgerWarningDetailItem.setCoreRisksOrOutstandingAchievements(coreRisksOrOutstandingAchievements);
180
+            }
181
+            ledgerWarningDetailItemList.add(ledgerWarningDetailItem);
182
+        });
183
+        List<LedgerWarningDetailItemVO> redAlertList = ledgerWarningDetailItemList.stream().filter(item -> StrUtil.equals(LedgerAlertLevelEnum.RED_ALERT.getCode(), item.getWarningLevel())).collect(Collectors.toList());
184
+        List<LedgerWarningDetailItemVO> excellentBenchmarkList = ledgerWarningDetailItemList.stream().filter(item -> StrUtil.equals(LedgerAlertLevelEnum.EXCELLENT_BENCHMARK.getCode(), item.getWarningLevel())).collect(Collectors.toList());
185
+        result.setRedAlertNum(redAlertList.size());
186
+        result.setExcellentBenchmarkNum(excellentBenchmarkList.size());
187
+        BigDecimal sum = ledgerWarningDetailItemList.stream().map(LedgerWarningDetailItemVO::getOverallScore).reduce(BigDecimal.ZERO, BigDecimal::add);
188
+        BigDecimal averageComprehensiveScore = CollUtil.isEmpty(ledgerWarningDetailItemList) ? BigDecimal.ZERO : sum.divide(BigDecimal.valueOf(ledgerWarningDetailItemList.size()), 2, RoundingMode.HALF_UP);
189
+        result.setAverageComprehensiveScore(averageComprehensiveScore);
190
+        result.setLedgerWarningDetailItemList(ledgerWarningDetailItemList);
191
+        return result;
192
+    }
193
+
194
+    /**
195
+     * 获取部门映射表
196
+     */
197
+    private Map<Long, SysDept> getDeptMap() {
198
+        List<SysDept> allDepts = sysDeptService.selectDeptInfoAll(new SysDept());
199
+        return allDepts.stream()
200
+                .collect(Collectors.toMap(SysDept::getDeptId, dept -> dept, (v1, v2) -> v1));
201
+    }
202
+
203
+    /**
204
+     * 构建大队到其所有子部门ID的映射
205
+     * 用于按大队级别统计,包括大队及其下属所有部门
206
+     *
207
+     * @param deptMap 部门映射表
208
+     * @return 大队ID到其所有子部门ID集合的映射
209
+     */
210
+    private Map<Long, Set<Long>> buildBrigadeSubDeptsMap(Map<Long, SysDept> deptMap) {
211
+        // 获取所有大队部门
212
+        List<SysDept> allBrigades = deptMap.values().stream()
213
+                .filter(dept -> DeptTypeEnum.BRIGADE.getCode().equals(dept.getDeptType()))
214
+                .collect(Collectors.toList());
215
+        // 构建大队到其所有子部门ID的映射
216
+        Map<Long, Set<Long>> brigadeSubDeptsMap = new HashMap<>();
217
+        for (SysDept brigade : allBrigades) {
218
+            Set<Long> subDeptIds = getAllSubDeptIds(brigade.getDeptId(), deptMap);
219
+            brigadeSubDeptsMap.put(brigade.getDeptId(), subDeptIds);
220
+        }
221
+        return brigadeSubDeptsMap;
222
+    }
223
+
224
+    /**
225
+     * 获取指定部门及其所有子部门的ID集合
226
+     *
227
+     * @param deptId 部门ID
228
+     * @param deptMap 部门映射表
229
+     * @return 包含当前部门及所有子部门的ID集合
230
+     */
231
+    private Set<Long> getAllSubDeptIds(Long deptId, Map<Long, SysDept> deptMap) {
232
+        Set<Long> result = new HashSet<>();
233
+        // 包含当前部门
234
+        result.add(deptId);
235
+        for (SysDept dept : deptMap.values()) {
236
+            if (dept.getParentId() != null && dept.getParentId().equals(deptId)) {
237
+                // 递归获取子部门的子部门
238
+                result.addAll(getAllSubDeptIds(dept.getDeptId(), deptMap));
239
+            }
240
+        }
241
+        return result;
242
+    }
243
+
244
+    /**
245
+     * 查找用户所属的大队ID
246
+     *
247
+     * @param userDeptId 用户所在部门ID
248
+     * @param brigadeSubDeptsMap 大队到其所有子部门ID的映射
249
+     * @return 所属大队ID,如果未找到则返回null
250
+     */
251
+    private Long findUserBrigade(Long userDeptId, Map<Long, Set<Long>> brigadeSubDeptsMap) {
252
+        for (Map.Entry<Long, Set<Long>> entry : brigadeSubDeptsMap.entrySet()) {
253
+            if (entry.getValue().contains(userDeptId)) {
254
+                return entry.getKey();
255
+            }
256
+        }
257
+        return null;
258
+    }
259
+
260
+}

+ 202 - 0
airport-ledger/src/main/resources/mapper/ledger/LedgerWarningMapper.xml

@@ -0,0 +1,202 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.sundot.airport.ledger.mapper.LedgerWarningMapper">
4
+
5
+    <select id="selectLedgerSupervisionProblem"
6
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
7
+            resultType="java.lang.Integer">
8
+        select count(1)
9
+        from ledger_supervision_problem
10
+        where 1 = 1
11
+        <if test="deptId != null">and dept_id = #{deptId}</if>
12
+        <if test="teamId != null">and team_id = #{teamId}</if>
13
+        <if test="groupId != null">and group_id = #{groupId}</if>
14
+        <if test="userId != null">and inspected_id = #{userId}</if>
15
+        <if test="startDate != null">
16
+            and record_date >= #{startDate}
17
+        </if>
18
+        <if test="endDate != null">
19
+            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
20
+        </if>
21
+    </select>
22
+
23
+    <select id="selectLedgerRealtimeInterception"
24
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
25
+            resultType="java.lang.Integer">
26
+        select count(1)
27
+        from ledger_realtime_interception
28
+        where 1 = 1
29
+        <if test="deptId != null">and dept_id = #{deptId}</if>
30
+        <if test="teamId != null">and team_id = #{teamId}</if>
31
+        <if test="groupId != null">and group_id = #{groupId}</if>
32
+        <if test="userId != null">and inspected_id = #{userId}</if>
33
+        <if test="startDate != null">
34
+            and record_date >= #{startDate}
35
+        </if>
36
+        <if test="endDate != null">
37
+            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
38
+        </if>
39
+    </select>
40
+
41
+    <select id="selectLedgerUnsafeEvent"
42
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
43
+            resultType="java.lang.Integer">
44
+        select count(1)
45
+        from ledger_unsafe_event
46
+        where 1 = 1
47
+        <if test="deptId != null">and dept_id = #{deptId}</if>
48
+        <if test="teamId != null">and team_id = #{teamId}</if>
49
+        <if test="groupId != null">and group_id = #{groupId}</if>
50
+        <if test="userId != null">and responsible_id = #{userId}</if>
51
+        <if test="startDate != null">
52
+            and record_date >= #{startDate}
53
+        </if>
54
+        <if test="endDate != null">
55
+            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
56
+        </if>
57
+    </select>
58
+
59
+    <select id="selectLedgerSecurityTest"
60
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
61
+            resultType="java.lang.Integer">
62
+        select count(1)
63
+        from ledger_security_test
64
+        where 1 = 1
65
+        <if test="deptId != null">and dept_id = #{deptId}</if>
66
+        <if test="teamId != null">and team_id = #{teamId}</if>
67
+        <if test="groupId != null">and group_id = #{groupId}</if>
68
+        <if test="userId != null">and tested_id = #{userId}</if>
69
+        <if test="startDate != null">
70
+            and record_date >= #{startDate}
71
+        </if>
72
+        <if test="endDate != null">
73
+            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
74
+        </if>
75
+    </select>
76
+
77
+    <select id="selectLedgerComplaint"
78
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
79
+            resultType="java.lang.Integer">
80
+        select count(1)
81
+        from ledger_complaint
82
+        where 1 = 1
83
+        <if test="deptId != null">and dept_id = #{deptId}</if>
84
+        <if test="teamId != null">and team_id = #{teamId}</if>
85
+        <if test="groupId != null">and group_id = #{groupId}</if>
86
+        <if test="userId != null">and responsible_id = #{userId}</if>
87
+        <if test="startDate != null">
88
+            and record_date >= #{startDate}
89
+        </if>
90
+        <if test="endDate != null">
91
+            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
92
+        </if>
93
+    </select>
94
+
95
+    <select id="selectLedgerServicePatrol"
96
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
97
+            resultType="java.lang.Integer">
98
+        select count(1)
99
+        from ledger_service_patrol
100
+        where 1 = 1
101
+        <if test="deptId != null">and dept_id = #{deptId}</if>
102
+        <if test="teamId != null">and team_id = #{teamId}</if>
103
+        <if test="groupId != null">and group_id = #{groupId}</if>
104
+        <if test="userId != null">and inspected_id = #{userId}</if>
105
+        <if test="startDate != null">
106
+            and record_date >= #{startDate}
107
+        </if>
108
+        <if test="endDate != null">
109
+            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
110
+        </if>
111
+    </select>
112
+
113
+    <select id="selectLedgerTerminalBonus"
114
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
115
+            resultType="java.lang.Integer">
116
+        select count(1)
117
+        from ledger_terminal_bonus
118
+        where 1 = 1
119
+        <if test="deptId != null">and dept_id = #{deptId}</if>
120
+        <if test="teamId != null">and team_id = #{teamId}</if>
121
+        <if test="groupId != null">and group_id = #{groupId}</if>
122
+        <if test="userId != null">and person_id = #{userId}</if>
123
+        <if test="startDate != null">
124
+            and approve_date >= #{startDate}
125
+        </if>
126
+        <if test="endDate != null">
127
+            and approve_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
128
+        </if>
129
+    </select>
130
+
131
+    <select id="selectLedgerRewardApproval"
132
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
133
+            resultType="java.lang.Integer">
134
+        select count(1)
135
+        from ledger_reward_approval
136
+        where 1 = 1
137
+        <if test="deptId != null">and dept_id = #{deptId}</if>
138
+        <if test="teamId != null">and team_id = #{teamId}</if>
139
+        <if test="groupId != null">and group_id = #{groupId}</if>
140
+        <if test="userId != null">and person_id = #{userId}</if>
141
+        <if test="startDate != null">
142
+            and approve_date >= #{startDate}
143
+        </if>
144
+        <if test="endDate != null">
145
+            and approve_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
146
+        </if>
147
+    </select>
148
+
149
+    <select id="selectLedgerExamScore"
150
+            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
151
+            resultType="java.lang.Integer">
152
+        select count(1)
153
+        from ledger_exam_score
154
+        where 1 = 1
155
+        <if test="deptId != null">and dept_id = #{deptId}</if>
156
+        <if test="teamId != null">and team_id = #{teamId}</if>
157
+        <if test="groupId != null">and group_id = #{groupId}</if>
158
+        <if test="userId != null">and person_id = #{userId}</if>
159
+        <if test="startDate != null">
160
+            and exam_date >= #{startDate}
161
+        </if>
162
+        <if test="endDate != null">
163
+            and exam_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
164
+        </if>
165
+    </select>
166
+
167
+    <select id="selectScoreEventList"
168
+            resultType="com.sundot.airport.ledger.domain.ScoreEvent">
169
+        select person_id personId,
170
+        person_name personName,
171
+        dept_id deptId,
172
+        dept_name deptName,
173
+        dimension_id dimensionId,
174
+        dimension_name dimensionName,
175
+        level2_id level2Id,
176
+        level2_name level2Name,
177
+        event_time eventTime
178
+        from score_event
179
+        where 1 = 1
180
+        and org = '4'
181
+        <if test="startDate != null">
182
+            and event_time >= #{startDate}
183
+        </if>
184
+        <if test="endDate != null">
185
+            and event_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
186
+        </if>
187
+        <if test="scoreIndicatorIdList != null and scoreIndicatorIdList.size() > 0">
188
+            and level2_id in
189
+            <foreach collection="scoreIndicatorIdList" item="item" open="(" separator="," close=")">
190
+                #{item}
191
+            </foreach>
192
+        </if>
193
+        <!--        由于person_name存在多用户时person_id为空,因此不能根据person_id进行查询-->
194
+        <!--        <if test="userIdList != null and userIdList.size() > 0">-->
195
+        <!--            and person_id in-->
196
+        <!--            <foreach collection="userIdList" item="item" open="(" separator="," close=")">-->
197
+        <!--                #{item}-->
198
+        <!--            </foreach>-->
199
+        <!--        </if>-->
200
+    </select>
201
+
202
+</mapper>