From 3819057382c03527d293a63f742adbc424041fa4 Mon Sep 17 00:00:00 2001 From: zhuxinru Date: Tue, 27 Jan 2026 09:05:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=90=8C=E6=AD=A5=E5=88=A9=E5=85=83?= =?UTF-8?q?=E4=BA=A8=E7=94=A8=E6=88=B7=E9=83=A8=E9=97=A8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- honeycom-spdm/pom.xml | 6 ++ .../spdm/controller/SpdmTenantController.java | 18 ++++ .../honeycom/spdm/dto/LyricUserDto.java | 67 +++++++++++++ .../spdm/feign/SpdmServiceFeignClient.java | 3 + .../tenant/feign/RemoteSpdmService.java | 7 ++ .../tenant/vo/lyric/LyricUserDto.java | 67 +++++++++++++ .../controller/SysHrSyncController.java | 23 +++++ .../tenant/service/SysTKMoldService.java | 3 + .../service/converter/TKMoldHrConverter.java | 89 +++++++++++++++++ .../service/impl/SysTKMoldServiceImpl.java | 98 +++++++++++++++++++ 10 files changed, 381 insertions(+) create mode 100644 honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/dto/LyricUserDto.java create mode 100644 honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/vo/lyric/LyricUserDto.java diff --git a/honeycom-spdm/pom.xml b/honeycom-spdm/pom.xml index 20acfb2..28c21ae 100644 --- a/honeycom-spdm/pom.xml +++ b/honeycom-spdm/pom.xml @@ -84,6 +84,12 @@ hutool-all 5.8.38 + + + com.alibaba.fastjson2 + fastjson2 + 2.0.50 + diff --git a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmTenantController.java b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmTenantController.java index 803ee75..963ab32 100644 --- a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmTenantController.java +++ b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/controller/SpdmTenantController.java @@ -19,9 +19,11 @@ package com.honeycombis.honeycom.spdm.controller; +import com.alibaba.fastjson2.JSONArray; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.databind.ObjectMapper; import com.honeycombis.honeycom.common.core.util.R; +import com.honeycombis.honeycom.spdm.dto.LyricUserDto; import com.honeycombis.honeycom.spdm.dto.TenantPageQueryDto; import com.honeycombis.honeycom.spdm.feign.RemoteTenantServiceFeign; import com.honeycombis.honeycom.spdm.feign.SpdmServiceFeignClient; @@ -35,8 +37,10 @@ import jakarta.annotation.Resource; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.List; @@ -88,4 +92,18 @@ public class SpdmTenantController { log.info("[initNewTenant] tenantId:{}, responseR:{}", tenantId, responseR); } + @PostMapping("/queryUserList") + public R> queryUserList(@RequestParam String workType) { + ResponseR sdmResponse = spdmServiceFeignClient.queryUserList(workType); + log.info("[queryUserList] sdmResponse:{}", sdmResponse); + if (sdmResponse.isSuccess() && sdmResponse.getData() != null) { + JSONArray jsonArray = (JSONArray) sdmResponse.getData(); + List userToDmList = jsonArray.toJavaList(LyricUserDto.class); + return R.ok(userToDmList); + } else { + return R.ok(new ArrayList()); + } + } + + } diff --git a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/dto/LyricUserDto.java b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/dto/LyricUserDto.java new file mode 100644 index 0000000..843818e --- /dev/null +++ b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/dto/LyricUserDto.java @@ -0,0 +1,67 @@ +package com.honeycombis.honeycom.spdm.dto; + +import lombok.Data; + +@Data +public class LyricUserDto { + /** + * 部门编码 + */ + private String dept_code; + /** + * 三级部门编码 + */ + private String dept_grp_code3; + /** + * 四级部门编码 + */ + private String dept_grp_code4; + /** + * 部门名称 + */ + private String dept_name; + /** + * 一级部门编码 + */ + private String dept_grp_code1; + /** + * 二级部门编码 + */ + private String dept_grp_code2; + /** + * 人员姓名 + */ + private String psn_name; + /** + * 人员编码 + */ + private String psn_code; + /** + * 完整部门名称 + */ + private String full_dept_name; + /** + * 工种名称 + */ + private String work_type_name; + /** + * 岗位名称 + */ + private String job_name; + /** + * 四级部门名称 + */ + private String dept_grp_name4; + /** + * 三级部门名称 + */ + private String dept_grp_name3; + /** + * 二级部门名称 + */ + private String dept_grp_name2; + /** + * 一级部门名称 + */ + private String dept_grp_name1; +} diff --git a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/feign/SpdmServiceFeignClient.java b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/feign/SpdmServiceFeignClient.java index fbbd350..016f68e 100644 --- a/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/feign/SpdmServiceFeignClient.java +++ b/honeycom-spdm/src/main/java/com/honeycombis/honeycom/spdm/feign/SpdmServiceFeignClient.java @@ -22,4 +22,7 @@ public interface SpdmServiceFeignClient { @PostMapping("/tenant/initNewTenant") ResponseR initNewTenant(@RequestParam Long tenantId); + @PostMapping("/lyricUser/queryUserList") + ResponseR queryUserList(@RequestParam String workType); + } diff --git a/honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/feign/RemoteSpdmService.java b/honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/feign/RemoteSpdmService.java index f81230e..3b92e9e 100644 --- a/honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/feign/RemoteSpdmService.java +++ b/honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/feign/RemoteSpdmService.java @@ -1,10 +1,13 @@ package com.honeycombis.honeycom.tenant.feign; import com.honeycombis.honeycom.common.core.constant.ServiceNameConstants; +import com.honeycombis.honeycom.common.core.util.R; +import com.honeycombis.honeycom.tenant.vo.lyric.LyricUserDto; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; +import java.util.List; @FeignClient(contextId = "remoteSpdmTenantService", value = ServiceNameConstants.SPDM_SERVICE) @@ -12,4 +15,8 @@ public interface RemoteSpdmService { @PostMapping("/honeycom-spdm/spdm-tenant/initNewTenant") void initNewTenant(@RequestParam Long tenantId); + + @PostMapping("/honeycom-spdm/spdm-tenant/queryUserList") + R> queryUserList(@RequestParam String workType); + } diff --git a/honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/vo/lyric/LyricUserDto.java b/honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/vo/lyric/LyricUserDto.java new file mode 100644 index 0000000..977b6a8 --- /dev/null +++ b/honeycom-tenant/honeycom-tenant-api/src/main/java/com/honeycombis/honeycom/tenant/vo/lyric/LyricUserDto.java @@ -0,0 +1,67 @@ +package com.honeycombis.honeycom.tenant.vo.lyric; + +import lombok.Data; + +@Data +public class LyricUserDto { + /** + * 部门编码 + */ + private String dept_code; + /** + * 三级部门编码 + */ + private String dept_grp_code3; + /** + * 四级部门编码 + */ + private String dept_grp_code4; + /** + * 部门名称 + */ + private String dept_name; + /** + * 一级部门编码 + */ + private String dept_grp_code1; + /** + * 二级部门编码 + */ + private String dept_grp_code2; + /** + * 人员姓名 + */ + private String psn_name; + /** + * 人员编码 + */ + private String psn_code; + /** + * 完整部门名称 + */ + private String full_dept_name; + /** + * 工种名称 + */ + private String work_type_name; + /** + * 岗位名称 + */ + private String job_name; + /** + * 四级部门名称 + */ + private String dept_grp_name4; + /** + * 三级部门名称 + */ + private String dept_grp_name3; + /** + * 二级部门名称 + */ + private String dept_grp_name2; + /** + * 一级部门名称 + */ + private String dept_grp_name1; +} diff --git a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/controller/SysHrSyncController.java b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/controller/SysHrSyncController.java index f2bd412..16ac677 100644 --- a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/controller/SysHrSyncController.java +++ b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/controller/SysHrSyncController.java @@ -15,6 +15,7 @@ import com.honeycombis.honeycom.tenant.service.SysHrSyncLogService; import com.honeycombis.honeycom.tenant.service.SysTKMoldService; import com.honeycombis.honeycom.tenant.vo.hr.HrUserInfoAddDataVO; import com.honeycombis.honeycom.tenant.vo.hr.HrUserInfoAllDataVO; +import com.honeycombis.honeycom.tenant.vo.lyric.LyricUserDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; @@ -24,6 +25,7 @@ import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.*; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -37,6 +39,10 @@ public class SysHrSyncController { private final SysTKMoldService tkMoldService; private final SysHrSyncLogService sysHrSyncLogService; + + public static final List WORK_TYPES = Arrays.asList( + "设计", "仿真", "产品工艺", "方案", "程序", "激光" + ); /** * 分页查询 * @param page 分页对象 @@ -99,6 +105,23 @@ public class SysHrSyncController { } + /** + * 全量同步用户数据 + */ + @Inner(value = false) + @PostMapping("/allSyncLyricUsers") + public R allSyncLyricUsers(@RequestBody List userDtoList) { + for (String workType : WORK_TYPES) { + try { + tkMoldService.allSyncLyricUsers(userDtoList, workType); + } catch (Exception e) { + log.error("全量同步用户数据失败", e); + throw new HoneycomException(e.getMessage()); + } + } + return R.ok(); + } + } diff --git a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/SysTKMoldService.java b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/SysTKMoldService.java index 4001080..6b2635e 100644 --- a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/SysTKMoldService.java +++ b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/SysTKMoldService.java @@ -3,6 +3,7 @@ package com.honeycombis.honeycom.tenant.service; import com.honeycombis.honeycom.tenant.vo.hr.HrUserInfoAddDataVO; import com.honeycombis.honeycom.tenant.vo.hr.HrUserInfoAllDataVO; import com.honeycombis.honeycom.tenant.vo.hr.HrUserInfoVO; +import com.honeycombis.honeycom.tenant.vo.lyric.LyricUserDto; import java.util.List; @@ -11,4 +12,6 @@ public interface SysTKMoldService { void allSyncUsers(HrUserInfoAllDataVO hrUserInfoAllDataVO); void addSyncUsers(HrUserInfoAddDataVO hrUserInfoAddDataVO); + + void allSyncLyricUsers(List userDtoList, String workType); } diff --git a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/converter/TKMoldHrConverter.java b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/converter/TKMoldHrConverter.java index 2cae109..25be802 100644 --- a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/converter/TKMoldHrConverter.java +++ b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/converter/TKMoldHrConverter.java @@ -13,6 +13,7 @@ import com.honeycombis.honeycom.tenant.vo.hr.HrDeptVO; import com.honeycombis.honeycom.tenant.vo.hr.HrEDetailVO; import com.honeycombis.honeycom.tenant.vo.hr.HrEmpVO; import com.honeycombis.honeycom.tenant.vo.hr.HrJobVO; +import com.honeycombis.honeycom.tenant.vo.lyric.LyricUserDto; import com.honeycombis.honeycom.user.dto.TenantUserDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -67,6 +68,26 @@ public class TKMoldHrConverter { } return tenantUserDtos; } + + public List lyricUserToTenantUserDto(List lyricUserList, Map empIdAndUserIds) { + List tenantUserDtos = new ArrayList<>(); + for (LyricUserDto lyricUser : lyricUserList) { + + TenantUserDto tenantUserDto = new TenantUserDto(); + long userId = IdWorker.getId(); + // 工号与cid userId映射关系 + empIdAndUserIds.put(lyricUser.getPsn_code(), userId); + tenantUserDto.setUserId(userId); + tenantUserDto.setUsername(lyricUser.getPsn_code()); + tenantUserDto.setNickname(lyricUser.getPsn_name()); + // 初始化手机号 + String format = StrUtil.padPre(lyricUser.getPsn_code(), 6, '9'); + String iphone = "199"+RandomUtil.randomNumbers(2)+format; + tenantUserDto.setPhone(iphone); + tenantUserDtos.add(tenantUserDto); + } + return tenantUserDtos; + } /** * 转换成单个用户信息 * @param emp @@ -143,6 +164,63 @@ public class TKMoldHrConverter { return sysDeptEntities; } + public List lyricDeptToTenantDept(List depts, Map deptIdAndDeptIds,Long tenantId) { + List sysDeptEntities = new ArrayList<>(depts.size()); + depts.forEach(dept -> { + SysDeptEntity sysDeptEntity = new SysDeptEntity(); + sysDeptEntity.setTenantId(tenantId); + sysDeptEntity.setDeptCode(dept.getDept_grp_code1()); + sysDeptEntity.setDeptName(dept.getDept_grp_name1()); + + long id = IdWorker.getId(sysDeptEntity); + sysDeptEntity.setDeptId(id); + sysDeptEntity.setParentId(0L); + sysDeptEntity.setCreateBy(0L); + sysDeptEntity.setUpdateBy(0L); + deptIdAndDeptIds.put(dept.getDept_grp_code1(), id); + sysDeptEntities.add(sysDeptEntity); + }); + return sysDeptEntities; + } + + public List lyricDeptToTenantDept2(String workType, Map deptIdAndDeptIds,Long tenantId) { + List sysDeptEntities = new ArrayList<>(); + SysDeptEntity sysDeptEntity = new SysDeptEntity(); + sysDeptEntity.setTenantId(tenantId); + sysDeptEntity.setDeptName(workType + "组"); + switch (workType) { + case "设计": + sysDeptEntity.setDeptCode("GROUP_01"); + break; + case "仿真": + sysDeptEntity.setDeptCode("GROUP_02"); + break; + case "产品工艺": + sysDeptEntity.setDeptCode("GROUP_03"); + break; + case "方案": + sysDeptEntity.setDeptCode("GROUP_04"); + break; + case "程序": + sysDeptEntity.setDeptCode("GROUP_05"); + break; + case "激光": + sysDeptEntity.setDeptCode("GROUP_06"); + break; + default: + break; + } + + long id = IdWorker.getId(sysDeptEntity); + sysDeptEntity.setDeptId(id); + sysDeptEntity.setParentId(0L); + sysDeptEntity.setCreateBy(0L); + sysDeptEntity.setUpdateBy(0L); + deptIdAndDeptIds.put(workType, id); + sysDeptEntities.add(sysDeptEntity); + return sysDeptEntities; + } + /** * 返回单个部门信息 * @param dept @@ -239,6 +317,17 @@ public class TKMoldHrConverter { return sysStaffDeptEntities; } + public List convertStaffDept(Map deptMap){ + List sysStaffDeptEntities = new ArrayList<>(); + deptMap.forEach((staffId,deptId) -> { + SysStaffDeptEntity sysStaffDeptEntity = new SysStaffDeptEntity(); + sysStaffDeptEntity.setStaffId(staffId); + sysStaffDeptEntity.setDeptId(deptId); + sysStaffDeptEntities.add(sysStaffDeptEntity); + }); + return sysStaffDeptEntities; + } + public List converterStaffPost(Map postDept, Map jobIdAndPostIds){ List sysStaffDeptEntities = new ArrayList<>(); diff --git a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/impl/SysTKMoldServiceImpl.java b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/impl/SysTKMoldServiceImpl.java index 4496b85..b2735f7 100644 --- a/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/impl/SysTKMoldServiceImpl.java +++ b/honeycom-tenant/honeycom-tenant-biz/src/main/java/com/honeycombis/honeycom/tenant/service/impl/SysTKMoldServiceImpl.java @@ -13,10 +13,12 @@ import com.honeycombis.honeycom.common.core.util.R; import com.honeycombis.honeycom.tenant.constants.TenantConstants; import com.honeycombis.honeycom.tenant.entity.*; import com.honeycombis.honeycom.tenant.enums.HrTableEnum; +import com.honeycombis.honeycom.tenant.feign.RemoteSpdmService; import com.honeycombis.honeycom.tenant.service.*; import com.honeycombis.honeycom.tenant.service.converter.TKMoldHrConverter; import com.honeycombis.honeycom.tenant.vo.*; import com.honeycombis.honeycom.tenant.vo.hr.*; +import com.honeycombis.honeycom.tenant.vo.lyric.LyricUserDto; import com.honeycombis.honeycom.tenant.vo.tenant.SysTenantVO; import com.honeycombis.honeycom.user.dto.TenantUserDto; import com.honeycombis.honeycom.user.entity.SysUserEntity; @@ -53,6 +55,7 @@ public class SysTKMoldServiceImpl implements SysTKMoldService { private final SysHrSyncLogService sysHrSyncLogService; private final SysRoleService sysRoleService; private final SysStaffRoleService sysStaffRoleService; + private final RemoteSpdmService remoteSpdmService; @Async("tenantAsyncTask") @Override @@ -361,5 +364,100 @@ public class SysTKMoldServiceImpl implements SysTKMoldService { sysHrSyncLogEntity.setHrEndId(hrUserInfoAddDataVO.getSyncEndId()); sysHrSyncLogService.save(sysHrSyncLogEntity); } + +// @Async("tenantAsyncTask") + @Override + @Transactional(rollbackFor = Exception.class) + public void allSyncLyricUsers(List userList, String workType) { +// Long tenantId = 2001184963854700545L; + Long tenantId = 7244250568405852160L; + // 获取利元亨用户数据(带部门) +// R> userListR = remoteSpdmService.queryUserList(workType); +// List userList = userListR.getData(); + if (!userList.isEmpty()) { + log.info("开始同步,租户{}",tenantId); + StringBuilder message = new StringBuilder("全量同步:"); + + SysRoleVO sysRole = sysRoleService.getByRoleCodeAndTenantId(TenantConstants.ROLE_NORMAL_USER_CODE, tenantId); + if (sysRole != null) { + Map empIdAndUserIds = new HashMap<>(); + List tenantUserDtos = tkMoldHrConverter.lyricUserToTenantUserDto(userList, empIdAndUserIds); + List> lists = ListUtil.split(tenantUserDtos, 500); + int index = 0; + for (List 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 deptList = getDistinctDeptByDeptCode1(userList); + Map deptIdAndDeptIds = new HashMap<>(); + List sysDeptEntities = tkMoldHrConverter.lyricDeptToTenantDept2(workType, deptIdAndDeptIds, tenantId); + sysDeptService.saveBatch(sysDeptEntities); + message.append(String.format("新增部门%s;",sysDeptEntities.size())); + log.info("新增部门{}",sysDeptEntities.size()); + + //生成员工信息 + List sysStaffEntities = new ArrayList<>(userList.size()); + // cid部门id和员工id映射 + Map deptMap = new HashMap<>(); + Map postMap = new HashMap<>(); + List 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(emp.getJobId(),staffId); + sysStaffEntities.add(sysStaffEntity); + SysStaffRoleEntity sysStaffRoleEntity = new SysStaffRoleEntity(); + sysStaffRoleEntity.setStaffId(staffId); + sysStaffRoleEntity.setRoleId(sysRole.getRoleId()); + staffRoleList.add(sysStaffRoleEntity); + }); + //保存员工信息 + sysStaffService.saveBatch(sysStaffEntities); + //处理员工关联关系 + List sysStaffDeptEntities = tkMoldHrConverter.convertStaffDept(deptMap); +// List sysStaffPostEntities = tkMoldHrConverter.converterStaffPost(postMap, jobIdAndPostIds); + sysStaffDeptService.saveBatch(sysStaffDeptEntities); +// sysStaffPostService.saveBatch(sysStaffPostEntities); + sysStaffRoleService.saveBatch(staffRoleList); + } + } + } + + private List getDistinctDeptByDeptCode1(List originalList) { + // 核心:用HashMap底层实现去重,key是dept_grp_code1,value是DTO + Map deptMap = originalList.stream() + // 过滤掉code1为空的无效数据(避免空指针,提升效率) + .filter(dto -> dto.getDept_grp_code1() != null && !dto.getDept_grp_code1().isEmpty()) + .collect(Collectors.toMap( + LyricUserDto::getDept_grp_code1, // 按code1作为唯一key + dto -> { + // 只保留需要的两个字段,减少内存占用 + LyricUserDto newDto = new LyricUserDto(); + newDto.setDept_grp_code1(dto.getDept_grp_code1()); + newDto.setDept_grp_name1(dto.getDept_grp_name1()); + return newDto; + }, + (existing, replacement) -> existing // 重复时保留第一个,避免覆盖 + )); + // 转成列表(HashMap.values()遍历效率极高) + return new ArrayList<>(deptMap.values()); + } }