| | |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserCreateReqDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserUpdateReqDTO; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | @Slf4j |
| | | public class HrmEmployeeServiceImpl implements HrmEmployeeService { |
| | | |
| | | /** 员工状态:离职(1-在职,2-试用,3-离职) */ |
| | | private static final Integer EMPLOYEE_STATUS_RESIGNED = 3; |
| | | |
| | | @Resource |
| | | private HrmEmployeeMapper employeeMapper; |
| | |
| | | |
| | | @Override |
| | | public List<HrmEmployeeDO> getEmployeeList(Collection<Long> ids) { |
| | | // 防御:MyBatis-Plus 的 selectByIds(null) 会抛 |
| | | // BuilderException: The expression 'coll' evaluated to a null value |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return employeeMapper.selectByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<HrmEmployeeDO> getEmployeeListByStatus(Integer employeeStatus) { |
| | | return employeeMapper.selectListByStatus(employeeStatus); |
| | | } |
| | | |
| | | @Override |
| | | public void syncEmployeeTransfer(Long employeeId, Long targetDeptId, Long targetPostId) { |
| | | if (employeeId == null) { |
| | | return; |
| | | } |
| | | HrmEmployeeDO employee = employeeMapper.selectById(employeeId); |
| | | if (employee == null) { |
| | | log.warn("[syncEmployeeTransfer][员工({}) 不存在,跳过调岗同步]", employeeId); |
| | | return; |
| | | } |
| | | if (targetDeptId == null && targetPostId == null) { |
| | | return; |
| | | } |
| | | HrmEmployeeDO updateObj = new HrmEmployeeDO(); |
| | | updateObj.setId(employeeId); |
| | | if (targetDeptId != null) { |
| | | updateObj.setDeptId(targetDeptId); |
| | | } |
| | | if (targetPostId != null) { |
| | | // hrm_employee.post_ids 存 JSON 数组字符串,如 [38] |
| | | updateObj.setPostIds(JSONUtil.toJsonStr(java.util.List.of(targetPostId))); |
| | | } |
| | | employeeMapper.updateById(updateObj); |
| | | log.info("[syncEmployeeTransfer][员工({}) 调岗生效:部门 {} -> {},岗位 -> {}]", |
| | | employeeId, employee.getDeptId(), targetDeptId, targetPostId); |
| | | } |
| | | |
| | | @Override |
| | | public void syncEmployeeResignation(Long systemUserId, java.time.LocalDate leaveDate) { |
| | | if (systemUserId == null) { |
| | | return; |
| | | } |
| | | HrmEmployeeDO employee = employeeMapper.selectByUserId(systemUserId); |
| | | if (employee == null) { |
| | | log.warn("[syncEmployeeResignation][系统用户({}) 没有对应员工档案,跳过离职同步]", systemUserId); |
| | | return; |
| | | } |
| | | employeeMapper.updateById(HrmEmployeeDO.builder() |
| | | .id(employee.getId()) |
| | | .employeeStatus(EMPLOYEE_STATUS_RESIGNED) |
| | | .leaveDate(leaveDate != null ? leaveDate : java.time.LocalDate.now()) |
| | | .build()); |
| | | log.info("[syncEmployeeResignation][员工({}) 离职生效,状态 {} -> {}]", |
| | | employee.getId(), employee.getEmployeeStatus(), EMPLOYEE_STATUS_RESIGNED); |
| | | } |
| | | |
| | | @Override |
| | | public List<HrmEmployeeSimpleRespVO> getEmployeeSimpleList(Integer employeeStatus) { |
| | | List<HrmEmployeeDO> list = employeeMapper.selectListByStatus(employeeStatus); |
| | | // 填充部门名称 |