|
|
@@ -121,31 +121,41 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
121
|
121
|
@Override
|
|
122
|
122
|
@Transactional(rollbackFor = Exception.class)
|
|
123
|
123
|
public SyncResult syncAll() {
|
|
124
|
|
- loadDimCache();
|
|
125
|
|
- loadDeptCache();
|
|
126
|
|
- loadUserCache();
|
|
127
|
|
- StringBuilder sb = new StringBuilder();
|
|
128
|
|
- int totalIns = 0, totalSkip = 0;
|
|
129
|
|
- for (String type : Arrays.asList(
|
|
130
|
|
- "supervision_problem", "realtime_interception", "security_test",
|
|
131
|
|
- "unsafe_event", "seizure_stats", "reward_approval",
|
|
132
|
|
- "service_patrol", "complaint", "terminal_bonus", "exam_score")) {
|
|
133
|
|
- SyncResult r = doSync(type);
|
|
134
|
|
- sb.append(type).append(":+").append(r.getTotalInserted())
|
|
135
|
|
- .append("/skip").append(r.getTotalSkipped()).append(" ");
|
|
136
|
|
- totalIns += r.getTotalInserted();
|
|
137
|
|
- totalSkip += r.getTotalSkipped();
|
|
|
124
|
+ try {
|
|
|
125
|
+ loadDimCache();
|
|
|
126
|
+ loadDeptCache();
|
|
|
127
|
+ loadUserCache();
|
|
|
128
|
+ StringBuilder sb = new StringBuilder();
|
|
|
129
|
+ int totalIns = 0, totalSkip = 0;
|
|
|
130
|
+ for (String type : Arrays.asList(
|
|
|
131
|
+ "supervision_problem", "realtime_interception", "security_test",
|
|
|
132
|
+ "unsafe_event", "seizure_stats", "reward_approval",
|
|
|
133
|
+ "service_patrol", "complaint", "terminal_bonus", "exam_score")) {
|
|
|
134
|
+ SyncResult r = doSync(type);
|
|
|
135
|
+ sb.append(type).append(":+").append(r.getTotalInserted())
|
|
|
136
|
+ .append("/skip").append(r.getTotalSkipped()).append(" ");
|
|
|
137
|
+ totalIns += r.getTotalInserted();
|
|
|
138
|
+ totalSkip += r.getTotalSkipped();
|
|
|
139
|
+ }
|
|
|
140
|
+ return new SyncResult(totalIns, totalSkip, sb.toString());
|
|
|
141
|
+ } finally {
|
|
|
142
|
+ // 同步完成后清除缓存
|
|
|
143
|
+ clearCaches();
|
|
138
|
144
|
}
|
|
139
|
|
- return new SyncResult(totalIns, totalSkip, sb.toString());
|
|
140
|
145
|
}
|
|
141
|
146
|
|
|
142
|
147
|
@Override
|
|
143
|
148
|
@Transactional(rollbackFor = Exception.class)
|
|
144
|
149
|
public SyncResult syncByType(String ledgerType) {
|
|
145
|
|
- loadDimCache();
|
|
146
|
|
- loadDeptCache();
|
|
147
|
|
- loadUserCache();
|
|
148
|
|
- return doSync(ledgerType);
|
|
|
150
|
+ try {
|
|
|
151
|
+ loadDimCache();
|
|
|
152
|
+ loadDeptCache();
|
|
|
153
|
+ loadUserCache();
|
|
|
154
|
+ return doSync(ledgerType);
|
|
|
155
|
+ } finally {
|
|
|
156
|
+ // 同步完成后清除缓存
|
|
|
157
|
+ clearCaches();
|
|
|
158
|
+ }
|
|
149
|
159
|
}
|
|
150
|
160
|
|
|
151
|
161
|
// ═════════════════════════════════════════════════════════
|
|
|
@@ -158,7 +168,7 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
158
|
168
|
case "realtime_interception": return syncRealtimeInterception();
|
|
159
|
169
|
case "security_test": return syncSecurityTest();
|
|
160
|
170
|
case "unsafe_event": return syncUnsafeEvent();
|
|
161
|
|
- case "seizure_stats": return syncSeizureStats();
|
|
|
171
|
+// case "seizure_stats": return syncSeizureStats();
|
|
162
|
172
|
case "reward_approval": return syncRewardApproval();
|
|
163
|
173
|
case "service_patrol": return syncServicePatrol();
|
|
164
|
174
|
case "complaint": return syncComplaint();
|
|
|
@@ -182,7 +192,7 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
182
|
192
|
String src = "supervision_problem:" + row.getId();
|
|
183
|
193
|
if (existsBySrc(src)) { skip++; continue; }
|
|
184
|
194
|
if (!hasName(row.getInspectedName())) { skip++; continue; }
|
|
185
|
|
- // 按问题层级选取L3指标和默认分值(修正:取problemLevel字段)
|
|
|
195
|
+ // 按问题层级选取L3指标和默认分值
|
|
186
|
196
|
String level = row.getProblemLevel() != null ? row.getProblemLevel() : "";
|
|
187
|
197
|
long l3Id; BigDecimal defaultSv;
|
|
188
|
198
|
if (level.contains("上级")) { l3Id = IND_SUPERVISION_L3_LEADER; defaultSv = BigDecimal.valueOf(-1.20); }
|
|
|
@@ -213,10 +223,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
213
|
223
|
// 取【问题层级】字段,站层级扣1分,部门层级扣0.8分,其它层级跳过
|
|
214
|
224
|
String level = row.getProblemLevel() != null ? row.getProblemLevel() : "";
|
|
215
|
225
|
long l3Id; BigDecimal sv;
|
|
216
|
|
- if (level.contains("站层级")) {
|
|
|
226
|
+ if (level.contains("站")) {
|
|
217
|
227
|
l3Id = IND_INTERCEPT_L3_STATION;
|
|
218
|
228
|
sv = row.getDeductScore() != null ? row.getDeductScore().negate() : NEG_ONE;
|
|
219
|
|
- } else if (level.contains("部门层级")) {
|
|
|
229
|
+ } else if (level.contains("部门")) {
|
|
220
|
230
|
l3Id = IND_INTERCEPT_L3_DEPT;
|
|
221
|
231
|
sv = row.getDeductScore() != null ? row.getDeductScore().negate() : NEG_08;
|
|
222
|
232
|
} else {
|
|
|
@@ -463,7 +473,96 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
463
|
473
|
sysUserMapper.selectUserList(new SysUser()).forEach(d -> userCache.put(d.getNickName(), d.getUserId()));
|
|
464
|
474
|
}
|
|
465
|
475
|
|
|
|
476
|
+ /**
|
|
|
477
|
+ * 清除所有缓存
|
|
|
478
|
+ */
|
|
|
479
|
+ private void clearCaches() {
|
|
|
480
|
+ dimCache.clear();
|
|
|
481
|
+ deptCache.clear();
|
|
|
482
|
+ userCache.clear();
|
|
|
483
|
+ indCache.clear();
|
|
|
484
|
+ indicatorNameToIdCache.clear();
|
|
|
485
|
+ }
|
|
|
486
|
+
|
|
|
487
|
+ /**
|
|
|
488
|
+ * 通过用户名称解析组织信息(ID和名称)
|
|
|
489
|
+ * @param personName 人员名称
|
|
|
490
|
+ * @return Map包含: userId, deptId, deptName, teamId, teamName, groupId, groupName
|
|
|
491
|
+ */
|
|
|
492
|
+ private Map<String, Object> resolveOrgInfoByName(String personName) {
|
|
|
493
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
494
|
+ if (personName == null || personName.trim().isEmpty()) {
|
|
|
495
|
+ return result;
|
|
|
496
|
+ }
|
|
|
497
|
+
|
|
|
498
|
+ String name = personName.trim();
|
|
|
499
|
+
|
|
|
500
|
+ // 1. 从缓存中查找用户
|
|
|
501
|
+ Long userId = userCache.get(name);
|
|
|
502
|
+ if (userId == null) {
|
|
|
503
|
+ return result;
|
|
|
504
|
+ }
|
|
|
505
|
+ result.put("userId", userId);
|
|
|
506
|
+
|
|
|
507
|
+ // 2. 查询用户详情获取部门ID
|
|
|
508
|
+ SysUser user = sysUserMapper.selectUserById(userId);
|
|
|
509
|
+ if (user == null || user.getDeptId() == null) {
|
|
|
510
|
+ return result;
|
|
|
511
|
+ }
|
|
|
512
|
+
|
|
|
513
|
+ // 3. 从缓存中获取用户部门信息
|
|
|
514
|
+ SysDept userDept = sysDeptMapper.selectDeptById(user.getDeptId());
|
|
|
515
|
+ if (userDept == null) {
|
|
|
516
|
+ return result;
|
|
|
517
|
+ }
|
|
|
518
|
+
|
|
|
519
|
+ String deptType = userDept.getDeptType();
|
|
|
520
|
+
|
|
|
521
|
+ // 4. 根据部门类型递归获取各级组织ID和名称
|
|
|
522
|
+ if ("BRIGADE".equals(deptType)) {
|
|
|
523
|
+ // 用户部门是大队
|
|
|
524
|
+ result.put("deptId", user.getDeptId());
|
|
|
525
|
+ result.put("deptName", userDept.getDeptName());
|
|
|
526
|
+ } else if ("MANAGER".equals(deptType)) {
|
|
|
527
|
+ // 用户部门是队室/班组,向上找大队
|
|
|
528
|
+ result.put("teamId", user.getDeptId());
|
|
|
529
|
+ result.put("teamName", userDept.getDeptName());
|
|
|
530
|
+ if (userDept.getParentId() != null && userDept.getParentId() != 0) {
|
|
|
531
|
+ result.put("deptId", userDept.getParentId());
|
|
|
532
|
+ // 获取父级部门(大队)
|
|
|
533
|
+ SysDept parentDept = sysDeptMapper.selectDeptById(userDept.getParentId());
|
|
|
534
|
+ if (parentDept != null) {
|
|
|
535
|
+ result.put("deptName", parentDept.getDeptName());
|
|
|
536
|
+ }
|
|
|
537
|
+ }
|
|
|
538
|
+ } else if ("TEAMS".equals(deptType)) {
|
|
|
539
|
+ // 用户部门是小组,向上找队室和大队
|
|
|
540
|
+ result.put("groupId", user.getDeptId());
|
|
|
541
|
+ result.put("groupName", userDept.getDeptName());
|
|
|
542
|
+ if (userDept.getParentId() != null && userDept.getParentId() != 0) {
|
|
|
543
|
+ result.put("teamId", userDept.getParentId());
|
|
|
544
|
+ // 获取父级部门(队室)
|
|
|
545
|
+ SysDept parentDept = sysDeptMapper.selectDeptById(userDept.getParentId());
|
|
|
546
|
+ if (parentDept != null) {
|
|
|
547
|
+ result.put("teamName", parentDept.getDeptName());
|
|
|
548
|
+ if (parentDept.getParentId() != null && parentDept.getParentId() != 0) {
|
|
|
549
|
+ result.put("deptId", parentDept.getParentId());
|
|
|
550
|
+ // 获取祖父级部门(大队)
|
|
|
551
|
+ SysDept grandParentDept = sysDeptMapper.selectDeptById(parentDept.getParentId());
|
|
|
552
|
+ if (grandParentDept != null) {
|
|
|
553
|
+ result.put("deptName", grandParentDept.getDeptName());
|
|
|
554
|
+ }
|
|
|
555
|
+ }
|
|
|
556
|
+ }
|
|
|
557
|
+ }
|
|
|
558
|
+ }
|
|
|
559
|
+
|
|
|
560
|
+ return result;
|
|
|
561
|
+ }
|
|
|
562
|
+
|
|
466
|
563
|
private final Map<Long, ScoreIndicator> indCache = new HashMap<>();
|
|
|
564
|
+ private final Map<String, Long> indicatorNameToIdCache = new HashMap<>(); // 指标名称到ID的映射
|
|
|
565
|
+
|
|
467
|
566
|
private ScoreIndicator getIndicator(long id) {
|
|
468
|
567
|
return indCache.computeIfAbsent(id, indicatorMapper::selectById);
|
|
469
|
568
|
}
|
|
|
@@ -488,12 +587,24 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
488
|
587
|
.filter(x -> x.getValue().equals(dimId)).map(Map.Entry::getKey).findFirst().orElse("") : "");
|
|
489
|
588
|
if (lv2 != null) {
|
|
490
|
589
|
e.setIndicatorId(lv2.getId());
|
|
|
590
|
+ e.setLevel2Id(lv2.getId());
|
|
491
|
591
|
e.setLevel2Name(lv2.getName());
|
|
492
|
592
|
}
|
|
493
|
593
|
if (lv3 != null) {
|
|
494
|
594
|
e.setIndicatorId(lv3.getId());
|
|
495
|
595
|
e.setLevel3Id(lv3.getId());
|
|
496
|
596
|
e.setLevel3Name(lv3.getName());
|
|
|
597
|
+ // 如果lv3有父级(即lv2),确保level2Id也被设置
|
|
|
598
|
+ if (lv3.getParentId() != null && lv3.getParentId() != 0) {
|
|
|
599
|
+ e.setLevel2Id(lv3.getParentId());
|
|
|
600
|
+ // 通过ID获取lv2的名称(如果之前没设置)
|
|
|
601
|
+ if (e.getLevel2Name() == null) {
|
|
|
602
|
+ ScoreIndicator parentLv2 = getIndicator(lv3.getParentId());
|
|
|
603
|
+ if (parentLv2 != null) {
|
|
|
604
|
+ e.setLevel2Name(parentLv2.getName());
|
|
|
605
|
+ }
|
|
|
606
|
+ }
|
|
|
607
|
+ }
|
|
497
|
608
|
} else if (lv2 != null) {
|
|
498
|
609
|
e.setIndicatorId(lv2.getId());
|
|
499
|
610
|
}
|
|
|
@@ -511,18 +622,21 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
511
|
622
|
e.setEvidenceFile(evidenceFile);
|
|
512
|
623
|
e.setCreateBy("system");
|
|
513
|
624
|
e.setCreateTime(DateUtils.getNowDate());
|
|
|
625
|
+
|
|
|
626
|
+ // 通过人员名称解析组织信息(ID和名称)
|
|
514
|
627
|
if (StrUtil.isNotEmpty(e.getPersonName())) {
|
|
515
|
|
- e.setPersonId(userCache.get(e.getPersonName()));
|
|
516
|
|
- }
|
|
517
|
|
- if (StrUtil.isNotEmpty(e.getGroupName())) {
|
|
518
|
|
- e.setGroupId(deptCache.get(e.getGroupName()));
|
|
519
|
|
- }
|
|
520
|
|
- if (StrUtil.isNotEmpty(e.getTeamName())) {
|
|
521
|
|
- e.setTeamId(deptCache.get(e.getTeamName()));
|
|
522
|
|
- }
|
|
523
|
|
- if (StrUtil.isNotEmpty(e.getDeptName())) {
|
|
524
|
|
- e.setDeptId(deptCache.get(e.getDeptName()));
|
|
|
628
|
+ Map<String, Object> orgInfo = resolveOrgInfoByName(e.getPersonName());
|
|
|
629
|
+ if (!orgInfo.isEmpty()) {
|
|
|
630
|
+ e.setPersonId((Long) orgInfo.get("userId"));
|
|
|
631
|
+ e.setDeptId((Long) orgInfo.get("deptId"));
|
|
|
632
|
+ e.setDeptName((String) orgInfo.get("deptName"));
|
|
|
633
|
+ e.setTeamId((Long) orgInfo.get("teamId"));
|
|
|
634
|
+ e.setTeamName((String) orgInfo.get("teamName"));
|
|
|
635
|
+ e.setGroupId((Long) orgInfo.get("groupId"));
|
|
|
636
|
+ e.setGroupName((String) orgInfo.get("groupName"));
|
|
|
637
|
+ }
|
|
525
|
638
|
}
|
|
|
639
|
+
|
|
526
|
640
|
return e;
|
|
527
|
641
|
}
|
|
528
|
642
|
}
|