|
|
@@ -2,6 +2,8 @@ package com.sundot.airport.ledger.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
4
|
4
|
import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
5
|
+import com.sundot.airport.common.core.domain.entity.SysDept;
|
|
|
6
|
+import com.sundot.airport.common.core.domain.entity.SysUser;
|
|
5
|
7
|
import com.sundot.airport.ledger.domain.*;
|
|
6
|
8
|
import com.sundot.airport.ledger.domain.LedgerDailyTraining;
|
|
7
|
9
|
import com.sundot.airport.ledger.domain.LedgerLeaderDuty;
|
|
|
@@ -14,6 +16,8 @@ import com.sundot.airport.ledger.service.ILedgerLeaderDutyService;
|
|
14
|
16
|
import com.sundot.airport.ledger.service.ILedgerHealthSoldierService;
|
|
15
|
17
|
import com.sundot.airport.ledger.service.ILedgerDormFireSafetyService;
|
|
16
|
18
|
import com.sundot.airport.ledger.service.ILedgerTrainingIssueService;
|
|
|
19
|
+import com.sundot.airport.system.mapper.SysDeptMapper;
|
|
|
20
|
+import com.sundot.airport.system.mapper.SysUserMapper;
|
|
17
|
21
|
import org.apache.poi.ss.usermodel.*;
|
|
18
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
19
|
23
|
import org.springframework.stereotype.Service;
|
|
|
@@ -54,6 +58,11 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
54
|
58
|
@Autowired private ILedgerDormFireSafetyService dormFireSafetyService;
|
|
55
|
59
|
@Autowired private ILedgerTrainingIssueService trainingIssueService;
|
|
56
|
60
|
@Autowired private IScoreEventService scoreEventService;
|
|
|
61
|
+ @Autowired private SysUserMapper sysUserMapper;
|
|
|
62
|
+ @Autowired private SysDeptMapper sysDeptMapper;
|
|
|
63
|
+
|
|
|
64
|
+ // 导入缓存(在导入开始时构建,导入结束后释放)
|
|
|
65
|
+ private ImportCache importCache;
|
|
57
|
66
|
|
|
58
|
67
|
// ── Sheet 名称 → 处理方法路由表 ──────────────────────────────────
|
|
59
|
68
|
private static final Map<String, String> SHEET_ROUTE = new LinkedHashMap<>();
|
|
|
@@ -91,6 +100,9 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
91
|
100
|
public Map<String, String> importAll(MultipartFile file, String batchNo, String username) throws Exception {
|
|
92
|
101
|
Map<String, String> result = new LinkedHashMap<>();
|
|
93
|
102
|
try (Workbook wb = WorkbookFactory.create(file.getInputStream())) {
|
|
|
103
|
+ // 构建导入缓存
|
|
|
104
|
+ buildImportCache();
|
|
|
105
|
+
|
|
94
|
106
|
for (Map.Entry<String, String> entry : SHEET_ROUTE.entrySet()) {
|
|
95
|
107
|
String sheetName = entry.getKey();
|
|
96
|
108
|
String handler = entry.getValue();
|
|
|
@@ -106,6 +118,9 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
106
|
118
|
result.put(sheetName, "错误: " + e.getMessage());
|
|
107
|
119
|
}
|
|
108
|
120
|
}
|
|
|
121
|
+ } finally {
|
|
|
122
|
+ // 导入完成后释放缓存
|
|
|
123
|
+ clearImportCache();
|
|
109
|
124
|
}
|
|
110
|
125
|
return result;
|
|
111
|
126
|
}
|
|
|
@@ -389,8 +404,11 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
389
|
404
|
}
|
|
390
|
405
|
|
|
391
|
406
|
/** 9. 2026查获违规品统计 → ledger_seizure_stats
|
|
392
|
|
- * R2: 查获时间(0) ...(1,2) 部门/队室(3) 区域(4) 安检员(5) ...
|
|
393
|
|
- * 航班号(8) ... 旅客姓名(12) ... 违规类别(16) 物品种类(17) ...(18) 数量(19)
|
|
|
407
|
+ * R2: 查获时间(0) 信息提取(1) 信息提取2(2) 部门/队室(3) 工作区域(4) 安检员(5)
|
|
|
408
|
+ * 安检资格证书等级(6) 岗位(7) 航班号(8) 目的地(9) 进/出港(10) 违规主体(11)
|
|
|
409
|
+ * 旅客姓名(12) 旅客性别(13) 旅客民族(14) 旅客年龄(15) 违规类别(16)
|
|
|
410
|
+ * 违规物品种类(17) 二级分类(18) 数量(19) 事件简况(20) 查获位置(21)
|
|
|
411
|
+ * 处理结果(22) 班组(23) 队室内勤(24) 备注(25) 查获数量(26)
|
|
394
|
412
|
*/
|
|
395
|
413
|
private int doSeizureStats(Sheet sheet, String batchNo, String username) {
|
|
396
|
414
|
List<LedgerSeizureStats> list = new ArrayList<>();
|
|
|
@@ -398,12 +416,39 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
398
|
416
|
LedgerSeizureStats o = new LedgerSeizureStats();
|
|
399
|
417
|
o.setRecordDate(date(c, 0));
|
|
400
|
418
|
o.setTeamName(str(c, 3));
|
|
401
|
|
- o.setInspectorName(str(c, 5));
|
|
|
419
|
+ o.setWorkArea(str(c, 4));
|
|
|
420
|
+ String inspectorName = str(c, 5);
|
|
|
421
|
+ o.setInspectorName(inspectorName);
|
|
|
422
|
+ o.setQualificationLevel(str(c, 6));
|
|
|
423
|
+ o.setPosition(str(c, 7));
|
|
402
|
424
|
o.setFlightNo(str(c, 8));
|
|
|
425
|
+ o.setDestination(str(c, 9));
|
|
|
426
|
+ o.setInOutPort(str(c, 10));
|
|
|
427
|
+ o.setViolationSubject(str(c, 11));
|
|
403
|
428
|
o.setPassengerName(str(c, 12));
|
|
|
429
|
+ o.setPassengerGender(str(c, 13));
|
|
|
430
|
+ o.setPassengerEthnicity(str(c, 14));
|
|
|
431
|
+ o.setPassengerAge(integer(c, 15));
|
|
404
|
432
|
o.setItemCategory(str(c, 16));
|
|
405
|
|
- o.setItemName(str(c, 17));
|
|
|
433
|
+ o.setItemName(str(c, 17)); // 违规物品种类
|
|
|
434
|
+ o.setSecondaryCategory(str(c, 18));
|
|
406
|
435
|
o.setItemQuantity(integer(c, 19));
|
|
|
436
|
+ o.setEventBrief(str(c, 20));
|
|
|
437
|
+ o.setConcealmentPart(str(c, 21)); // 查获位置
|
|
|
438
|
+ o.setHandlingMethod(str(c, 22)); // 处理结果
|
|
|
439
|
+ o.setTeamInternalDuty(str(c, 24));
|
|
|
440
|
+ o.setRemark(str(c, 25));
|
|
|
441
|
+ o.setSeizureQuantity(integer(c, 26)); // 查获数量
|
|
|
442
|
+
|
|
|
443
|
+ // 使用缓存查找组织信息
|
|
|
444
|
+ Map<String, Long> orgInfo = resolveOrgInfoByNameWithCache(inspectorName);
|
|
|
445
|
+ if (!orgInfo.isEmpty()) {
|
|
|
446
|
+ o.setInspectorId(orgInfo.get("userId"));
|
|
|
447
|
+ o.setDeptId(orgInfo.get("deptId"));
|
|
|
448
|
+ o.setTeamId(orgInfo.get("teamId"));
|
|
|
449
|
+ o.setGroupId(orgInfo.get("groupId"));
|
|
|
450
|
+ }
|
|
|
451
|
+
|
|
407
|
452
|
o.setImportBatch(batchNo);
|
|
408
|
453
|
o.setSourceType("1");
|
|
409
|
454
|
o.setCreateBy(username);
|
|
|
@@ -864,4 +909,124 @@ public class LedgerCombinedImportServiceImpl implements ILedgerCombinedImportSer
|
|
864
|
909
|
}
|
|
865
|
910
|
return count;
|
|
866
|
911
|
}
|
|
|
912
|
+
|
|
|
913
|
+ // ════════════════════════════════════════════════════════════════
|
|
|
914
|
+ // 导入缓存类
|
|
|
915
|
+ // ════════════════════════════════════════════════════════════════
|
|
|
916
|
+
|
|
|
917
|
+ /**
|
|
|
918
|
+ * 导入时的统一缓存,避免重复查询数据库
|
|
|
919
|
+ */
|
|
|
920
|
+ private static class ImportCache {
|
|
|
921
|
+ private final Map<String, SysUser> userCache; // Map<昵称, 用户>
|
|
|
922
|
+ private final Map<Long, SysDept> deptCache; // Map<部门ID, 部门>
|
|
|
923
|
+
|
|
|
924
|
+ public ImportCache(Map<String, SysUser> userCache, Map<Long, SysDept> deptCache) {
|
|
|
925
|
+ this.userCache = userCache;
|
|
|
926
|
+ this.deptCache = deptCache;
|
|
|
927
|
+ }
|
|
|
928
|
+
|
|
|
929
|
+ public SysUser getUserByNickName(String nickName) {
|
|
|
930
|
+ return userCache.get(nickName);
|
|
|
931
|
+ }
|
|
|
932
|
+
|
|
|
933
|
+ public SysDept getDeptById(Long deptId) {
|
|
|
934
|
+ return deptCache.get(deptId);
|
|
|
935
|
+ }
|
|
|
936
|
+ }
|
|
|
937
|
+
|
|
|
938
|
+ // ════════════════════════════════════════════════════════════════
|
|
|
939
|
+ // 辅助方法:根据人员名称补充组织信息
|
|
|
940
|
+ // ════════════════════════════════════════════════════════════════
|
|
|
941
|
+
|
|
|
942
|
+ /**
|
|
|
943
|
+ * 根据人员名称查找用户,并补充组织架构ID
|
|
|
944
|
+ * @param personName 人员名称
|
|
|
945
|
+ * @return Map包含: userId, deptId(BRIGADE), teamId(MANAGER), groupId(TEAMS)
|
|
|
946
|
+ */
|
|
|
947
|
+ private Map<String, Long> resolveOrgInfoByNameWithCache(String personName) {
|
|
|
948
|
+ Map<String, Long> result = new HashMap<>();
|
|
|
949
|
+ if (personName == null || personName.trim().isEmpty() || importCache == null) {
|
|
|
950
|
+ return result;
|
|
|
951
|
+ }
|
|
|
952
|
+
|
|
|
953
|
+ String name = personName.trim();
|
|
|
954
|
+
|
|
|
955
|
+ // 1. 从缓存中查找用户
|
|
|
956
|
+ SysUser user = importCache.getUserByNickName(name);
|
|
|
957
|
+ if (user == null || user.getDeptId() == null) {
|
|
|
958
|
+ return result;
|
|
|
959
|
+ }
|
|
|
960
|
+
|
|
|
961
|
+ result.put("userId", user.getUserId());
|
|
|
962
|
+
|
|
|
963
|
+ // 2. 从缓存中获取用户部门信息
|
|
|
964
|
+ SysDept userDept = importCache.getDeptById(user.getDeptId());
|
|
|
965
|
+ if (userDept == null) {
|
|
|
966
|
+ return result;
|
|
|
967
|
+ }
|
|
|
968
|
+
|
|
|
969
|
+ String deptType = userDept.getDeptType();
|
|
|
970
|
+
|
|
|
971
|
+ // 3. 根据部门类型递归获取各级组织ID
|
|
|
972
|
+ if ("BRIGADE".equals(deptType)) {
|
|
|
973
|
+ // 用户部门是大队
|
|
|
974
|
+ result.put("deptId", user.getDeptId());
|
|
|
975
|
+ } else if ("MANAGER".equals(deptType)) {
|
|
|
976
|
+ // 用户部门是队室/班组,向上找大队
|
|
|
977
|
+ result.put("teamId", user.getDeptId());
|
|
|
978
|
+ if (userDept.getParentId() != null && userDept.getParentId() != 0) {
|
|
|
979
|
+ result.put("deptId", userDept.getParentId());
|
|
|
980
|
+ }
|
|
|
981
|
+ } else if ("TEAMS".equals(deptType)) {
|
|
|
982
|
+ // 用户部门是小组,向上找队室和大队
|
|
|
983
|
+ result.put("groupId", user.getDeptId());
|
|
|
984
|
+ if (userDept.getParentId() != null && userDept.getParentId() != 0) {
|
|
|
985
|
+ result.put("teamId", userDept.getParentId());
|
|
|
986
|
+ // 从缓存中获取父级部门
|
|
|
987
|
+ SysDept parentDept = importCache.getDeptById(userDept.getParentId());
|
|
|
988
|
+ if (parentDept != null && parentDept.getParentId() != null && parentDept.getParentId() != 0) {
|
|
|
989
|
+ result.put("deptId", parentDept.getParentId());
|
|
|
990
|
+ }
|
|
|
991
|
+ }
|
|
|
992
|
+ }
|
|
|
993
|
+
|
|
|
994
|
+ return result;
|
|
|
995
|
+ }
|
|
|
996
|
+
|
|
|
997
|
+ /**
|
|
|
998
|
+ * 构建导入缓存
|
|
|
999
|
+ */
|
|
|
1000
|
+ private void buildImportCache() {
|
|
|
1001
|
+ // 构建用户缓存:Map<昵称, SysUser>
|
|
|
1002
|
+ Map<String, SysUser> userCache = new HashMap<>();
|
|
|
1003
|
+ List<SysUser> allUsers = sysUserMapper.selectUserList(new SysUser());
|
|
|
1004
|
+ if (allUsers != null) {
|
|
|
1005
|
+ for (SysUser user : allUsers) {
|
|
|
1006
|
+ if (user.getNickName() != null && !user.getNickName().trim().isEmpty()) {
|
|
|
1007
|
+ userCache.put(user.getNickName().trim(), user);
|
|
|
1008
|
+ }
|
|
|
1009
|
+ }
|
|
|
1010
|
+ }
|
|
|
1011
|
+
|
|
|
1012
|
+ // 构建部门缓存:Map<部门ID, SysDept>
|
|
|
1013
|
+ Map<Long, SysDept> deptCache = new HashMap<>();
|
|
|
1014
|
+ SysDept queryDept = new SysDept();
|
|
|
1015
|
+ List<SysDept> allDepts = sysDeptMapper.selectDeptList(queryDept);
|
|
|
1016
|
+ if (allDepts != null) {
|
|
|
1017
|
+ for (SysDept dept : allDepts) {
|
|
|
1018
|
+ deptCache.put(dept.getDeptId(), dept);
|
|
|
1019
|
+ }
|
|
|
1020
|
+ }
|
|
|
1021
|
+
|
|
|
1022
|
+ // 创建统一缓存对象
|
|
|
1023
|
+ this.importCache = new ImportCache(userCache, deptCache);
|
|
|
1024
|
+ }
|
|
|
1025
|
+
|
|
|
1026
|
+ /**
|
|
|
1027
|
+ * 释放导入缓存
|
|
|
1028
|
+ */
|
|
|
1029
|
+ private void clearImportCache() {
|
|
|
1030
|
+ this.importCache = null;
|
|
|
1031
|
+ }
|
|
867
|
1032
|
}
|