fix:同步利元亨用户岗位数据

This commit is contained in:
2026-02-02 17:58:13 +08:00
parent 38048f94e0
commit 17288f9f21
12 changed files with 171 additions and 102 deletions

View File

@@ -11,6 +11,7 @@ import com.honeycombis.honeycom.common.core.exception.HoneycomException;
import com.honeycombis.honeycom.common.core.util.R;
import com.honeycombis.honeycom.common.security.annotation.Inner;
import com.honeycombis.honeycom.tenant.entity.SysHrSyncLogEntity;
import com.honeycombis.honeycom.tenant.feign.RemoteSpdmService;
import com.honeycombis.honeycom.tenant.service.SysHrSyncLogService;
import com.honeycombis.honeycom.tenant.service.SysTKMoldService;
import com.honeycombis.honeycom.tenant.vo.hr.HrUserInfoAddDataVO;
@@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@RestController
@@ -39,10 +41,11 @@ public class SysHrSyncController {
private final SysTKMoldService tkMoldService;
private final SysHrSyncLogService sysHrSyncLogService;
private final RemoteSpdmService remoteSpdmService;
public static final List<String> WORK_TYPES = Arrays.asList(
"设计", "仿真", "产品工艺", "方案", "程序", "激光"
);
// public static final List<String> WORK_TYPES = Arrays.asList(
// "设计", "仿真", "产品工艺", "方案", "程序", "激光"
// );
/**
* 分页查询
* @param page 分页对象
@@ -111,12 +114,18 @@ public class SysHrSyncController {
@Inner(value = false)
@PostMapping("/allSyncLyricUsers")
public R<Boolean> allSyncLyricUsers(@RequestBody List<LyricUserDto> userDtoList) {
for (String workType : WORK_TYPES) {
try {
tkMoldService.allSyncLyricUsers(userDtoList, workType);
} catch (Exception e) {
log.error("全量同步用户数据失败", e);
throw new HoneycomException(e.getMessage());
// 获取利元亨用户数据(带部门)
R<List<LyricUserDto>> userListR = remoteSpdmService.queryUserList(null);
if (userListR.getData() != null) {
Map<String, List<LyricUserDto>> userMapByWorkType = userListR.getData().stream().collect(Collectors.groupingBy(LyricUserDto::getWork_type_name));
for (String workType : userMapByWorkType.keySet()) {
log.info("-------------------------开始同步{}的用户数据----------------------", workType);
try {
tkMoldService.allSyncLyricUsers(userDtoList, workType);
} catch (Exception e) {
log.error("全量同步用户数据失败", e);
throw new HoneycomException(e.getMessage());
}
}
}
return R.ok();

View File

@@ -52,7 +52,6 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
private final SysHrSyncLogService sysHrSyncLogService;
private final SysRoleService sysRoleService;
private final SysStaffRoleService sysStaffRoleService;
private final RemoteSpdmService remoteSpdmService;
@Async("tenantAsyncTask")
@Override
@@ -362,88 +361,87 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
sysHrSyncLogService.save(sysHrSyncLogEntity);
}
// @Async("tenantAsyncTask")
@Async("tenantAsyncTask")
@Override
@Transactional(rollbackFor = Exception.class)
public void allSyncLyricUsers(List<LyricUserDto> userList, String workType) {
// Long tenantId = 2001184963854700545L;
Long tenantId = 7244250568405852160L;
// 获取利元亨用户数据(带部门)
// R<List<LyricUserDto>> userListR = remoteSpdmService.queryUserList(workType);
// List<LyricUserDto> userList = userListR.getData();
if (!userList.isEmpty()) {
// 筛选新用户
userList = filerNewUserList(userList);
if (userList.size() > 0) {
log.info("开始同步,租户{}",tenantId);
StringBuilder message = new StringBuilder("全量同步:");
log.info("开始同步,租户{}",tenantId);
StringBuilder message = new StringBuilder("全量同步:");
SysRoleVO sysRole = sysRoleService.getByRoleCodeAndTenantId(TenantConstants.ROLE_NORMAL_USER_CODE, tenantId);
if (sysRole != null) {
Map<String,Long> empIdAndUserIds = new HashMap<>();
List<TenantUserDto> tenantUserDtos = tkMoldHrConverter.lyricUserToTenantUserDto(userList, empIdAndUserIds);
List<List<TenantUserDto>> lists = ListUtil.split(tenantUserDtos, 500);
int index = 0;
for (List<TenantUserDto> tenantUserDtoList : lists) {
log.info("执行第{}到{}用户",index+1,index += tenantUserDtoList.size());
//生成用户信息
honeycomUserServiceFeign.hrBatchAdd(tenantUserDtoList, SecurityConstants.FROM_IN, new Request.Options(300, TimeUnit.SECONDS, 300, TimeUnit.SECONDS, true));
}
message.append(String.format("新增用户%s;",tenantUserDtos.size()));
log.info("新增用户{}",tenantUserDtos.size());
SysRoleVO sysRole = sysRoleService.getByRoleCodeAndTenantId(TenantConstants.ROLE_NORMAL_USER_CODE, tenantId);
if (sysRole != null) {
Map<String,Long> empIdAndUserIds = new HashMap<>();
List<TenantUserDto> tenantUserDtos = tkMoldHrConverter.lyricUserToTenantUserDto(userList, empIdAndUserIds);
List<List<TenantUserDto>> lists = ListUtil.split(tenantUserDtos, 500);
int index = 0;
for (List<TenantUserDto> tenantUserDtoList : lists) {
log.info("执行第{}到{}用户",index+1,index += tenantUserDtoList.size());
//生成用户信息
honeycomUserServiceFeign.hrBatchAdd(tenantUserDtoList, SecurityConstants.FROM_IN, new Request.Options(300, TimeUnit.SECONDS, 300, TimeUnit.SECONDS, true));
}
message.append(String.format("新增用户%s;",tenantUserDtos.size()));
log.info("新增用户{}",tenantUserDtos.size());
// 生成部门信息 按工种分组 挂租户下面
// 获取去重后的一级部门列表
// 生成部门信息 按工种分组 挂租户下面
// 获取去重后的一级部门列表
// List<LyricUserDto> deptList = getDistinctDeptByDeptCode1(userList);
Map<String,Long> deptIdAndDeptIds = new HashMap<>();
List<SysDeptEntity> sysDeptEntities = tkMoldHrConverter.lyricDeptToTenantDept2(workType, deptIdAndDeptIds, tenantId);
sysDeptService.saveBatch(sysDeptEntities);
message.append(String.format("新增部门%s;",sysDeptEntities.size()));
log.info("新增部门{}",sysDeptEntities.size());
Map<String,Long> deptIdAndDeptIds = new HashMap<>();
List<SysDeptEntity> sysDeptEntities = tkMoldHrConverter.lyricDeptToTenantDept2(workType, deptIdAndDeptIds, tenantId);
sysDeptService.saveBatch(sysDeptEntities);
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<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<Long,Long> postMap = new HashMap<>();
List<SysStaffRoleEntity> staffRoleList = new ArrayList<>();
userList.forEach(emp -> {
SysStaffEntity sysStaffEntity = new SysStaffEntity();
sysStaffEntity.setUserId(empIdAndUserIds.get(emp.getPsn_code()));
sysStaffEntity.setLoginDefault(CommonConstants.FALSE_S);
sysStaffEntity.setTenantId(tenantId);
// 用户状态默认正常
sysStaffEntity.setStatus(CommonConstants.STATUS_NORMAL);
long staffId = IdWorker.getId(sysStaffEntity);
sysStaffEntity.setStaffId(staffId);
sysStaffEntity.setStaffCode(TenantConstants.STAFF_CODE_PREFIX + staffId);
sysStaffEntity.setCreateBy(0L);
sysStaffEntity.setUpdateBy(0L);
//生成员工信息
List<SysStaffEntity> sysStaffEntities = new ArrayList<>(userList.size());
// cid部门id和员工id映射
Map<Long,Long> deptMap = new HashMap<>();
Map<Long,Long> postMap = new HashMap<>();
List<SysStaffRoleEntity> staffRoleList = new ArrayList<>();
userList.forEach(emp -> {
SysStaffEntity sysStaffEntity = new SysStaffEntity();
sysStaffEntity.setUserId(empIdAndUserIds.get(emp.getPsn_code()));
sysStaffEntity.setLoginDefault(CommonConstants.FALSE_S);
sysStaffEntity.setTenantId(tenantId);
// 用户状态默认正常
sysStaffEntity.setStatus(CommonConstants.STATUS_NORMAL);
long staffId = IdWorker.getId(sysStaffEntity);
sysStaffEntity.setStaffId(staffId);
sysStaffEntity.setStaffCode(TenantConstants.STAFF_CODE_PREFIX + staffId);
sysStaffEntity.setCreateBy(0L);
sysStaffEntity.setUpdateBy(0L);
// deptMap.put(staffId, deptIdAndDeptIds.get(emp.getDept_grp_code1()));
deptMap.put(staffId, deptIdAndDeptIds.get(workType));
postMap.put(staffId, jobIdAndPostIds.get(emp.getJob_code()));
sysStaffEntities.add(sysStaffEntity);
SysStaffRoleEntity sysStaffRoleEntity = new SysStaffRoleEntity();
sysStaffRoleEntity.setStaffId(staffId);
sysStaffRoleEntity.setRoleId(sysRole.getRoleId());
staffRoleList.add(sysStaffRoleEntity);
});
//保存员工信息
sysStaffService.saveBatch(sysStaffEntities);
//处理员工关联关系
List<SysStaffDeptEntity> sysStaffDeptEntities = tkMoldHrConverter.convertStaffDept(deptMap);
List<SysStaffPostEntity> sysStaffPostEntities = tkMoldHrConverter.convertStaffPost(postMap);
sysStaffDeptService.saveBatch(sysStaffDeptEntities);
sysStaffPostService.saveBatch(sysStaffPostEntities);
sysStaffRoleService.saveBatch(staffRoleList);
deptMap.put(staffId, deptIdAndDeptIds.get(workType));
postMap.put(staffId, jobIdAndPostIds.get(emp.getJob_code()));
sysStaffEntities.add(sysStaffEntity);
SysStaffRoleEntity sysStaffRoleEntity = new SysStaffRoleEntity();
sysStaffRoleEntity.setStaffId(staffId);
sysStaffRoleEntity.setRoleId(sysRole.getRoleId());
staffRoleList.add(sysStaffRoleEntity);
});
//保存员工信息
sysStaffService.saveBatch(sysStaffEntities);
//处理员工关联关系
List<SysStaffDeptEntity> sysStaffDeptEntities = tkMoldHrConverter.convertStaffDept(deptMap);
List<SysStaffPostEntity> sysStaffPostEntities = tkMoldHrConverter.convertStaffPost(postMap);
sysStaffDeptService.saveBatch(sysStaffDeptEntities);
sysStaffPostService.saveBatch(sysStaffPostEntities);
sysStaffRoleService.saveBatch(staffRoleList);
}
}
}
}
@@ -489,8 +487,8 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
LyricUserDto::getJob_code,
dto -> {
LyricUserDto newDto = new LyricUserDto();
newDto.setDept_grp_code1(dto.getJob_code());
newDto.setDept_grp_name1(dto.getJob_name());
newDto.setJob_code(dto.getJob_code());
newDto.setJob_name(dto.getJob_name());
return newDto;
},
(existing, replacement) -> existing // 重复时保留第一个,避免覆盖