|
|
@@ -11,11 +11,13 @@ import com.sundot.airport.common.enums.DeptTypeEnum;
|
|
11
|
11
|
import com.sundot.airport.common.enums.LedgerAlertLevelEnum;
|
|
12
|
12
|
import com.sundot.airport.common.enums.LedgerStatusLabelEnum;
|
|
13
|
13
|
import com.sundot.airport.common.enums.ScoreLevelEnum;
|
|
|
14
|
+import com.sundot.airport.common.utils.DateMonthUtils;
|
|
14
|
15
|
import com.sundot.airport.common.utils.DeptUtils;
|
|
15
|
16
|
import com.sundot.airport.common.utils.SecurityUtils;
|
|
16
|
17
|
import com.sundot.airport.common.utils.StreamSortUtils;
|
|
17
|
18
|
import com.sundot.airport.ledger.domain.ScoreEvent;
|
|
18
|
19
|
import com.sundot.airport.ledger.domain.ScoreIndicator;
|
|
|
20
|
+import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailItemReduceVO;
|
|
19
|
21
|
import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailItemVO;
|
|
20
|
22
|
import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailVO;
|
|
21
|
23
|
import com.sundot.airport.ledger.domain.vo.LedgerWarningVO;
|
|
|
@@ -266,4 +268,114 @@ public class LedgerWarningServiceImpl implements ILedgerWarningService {
|
|
266
|
268
|
return null;
|
|
267
|
269
|
}
|
|
268
|
270
|
|
|
|
271
|
+ /**
|
|
|
272
|
+ * 红线指标预警
|
|
|
273
|
+ */
|
|
|
274
|
+ @Override
|
|
|
275
|
+ public List<LedgerWarningDetailItemReduceVO> ledgerReduceDetail(LedgerCommonQueryReqVO queryReq) {
|
|
|
276
|
+ List<String> scoreIndicatorNameList = Arrays.asList("员工规范化操作", "后台实时质控拦截", "不安全事件", "安保测试未通过");
|
|
|
277
|
+ Map<String, String> unitMap = new HashMap<>();
|
|
|
278
|
+ unitMap.put("员工规范化操作", "项");
|
|
|
279
|
+ unitMap.put("后台实时质控拦截", "次");
|
|
|
280
|
+ unitMap.put("不安全事件", "起");
|
|
|
281
|
+ unitMap.put("安保测试未通过", "项");
|
|
|
282
|
+
|
|
|
283
|
+ Long topSiteId = DeptUtils.getTopSiteId(sysDeptService.selectDeptById(SecurityUtils.getDeptId()));
|
|
|
284
|
+ // 获取所有部门信息
|
|
|
285
|
+ Map<Long, SysDept> deptMap = getDeptMap();
|
|
|
286
|
+ // 构建大队到其所有子部门ID的映射
|
|
|
287
|
+ Map<Long, Set<Long>> brigadeSubDeptsMap = buildBrigadeSubDeptsMap(getDeptMap());
|
|
|
288
|
+
|
|
|
289
|
+ ScoreIndicator scoreIndicatorQuery = new ScoreIndicator();
|
|
|
290
|
+ scoreIndicatorQuery.setStatus("0");
|
|
|
291
|
+ scoreIndicatorQuery.setOrg(ScoreLevelEnum.PERSON.getCode());
|
|
|
292
|
+ scoreIndicatorQuery.setLevel(2);
|
|
|
293
|
+ List<ScoreIndicator> scoreIndicatorList = scoreIndicatorService.selectList(scoreIndicatorQuery);
|
|
|
294
|
+ scoreIndicatorList = scoreIndicatorList.stream().filter(scoreIndicator -> scoreIndicatorNameList.contains(scoreIndicator.getName())).collect(Collectors.toList());
|
|
|
295
|
+ List<Long> scoreIndicatorIdList = scoreIndicatorList.stream().map(ScoreIndicator::getId).collect(Collectors.toList());
|
|
|
296
|
+ List<Long> userIdList = new ArrayList<>();
|
|
|
297
|
+ List<String> userNameList = new ArrayList<>();
|
|
|
298
|
+ Map<Long, SysUser> sysUserMap = new HashMap<>();
|
|
|
299
|
+ if (ObjUtil.isNotNull(queryReq.getUserId())) {
|
|
|
300
|
+ userIdList.add(queryReq.getUserId());
|
|
|
301
|
+ SysUser sysUser = sysUserService.selectUserById(queryReq.getUserId());
|
|
|
302
|
+ userNameList.add(sysUser.getNickName());
|
|
|
303
|
+ sysUserMap.put(queryReq.getUserId(), sysUser);
|
|
|
304
|
+ } else {
|
|
|
305
|
+ Long targetDeptId = ObjUtil.isNotNull(queryReq.getGroupId()) ? queryReq.getGroupId()
|
|
|
306
|
+ : ObjUtil.isNotNull(queryReq.getTeamId()) ? queryReq.getTeamId()
|
|
|
307
|
+ : ObjUtil.isNotNull(queryReq.getDeptId()) ? queryReq.getDeptId()
|
|
|
308
|
+ : topSiteId;
|
|
|
309
|
+ List<SysUser> sysUserList = sysUserService.selectUserByDeptId(targetDeptId);
|
|
|
310
|
+ userIdList.addAll(sysUserList.stream().map(SysUser::getUserId).collect(Collectors.toList()));
|
|
|
311
|
+ userNameList.addAll(sysUserList.stream().map(SysUser::getNickName).collect(Collectors.toList()));
|
|
|
312
|
+ sysUserMap.putAll(sysUserList.stream().collect(Collectors.toMap(SysUser::getUserId, user -> user)));
|
|
|
313
|
+ }
|
|
|
314
|
+ List<ScoreEvent> scoreEventList = ledgerWarningMapper.selectScoreEventList(queryReq.getStartDate(), queryReq.getEndDate(), scoreIndicatorIdList, userIdList);
|
|
|
315
|
+// // 由于person_name存在多用户时person_id为空,因此不能根据person_id进行分组处理数据
|
|
|
316
|
+// Map<Long, List<ScoreEvent>> scoreEventMap = scoreEventList.stream().collect(Collectors.groupingBy(ScoreEvent::getPersonId));
|
|
|
317
|
+ List<LedgerWarningDetailItemReduceVO> resultList = new ArrayList<>();
|
|
|
318
|
+ userIdList.forEach(userId -> {
|
|
|
319
|
+ SysUser sysUser = sysUserMap.get(userId);
|
|
|
320
|
+// // 由于person_name存在多用户时person_id为空,因此不能根据person_id进行分组处理数据
|
|
|
321
|
+// List<ScoreEvent> userScoreEventList = scoreEventMap.get(userId);
|
|
|
322
|
+ List<ScoreEvent> userScoreEventList = scoreEventList.stream()
|
|
|
323
|
+ .filter(scoreEvent -> {
|
|
|
324
|
+ if (ObjUtil.isNull(scoreEvent.getDimensionId()) || StrUtil.isEmpty(scoreEvent.getPersonName())) {
|
|
|
325
|
+ return false;
|
|
|
326
|
+ }
|
|
|
327
|
+ boolean matched = false;
|
|
|
328
|
+ for (String n : scoreEvent.getPersonName().split("[,,]")) {
|
|
|
329
|
+ if (sysUser.getNickName().equals(n.trim())) {
|
|
|
330
|
+ matched = true;
|
|
|
331
|
+ break;
|
|
|
332
|
+ }
|
|
|
333
|
+ }
|
|
|
334
|
+ return matched;
|
|
|
335
|
+ })
|
|
|
336
|
+ .collect(Collectors.toList());
|
|
|
337
|
+ if (CollUtil.isNotEmpty(userScoreEventList)) {
|
|
|
338
|
+ Map<String, List<ScoreEvent>> userScoreEventListMap = userScoreEventList.stream().collect(Collectors.groupingBy(item -> item.getLevel2Id() + "_" + item.getLevel2Name()));
|
|
|
339
|
+ userScoreEventListMap.forEach((level2IdName, eventList) -> {
|
|
|
340
|
+ LedgerWarningDetailItemReduceVO ledgerWarningDetailItemReduce = new LedgerWarningDetailItemReduceVO();
|
|
|
341
|
+ ledgerWarningDetailItemReduce.setUserId(sysUser.getUserId());
|
|
|
342
|
+ ledgerWarningDetailItemReduce.setUserName(sysUser.getUserName());
|
|
|
343
|
+ ledgerWarningDetailItemReduce.setNickName(sysUser.getNickName());
|
|
|
344
|
+ ledgerWarningDetailItemReduce.setDeptId(sysUser.getDeptId());
|
|
|
345
|
+ SysDept dept = deptMap.get(findUserBrigade(sysUser.getDeptId(), brigadeSubDeptsMap));
|
|
|
346
|
+ if (ObjUtil.isNotNull(dept)) {
|
|
|
347
|
+ ledgerWarningDetailItemReduce.setDeptName(dept.getDeptName());
|
|
|
348
|
+ }
|
|
|
349
|
+ ledgerWarningDetailItemReduce.setDimensionId(eventList.get(0).getDimensionId());
|
|
|
350
|
+ ledgerWarningDetailItemReduce.setDimensionName(eventList.get(0).getDimensionName());
|
|
|
351
|
+ ledgerWarningDetailItemReduce.setLevel2Id(Long.valueOf(level2IdName.split("_")[0]));
|
|
|
352
|
+ ledgerWarningDetailItemReduce.setLevel2Name(level2IdName.split("_")[1]);
|
|
|
353
|
+ ledgerWarningDetailItemReduce.setTotalScore(eventList.stream().map(ScoreEvent::getTotalScore).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
354
|
+ ledgerWarningDetailItemReduce.setOccurrenceCount(eventList.size());
|
|
|
355
|
+ ledgerWarningDetailItemReduce.setMonthCount(DateMonthUtils.calculateMonths(queryReq.getStartDate(), queryReq.getEndDate()));
|
|
|
356
|
+ ledgerWarningDetailItemReduce.setAverageCount(ObjUtil.isNull(ledgerWarningDetailItemReduce.getMonthCount()) ? BigDecimal.ZERO : BigDecimal.valueOf(ledgerWarningDetailItemReduce.getOccurrenceCount()).divide(BigDecimal.valueOf(ledgerWarningDetailItemReduce.getMonthCount()), 1, RoundingMode.HALF_UP));
|
|
|
357
|
+ if (ledgerWarningDetailItemReduce.getAverageCount().compareTo(BigDecimal.valueOf(3)) >= 0) {
|
|
|
358
|
+ ledgerWarningDetailItemReduce.setWarningLevel(LedgerAlertLevelEnum.RED_ALERT.getCode());
|
|
|
359
|
+ ledgerWarningDetailItemReduce.setStatusLabel(LedgerStatusLabelEnum.EMERGENCY_INTERVENTION.getCode());
|
|
|
360
|
+ } else {
|
|
|
361
|
+ ledgerWarningDetailItemReduce.setWarningLevel(LedgerAlertLevelEnum.NORMAL_RANGE.getCode());
|
|
|
362
|
+ ledgerWarningDetailItemReduce.setStatusLabel(LedgerStatusLabelEnum.REGULAR_COACHING.getCode());
|
|
|
363
|
+ }
|
|
|
364
|
+ ledgerWarningDetailItemReduce.setCoreRisks(ledgerWarningDetailItemReduce.getLevel2Name() + ledgerWarningDetailItemReduce.getOccurrenceCount() + unitMap.get(ledgerWarningDetailItemReduce.getLevel2Name()));
|
|
|
365
|
+ resultList.add(ledgerWarningDetailItemReduce);
|
|
|
366
|
+ });
|
|
|
367
|
+ }
|
|
|
368
|
+ });
|
|
|
369
|
+
|
|
|
370
|
+ // 排序
|
|
|
371
|
+ if (ObjUtil.isNull(queryReq.getSorts())) {
|
|
|
372
|
+ Map<String, String> sorts = new LinkedHashMap<>();
|
|
|
373
|
+ sorts.put("userId", "asc");
|
|
|
374
|
+ sorts.put("dimensionId", "asc");
|
|
|
375
|
+ queryReq.setSorts(sorts);
|
|
|
376
|
+ }
|
|
|
377
|
+ List<LedgerWarningDetailItemReduceVO> result = StreamSortUtils.sort(resultList, queryReq.getSorts());
|
|
|
378
|
+ return result;
|
|
|
379
|
+ }
|
|
|
380
|
+
|
|
269
|
381
|
}
|