gaoluyang
2 天以前 81f52ac9801dfa11ce419f4930364d6b7e960749
fix(hrm): 调岗申请改为按被调岗人员生成,原部门/原岗位自动兜底

- 新增调岗申请时 currentDeptId/currentPostId 为空按所选人员的用户档案兜底,
不再因 NOT NULL 列插入失败;同时补明确提示(人员不存在 / 未设部门 / 未设岗位)
- 申请人默认取当前登录用户,修正 getCurrentUserId 写死返回 1

Co-Authored-By: Claude Code <noreply@anthropic.com>
已修改2个文件
51 ■■■■■ 文件已修改
yudao-module-hrm-api/src/main/java/cn/iocoder/yudao/module/hrm/enums/ErrorCodeConstants.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/HrmTransferApplicationServiceImpl.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-hrm-api/src/main/java/cn/iocoder/yudao/module/hrm/enums/ErrorCodeConstants.java
@@ -50,6 +50,9 @@
    ErrorCode TRANSFER_APPLICATION_SAME_DEPT = new ErrorCode(1_030_002_005, "调岗失败,原因:目标部门与原部门相同");
    ErrorCode TRANSFER_APPLICATION_SAME_POST = new ErrorCode(1_030_002_006, "调岗失败,原因:目标岗位与原岗位相同");
    ErrorCode TRANSFER_APPLICATION_BPM_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1_030_002_007, "调岗审批流程不存在");
    ErrorCode TRANSFER_APPLICATION_APPLICANT_NOT_EXISTS = new ErrorCode(1_030_002_008, "所选调岗人员不存在或已被删除,请重新选择调岗人员");
    ErrorCode TRANSFER_APPLICATION_APPLICANT_NO_DEPT = new ErrorCode(1_030_002_009, "所选调岗人员「{}」未设置所属部门,无法生成调岗申请,请先在「系统管理-用户管理」中为其设置部门后再试");
    ErrorCode TRANSFER_APPLICATION_APPLICANT_NO_POST = new ErrorCode(1_030_002_010, "所选调岗人员「{}」未设置岗位,无法生成调岗申请,请先在「系统管理-用户管理」中为其设置岗位后再试");
    // ========== 离职申请 1-030-003-000 ==========
    ErrorCode RESIGNATION_APPLICATION_NOT_EXISTS = new ErrorCode(1_030_003_000, "离职申请不存在");
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/HrmTransferApplicationServiceImpl.java
@@ -4,6 +4,7 @@
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;
@@ -77,29 +78,40 @@
    @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",
@@ -108,7 +120,7 @@
    }
    private Long getCurrentUserId() {
        return 1L;
        return SecurityFrameworkUtils.getLoginUserId();
    }
    private String generateUniqueNo() {