|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+package com.sundot.airport.ledger.service.impl;
|
|
|
2
|
+
|
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
4
|
+import com.sundot.airport.common.core.domain.entity.SysDept;
|
|
|
5
|
+import com.sundot.airport.common.core.domain.entity.SysUser;
|
|
|
6
|
+import com.sundot.airport.ledger.domain.LedgerBannerLetter;
|
|
|
7
|
+import com.sundot.airport.ledger.domain.LedgerExamScore;
|
|
|
8
|
+import com.sundot.airport.ledger.domain.LedgerTerminalBonus;
|
|
|
9
|
+import com.sundot.airport.ledger.domain.ScoreDimension;
|
|
|
10
|
+import com.sundot.airport.ledger.domain.ScoreEvent;
|
|
|
11
|
+import com.sundot.airport.ledger.domain.vo.EmployeePortraitVO;
|
|
|
12
|
+import com.sundot.airport.ledger.mapper.LedgerBannerLetterMapper;
|
|
|
13
|
+import com.sundot.airport.ledger.mapper.LedgerExamScoreMapper;
|
|
|
14
|
+import com.sundot.airport.ledger.mapper.LedgerTerminalBonusMapper;
|
|
|
15
|
+import com.sundot.airport.ledger.mapper.ScoreDimensionMapper;
|
|
|
16
|
+import com.sundot.airport.ledger.mapper.ScoreEventMapper;
|
|
|
17
|
+import com.sundot.airport.ledger.service.IEmployeePortraitService;
|
|
|
18
|
+import com.sundot.airport.system.mapper.SysDeptMapper;
|
|
|
19
|
+import com.sundot.airport.system.mapper.SysUserMapper;
|
|
|
20
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
21
|
+import org.springframework.stereotype.Service;
|
|
|
22
|
+
|
|
|
23
|
+import java.math.BigDecimal;
|
|
|
24
|
+import java.math.RoundingMode;
|
|
|
25
|
+import java.util.*;
|
|
|
26
|
+import java.util.stream.Collectors;
|
|
|
27
|
+
|
|
|
28
|
+@Service
|
|
|
29
|
+public class EmployeePortraitServiceImpl implements IEmployeePortraitService {
|
|
|
30
|
+
|
|
|
31
|
+ @Autowired
|
|
|
32
|
+ private SysUserMapper sysUserMapper;
|
|
|
33
|
+
|
|
|
34
|
+ @Autowired
|
|
|
35
|
+ private SysDeptMapper sysDeptMapper;
|
|
|
36
|
+
|
|
|
37
|
+ @Autowired
|
|
|
38
|
+ private ScoreEventMapper scoreEventMapper;
|
|
|
39
|
+
|
|
|
40
|
+ @Autowired
|
|
|
41
|
+ private ScoreDimensionMapper scoreDimensionMapper;
|
|
|
42
|
+
|
|
|
43
|
+ @Autowired
|
|
|
44
|
+ private LedgerExamScoreMapper ledgerExamScoreMapper;
|
|
|
45
|
+
|
|
|
46
|
+ @Autowired
|
|
|
47
|
+ private LedgerBannerLetterMapper ledgerBannerLetterMapper;
|
|
|
48
|
+
|
|
|
49
|
+ @Autowired
|
|
|
50
|
+ private LedgerTerminalBonusMapper ledgerTerminalBonusMapper;
|
|
|
51
|
+
|
|
|
52
|
+ // ── 搜索员工 ─────────────────────────────────────────────────────────────
|
|
|
53
|
+
|
|
|
54
|
+ @Override
|
|
|
55
|
+ public List<Map<String, Object>> searchUsers(String keyword) {
|
|
|
56
|
+ SysUser query = new SysUser();
|
|
|
57
|
+ query.setNickName(keyword);
|
|
|
58
|
+ List<SysUser> users = sysUserMapper.selectUserList(query);
|
|
|
59
|
+ if (users == null) return Collections.emptyList();
|
|
|
60
|
+ return users.stream()
|
|
|
61
|
+ .filter(u -> "0".equals(u.getStatus()) && "0".equals(u.getDelFlag()))
|
|
|
62
|
+ .limit(20)
|
|
|
63
|
+ .map(u -> {
|
|
|
64
|
+ Map<String, Object> m = new LinkedHashMap<>();
|
|
|
65
|
+ m.put("userId", u.getUserId());
|
|
|
66
|
+ m.put("nickName", u.getNickName());
|
|
|
67
|
+ m.put("deptName", u.getDept() != null ? u.getDept().getDeptName() : "");
|
|
|
68
|
+ return m;
|
|
|
69
|
+ })
|
|
|
70
|
+ .collect(Collectors.toList());
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ // ── 获取员工完整画像 ──────────────────────────────────────────────────────
|
|
|
74
|
+
|
|
|
75
|
+ @Override
|
|
|
76
|
+ public EmployeePortraitVO getPortrait(String personName, String beginTime, String endTime) {
|
|
|
77
|
+ EmployeePortraitVO vo = new EmployeePortraitVO();
|
|
|
78
|
+ vo.setPersonName(personName);
|
|
|
79
|
+
|
|
|
80
|
+ // 1. 用户基本信息
|
|
|
81
|
+ fillUserInfo(vo, personName);
|
|
|
82
|
+
|
|
|
83
|
+ // 2. 六维度评分(从 score_event 聚合)
|
|
|
84
|
+ fillScores(vo, personName, beginTime, endTime);
|
|
|
85
|
+
|
|
|
86
|
+ // 3. 最新考试成绩
|
|
|
87
|
+ fillExamScore(vo, personName);
|
|
|
88
|
+
|
|
|
89
|
+ // 4. 获奖记录(锦旗/感谢信 + 航站楼加分)
|
|
|
90
|
+ fillAwards(vo, personName);
|
|
|
91
|
+
|
|
|
92
|
+ return vo;
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+ // ── 用户基本信息 ─────────────────────────────────────────────────────────
|
|
|
96
|
+
|
|
|
97
|
+ private void fillUserInfo(EmployeePortraitVO vo, String personName) {
|
|
|
98
|
+ SysUser query = new SysUser();
|
|
|
99
|
+ query.setNickName(personName);
|
|
|
100
|
+ List<SysUser> users = sysUserMapper.selectUserList(query);
|
|
|
101
|
+ if (users == null || users.isEmpty()) return;
|
|
|
102
|
+
|
|
|
103
|
+ SysUser user = users.stream()
|
|
|
104
|
+ .filter(u -> personName.equals(u.getNickName()))
|
|
|
105
|
+ .findFirst()
|
|
|
106
|
+ .orElse(users.get(0));
|
|
|
107
|
+
|
|
|
108
|
+ vo.setUserId(user.getUserId());
|
|
|
109
|
+ vo.setAvatar(user.getAvatar());
|
|
|
110
|
+ vo.setPhonenumber(user.getPhonenumber());
|
|
|
111
|
+ vo.setSex(user.getSex());
|
|
|
112
|
+ vo.setSexText("0".equals(user.getSex()) ? "男" : "1".equals(user.getSex()) ? "女" : "");
|
|
|
113
|
+ vo.setSchooling(user.getSchooling());
|
|
|
114
|
+ vo.setQualificationLevelText(decodeQualLevel(user.getQualificationLevel()));
|
|
|
115
|
+ vo.setPoliticalStatusText(decodePolitical(user.getPoliticalStatus()));
|
|
|
116
|
+ vo.setCharacterCharacteristics(decodeChar(user.getCharacterCharacteristics()));
|
|
|
117
|
+ vo.setWorkingStyle(decodeWorkStyle(user.getWorkingStyle()));
|
|
|
118
|
+ vo.setStartWorkingDate(user.getStartWorkingDate());
|
|
|
119
|
+ vo.setSecurityCheckStartDate(user.getSecurityCheckStartDate());
|
|
|
120
|
+ vo.setSecurityInspectionPosition(user.getSecurityInspectionPosition());
|
|
|
121
|
+
|
|
|
122
|
+ // 司龄、开机年限
|
|
|
123
|
+ long nowMs = System.currentTimeMillis();
|
|
|
124
|
+ if (user.getStartWorkingDate() != null) {
|
|
|
125
|
+ vo.setWorkYears((int) ((nowMs - user.getStartWorkingDate().getTime()) / (365L * 24 * 3600 * 1000)));
|
|
|
126
|
+ }
|
|
|
127
|
+ if (user.getSecurityCheckStartDate() != null) {
|
|
|
128
|
+ vo.setSecurityCheckYears((int) ((nowMs - user.getSecurityCheckStartDate().getTime()) / (365L * 24 * 3600 * 1000)));
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+ // 部门路径
|
|
|
132
|
+ if (user.getDept() != null) {
|
|
|
133
|
+ String deptName = user.getDept().getDeptName();
|
|
|
134
|
+ String parentDeptName = "";
|
|
|
135
|
+ Long parentId = user.getDept().getParentId();
|
|
|
136
|
+ if (parentId != null && parentId > 0) {
|
|
|
137
|
+ SysDept parent = sysDeptMapper.selectDeptById(parentId);
|
|
|
138
|
+ if (parent != null) parentDeptName = parent.getDeptName();
|
|
|
139
|
+ }
|
|
|
140
|
+ vo.setDeptName(deptName);
|
|
|
141
|
+ vo.setParentDeptName(parentDeptName);
|
|
|
142
|
+ vo.setDeptPath(parentDeptName.isEmpty() ? deptName : parentDeptName + "/" + deptName);
|
|
|
143
|
+ }
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
|
146
|
+ // ── 六维度评分 ────────────────────────────────────────────────────────────
|
|
|
147
|
+
|
|
|
148
|
+ private void fillScores(EmployeePortraitVO vo, String personName, String beginTime, String endTime) {
|
|
|
149
|
+ // 加载全部事件,按姓名 LIKE 过滤(支持逗号分隔多人)
|
|
|
150
|
+ ScoreEvent eventQuery = new ScoreEvent();
|
|
|
151
|
+ eventQuery.setPersonName(personName);
|
|
|
152
|
+ if (beginTime != null && !beginTime.isEmpty()) {
|
|
|
153
|
+ eventQuery.getParams().put("beginTime", beginTime);
|
|
|
154
|
+ }
|
|
|
155
|
+ if (endTime != null && !endTime.isEmpty()) {
|
|
|
156
|
+ eventQuery.getParams().put("endTime", endTime);
|
|
|
157
|
+ }
|
|
|
158
|
+ List<ScoreEvent> events = scoreEventMapper.selectList(eventQuery);
|
|
|
159
|
+
|
|
|
160
|
+ // 精确匹配(防止逗号多人字段的误匹配)
|
|
|
161
|
+ Map<Long, BigDecimal> dimMap = new HashMap<>();
|
|
|
162
|
+ for (ScoreEvent e : events) {
|
|
|
163
|
+ Long dimId = e.getDimensionId();
|
|
|
164
|
+ if (dimId == null) continue;
|
|
|
165
|
+ String raw = e.getPersonName();
|
|
|
166
|
+ if (raw == null) continue;
|
|
|
167
|
+ boolean matched = false;
|
|
|
168
|
+ for (String n : raw.split("[,,]")) {
|
|
|
169
|
+ if (personName.equals(n.trim())) { matched = true; break; }
|
|
|
170
|
+ }
|
|
|
171
|
+ if (!matched) continue;
|
|
|
172
|
+ BigDecimal val = e.getTotalScore() != null ? e.getTotalScore() : BigDecimal.ZERO;
|
|
|
173
|
+ dimMap.merge(dimId, val, BigDecimal::add);
|
|
|
174
|
+ }
|
|
|
175
|
+
|
|
|
176
|
+ // 加载维度定义
|
|
|
177
|
+ ScoreDimension dq = new ScoreDimension();
|
|
|
178
|
+ dq.setStatus("0");
|
|
|
179
|
+ List<ScoreDimension> dims = scoreDimensionMapper.selectList(dq);
|
|
|
180
|
+ dims.sort(Comparator.comparing(d -> d.getSortOrder() == null ? 999 : d.getSortOrder()));
|
|
|
181
|
+
|
|
|
182
|
+ List<EmployeePortraitVO.DimScoreItem> items = new ArrayList<>();
|
|
|
183
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
184
|
+
|
|
|
185
|
+ for (ScoreDimension dim : dims) {
|
|
|
186
|
+ BigDecimal eventScore = dimMap.getOrDefault(dim.getId(), BigDecimal.ZERO);
|
|
|
187
|
+ BigDecimal base = dim.getBaseScore() != null ? dim.getBaseScore() : BigDecimal.valueOf(80);
|
|
|
188
|
+ BigDecimal dimScore = base.add(eventScore);
|
|
|
189
|
+ BigDecimal weight = dim.getWeight() != null ? dim.getWeight() : BigDecimal.ZERO;
|
|
|
190
|
+ BigDecimal contribution = dimScore.multiply(weight)
|
|
|
191
|
+ .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
|
|
|
192
|
+ total = total.add(contribution);
|
|
|
193
|
+
|
|
|
194
|
+ EmployeePortraitVO.DimScoreItem item = new EmployeePortraitVO.DimScoreItem();
|
|
|
195
|
+ item.setName(dim.getName());
|
|
|
196
|
+ item.setScore(dimScore.setScale(1, RoundingMode.HALF_UP));
|
|
|
197
|
+ item.setWeight(weight);
|
|
|
198
|
+ item.setBaseScore(base);
|
|
|
199
|
+ item.setEventScore(eventScore.setScale(2, RoundingMode.HALF_UP));
|
|
|
200
|
+ items.add(item);
|
|
|
201
|
+ }
|
|
|
202
|
+
|
|
|
203
|
+ vo.setDimensions(items);
|
|
|
204
|
+ vo.setTotalScore(total.setScale(1, RoundingMode.HALF_UP));
|
|
|
205
|
+ }
|
|
|
206
|
+
|
|
|
207
|
+ // ── 考试成绩 ──────────────────────────────────────────────────────────────
|
|
|
208
|
+
|
|
|
209
|
+ private void fillExamScore(EmployeePortraitVO vo, String personName) {
|
|
|
210
|
+ QueryWrapper<LedgerExamScore> qw = new QueryWrapper<>();
|
|
|
211
|
+ qw.like("person_name", personName)
|
|
|
212
|
+ .eq("del_flag", "0")
|
|
|
213
|
+ .orderByDesc("exam_date")
|
|
|
214
|
+ .last("LIMIT 1");
|
|
|
215
|
+ List<LedgerExamScore> list = ledgerExamScoreMapper.selectList(qw);
|
|
|
216
|
+ if (list == null || list.isEmpty()) return;
|
|
|
217
|
+ LedgerExamScore exam = list.get(0);
|
|
|
218
|
+ vo.setTheoryScore(exam.getTheoryScore());
|
|
|
219
|
+ vo.setImageScore(exam.getImageScore());
|
|
|
220
|
+ vo.setExamDate(exam.getExamDate());
|
|
|
221
|
+ vo.setExamCategory(exam.getExamCategory());
|
|
|
222
|
+ vo.setExamPeriod(exam.getExamPeriod());
|
|
|
223
|
+ }
|
|
|
224
|
+
|
|
|
225
|
+ // ── 获奖记录 ──────────────────────────────────────────────────────────────
|
|
|
226
|
+
|
|
|
227
|
+ private void fillAwards(EmployeePortraitVO vo, String personName) {
|
|
|
228
|
+ List<EmployeePortraitVO.AwardRecord> awards = new ArrayList<>();
|
|
|
229
|
+
|
|
|
230
|
+ // 锦旗及感谢信
|
|
|
231
|
+ QueryWrapper<LedgerBannerLetter> bq = new QueryWrapper<>();
|
|
|
232
|
+ bq.like("person_name", personName).eq("del_flag", "0").orderByDesc("record_date");
|
|
|
233
|
+ for (LedgerBannerLetter b : ledgerBannerLetterMapper.selectList(bq)) {
|
|
|
234
|
+ EmployeePortraitVO.AwardRecord ar = new EmployeePortraitVO.AwardRecord();
|
|
|
235
|
+ ar.setType("1".equals(b.getType()) ? "锦旗" : "感谢信");
|
|
|
236
|
+ ar.setContent(b.getContentDesc());
|
|
|
237
|
+ ar.setScore(b.getAddScore());
|
|
|
238
|
+ ar.setDate(b.getRecordDate());
|
|
|
239
|
+ awards.add(ar);
|
|
|
240
|
+ }
|
|
|
241
|
+
|
|
|
242
|
+ // 航站楼加分
|
|
|
243
|
+ QueryWrapper<LedgerTerminalBonus> tq = new QueryWrapper<>();
|
|
|
244
|
+ tq.like("person_name", personName).eq("del_flag", "0").orderByDesc("approve_date");
|
|
|
245
|
+ for (LedgerTerminalBonus t : ledgerTerminalBonusMapper.selectList(tq)) {
|
|
|
246
|
+ EmployeePortraitVO.AwardRecord ar = new EmployeePortraitVO.AwardRecord();
|
|
|
247
|
+ ar.setType("航站楼加分");
|
|
|
248
|
+ ar.setContent(t.getBonusType());
|
|
|
249
|
+ ar.setScore(t.getAddScore());
|
|
|
250
|
+ ar.setDate(t.getApproveDate());
|
|
|
251
|
+ awards.add(ar);
|
|
|
252
|
+ }
|
|
|
253
|
+
|
|
|
254
|
+ // 按日期降序
|
|
|
255
|
+ awards.sort((a, b) -> {
|
|
|
256
|
+ if (a.getDate() == null) return 1;
|
|
|
257
|
+ if (b.getDate() == null) return -1;
|
|
|
258
|
+ return b.getDate().compareTo(a.getDate());
|
|
|
259
|
+ });
|
|
|
260
|
+
|
|
|
261
|
+ vo.setAwards(awards);
|
|
|
262
|
+ }
|
|
|
263
|
+
|
|
|
264
|
+ // ── 枚举解码工具 ─────────────────────────────────────────────────────────
|
|
|
265
|
+
|
|
|
266
|
+ private static String decodeQualLevel(String v) {
|
|
|
267
|
+ if (v == null) return "";
|
|
|
268
|
+ switch (v) {
|
|
|
269
|
+ case "LEVEL_ONE": return "一级";
|
|
|
270
|
+ case "LEVEL_TWO": return "二级";
|
|
|
271
|
+ case "LEVEL_THREE": return "三级";
|
|
|
272
|
+ case "LEVEL_FOUR": return "四级";
|
|
|
273
|
+ case "LEVEL_FIVE": return "五级";
|
|
|
274
|
+ default: return v;
|
|
|
275
|
+ }
|
|
|
276
|
+ }
|
|
|
277
|
+
|
|
|
278
|
+ private static String decodePolitical(String v) {
|
|
|
279
|
+ if (v == null) return "";
|
|
|
280
|
+ switch (v) {
|
|
|
281
|
+ case "COMMUNIST_PARTY_MEMBER": return "中共党员";
|
|
|
282
|
+ case "PROBATIONARY_COMMUNIST_PARTY_MEMBER":return "中共预备党员";
|
|
|
283
|
+ case "COMMUNIST_YOUTH_LEAGUE_MEMBER": return "共青团员";
|
|
|
284
|
+ case "MASS_PUBLIC": return "群众";
|
|
|
285
|
+ default: return v;
|
|
|
286
|
+ }
|
|
|
287
|
+ }
|
|
|
288
|
+
|
|
|
289
|
+ private static String decodeChar(String v) {
|
|
|
290
|
+ if (v == null) return "";
|
|
|
291
|
+ // 值格式如 "ISTJ",映射为 "ISTJ(检查员型)"
|
|
|
292
|
+ Map<String, String> m = new LinkedHashMap<>();
|
|
|
293
|
+ m.put("ISTJ", "ISTJ(检查员型)"); m.put("ISFJ", "ISFJ(守护者型)");
|
|
|
294
|
+ m.put("INFJ", "INFJ(咨询师型)"); m.put("INTJ", "INTJ(战略家型)");
|
|
|
295
|
+ m.put("ISTP", "ISTP(手艺人型)"); m.put("ISFP", "ISFP(艺术家型)");
|
|
|
296
|
+ m.put("INFP", "INFP(调停者型)"); m.put("INTP", "INTP(逻辑学家型)");
|
|
|
297
|
+ m.put("ESTP", "ESTP(企业家型)"); m.put("ESFP", "ESFP(表演者型)");
|
|
|
298
|
+ m.put("ENFP", "ENFP(活动家型)"); m.put("ENTP", "ENTP(辩论家型)");
|
|
|
299
|
+ m.put("ESTJ", "ESTJ(总经理型)"); m.put("ESFJ", "ESFJ(执政官型)");
|
|
|
300
|
+ m.put("ENFJ", "ENFJ(教育家型)"); m.put("ENTJ", "ENTJ(指挥官型)");
|
|
|
301
|
+ return m.getOrDefault(v, v);
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ private static String decodeWorkStyle(String v) {
|
|
|
305
|
+ if (v == null) return "";
|
|
|
306
|
+ switch (v) {
|
|
|
307
|
+ case "D": return "D型(支配型)";
|
|
|
308
|
+ case "I": return "I型(影响型)";
|
|
|
309
|
+ case "S": return "S型(稳健型)";
|
|
|
310
|
+ case "C": return "C型(尽责型)";
|
|
|
311
|
+ default: return v;
|
|
|
312
|
+ }
|
|
|
313
|
+ }
|
|
|
314
|
+}
|