gaoluyang
2 天以前 093fc57beccecbf8d5d51d45edb3ae484e8f8ffd
fix(hrm/transfer): 调岗申请按所选员工创建并补齐校验提示

- 创建调岗申请优先使用请求中的 userId,未传时回退当前登录用户(原先固定默认为 1 号用户)
- 所选员工未绑定有效账号、未设置部门、未设置岗位时分别返回精确错误提示与处理指引
- 新增错误码 1_030_002_008 / 009 / 010

Co-Authored-By: Claude Code <noreply@anthropic.com>
已修改2个文件
36 ■■■■■ 文件已修改
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 33 ●●●●● 补丁 | 查看 | 原始文档 | 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_DEPT_EMPTY = new ErrorCode(1_030_002_009, "调岗申请失败:所选员工未设置部门");
    ErrorCode TRANSFER_APPLICATION_APPLICANT_POST_EMPTY = 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
@@ -2,8 +2,10 @@
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;
@@ -85,18 +87,25 @@
        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);
@@ -107,8 +116,8 @@
        return application.getId();
    }
    private Long getCurrentUserId() {
        return 1L;
    private Long getLoginUserId() {
        return SecurityFrameworkUtils.getLoginUserId();
    }
    private String generateUniqueNo() {