| | |
| | | employeeMapper.insert(employee); |
| | | Long employeeId = employee.getId(); |
| | | // 7. 同步添加教育经历 |
| | | if (CollUtil.isNotEmpty(createReqVO.getEducationList())) { |
| | | createReqVO.getEducationList().forEach(educationVO -> { |
| | | if (CollUtil.isNotEmpty(createReqVO.getEducations())) { |
| | | createReqVO.getEducations().forEach(educationVO -> { |
| | | HrmEmployeeEducationDO education = BeanUtils.toBean(educationVO, HrmEmployeeEducationDO.class); |
| | | education.setEmployeeId(employeeId); |
| | | educationMapper.insert(education); |
| | | }); |
| | | } |
| | | // 8. 同步添加工作经历 |
| | | if (CollUtil.isNotEmpty(createReqVO.getWorkHistoryList())) { |
| | | createReqVO.getWorkHistoryList().forEach(workHistoryVO -> { |
| | | if (CollUtil.isNotEmpty(createReqVO.getWorkHistories())) { |
| | | createReqVO.getWorkHistories().forEach(workHistoryVO -> { |
| | | HrmEmployeeWorkHistoryDO workHistory = BeanUtils.toBean(workHistoryVO, HrmEmployeeWorkHistoryDO.class); |
| | | workHistory.setEmployeeId(employeeId); |
| | | workHistoryMapper.insert(workHistory); |
| | | }); |
| | | } |
| | | // 9. 同步添加紧急联系人 |
| | | if (CollUtil.isNotEmpty(createReqVO.getEmergencyContactList())) { |
| | | createReqVO.getEmergencyContactList().forEach(emergencyContactVO -> { |
| | | if (CollUtil.isNotEmpty(createReqVO.getEmergencyContacts())) { |
| | | createReqVO.getEmergencyContacts().forEach(emergencyContactVO -> { |
| | | HrmEmployeeEmergencyContactDO emergencyContact = BeanUtils.toBean(emergencyContactVO, HrmEmployeeEmergencyContactDO.class); |
| | | emergencyContact.setEmployeeId(employeeId); |
| | | emergencyContactMapper.insert(emergencyContact); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateEmployee(HrmEmployeeSaveReqVO updateReqVO) { |
| | | // 校验存在 |
| | | HrmEmployeeDO employee = validateEmployeeExists(updateReqVO.getId()); |
| | |
| | | && employeeMapper.selectByPhone(updateReqVO.getPhone()) != null) { |
| | | throw exception(EMPLOYEE_PHONE_EXISTS); |
| | | } |
| | | // 更新 |
| | | // 更新员工主表 |
| | | HrmEmployeeDO updateObj = BeanUtils.toBean(updateReqVO, HrmEmployeeDO.class); |
| | | // roleIds 存储为 JSON |
| | | if (CollUtil.isNotEmpty(updateReqVO.getRoleIds())) { |
| | | updateObj.setRoleIds(JSONUtil.toJsonStr(updateReqVO.getRoleIds())); |
| | | } |
| | | employeeMapper.updateById(updateObj); |
| | | Long employeeId = updateReqVO.getId(); |
| | | |
| | | // 同步教育经历 |
| | | syncEducationList(employeeId, updateReqVO.getEducations()); |
| | | // 同步工作经历 |
| | | syncWorkHistoryList(employeeId, updateReqVO.getWorkHistories()); |
| | | // 同步紧急联系人 |
| | | syncEmergencyContactList(employeeId, updateReqVO.getEmergencyContacts()); |
| | | } |
| | | |
| | | private void syncEducationList(Long employeeId, List<HrmEmployeeEducationSaveReqVO> newList) { |
| | | educationMapper.deleteByEmployeeId(employeeId); |
| | | if (CollUtil.isNotEmpty(newList)) { |
| | | newList.forEach(vo -> { |
| | | HrmEmployeeEducationDO education = BeanUtils.toBean(vo, HrmEmployeeEducationDO.class); |
| | | education.setId(null); |
| | | education.setEmployeeId(employeeId); |
| | | educationMapper.insert(education); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private void syncWorkHistoryList(Long employeeId, List<HrmEmployeeWorkHistorySaveReqVO> newList) { |
| | | workHistoryMapper.deleteByEmployeeId(employeeId); |
| | | if (CollUtil.isNotEmpty(newList)) { |
| | | newList.forEach(vo -> { |
| | | HrmEmployeeWorkHistoryDO workHistory = BeanUtils.toBean(vo, HrmEmployeeWorkHistoryDO.class); |
| | | workHistory.setId(null); |
| | | workHistory.setEmployeeId(employeeId); |
| | | workHistoryMapper.insert(workHistory); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private void syncEmergencyContactList(Long employeeId, List<HrmEmployeeEmergencyContactSaveReqVO> newList) { |
| | | emergencyContactMapper.deleteByEmployeeId(employeeId); |
| | | if (CollUtil.isNotEmpty(newList)) { |
| | | newList.forEach(vo -> { |
| | | HrmEmployeeEmergencyContactDO emergencyContact = BeanUtils.toBean(vo, HrmEmployeeEmergencyContactDO.class); |
| | | emergencyContact.setId(null); |
| | | emergencyContact.setEmployeeId(employeeId); |
| | | emergencyContactMapper.insert(emergencyContact); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteEmployee(Long id) { |
| | | // 校验存在 |
| | | validateEmployeeExists(id); |
| | | // 删除 |
| | | // 级联删除子表 |
| | | educationMapper.deleteByEmployeeId(id); |
| | | workHistoryMapper.deleteByEmployeeId(id); |
| | | emergencyContactMapper.deleteByEmployeeId(id); |
| | | // 删除员工 |
| | | employeeMapper.deleteById(id); |
| | | } |
| | | |