| | |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| | | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
| | |
| | | import cn.iocoder.yudao.module.hrm.enums.HrmTransferTypeEnum; |
| | | 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.storage.StorageAttachmentApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | |
| | | /** |
| | | * 调岗申请 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | @Resource |
| | | private BpmCategoryService bpmCategoryService; |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | @Resource |
| | | private BpmProcessDefinitionService bpmProcessDefinitionService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createTransferApplication(HrmTransferApplicationSaveReqVO createReqVO) { |
| | | // 1. 校验目标部门与原部门不能相同 |
| | | if (Objects.equals(createReqVO.getTargetDeptId(), createReqVO.getCurrentDeptId())) { |
| | | throw exception(TRANSFER_APPLICATION_SAME_DEPT); |
| | | } |
| | | // 2. 校验目标岗位与原岗位不能相同 |
| | | if (Objects.equals(createReqVO.getTargetPostId(), createReqVO.getCurrentPostId())) { |
| | | throw exception(TRANSFER_APPLICATION_SAME_POST); |
| | | } |
| | | // 3. 生成申请单号 |
| | | String no = generateUniqueNo(); |
| | | // 4. 设置申请人信息 |
| | | Long userId = createReqVO.getUserId(); |
| | | if (userId == null) { |
| | | userId = getCurrentUserId(); |
| | | } |
| | | // 1. 确定调岗人员:未指定时默认当前登录人 |
| | | Long userId = createReqVO.getUserId() != null ? createReqVO.getUserId() : getCurrentUserId(); |
| | | AdminUserRespDTO user = adminUserApi.getUser(userId); |
| | | if (user == null) { |
| | | userId = getCurrentUserId(); |
| | | throw exception(TRANSFER_APPLICATION_APPLICANT_NOT_EXISTS); |
| | | } |
| | | // 5. 插入 |
| | | // 2. 原部门 / 原岗位未传时,按调岗人员的用户档案兜底 |
| | | Long currentDeptId = createReqVO.getCurrentDeptId() != null ? createReqVO.getCurrentDeptId() : user.getDeptId(); |
| | | Long currentPostId = createReqVO.getCurrentPostId(); |
| | | if (currentPostId == null && CollUtil.isNotEmpty(user.getPostIds())) { |
| | | currentPostId = user.getPostIds().iterator().next(); |
| | | } |
| | | if (currentDeptId == null) { |
| | | throw exception(TRANSFER_APPLICATION_APPLICANT_NO_DEPT, user.getNickname()); |
| | | } |
| | | if (currentPostId == null) { |
| | | throw exception(TRANSFER_APPLICATION_APPLICANT_NO_POST, user.getNickname()); |
| | | } |
| | | // 3. 校验目标部门与原部门不能相同 |
| | | if (Objects.equals(createReqVO.getTargetDeptId(), currentDeptId)) { |
| | | throw exception(TRANSFER_APPLICATION_SAME_DEPT); |
| | | } |
| | | // 4. 校验目标岗位与原岗位不能相同 |
| | | if (Objects.equals(createReqVO.getTargetPostId(), currentPostId)) { |
| | | throw exception(TRANSFER_APPLICATION_SAME_POST); |
| | | } |
| | | // 5. 生成申请单号 |
| | | String no = generateUniqueNo(); |
| | | // 6. 插入 |
| | | HrmTransferApplicationDO application = BeanUtils.toBean(createReqVO, HrmTransferApplicationDO.class); |
| | | application.setNo(no); |
| | | application.setUserId(userId); |
| | | application.setCurrentDeptId(currentDeptId); |
| | | application.setCurrentPostId(currentPostId); |
| | | application.setStatus(HrmAuditStatusEnum.DRAFT.getStatus()); |
| | | transferApplicationMapper.insert(application); |
| | | storageAttachmentApi.bindAttachments("file", "hrm_transfer_application", |
| | | application.getId(), createReqVO.getBlobIds()); |
| | | return application.getId(); |
| | | } |
| | | |
| | | private Long getCurrentUserId() { |
| | | return 1L; |
| | | return SecurityFrameworkUtils.getLoginUserId(); |
| | | } |
| | | |
| | | private String generateUniqueNo() { |
| | |
| | | } |
| | | HrmTransferApplicationDO updateObj = BeanUtils.toBean(updateReqVO, HrmTransferApplicationDO.class); |
| | | transferApplicationMapper.updateById(updateObj); |
| | | storageAttachmentApi.updateAttachments("file", "hrm_transfer_application", updateReqVO.getId(), updateReqVO.getBlobIds()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (!Objects.equals(application.getStatus(), HrmAuditStatusEnum.DRAFT.getStatus())) { |
| | | throw exception(TRANSFER_APPLICATION_UPDATE_FAIL_NOT_DRAFT); |
| | | } |
| | | storageAttachmentApi.deleteAttachmentsByRecord("hrm_transfer_application", id); |
| | | transferApplicationMapper.deleteById(id); |
| | | } |
| | | |
| | |
| | | fillPostNames(respVO, application); |
| | | respVO.setTransferTypeName(HrmTransferTypeEnum.getNameByStatus(application.getTransferType())); |
| | | respVO.setStatusName(HrmAuditStatusEnum.getNameByStatus(application.getStatus())); |
| | | respVO.setAttachmentList(storageAttachmentApi.listAttachments("hrm_transfer_application", id)); |
| | | return respVO; |
| | | } |
| | | |