fix:同步利元亨用户岗位数据
This commit is contained in:
@@ -44,6 +44,10 @@ public class LyricUserDto {
|
|||||||
* 工种名称
|
* 工种名称
|
||||||
*/
|
*/
|
||||||
private String work_type_name;
|
private String work_type_name;
|
||||||
|
/**
|
||||||
|
* 岗位编码
|
||||||
|
*/
|
||||||
|
private String job_code;
|
||||||
/**
|
/**
|
||||||
* 岗位名称
|
* 岗位名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ public class LyricUserDto {
|
|||||||
* 工种名称
|
* 工种名称
|
||||||
*/
|
*/
|
||||||
private String work_type_name;
|
private String work_type_name;
|
||||||
|
/**
|
||||||
|
* 岗位编码
|
||||||
|
*/
|
||||||
|
private String job_code;
|
||||||
/**
|
/**
|
||||||
* 岗位名称
|
* 岗位名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -273,6 +273,25 @@ public class TKMoldHrConverter {
|
|||||||
return sysPostEntities;
|
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
|
* @param job
|
||||||
@@ -345,4 +364,15 @@ public class TKMoldHrConverter {
|
|||||||
return sysStaffDeptEntities;
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -375,6 +372,9 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
|||||||
// R<List<LyricUserDto>> userListR = remoteSpdmService.queryUserList(workType);
|
// R<List<LyricUserDto>> userListR = remoteSpdmService.queryUserList(workType);
|
||||||
// List<LyricUserDto> userList = userListR.getData();
|
// List<LyricUserDto> userList = userListR.getData();
|
||||||
if (!userList.isEmpty()) {
|
if (!userList.isEmpty()) {
|
||||||
|
// 筛选新用户
|
||||||
|
userList = filerNewUserList(userList);
|
||||||
|
|
||||||
log.info("开始同步,租户{}",tenantId);
|
log.info("开始同步,租户{}",tenantId);
|
||||||
StringBuilder message = new StringBuilder("全量同步:");
|
StringBuilder message = new StringBuilder("全量同步:");
|
||||||
|
|
||||||
@@ -401,11 +401,19 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
|||||||
message.append(String.format("新增部门%s;",sysDeptEntities.size()));
|
message.append(String.format("新增部门%s;",sysDeptEntities.size()));
|
||||||
log.info("新增部门{}",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());
|
List<SysStaffEntity> sysStaffEntities = new ArrayList<>(userList.size());
|
||||||
// cid部门id和员工id映射
|
// cid部门id和员工id映射
|
||||||
Map<Long,Long> deptMap = new HashMap<>();
|
Map<Long,Long> deptMap = new HashMap<>();
|
||||||
Map<Integer,Long> postMap = new HashMap<>();
|
Map<Long,Long> postMap = new HashMap<>();
|
||||||
List<SysStaffRoleEntity> staffRoleList = new ArrayList<>();
|
List<SysStaffRoleEntity> staffRoleList = new ArrayList<>();
|
||||||
userList.forEach(emp -> {
|
userList.forEach(emp -> {
|
||||||
SysStaffEntity sysStaffEntity = new SysStaffEntity();
|
SysStaffEntity sysStaffEntity = new SysStaffEntity();
|
||||||
@@ -421,7 +429,7 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
|||||||
sysStaffEntity.setUpdateBy(0L);
|
sysStaffEntity.setUpdateBy(0L);
|
||||||
// deptMap.put(staffId, deptIdAndDeptIds.get(emp.getDept_grp_code1()));
|
// deptMap.put(staffId, deptIdAndDeptIds.get(emp.getDept_grp_code1()));
|
||||||
deptMap.put(staffId, deptIdAndDeptIds.get(workType));
|
deptMap.put(staffId, deptIdAndDeptIds.get(workType));
|
||||||
// postMap.put(emp.getJobId(),staffId);
|
postMap.put(staffId, jobIdAndPostIds.get(emp.getJob_code()));
|
||||||
sysStaffEntities.add(sysStaffEntity);
|
sysStaffEntities.add(sysStaffEntity);
|
||||||
SysStaffRoleEntity sysStaffRoleEntity = new SysStaffRoleEntity();
|
SysStaffRoleEntity sysStaffRoleEntity = new SysStaffRoleEntity();
|
||||||
sysStaffRoleEntity.setStaffId(staffId);
|
sysStaffRoleEntity.setStaffId(staffId);
|
||||||
@@ -432,14 +440,28 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
|||||||
sysStaffService.saveBatch(sysStaffEntities);
|
sysStaffService.saveBatch(sysStaffEntities);
|
||||||
//处理员工关联关系
|
//处理员工关联关系
|
||||||
List<SysStaffDeptEntity> sysStaffDeptEntities = tkMoldHrConverter.convertStaffDept(deptMap);
|
List<SysStaffDeptEntity> sysStaffDeptEntities = tkMoldHrConverter.convertStaffDept(deptMap);
|
||||||
// List<SysStaffPostEntity> sysStaffPostEntities = tkMoldHrConverter.converterStaffPost(postMap, jobIdAndPostIds);
|
List<SysStaffPostEntity> sysStaffPostEntities = tkMoldHrConverter.convertStaffPost(postMap);
|
||||||
sysStaffDeptService.saveBatch(sysStaffDeptEntities);
|
sysStaffDeptService.saveBatch(sysStaffDeptEntities);
|
||||||
// sysStaffPostService.saveBatch(sysStaffPostEntities);
|
sysStaffPostService.saveBatch(sysStaffPostEntities);
|
||||||
sysStaffRoleService.saveBatch(staffRoleList);
|
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) {
|
private List<LyricUserDto> getDistinctDeptByDeptCode1(List<LyricUserDto> originalList) {
|
||||||
// 核心:用HashMap底层实现去重,key是dept_grp_code1,value是DTO
|
// 核心:用HashMap底层实现去重,key是dept_grp_code1,value是DTO
|
||||||
Map<String, LyricUserDto> deptMap = originalList.stream()
|
Map<String, LyricUserDto> deptMap = originalList.stream()
|
||||||
@@ -459,5 +481,21 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
|
|||||||
// 转成列表(HashMap.values()遍历效率极高)
|
// 转成列表(HashMap.values()遍历效率极高)
|
||||||
return new ArrayList<>(deptMap.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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.springframework.cloud.openfeign.FeignClient;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@FeignClient(contextId = "honeycomUserServiceFeign", value = ServiceNameConstants.USER_SERVICE, configuration = FeignConfig.class)
|
@FeignClient(contextId = "honeycomUserServiceFeign", value = ServiceNameConstants.USER_SERVICE, configuration = FeignConfig.class)
|
||||||
public interface HoneycomUserServiceFeign {
|
public interface HoneycomUserServiceFeign {
|
||||||
@@ -121,4 +122,6 @@ public interface HoneycomUserServiceFeign {
|
|||||||
@PostMapping("/user/tenant/getUserByHrEmpId")
|
@PostMapping("/user/tenant/getUserByHrEmpId")
|
||||||
R<SysUserEntity> getUserByHrEmpId(@RequestParam Integer hrEmpId, @RequestHeader(SecurityConstants.FROM) String from);
|
R<SysUserEntity> getUserByHrEmpId(@RequestParam Integer hrEmpId, @RequestHeader(SecurityConstants.FROM) String from);
|
||||||
|
|
||||||
|
@GetMapping("/user/getUserListByUserNamesForSpdm")
|
||||||
|
R<Set<String>> getUserListByUserNamesForSpdm(@RequestParam("userNames") List<String> userNames);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,6 +297,13 @@ public class SysUserController {
|
|||||||
return R.ok(sysUserService.findByUsernameList(userNames));
|
return R.ok(sysUserService.findByUsernameList(userNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inner(false)
|
||||||
|
@Operation(summary = "通过用户名(工号)集合查询用户信息" , description = "通过用户名(工号)集合查询用户信息" )
|
||||||
|
@GetMapping("/getUserListByUserNamesForSpdm")
|
||||||
|
public R<Set<String>> getUserListByUserNamesForSpdm(@RequestParam("userNames") List<String> userNames) {
|
||||||
|
return R.ok(sysUserService.getUserListByUserNamesForSpdm(userNames));
|
||||||
|
}
|
||||||
|
|
||||||
@Inner
|
@Inner
|
||||||
@Operation(summary = "通过电话号码集合查询用户信息" , description = "通过电话号码集合查询用户信息" )
|
@Operation(summary = "通过电话号码集合查询用户信息" , description = "通过电话号码集合查询用户信息" )
|
||||||
@GetMapping("/retrieve/phone-list")
|
@GetMapping("/retrieve/phone-list")
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.honeycombis.honeycom.user.vo.SysUserPageQueryVO;
|
|||||||
import com.honeycombis.honeycom.user.vo.SysUserVO;
|
import com.honeycombis.honeycom.user.vo.SysUserVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author luobin@honeycombis.com
|
* @author luobin@honeycombis.com
|
||||||
@@ -39,6 +40,8 @@ public interface SysUserService extends IService<SysUserEntity> {
|
|||||||
|
|
||||||
List<SysUserVO> findByUsernameList(List<String> usernameList);
|
List<SysUserVO> findByUsernameList(List<String> usernameList);
|
||||||
|
|
||||||
|
Set<String> getUserListByUserNamesForSpdm(List<String> usernameList);
|
||||||
|
|
||||||
List<SysUserNoSensitiveInfoVO> findByPhoneList(List<String> phoneList);
|
List<SysUserNoSensitiveInfoVO> findByPhoneList(List<String> phoneList);
|
||||||
|
|
||||||
List<SysUserVO> findByIds(List<Long> ids);
|
List<SysUserVO> findByIds(List<Long> ids);
|
||||||
|
|||||||
@@ -333,6 +333,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|||||||
return getSysUserVOList(result, queryWrapper);
|
return getSysUserVOList(result, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getUserListByUserNamesForSpdm(List<String> usernameList) {
|
||||||
|
if (Objects.isNull(usernameList)) {
|
||||||
|
throw new HoneycomException(ErrorType.PARAM_ERROR.getCode());
|
||||||
|
} else if (CollectionUtils.isEmpty(usernameList)) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
LambdaQueryWrapper<SysUserEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.select(SysUserEntity::getUsername)
|
||||||
|
.in(SysUserEntity::getUsername, usernameList);
|
||||||
|
List<SysUserEntity> existing = this.list(queryWrapper);
|
||||||
|
return existing.stream()
|
||||||
|
.map(SysUserEntity::getUsername)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysUserNoSensitiveInfoVO> findByPhoneList(List<String> phoneList) {
|
public List<SysUserNoSensitiveInfoVO> findByPhoneList(List<String> phoneList) {
|
||||||
if (CollectionUtils.isEmpty(phoneList)) {
|
if (CollectionUtils.isEmpty(phoneList)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user