fix:同步利元亨用户岗位数据
This commit is contained in:
@@ -44,6 +44,10 @@ public class LyricUserDto {
|
||||
* 工种名称
|
||||
*/
|
||||
private String work_type_name;
|
||||
/**
|
||||
* 岗位编码
|
||||
*/
|
||||
private String job_code;
|
||||
/**
|
||||
* 岗位名称
|
||||
*/
|
||||
|
||||
@@ -273,6 +273,25 @@ public class TKMoldHrConverter {
|
||||
return sysPostEntities;
|
||||
}
|
||||
|
||||
public List<SysPostEntity> lyricJobToPost(List<LyricUserDto> jobs, Map<String,Long> jobIdAndPostIds,Long tenantId) {
|
||||
List<SysPostEntity> sysPostEntities = new ArrayList<>(jobs.size());
|
||||
jobs.forEach(job->{
|
||||
SysPostEntity sysPostEntity = new SysPostEntity();
|
||||
sysPostEntity.setPostCode(job.getJob_code());
|
||||
sysPostEntity.setPostName(job.getJob_name());
|
||||
|
||||
long id = IdWorker.getId(sysPostEntity);
|
||||
sysPostEntity.setPostId(id);
|
||||
sysPostEntity.setTenantId(tenantId);
|
||||
sysPostEntity.setCreateBy(0L);
|
||||
sysPostEntity.setUpdateBy(0L);
|
||||
sysPostEntity.setSortOrder(0);
|
||||
jobIdAndPostIds.put(job.getJob_code(),id);
|
||||
sysPostEntities.add(sysPostEntity);
|
||||
});
|
||||
return sysPostEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回单个岗位
|
||||
* @param job
|
||||
@@ -345,4 +364,15 @@ public class TKMoldHrConverter {
|
||||
return sysStaffDeptEntities;
|
||||
}
|
||||
|
||||
public List<SysStaffPostEntity> convertStaffPost(Map<Long,Long> postDept){
|
||||
List<SysStaffPostEntity> sysStaffDeptEntities = new ArrayList<>();
|
||||
postDept.forEach((staffId,postId) -> {
|
||||
SysStaffPostEntity sysStaffPostEntity = new SysStaffPostEntity();
|
||||
sysStaffPostEntity.setStaffId(staffId);
|
||||
sysStaffPostEntity.setPostId(postId);
|
||||
sysStaffDeptEntities.add(sysStaffPostEntity);
|
||||
});
|
||||
return sysStaffDeptEntities;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,10 +31,7 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -375,6 +372,9 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
||||
// R<List<LyricUserDto>> userListR = remoteSpdmService.queryUserList(workType);
|
||||
// List<LyricUserDto> userList = userListR.getData();
|
||||
if (!userList.isEmpty()) {
|
||||
// 筛选新用户
|
||||
userList = filerNewUserList(userList);
|
||||
|
||||
log.info("开始同步,租户{}",tenantId);
|
||||
StringBuilder message = new StringBuilder("全量同步:");
|
||||
|
||||
@@ -401,11 +401,19 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
||||
message.append(String.format("新增部门%s;",sysDeptEntities.size()));
|
||||
log.info("新增部门{}",sysDeptEntities.size());
|
||||
|
||||
//生成岗位信息
|
||||
List<LyricUserDto> jobList = getDistinctJobByJobCode(userList);
|
||||
Map<String,Long> jobIdAndPostIds = new HashMap<>();
|
||||
List<SysPostEntity> sysPostEntities = tkMoldHrConverter.lyricJobToPost(jobList, jobIdAndPostIds, tenantId);
|
||||
sysPostService.saveBatch(sysPostEntities);
|
||||
message.append(String.format("新增职位%s;",sysPostEntities.size()));
|
||||
log.info("新增职位{}",sysPostEntities.size());
|
||||
|
||||
//生成员工信息
|
||||
List<SysStaffEntity> sysStaffEntities = new ArrayList<>(userList.size());
|
||||
// cid部门id和员工id映射
|
||||
Map<Long,Long> deptMap = new HashMap<>();
|
||||
Map<Integer,Long> postMap = new HashMap<>();
|
||||
Map<Long,Long> postMap = new HashMap<>();
|
||||
List<SysStaffRoleEntity> staffRoleList = new ArrayList<>();
|
||||
userList.forEach(emp -> {
|
||||
SysStaffEntity sysStaffEntity = new SysStaffEntity();
|
||||
@@ -421,7 +429,7 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
||||
sysStaffEntity.setUpdateBy(0L);
|
||||
// deptMap.put(staffId, deptIdAndDeptIds.get(emp.getDept_grp_code1()));
|
||||
deptMap.put(staffId, deptIdAndDeptIds.get(workType));
|
||||
// postMap.put(emp.getJobId(),staffId);
|
||||
postMap.put(staffId, jobIdAndPostIds.get(emp.getJob_code()));
|
||||
sysStaffEntities.add(sysStaffEntity);
|
||||
SysStaffRoleEntity sysStaffRoleEntity = new SysStaffRoleEntity();
|
||||
sysStaffRoleEntity.setStaffId(staffId);
|
||||
@@ -432,14 +440,28 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
||||
sysStaffService.saveBatch(sysStaffEntities);
|
||||
//处理员工关联关系
|
||||
List<SysStaffDeptEntity> sysStaffDeptEntities = tkMoldHrConverter.convertStaffDept(deptMap);
|
||||
// List<SysStaffPostEntity> sysStaffPostEntities = tkMoldHrConverter.converterStaffPost(postMap, jobIdAndPostIds);
|
||||
List<SysStaffPostEntity> sysStaffPostEntities = tkMoldHrConverter.convertStaffPost(postMap);
|
||||
sysStaffDeptService.saveBatch(sysStaffDeptEntities);
|
||||
// sysStaffPostService.saveBatch(sysStaffPostEntities);
|
||||
sysStaffPostService.saveBatch(sysStaffPostEntities);
|
||||
sysStaffRoleService.saveBatch(staffRoleList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<LyricUserDto> filerNewUserList(List<LyricUserDto> allUserList) {
|
||||
// 1. 从Lyric系统获取所有员工工号数据
|
||||
List<String> allJobNumbers = allUserList.stream().map(LyricUserDto::getPsn_code)
|
||||
.distinct().collect(Collectors.toList());
|
||||
|
||||
// 2. 查询已存在的工号
|
||||
Set<String> existingJobNumbers = honeycomUserServiceFeign.getUserListByUserNamesForSpdm(allJobNumbers).getData();
|
||||
|
||||
// 3. 筛选新员工
|
||||
return allUserList.stream()
|
||||
.filter(dto -> !existingJobNumbers.contains(dto.getPsn_code()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<LyricUserDto> getDistinctDeptByDeptCode1(List<LyricUserDto> originalList) {
|
||||
// 核心:用HashMap底层实现去重,key是dept_grp_code1,value是DTO
|
||||
Map<String, LyricUserDto> deptMap = originalList.stream()
|
||||
@@ -459,5 +481,21 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
||||
// 转成列表(HashMap.values()遍历效率极高)
|
||||
return new ArrayList<>(deptMap.values());
|
||||
}
|
||||
|
||||
private List<LyricUserDto> getDistinctJobByJobCode(List<LyricUserDto> originalList) {
|
||||
Map<String, LyricUserDto> jobMap = originalList.stream()
|
||||
.filter(dto -> dto.getJob_code() != null && !dto.getJob_code().isEmpty())
|
||||
.collect(Collectors.toMap(
|
||||
LyricUserDto::getJob_code,
|
||||
dto -> {
|
||||
LyricUserDto newDto = new LyricUserDto();
|
||||
newDto.setDept_grp_code1(dto.getJob_code());
|
||||
newDto.setDept_grp_name1(dto.getJob_name());
|
||||
return newDto;
|
||||
},
|
||||
(existing, replacement) -> existing // 重复时保留第一个,避免覆盖
|
||||
));
|
||||
return new ArrayList<>(jobMap.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user