| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | 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.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 |
| | |
| | | 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(); |
| | | } |
| | | AdminUserRespDTO user = adminUserApi.getUser(userId); |
| | | // 3. 确定被调岗员工(未指定时默认当前登录用户) |
| | | Long userId = createReqVO.getUserId() != null ? createReqVO.getUserId() : getLoginUserId(); |
| | | AdminUserRespDTO user = userId != null ? adminUserApi.getUser(userId) : null; |
| | | if (user == null) { |
| | | userId = getCurrentUserId(); |
| | | throw new ServiceException(TRANSFER_APPLICATION_APPLICANT_NOT_EXISTS.getCode(), |
| | | String.format("调岗申请失败:所选员工未关联有效的系统账号(用户编号 %s)。请到「员工管理」确认该员工已绑定账号且账号未停用后重新选择。", userId)); |
| | | } |
| | | // 5. 插入 |
| | | // 4. 校验原部门、原岗位(表字段非空;员工档案缺失时给出可执行提示,避免直接抛数据库异常) |
| | | if (createReqVO.getCurrentDeptId() == null) { |
| | | throw new ServiceException(TRANSFER_APPLICATION_APPLICANT_DEPT_EMPTY.getCode(), |
| | | String.format("调岗申请失败:员工[%s]未设置部门,无法确定原部门。请先到「员工管理」编辑该员工档案补全部门,再重新发起调岗申请。", user.getNickname())); |
| | | } |
| | | if (createReqVO.getCurrentPostId() == null) { |
| | | throw new ServiceException(TRANSFER_APPLICATION_APPLICANT_POST_EMPTY.getCode(), |
| | | String.format("调岗申请失败:员工[%s]未设置岗位,无法确定原岗位。请先到「员工管理」编辑该员工档案补全岗位,再重新发起调岗申请。", user.getNickname())); |
| | | } |
| | | // 5. 生成申请单号 |
| | | String no = generateUniqueNo(); |
| | | // 6. 插入 |
| | | HrmTransferApplicationDO application = BeanUtils.toBean(createReqVO, HrmTransferApplicationDO.class); |
| | | application.setNo(no); |
| | | application.setUserId(userId); |
| | | 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; |
| | | private Long getLoginUserId() { |
| | | 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; |
| | | } |
| | | |
| | |
| | | if (ObjUtil.notEqual(application.getStatus(), HrmAuditStatusEnum.DRAFT.getStatus())) { |
| | | throw exception(TRANSFER_APPLICATION_SUBMIT_FAIL_NOT_DRAFT); |
| | | } |
| | | // 全局免审批:业务校验通过后直接执行审批通过逻辑,无需流程模型。 |
| | | if (bpmProcessInstanceApi.isGlobalAutoApprove()) { |
| | | transferApplicationMapper.updateById(HrmTransferApplicationDO.builder() |
| | | .id(id) |
| | | .processInstanceId("") |
| | | .status(HrmAuditStatusEnum.PROCESS.getStatus()) |
| | | .build()); |
| | | updateTransferApplicationAuditStatus(id, HrmAuditStatusEnum.APPROVE.getStatus()); |
| | | return; |
| | | } |
| | | |
| | | validateApproveCategoryAndProcessDefinition(); |
| | | ProcessDefinition processDefinition = bpmProcessDefinitionService.getActiveProcessDefinition(processDefinitionKey); |
| | | if (processDefinition == null) { |