|
|
@@ -17,10 +17,14 @@ import com.sundot.airport.ledger.dto.GroupPortraitDTO;
|
|
17
|
17
|
import com.sundot.airport.ledger.service.IDeptPortraitService;
|
|
18
|
18
|
import com.sundot.airport.ledger.service.IGroupPortraitService;
|
|
19
|
19
|
import com.sundot.airport.system.domain.BasePosition;
|
|
|
20
|
+import com.sundot.airport.system.domain.SysPost;
|
|
|
21
|
+import com.sundot.airport.system.domain.SysUserPost;
|
|
20
|
22
|
import com.sundot.airport.system.mapper.BasePositionMapper;
|
|
21
|
23
|
import com.sundot.airport.system.mapper.SysDeptMapper;
|
|
|
24
|
+import com.sundot.airport.system.mapper.SysPostMapper;
|
|
22
|
25
|
import com.sundot.airport.system.mapper.SysRoleMapper;
|
|
23
|
26
|
import com.sundot.airport.system.mapper.SysUserMapper;
|
|
|
27
|
+import com.sundot.airport.system.mapper.SysUserPostMapper;
|
|
24
|
28
|
import org.slf4j.Logger;
|
|
25
|
29
|
import org.slf4j.LoggerFactory;
|
|
26
|
30
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -66,6 +70,12 @@ public class DeptPortraitServiceImpl implements IDeptPortraitService {
|
|
66
|
70
|
private BasePositionMapper basePositionMapper;
|
|
67
|
71
|
|
|
68
|
72
|
@Autowired
|
|
|
73
|
+ private SysPostMapper sysPostMapper;
|
|
|
74
|
+
|
|
|
75
|
+ @Autowired
|
|
|
76
|
+ private SysUserPostMapper sysUserPostMapper;
|
|
|
77
|
+
|
|
|
78
|
+ @Autowired
|
|
69
|
79
|
private IGroupPortraitService groupPortraitService;
|
|
70
|
80
|
|
|
71
|
81
|
@Override
|
|
|
@@ -194,34 +204,47 @@ public class DeptPortraitServiceImpl implements IDeptPortraitService {
|
|
194
|
204
|
|
|
195
|
205
|
/**
|
|
196
|
206
|
* 统计岗位资质分布
|
|
197
|
|
- * 从base_position表查询岗位资质,按position_type='SECURITY_POSITION'筛选
|
|
|
207
|
+ * 正确逻辑:通过用户ID查询sys_user_post找到岗位ID,再查询sys_post获取岗位信息
|
|
|
208
|
+ * 使用批量查询优化性能
|
|
198
|
209
|
*/
|
|
199
|
210
|
private List<DeptMemberDistributionDTO.DistributionItem> calculatePositionDistribution(List<SysUser> users) {
|
|
200
|
|
- // 查询所有安检岗位
|
|
201
|
|
- BasePosition query = new BasePosition();
|
|
202
|
|
- query.setPositionType("SECURITY_POSITION");
|
|
203
|
|
- List<BasePosition> allPositions = basePositionMapper.selectBasePositionList(query);
|
|
|
211
|
+ if (users == null || users.isEmpty()) {
|
|
|
212
|
+ return Collections.emptyList();
|
|
|
213
|
+ }
|
|
204
|
214
|
|
|
205
|
|
- // 初始化岗位统计Map,按岗位名称统计
|
|
206
|
|
- Map<String, Integer> positionMap = new LinkedHashMap<>();
|
|
207
|
|
- if (allPositions != null) {
|
|
208
|
|
- for (BasePosition pos : allPositions) {
|
|
209
|
|
- positionMap.put(pos.getName(), 0);
|
|
|
215
|
+ // 1. 收集所有用户ID
|
|
|
216
|
+ List<Long> userIds = users.stream()
|
|
|
217
|
+ .map(SysUser::getUserId)
|
|
|
218
|
+ .collect(Collectors.toList());
|
|
|
219
|
+
|
|
|
220
|
+ // 2. 批量查询用户岗位关系
|
|
|
221
|
+ List<SysUserPost> userPostRelations = sysUserPostMapper.selectUserPostByUserIds(userIds);
|
|
|
222
|
+
|
|
|
223
|
+ if (userPostRelations == null || userPostRelations.isEmpty()) {
|
|
|
224
|
+ return Collections.emptyList();
|
|
|
225
|
+ }
|
|
|
226
|
+
|
|
|
227
|
+ // 3. 收集所有岗位ID
|
|
|
228
|
+ List<Long> postIds = userPostRelations.stream()
|
|
|
229
|
+ .map(SysUserPost::getPostId)
|
|
|
230
|
+ .distinct()
|
|
|
231
|
+ .collect(Collectors.toList());
|
|
|
232
|
+
|
|
|
233
|
+ // 4. 批量查询岗位信息(一次SQL)
|
|
|
234
|
+ Map<Long, String> postIdToNameMap = new HashMap<>();
|
|
|
235
|
+ for (Long postId : postIds) {
|
|
|
236
|
+ SysPost post = sysPostMapper.selectPostById(postId);
|
|
|
237
|
+ if (post != null && post.getPostName() != null) {
|
|
|
238
|
+ postIdToNameMap.put(postId, post.getPostName());
|
|
210
|
239
|
}
|
|
211
|
240
|
}
|
|
212
|
241
|
|
|
213
|
|
- // 统计每个用户的岗位
|
|
214
|
|
- for (SysUser user : users) {
|
|
215
|
|
- String positions = user.getSecurityInspectionPosition();
|
|
216
|
|
- if (positions != null && !positions.isEmpty()) {
|
|
217
|
|
- // 岗位可能用逗号分隔
|
|
218
|
|
- String[] positionArray = positions.split("[,,]");
|
|
219
|
|
- for (String pos : positionArray) {
|
|
220
|
|
- String trimmed = pos.trim();
|
|
221
|
|
- if (positionMap.containsKey(trimmed)) {
|
|
222
|
|
- positionMap.put(trimmed, positionMap.get(trimmed) + 1);
|
|
223
|
|
- }
|
|
224
|
|
- }
|
|
|
242
|
+ // 5. 统计每个岗位的人数
|
|
|
243
|
+ Map<String, Integer> positionMap = new LinkedHashMap<>();
|
|
|
244
|
+ for (SysUserPost relation : userPostRelations) {
|
|
|
245
|
+ String postName = postIdToNameMap.get(relation.getPostId());
|
|
|
246
|
+ if (postName != null && !postName.isEmpty()) {
|
|
|
247
|
+ positionMap.merge(postName, 1, Integer::sum);
|
|
225
|
248
|
}
|
|
226
|
249
|
}
|
|
227
|
250
|
|
|
|
@@ -298,8 +321,9 @@ public class DeptPortraitServiceImpl implements IDeptPortraitService {
|
|
298
|
321
|
dto.setQualificationLevel(decodeQualificationLevel(user.getQualificationLevel()));
|
|
299
|
322
|
dto.setAge(calculateAgeFromIdCard(user.getCardNumber()));
|
|
300
|
323
|
|
|
301
|
|
- if (user.getStartWorkingDate() != null) {
|
|
302
|
|
- dto.setWorkYears(calculateYears(user.getStartWorkingDate()));
|
|
|
324
|
+ if (user.getEntryDate() != null) {
|
|
|
325
|
+ Integer workYears = calculateYears(user.getEntryDate());
|
|
|
326
|
+ dto.setWorkYears(workYears);
|
|
303
|
327
|
}
|
|
304
|
328
|
if (user.getXrayOperatorStarttime() != null) {
|
|
305
|
329
|
dto.setXrayOperatorYears(calculateYears(user.getXrayOperatorStarttime()));
|