| | |
| | | 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; |
| | |
| | | @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", |
| | |
| | | } |
| | | |
| | | private Long getCurrentUserId() { |
| | | return 1L; |
| | | return SecurityFrameworkUtils.getLoginUserId(); |
| | | } |
| | | |
| | | private String generateUniqueNo() { |