|
|
@@ -15,13 +15,16 @@ import com.sundot.airport.common.utils.DateMonthUtils;
|
|
15
|
15
|
import com.sundot.airport.common.utils.DeptUtils;
|
|
16
|
16
|
import com.sundot.airport.common.utils.SecurityUtils;
|
|
17
|
17
|
import com.sundot.airport.common.utils.StreamSortUtils;
|
|
|
18
|
+import com.sundot.airport.ledger.domain.ScoreDimension;
|
|
18
|
19
|
import com.sundot.airport.ledger.domain.ScoreEvent;
|
|
19
|
20
|
import com.sundot.airport.ledger.domain.ScoreIndicator;
|
|
|
21
|
+import com.sundot.airport.ledger.domain.vo.EmployeeDimensionScoreVO;
|
|
20
|
22
|
import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailItemReduceVO;
|
|
21
|
23
|
import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailItemVO;
|
|
22
|
24
|
import com.sundot.airport.ledger.domain.vo.LedgerWarningDetailVO;
|
|
23
|
25
|
import com.sundot.airport.ledger.domain.vo.LedgerWarningVO;
|
|
24
|
26
|
import com.sundot.airport.ledger.mapper.LedgerWarningMapper;
|
|
|
27
|
+import com.sundot.airport.ledger.mapper.ScoreDimensionMapper;
|
|
25
|
28
|
import com.sundot.airport.ledger.service.IEmployeePortraitService;
|
|
26
|
29
|
import com.sundot.airport.ledger.service.ILedgerWarningService;
|
|
27
|
30
|
import com.sundot.airport.ledger.service.IScoreIndicatorService;
|
|
|
@@ -63,6 +66,9 @@ public class LedgerWarningServiceImpl implements ILedgerWarningService {
|
|
63
|
66
|
@Autowired
|
|
64
|
67
|
private ISysUserService sysUserService;
|
|
65
|
68
|
|
|
|
69
|
+ @Autowired
|
|
|
70
|
+ private ScoreDimensionMapper scoreDimensionMapper;
|
|
|
71
|
+
|
|
66
|
72
|
/**
|
|
67
|
73
|
* 台账数据
|
|
68
|
74
|
*/
|
|
|
@@ -131,7 +137,7 @@ public class LedgerWarningServiceImpl implements ILedgerWarningService {
|
|
131
|
137
|
sysUserMap.putAll(sysUserList.stream().collect(Collectors.toMap(SysUser::getUserId, user -> user)));
|
|
132
|
138
|
}
|
|
133
|
139
|
Map<String, BigDecimal> overallScoreMap = employeePortraitService.getPortraitTotalScore(userNameList, DateUtil.formatDate(queryReq.getStartDate()), DateUtil.formatDate(queryReq.getEndDate()));
|
|
134
|
|
- List<ScoreEvent> scoreEventList = ledgerWarningMapper.selectScoreEventList(queryReq.getStartDate(), queryReq.getEndDate(), scoreIndicatorIdList, userIdList);
|
|
|
140
|
+ List<ScoreEvent> scoreEventList = ledgerWarningMapper.selectScoreEventList(queryReq.getStartDate(), queryReq.getEndDate(), scoreIndicatorIdList, userIdList,null);
|
|
135
|
141
|
// // 由于person_name存在多用户时person_id为空,因此不能根据person_id进行分组处理数据
|
|
136
|
142
|
// Map<Long, List<ScoreEvent>> scoreEventMap = scoreEventList.stream().collect(Collectors.groupingBy(ScoreEvent::getPersonId));
|
|
137
|
143
|
List<LedgerWarningDetailItemVO> ledgerWarningDetailItemList = new ArrayList<>();
|
|
|
@@ -311,7 +317,7 @@ public class LedgerWarningServiceImpl implements ILedgerWarningService {
|
|
311
|
317
|
userNameList.addAll(sysUserList.stream().map(SysUser::getNickName).collect(Collectors.toList()));
|
|
312
|
318
|
sysUserMap.putAll(sysUserList.stream().collect(Collectors.toMap(SysUser::getUserId, user -> user)));
|
|
313
|
319
|
}
|
|
314
|
|
- List<ScoreEvent> scoreEventList = ledgerWarningMapper.selectScoreEventList(queryReq.getStartDate(), queryReq.getEndDate(), scoreIndicatorIdList, userIdList);
|
|
|
320
|
+ List<ScoreEvent> scoreEventList = ledgerWarningMapper.selectScoreEventList(queryReq.getStartDate(), queryReq.getEndDate(), scoreIndicatorIdList, userIdList,null);
|
|
315
|
321
|
// // 由于person_name存在多用户时person_id为空,因此不能根据person_id进行分组处理数据
|
|
316
|
322
|
// Map<Long, List<ScoreEvent>> scoreEventMap = scoreEventList.stream().collect(Collectors.groupingBy(ScoreEvent::getPersonId));
|
|
317
|
323
|
List<LedgerWarningDetailItemReduceVO> resultList = new ArrayList<>();
|
|
|
@@ -378,4 +384,220 @@ public class LedgerWarningServiceImpl implements ILedgerWarningService {
|
|
378
|
384
|
return result;
|
|
379
|
385
|
}
|
|
380
|
386
|
|
|
|
387
|
+ /**
|
|
|
388
|
+ * 员工维度评分明细(
|
|
|
389
|
+ * 从event表计算指定条件下,相关人员在六个维度下的维度分值和相关信息
|
|
|
390
|
+ */
|
|
|
391
|
+ @Override
|
|
|
392
|
+ public List<EmployeeDimensionScoreVO> getEmployeeDimensionScores(LedgerCommonQueryReqVO queryReq) {
|
|
|
393
|
+ // 1. 预加载基础数据
|
|
|
394
|
+ Long topSiteId = DeptUtils.getTopSiteId(sysDeptService.selectDeptById(SecurityUtils.getDeptId()));
|
|
|
395
|
+ Map<Long, SysDept> allDeptMap = sysDeptService.selectDeptInfoAll(new SysDept()).stream()
|
|
|
396
|
+ .collect(Collectors.toMap(SysDept::getDeptId, dept -> dept, (v1, v2) -> v1));
|
|
|
397
|
+ Map<Long, Set<Long>> brigadeSubDeptsMap = buildBrigadeSubDeptsMap(allDeptMap);
|
|
|
398
|
+
|
|
|
399
|
+ // 2. 确定需要查询的用户列表
|
|
|
400
|
+ List<Long> userIdList = new ArrayList<>();
|
|
|
401
|
+ Map<Long, SysUser> sysUserMap = new HashMap<>();
|
|
|
402
|
+
|
|
|
403
|
+ if (ObjUtil.isNotNull(queryReq.getUserId())) {
|
|
|
404
|
+ // 指定单个用户
|
|
|
405
|
+ SysUser sysUser = sysUserService.selectUserById(queryReq.getUserId());
|
|
|
406
|
+ if (sysUser != null) {
|
|
|
407
|
+ userIdList.add(sysUser.getUserId());
|
|
|
408
|
+ sysUserMap.put(sysUser.getUserId(), sysUser);
|
|
|
409
|
+ }
|
|
|
410
|
+ } else {
|
|
|
411
|
+ // 根据组织架构获取用户列表
|
|
|
412
|
+ Long targetDeptId = ObjUtil.isNotNull(queryReq.getGroupId()) ? queryReq.getGroupId()
|
|
|
413
|
+ : ObjUtil.isNotNull(queryReq.getTeamId()) ? queryReq.getTeamId()
|
|
|
414
|
+ : ObjUtil.isNotNull(queryReq.getDeptId()) ? queryReq.getDeptId()
|
|
|
415
|
+ : topSiteId;
|
|
|
416
|
+ List<SysUser> sysUserList = sysUserService.selectUserByDeptId(targetDeptId);
|
|
|
417
|
+ if (CollUtil.isNotEmpty(sysUserList)) {
|
|
|
418
|
+ userIdList = sysUserList.stream().map(SysUser::getUserId).collect(Collectors.toList());
|
|
|
419
|
+ sysUserMap = sysUserList.stream().collect(Collectors.toMap(SysUser::getUserId, user -> user));
|
|
|
420
|
+ }
|
|
|
421
|
+ }
|
|
|
422
|
+
|
|
|
423
|
+ if (CollUtil.isEmpty(userIdList)) {
|
|
|
424
|
+ return new ArrayList<>();
|
|
|
425
|
+ }
|
|
|
426
|
+
|
|
|
427
|
+ // 3. 一次性查询员工维度的所有维度配置(org='PERSON')
|
|
|
428
|
+ ScoreDimension dimensionQuery = new ScoreDimension();
|
|
|
429
|
+ dimensionQuery.setStatus("0");
|
|
|
430
|
+ dimensionQuery.setOrg(ScoreLevelEnum.PERSON.getCode());
|
|
|
431
|
+ if (ObjUtil.isNotNull(queryReq.getDimensionId())) {
|
|
|
432
|
+ dimensionQuery.setId(queryReq.getDimensionId());
|
|
|
433
|
+ }
|
|
|
434
|
+ List<ScoreDimension> dimensions = scoreDimensionMapper.selectList(dimensionQuery);
|
|
|
435
|
+
|
|
|
436
|
+ if (CollUtil.isEmpty(dimensions)) {
|
|
|
437
|
+ return new ArrayList<>();
|
|
|
438
|
+ }
|
|
|
439
|
+
|
|
|
440
|
+
|
|
|
441
|
+ List<Long> indicatorIdList = null;
|
|
|
442
|
+ if (ObjUtil.isNotNull(queryReq.getDimensionId())) {
|
|
|
443
|
+ indicatorIdList = dimensions.stream().map(ScoreDimension::getId).collect(Collectors.toList());
|
|
|
444
|
+
|
|
|
445
|
+ }
|
|
|
446
|
+
|
|
|
447
|
+ // 一次性查询event表中该时间段内的事件数据
|
|
|
448
|
+ List<ScoreEvent> scoreEventList = ledgerWarningMapper.selectScoreEventList(
|
|
|
449
|
+ queryReq.getStartDate(),
|
|
|
450
|
+ queryReq.getEndDate(),
|
|
|
451
|
+ null,
|
|
|
452
|
+ userIdList,
|
|
|
453
|
+ indicatorIdList);
|
|
|
454
|
+
|
|
|
455
|
+ // 5. 用户名到用户对象的映射
|
|
|
456
|
+ Map<String, SysUser> userNameToUserMap = sysUserMap.values().stream()
|
|
|
457
|
+ .collect(Collectors.toMap(SysUser::getNickName, user -> user, (u1, u2) -> u1));
|
|
|
458
|
+
|
|
|
459
|
+ // 6. 按用户和维度分组统计事件分值
|
|
|
460
|
+ // Key: userId_dimensionId, Value: eventScore总和
|
|
|
461
|
+ Map<String, BigDecimal> userDimEventScoreMap = new HashMap<>();
|
|
|
462
|
+
|
|
|
463
|
+ for (ScoreEvent event : scoreEventList) {
|
|
|
464
|
+ if (ObjUtil.isNull(event.getDimensionId()) || StrUtil.isEmpty(event.getPersonName())) {
|
|
|
465
|
+ continue;
|
|
|
466
|
+ }
|
|
|
467
|
+
|
|
|
468
|
+ Long dimId = event.getDimensionId();
|
|
|
469
|
+
|
|
|
470
|
+ // 如果指定了dimensionId,只统计该维度的事件
|
|
|
471
|
+ if (ObjUtil.isNotNull(queryReq.getDimensionId()) && !dimId.equals(queryReq.getDimensionId())) {
|
|
|
472
|
+ continue;
|
|
|
473
|
+ }
|
|
|
474
|
+
|
|
|
475
|
+ BigDecimal eventScore = event.getTotalScore() != null ? event.getTotalScore() : BigDecimal.ZERO;
|
|
|
476
|
+
|
|
|
477
|
+ // 处理person_name可能包含多个用户名的情况
|
|
|
478
|
+ String[] personNames = event.getPersonName().split("[,,]");
|
|
|
479
|
+ for (String personName : personNames) {
|
|
|
480
|
+ String trimmedName = personName.trim();
|
|
|
481
|
+ SysUser user = userNameToUserMap.get(trimmedName);
|
|
|
482
|
+ if (user != null) {
|
|
|
483
|
+ String key = user.getUserId() + "_" + dimId;
|
|
|
484
|
+ userDimEventScoreMap.merge(key, eventScore, BigDecimal::add);
|
|
|
485
|
+ }
|
|
|
486
|
+ }
|
|
|
487
|
+ }
|
|
|
488
|
+
|
|
|
489
|
+ // 7. 预计算用户的组织信息
|
|
|
490
|
+ Map<Long, UserOrgInfo> userOrgInfoMap = new HashMap<>();
|
|
|
491
|
+ for (SysUser user : sysUserMap.values()) {
|
|
|
492
|
+ UserOrgInfo orgInfo = buildUserOrgInfo(user, allDeptMap, brigadeSubDeptsMap);
|
|
|
493
|
+ userOrgInfoMap.put(user.getUserId(), orgInfo);
|
|
|
494
|
+ }
|
|
|
495
|
+
|
|
|
496
|
+ // 8. 构建结果列表
|
|
|
497
|
+ List<EmployeeDimensionScoreVO> resultList = new ArrayList<>(userIdList.size() * dimensions.size());
|
|
|
498
|
+
|
|
|
499
|
+ for (Long userId : userIdList) {
|
|
|
500
|
+ SysUser sysUser = sysUserMap.get(userId);
|
|
|
501
|
+ if (sysUser == null) {
|
|
|
502
|
+ continue;
|
|
|
503
|
+ }
|
|
|
504
|
+
|
|
|
505
|
+ UserOrgInfo orgInfo = userOrgInfoMap.get(userId);
|
|
|
506
|
+
|
|
|
507
|
+ // 为每个维度生成一条记录
|
|
|
508
|
+ for (ScoreDimension dimension : dimensions) {
|
|
|
509
|
+ EmployeeDimensionScoreVO vo = new EmployeeDimensionScoreVO();
|
|
|
510
|
+ vo.setUserId(userId);
|
|
|
511
|
+ vo.setPersonName(sysUser.getNickName());
|
|
|
512
|
+ vo.setDeptName(orgInfo != null ? orgInfo.deptName : "");
|
|
|
513
|
+ vo.setTeamName(orgInfo != null ? orgInfo.teamName : "");
|
|
|
514
|
+ vo.setGroupName(orgInfo != null ? orgInfo.groupName : "");
|
|
|
515
|
+ vo.setDimensionName(dimension.getName());
|
|
|
516
|
+
|
|
|
517
|
+ // 基础分
|
|
|
518
|
+ BigDecimal baseScore = dimension.getBaseScore() != null ? dimension.getBaseScore() : BigDecimal.valueOf(80);
|
|
|
519
|
+ vo.setBaseScore(baseScore);
|
|
|
520
|
+
|
|
|
521
|
+ // 事件加减分合计
|
|
|
522
|
+ String key = userId + "_" + dimension.getId();
|
|
|
523
|
+ BigDecimal eventScore = userDimEventScoreMap.getOrDefault(key, BigDecimal.ZERO);
|
|
|
524
|
+ vo.setEventScore(eventScore);
|
|
|
525
|
+
|
|
|
526
|
+ // 维度分值 = 基础分 + 事件加减分
|
|
|
527
|
+ BigDecimal dimensionScore = baseScore.add(eventScore);
|
|
|
528
|
+ vo.setDimensionScore(dimensionScore);
|
|
|
529
|
+
|
|
|
530
|
+ // 权重
|
|
|
531
|
+ vo.setWeight(dimension.getWeight() != null ? dimension.getWeight() : BigDecimal.ZERO);
|
|
|
532
|
+
|
|
|
533
|
+ resultList.add(vo);
|
|
|
534
|
+ }
|
|
|
535
|
+ }
|
|
|
536
|
+
|
|
|
537
|
+ // 9. 排序
|
|
|
538
|
+ if (ObjUtil.isNull(queryReq.getSorts())) {
|
|
|
539
|
+ Map<String, String> sorts = new LinkedHashMap<>();
|
|
|
540
|
+ sorts.put("userId", "asc");
|
|
|
541
|
+ sorts.put("dimensionName", "asc");
|
|
|
542
|
+ queryReq.setSorts(sorts);
|
|
|
543
|
+ }
|
|
|
544
|
+
|
|
|
545
|
+ List<EmployeeDimensionScoreVO> result = StreamSortUtils.sort(resultList, queryReq.getSorts());
|
|
|
546
|
+ return result;
|
|
|
547
|
+ }
|
|
|
548
|
+
|
|
|
549
|
+ /**
|
|
|
550
|
+ * 用户组织信息内部类
|
|
|
551
|
+ */
|
|
|
552
|
+ private static class UserOrgInfo {
|
|
|
553
|
+ String deptName;
|
|
|
554
|
+ String teamName;
|
|
|
555
|
+ String groupName;
|
|
|
556
|
+
|
|
|
557
|
+ UserOrgInfo(String deptName, String teamName, String groupName) {
|
|
|
558
|
+ this.deptName = deptName;
|
|
|
559
|
+ this.teamName = teamName;
|
|
|
560
|
+ this.groupName = groupName;
|
|
|
561
|
+ }
|
|
|
562
|
+ }
|
|
|
563
|
+
|
|
|
564
|
+ /**
|
|
|
565
|
+ * 构建用户组织信息
|
|
|
566
|
+ */
|
|
|
567
|
+ private UserOrgInfo buildUserOrgInfo(SysUser user, Map<Long, SysDept> allDeptMap, Map<Long, Set<Long>> brigadeSubDeptsMap) {
|
|
|
568
|
+ String deptName = "";
|
|
|
569
|
+ String teamName = "";
|
|
|
570
|
+ String groupName = "";
|
|
|
571
|
+
|
|
|
572
|
+ if (user.getDeptId() == null) {
|
|
|
573
|
+ return new UserOrgInfo(deptName, teamName, groupName);
|
|
|
574
|
+ }
|
|
|
575
|
+
|
|
|
576
|
+ // 获取用户所在大队名称
|
|
|
577
|
+ Long brigadeId = findUserBrigade(user.getDeptId(), brigadeSubDeptsMap);
|
|
|
578
|
+ if (brigadeId != null && allDeptMap.containsKey(brigadeId)) {
|
|
|
579
|
+ deptName = allDeptMap.get(brigadeId).getDeptName();
|
|
|
580
|
+ }
|
|
|
581
|
+
|
|
|
582
|
+ // 获取用户的直接部门信息
|
|
|
583
|
+ SysDept userDept = allDeptMap.get(user.getDeptId());
|
|
|
584
|
+ if (userDept != null) {
|
|
|
585
|
+ // 根据部门类型判断是班组还是小组
|
|
|
586
|
+ if (DeptTypeEnum.TEAMS.getCode().equals(userDept.getDeptType())) {
|
|
|
587
|
+ groupName = userDept.getDeptName();
|
|
|
588
|
+ // 查找上级班组
|
|
|
589
|
+ if (userDept.getParentId() != null && userDept.getParentId() != 0) {
|
|
|
590
|
+ SysDept parentDept = allDeptMap.get(userDept.getParentId());
|
|
|
591
|
+ if (parentDept != null && DeptTypeEnum.MANAGER.getCode().equals(parentDept.getDeptType())) {
|
|
|
592
|
+ teamName = parentDept.getDeptName();
|
|
|
593
|
+ }
|
|
|
594
|
+ }
|
|
|
595
|
+ } else if (DeptTypeEnum.MANAGER.getCode().equals(userDept.getDeptType())) {
|
|
|
596
|
+ teamName = userDept.getDeptName();
|
|
|
597
|
+ }
|
|
|
598
|
+ }
|
|
|
599
|
+
|
|
|
600
|
+ return new UserOrgInfo(deptName, teamName, groupName);
|
|
|
601
|
+ }
|
|
|
602
|
+
|
|
381
|
603
|
}
|