|
|
@@ -1,10 +1,15 @@
|
|
1
|
1
|
package com.sundot.airport.ledger.service.impl;
|
|
2
|
2
|
|
|
|
3
|
+import cn.hutool.core.util.StrUtil;
|
|
3
|
4
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
5
|
+import com.sundot.airport.common.core.domain.entity.SysDept;
|
|
|
6
|
+import com.sundot.airport.common.core.domain.entity.SysUser;
|
|
4
|
7
|
import com.sundot.airport.common.utils.DateUtils;
|
|
5
|
8
|
import com.sundot.airport.ledger.domain.*;
|
|
6
|
9
|
import com.sundot.airport.ledger.mapper.*;
|
|
7
|
10
|
import com.sundot.airport.ledger.service.ILedgerSyncService;
|
|
|
11
|
+import com.sundot.airport.system.mapper.SysDeptMapper;
|
|
|
12
|
+import com.sundot.airport.system.mapper.SysUserMapper;
|
|
8
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
9
|
14
|
import org.springframework.stereotype.Service;
|
|
10
|
15
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -53,9 +58,13 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
53
|
58
|
@Autowired private ScoreEventMapper scoreEventMapper;
|
|
54
|
59
|
@Autowired private ScoreDimensionMapper dimensionMapper;
|
|
55
|
60
|
@Autowired private ScoreIndicatorMapper indicatorMapper;
|
|
|
61
|
+ @Autowired private SysDeptMapper sysDeptMapper;
|
|
|
62
|
+ @Autowired private SysUserMapper sysUserMapper;
|
|
56
|
63
|
|
|
57
|
64
|
// ── Dimension ID cache (loaded once) ─────────────────────
|
|
58
|
65
|
private final Map<String, Long> dimCache = new HashMap<>();
|
|
|
66
|
+ private final Map<String, Long> deptCache = new HashMap<>();
|
|
|
67
|
+ private final Map<String, Long> userCache = new HashMap<>();
|
|
59
|
68
|
|
|
60
|
69
|
// ── Constants: Indicator IDs(与 score.sql 中的显式 ID 对应)─
|
|
61
|
70
|
// dim1 安全防控能力
|
|
|
@@ -113,6 +122,8 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
113
|
122
|
@Transactional(rollbackFor = Exception.class)
|
|
114
|
123
|
public SyncResult syncAll() {
|
|
115
|
124
|
loadDimCache();
|
|
|
125
|
+ loadDeptCache();
|
|
|
126
|
+ loadUserCache();
|
|
116
|
127
|
StringBuilder sb = new StringBuilder();
|
|
117
|
128
|
int totalIns = 0, totalSkip = 0;
|
|
118
|
129
|
for (String type : Arrays.asList(
|
|
|
@@ -132,6 +143,8 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
132
|
143
|
@Transactional(rollbackFor = Exception.class)
|
|
133
|
144
|
public SyncResult syncByType(String ledgerType) {
|
|
134
|
145
|
loadDimCache();
|
|
|
146
|
+ loadDeptCache();
|
|
|
147
|
+ loadUserCache();
|
|
135
|
148
|
return doSync(ledgerType);
|
|
136
|
149
|
}
|
|
137
|
150
|
|
|
|
@@ -427,6 +440,16 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
427
|
440
|
dimensionMapper.selectList(new ScoreDimension()).forEach(d -> dimCache.put(d.getName(), d.getId()));
|
|
428
|
441
|
}
|
|
429
|
442
|
|
|
|
443
|
+ private void loadDeptCache() {
|
|
|
444
|
+ if (!deptCache.isEmpty()) return;
|
|
|
445
|
+ sysDeptMapper.selectDeptList(new SysDept()).forEach(d -> deptCache.put(d.getDeptName(), d.getDeptId()));
|
|
|
446
|
+ }
|
|
|
447
|
+
|
|
|
448
|
+ private void loadUserCache() {
|
|
|
449
|
+ if (!userCache.isEmpty()) return;
|
|
|
450
|
+ sysUserMapper.selectUserList(new SysUser()).forEach(d -> userCache.put(d.getNickName(), d.getUserId()));
|
|
|
451
|
+ }
|
|
|
452
|
+
|
|
430
|
453
|
private final Map<Long, ScoreIndicator> indCache = new HashMap<>();
|
|
431
|
454
|
private ScoreIndicator getIndicator(long id) {
|
|
432
|
455
|
return indCache.computeIfAbsent(id, indicatorMapper::selectById);
|
|
|
@@ -475,6 +498,18 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
|
|
475
|
498
|
e.setEvidenceFile(evidenceFile);
|
|
476
|
499
|
e.setCreateBy("system");
|
|
477
|
500
|
e.setCreateTime(DateUtils.getNowDate());
|
|
|
501
|
+ if (StrUtil.isNotEmpty(e.getPersonName())) {
|
|
|
502
|
+ e.setPersonId(userCache.get(e.getPersonName()));
|
|
|
503
|
+ }
|
|
|
504
|
+ if (StrUtil.isNotEmpty(e.getGroupName())) {
|
|
|
505
|
+ e.setGroupId(deptCache.get(e.getGroupName()));
|
|
|
506
|
+ }
|
|
|
507
|
+ if (StrUtil.isNotEmpty(e.getTeamName())) {
|
|
|
508
|
+ e.setTeamId(deptCache.get(e.getTeamName()));
|
|
|
509
|
+ }
|
|
|
510
|
+ if (StrUtil.isNotEmpty(e.getDeptName())) {
|
|
|
511
|
+ e.setDeptId(deptCache.get(e.getDeptName()));
|
|
|
512
|
+ }
|
|
478
|
513
|
return e;
|
|
479
|
514
|
}
|
|
480
|
515
|
}
|