| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | @Slf4j |
| | | public class HrmEmployeeServiceImpl implements HrmEmployeeService { |
| | | |
| | | @Resource |
| | |
| | | if (StrUtil.isBlank(deptName)) { |
| | | throw exception(EMPLOYEE_IMPORT_FIELD_REQUIRED, "部门名称"); |
| | | } |
| | | DeptRespDTO dept = deptMap.get(deptName.trim()); |
| | | if (dept == null) { |
| | | throw exception(EMPLOYEE_DEPT_NAME_NOT_EXISTS, deptName.trim()); |
| | | String trimmed = deptName.trim(); |
| | | DeptRespDTO dept = deptMap.get(trimmed); |
| | | if (dept != null) { |
| | | return dept.getId(); |
| | | } |
| | | return dept.getId(); |
| | | // 客户表格里的部门名可能尚未在系统中建立(如「综合车间」): |
| | | // 部门是员工的必填项,直接报错会让整批导入全部失败,这里自动补建到根部门下 |
| | | Long deptId = deptApi.getOrCreateDeptByName(trimmed); |
| | | if (deptId == null) { |
| | | throw exception(EMPLOYEE_DEPT_NAME_NOT_EXISTS, trimmed); |
| | | } |
| | | return deptId; |
| | | } |
| | | |
| | | private Set<Long> parsePostIds(String postNames, Map<String, PostRespDTO> postMap) { |
| | |
| | | continue; |
| | | } |
| | | PostRespDTO post = postMap.get(trimmed); |
| | | if (post == null) { |
| | | throw exception(EMPLOYEE_POST_NAME_NOT_EXISTS, trimmed); |
| | | if (post != null) { |
| | | postIds.add(post.getId()); |
| | | continue; |
| | | } |
| | | postIds.add(post.getId()); |
| | | // 岗位未建立时自动补建,避免整批导入失败 |
| | | Long postId = postApi.getOrCreatePostByName(trimmed); |
| | | if (postId != null) { |
| | | postIds.add(postId); |
| | | } |
| | | } |
| | | if (CollUtil.isEmpty(postIds)) { |
| | | throw exception(EMPLOYEE_IMPORT_FIELD_REQUIRED, "岗位名称"); |
| | |
| | | } |
| | | RoleRespDTO role = roleMap.get(trimmed); |
| | | if (role == null) { |
| | | throw exception(EMPLOYEE_ROLE_NAME_NOT_EXISTS, trimmed); |
| | | // 角色对员工导入是可选项,表格里填了系统没有的角色名(常见是把部门名误填到角色列)时跳过,不阻塞导入 |
| | | log.warn("[parseRoleIds][角色({}) 不存在,已跳过]", trimmed); |
| | | continue; |
| | | } |
| | | roleIds.add(role.getId()); |
| | | } |