| | |
| | | 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; |
| | | import cn.iocoder.yudao.module.hrm.enums.HrmEmploymentTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.api.cal.MesCalTeamApi; |
| | | import cn.iocoder.yudao.module.mes.api.cal.dto.MesCalTeamRespDTO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.HrmEmployeeEducationSaveReqVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.HrmEmployeeEmergencyContactSaveReqVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.employee.vo.HrmEmployeeImportExcelVO; |
| | |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.employee.HrmEmployeeMapper; |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.employee.HrmEmployeeWorkHistoryMapper; |
| | | import cn.iocoder.yudao.module.hrm.dal.redis.HrmNoRedisDAO; |
| | | import cn.iocoder.yudao.module.infra.api.config.ConfigApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.PostApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| | |
| | | @Resource |
| | | private RoleApi roleApi; |
| | | @Resource |
| | | private MesCalTeamApi mesCalTeamApi; |
| | | @Resource |
| | | private ConfigApi configApi; |
| | | |
| | | /** |
| | | * 用户初始密码的系统参数配置项 |
| | | */ |
| | | private static final String USER_INIT_PASSWORD_KEY = "system.user.init-password"; |
| | | @Resource |
| | | @Lazy // 自注入需延迟加载,否则 bean 被代理包装后注入原始版本导致启动失败 |
| | | private HrmEmployeeService self; |
| | | |
| | |
| | | userCreateReqDTO.setDeptId(createReqVO.getDeptId()); |
| | | userCreateReqDTO.setPostIds(Collections.singleton(createReqVO.getPostId())); |
| | | userCreateReqDTO.setMobile(createReqVO.getPhone()); |
| | | userCreateReqDTO.setPassword(createReqVO.getPhone()); |
| | | // 初始密码:优先用导入/新增时指定的密码,否则读取系统参数;两者都没有则报错 |
| | | userCreateReqDTO.setPassword(resolveInitialPassword(createReqVO.getPassword())); |
| | | userCreateReqDTO.setSex(createReqVO.getGender()); |
| | | userCreateReqDTO.setEmail(createReqVO.getEmail()); |
| | | userCreateReqDTO.setRemark(createReqVO.getRemark()); |
| | |
| | | } |
| | | employeeMapper.updateById(updateObj); |
| | | Long employeeId = updateReqVO.getId(); |
| | | |
| | | // 同步系统用户密码:仅当显式填写了密码时才更新,未填写保持原密码不变 |
| | | if (StrUtil.isNotBlank(updateReqVO.getPassword()) && employee.getUserId() != null) { |
| | | adminUserApi.updateUserPassword(employee.getUserId(), updateReqVO.getPassword()); |
| | | } |
| | | |
| | | // 同步教育经历 |
| | | syncEducationList(employeeId, updateReqVO.getEducations()); |
| | |
| | | respVO.setRoleNames(roles.stream().map(RoleRespDTO::getName).collect(Collectors.joining(","))); |
| | | } |
| | | } |
| | | // 填充用工性质名称 |
| | | if (employee.getEmploymentType() != null) { |
| | | respVO.setEmploymentTypeName(HrmEmploymentTypeEnum.getNameByType(employee.getEmploymentType())); |
| | | } |
| | | // 填充所属班组名称 |
| | | if (employee.getTeamId() != null) { |
| | | List<MesCalTeamRespDTO> teams = mesCalTeamApi.getTeamList(Collections.singleton(employee.getTeamId())); |
| | | if (CollUtil.isNotEmpty(teams)) { |
| | | respVO.setTeamName(teams.get(0).getName()); |
| | | } |
| | | } |
| | | return respVO; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public HrmEmployeeDO getEmployeeByUserId(Long userId) { |
| | | return employeeMapper.selectByUserId(userId); |
| | | } |
| | | |
| | | @Override |
| | | public HrmEmployeeDO getEmployeeByName(String name) { |
| | | return employeeMapper.selectByName(name); |
| | | } |
| | | |
| | | @Override |
| | | public List<HrmEmployeeDO> getEmployeeListByName(String name) { |
| | | return employeeMapper.selectListByName(name); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return respVO; |
| | | } |
| | | |
| | | /** |
| | | * 解析员工初始密码: |
| | | * 1. 导入/新增时显式指定了密码,优先使用; |
| | | * 2. 未指定则读取系统参数 {@code system.user.init-password}; |
| | | * 3. 两者都没有时明确报错,避免悄悄用手机号等弱口令兜底。 |
| | | */ |
| | | private String resolveInitialPassword(String specifiedPassword) { |
| | | if (StrUtil.isNotBlank(specifiedPassword)) { |
| | | return specifiedPassword; |
| | | } |
| | | String initPassword = configApi.getConfigValueByKey(USER_INIT_PASSWORD_KEY); |
| | | if (StrUtil.isBlank(initPassword)) { |
| | | throw exception(EMPLOYEE_INIT_PASSWORD_NOT_CONFIGURED); |
| | | } |
| | | return initPassword; |
| | | } |
| | | |
| | | private HrmEmployeeSaveReqVO buildImportSaveReqVO(HrmEmployeeImportExcelVO importEmployee, |
| | | Long deptId, Long postId, Set<Long> roleIds) { |
| | | if (StrUtil.isBlank(importEmployee.getName())) { |
| | |
| | | reqVO.setName(importEmployee.getName()); |
| | | reqVO.setGender(importEmployee.getGender() != null ? importEmployee.getGender() : 1); // 默认男 |
| | | reqVO.setPhone(importEmployee.getPhone()); |
| | | reqVO.setPassword(importEmployee.getPassword()); |
| | | reqVO.setDeptId(deptId); |
| | | reqVO.setPostId(postId); |
| | | reqVO.setRoleIds(CollUtil.isEmpty(roleIds) ? null : new ArrayList<>(roleIds)); |