From 1ad49b6271bae8a74a3b3105a34e4c498fdb0eb4 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 06 十一月 2026 15:58:03 +0800
Subject: [PATCH] fix(hrm): 调岗申请改为按被调岗人员生成,原部门/原岗位自动兜底

---
 yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/HrmTransferApplicationServiceImpl.java |   48 ++++++++++++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/HrmTransferApplicationServiceImpl.java b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/HrmTransferApplicationServiceImpl.java
index c3272ee..9747b08 100644
--- a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/HrmTransferApplicationServiceImpl.java
+++ b/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() {

--
Gitblit v1.9.3