fix:同步利元亨用户部门修改

This commit is contained in:
2026-03-23 14:15:56 +08:00
parent c1dc6a3c92
commit a0ab5c9a0b
5 changed files with 66 additions and 70 deletions

View File

@@ -157,6 +157,10 @@ public class SysHrSyncController {
@Inner(value = false)
@PostMapping("/resyncLyricDept")
public R<Boolean> resyncLyricDept(@RequestBody List<LyricUserDto> userDtoList) {
R<List<LyricUserDto>> userListR = remoteSpdmService.queryUserList(null);
if (userListR.getData() != null) {
userDtoList = userListR.getData();
}
try {
tkMoldService.resyncLyricDept(userDtoList);
} catch (Exception e) {

View File

@@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.honeycombis.honeycom.tenant.dto.*;
import com.honeycombis.honeycom.tenant.entity.SysStaffEntity;
import com.honeycombis.honeycom.tenant.vo.SysRoleVO;
import com.honeycombis.honeycom.tenant.vo.SysStaffDetailVO;
import com.honeycombis.honeycom.tenant.vo.SysStaffUpdateUseVO;
import com.honeycombis.honeycom.tenant.vo.SysStaffVO;
import com.honeycombis.honeycom.tenant.vo.*;
import java.util.List;
import java.util.Map;
@@ -83,6 +80,8 @@ public interface SysStaffService extends IService<SysStaffEntity> {
List<Long> findUserIdByTenantId(Long tenantId);
List<SysStaffDetailVO> findUserInfoByTenantId(Long tenantId);
/**
* 获取员工邮箱信息
*

View File

@@ -167,14 +167,6 @@ public class TKMoldHrConverter {
}
/**
* 将Lyric用户数据转换为部门实体构造4级部门父子层级关系
* <p>
* 部门层级:
* - 一级部门(dept_grp_code1/name1): parentId = 0L
* - 二级部门(dept_grp_code2/name2): parentId = 一级部门deptId
* - 三级部门(dept_grp_code3/name3): parentId = 二级部门deptId
* - 四级部门(dept_grp_code4/name4): parentId = 三级部门deptId (可选有些用户只有3级)
* </p>
*
* @param userList 用户列表(包含部门信息)
* @param deptIdAndDeptIds 用户当前部门编码(dept_code)与部门主键ID的映射同时也包含数据库中已存在的部门
@@ -184,48 +176,27 @@ public class TKMoldHrConverter {
public List<SysDeptEntity> lyricDeptToTenantDept(List<LyricUserDto> userList, Map<String, Long> deptIdAndDeptIds, Map<String, Long> existingDeptMap, Long tenantId) {
List<SysDeptEntity> sysDeptEntities = new ArrayList<>();
// 用于存储已创建的部门编码与部门ID的映射(用于构建父子关系)
// 用于存储已创建的部门编码与部门ID的映射
Map<String, Long> createdDeptMap = new HashMap<>();
for (LyricUserDto user : userList) {
// 一级部门
createDeptIfNotExists(createdDeptMap, existingDeptMap, sysDeptEntities,
user.getDept_grp_code1(), user.getDept_grp_name1(),
0L, tenantId);
// 二级部门
if (StrUtil.isNotBlank(user.getDept_grp_code2()) && StrUtil.isNotBlank(user.getDept_grp_name2())) {
createDeptIfNotExists(createdDeptMap, existingDeptMap, sysDeptEntities,
user.getDept_grp_code2(), user.getDept_grp_name2(),
createdDeptMap.get(user.getDept_grp_code1()), tenantId);
// 使用 dept_grp_code1-dept_grp_code2 格式构造部门编码
if (StrUtil.isNotBlank(user.getDept_grp_code1()) && StrUtil.isNotBlank(user.getDept_grp_code2())) {
String deptCode = user.getDept_grp_code1() + "-" + user.getDept_grp_code2();
// 使用 dept_grp_name1-dept_grp_name2 格式构造部门名称
String deptName = "";
if (StrUtil.isNotBlank(user.getDept_grp_name1()) && StrUtil.isNotBlank(user.getDept_grp_name2())) {
deptName = user.getDept_grp_name1() + "-" + user.getDept_grp_name2();
}
// 三级部门
if (StrUtil.isNotBlank(user.getDept_grp_code3()) && StrUtil.isNotBlank(user.getDept_grp_name3())) {
Long parentId = createdDeptMap.get(user.getDept_grp_code2());
if (parentId != null) {
// 创建部门一维结构所有部门挂在租户下parentId = 0L
createDeptIfNotExists(createdDeptMap, existingDeptMap, sysDeptEntities,
user.getDept_grp_code3(), user.getDept_grp_name3(),
parentId, tenantId);
}
}
deptCode, deptName, 0L, tenantId);
// 四级部门(可选,有些用户只有三级部门)
if (StrUtil.isNotBlank(user.getDept_grp_code4()) && StrUtil.isNotBlank(user.getDept_grp_name4())) {
Long parentId = createdDeptMap.get(user.getDept_grp_code3());
if (parentId != null) {
createDeptIfNotExists(createdDeptMap, existingDeptMap, sysDeptEntities,
user.getDept_grp_code4(), user.getDept_grp_name4(),
parentId, tenantId);
}
}
// 记录用户当前部门(dept_code)与部门主键ID的映射
// dept_code可能是三级或四级部门编码
if (StrUtil.isNotBlank(user.getDept_code())) {
Long currentDeptId = createdDeptMap.get(user.getDept_code());
if (currentDeptId != null) {
deptIdAndDeptIds.put(user.getDept_code(), currentDeptId);
// 记录用户所属部门编码与部门主键ID的映射
Long deptId = createdDeptMap.get(deptCode);
if (deptId != null) {
deptIdAndDeptIds.put(deptCode, deptId);
}
}
}

View File

@@ -330,6 +330,30 @@ public class SysStaffServiceImpl extends ServiceImpl<SysStaffMapper, SysStaffEnt
return list.stream().map(SysStaffEntity::getUserId).distinct().toList();
}
@Override
public List<SysStaffDetailVO> findUserInfoByTenantId(Long tenantId) {
if (Objects.isNull(tenantId)) {
throw new HoneycomException(ErrorType.PARAM_ERROR.getCode());
}
LambdaQueryWrapper<SysStaffEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysStaffEntity::getTenantId, tenantId);
List<SysStaffEntity> list = this.list(queryWrapper);
if (CollectionUtils.isNotEmpty(list)) {
List<SysStaffDetailVO> result = list.stream().map(SysStaffDetailVO::new).toList();
List<Long> userIds = result.stream().map(SysStaffDetailVO::getUserId).distinct().toList();
Map<Long, SysUserOnTenantVO> userMap = this.getMapStaffUserInfo(userIds);
for (SysStaffDetailVO sysStaffDetailVO : result) {
if (userMap.containsKey(sysStaffDetailVO.getUserId())) {
sysStaffDetailVO.setUserInfo(userMap.get(sysStaffDetailVO.getUserId()));
}
}
return result;
}
return new ArrayList<>();
}
@Override
public Long countByTenantIds(List<Long> tenantIds) {
if (CollectionUtils.isEmpty(tenantIds)) {

View File

@@ -10,6 +10,7 @@ import com.honeycombis.honeycom.common.core.constant.CommonConstants;
import com.honeycombis.honeycom.common.core.constant.SecurityConstants;
import com.honeycombis.honeycom.common.core.exception.HoneycomException;
import com.honeycombis.honeycom.common.core.util.R;
import com.honeycombis.honeycom.common.data.tenant.TenantContextHolder;
import com.honeycombis.honeycom.tenant.constants.TenantConstants;
import com.honeycombis.honeycom.tenant.entity.*;
import com.honeycombis.honeycom.tenant.enums.HrTableEnum;
@@ -392,27 +393,14 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
log.info("新增用户{}",tenantUserDtos.size());
// 生成部门信息 按工种分组 挂租户下面
// 获取去重后的一级部门列表
// List<LyricUserDto> deptList = getDistinctDeptByDeptCode1(userList);
// 获取去重后的部门列表(使用 dept_grp_code1-dept_grp_code2 格式)
Map<String,Long> deptIdAndDeptIds = new HashMap<>();
// 收集所有需要的部门编码
// 收集所有需要的部门编码(使用 code1-code2 格式)
Set<String> allDeptCodes = new HashSet<>();
for (LyricUserDto user : userList) {
if (StrUtil.isNotBlank(user.getDept_grp_code1())) {
allDeptCodes.add(user.getDept_grp_code1());
}
if (StrUtil.isNotBlank(user.getDept_grp_code2())) {
allDeptCodes.add(user.getDept_grp_code2());
}
if (StrUtil.isNotBlank(user.getDept_grp_code3())) {
allDeptCodes.add(user.getDept_grp_code3());
}
if (StrUtil.isNotBlank(user.getDept_grp_code4())) {
allDeptCodes.add(user.getDept_grp_code4());
}
if (StrUtil.isNotBlank(user.getDept_code())) {
allDeptCodes.add(user.getDept_code());
if (StrUtil.isNotBlank(user.getDept_grp_code1()) && StrUtil.isNotBlank(user.getDept_grp_code2())) {
allDeptCodes.add(user.getDept_grp_code1() + "-" + user.getDept_grp_code2());
}
}
@@ -494,9 +482,12 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
sysStaffEntity.setStaffCode(TenantConstants.STAFF_CODE_PREFIX + staffId);
sysStaffEntity.setCreateBy(0L);
sysStaffEntity.setUpdateBy(0L);
// deptMap.put(staffId, deptIdAndDeptIds.get(emp.getDept_grp_code1()));
// 使用用户当前部门编码(dept_code)获取部门ID
deptMap.put(staffId, deptIdAndDeptIds.get(emp.getDept_code()));
// 使用 dept_grp_code1-dept_grp_code2 格式获取部门ID
String userDeptCode = null;
if (StrUtil.isNotBlank(emp.getDept_grp_code1()) && StrUtil.isNotBlank(emp.getDept_grp_code2())) {
userDeptCode = emp.getDept_grp_code1() + "-" + emp.getDept_grp_code2();
}
deptMap.put(staffId, deptIdAndDeptIds.get(userDeptCode));
postMap.put(staffId, jobIdAndPostIds.get(emp.getJob_code()));
sysStaffEntities.add(sysStaffEntity);
SysStaffRoleEntity sysStaffRoleEntity = new SysStaffRoleEntity();
@@ -677,6 +668,9 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
Long tenantId = 2001184963854700545L;
// Long tenantId = 1979091834410176514L;
// 设置租户上下文确保多租户插件使用正确的租户ID
TenantContextHolder.setTenantId(tenantId);
if (CollUtil.isEmpty(userList)) {
log.info("用户数据为空,跳过部门重新同步");
return;
@@ -685,7 +679,7 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
log.info("开始重新同步部门数据租户ID: {}, 用户数量: {}", tenantId, userList.size());
// 1. 查询该租户下所有员工,构建 username(psn_code) -> staffId 的映射
List<SysStaffDetailVO> staffList = sysStaffService.findByTenantId(tenantId);
List<SysStaffDetailVO> staffList = sysStaffService.findUserInfoByTenantId(tenantId);
if (CollUtil.isEmpty(staffList)) {
log.warn("租户 {} 下没有找到员工数据", tenantId);
return;
@@ -728,7 +722,11 @@ public class SysTKMoldServiceImpl implements SysTKMoldService {
for (LyricUserDto user : userList) {
String psnCode = user.getPsn_code();
String deptCode = user.getDept_code();
// 使用 dept_grp_code1-dept_grp_code2 格式获取部门编码
String deptCode = null;
if (StrUtil.isNotBlank(user.getDept_grp_code1()) && StrUtil.isNotBlank(user.getDept_grp_code2())) {
deptCode = user.getDept_grp_code1() + "-" + user.getDept_grp_code2();
}
if (StrUtil.isBlank(psnCode) || StrUtil.isBlank(deptCode)) {
continue;