From 093fc57beccecbf8d5d51d45edb3ae484e8f8ffd Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 06 十一月 2026 16:32:52 +0800
Subject: [PATCH] fix(hrm/transfer): 调岗申请按所选员工创建并补齐校验提示

---
 yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/HrmTransferApplicationServiceImpl.java |   54 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 41 insertions(+), 13 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 d63e58a..9482aed 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
@@ -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;
@@ -19,6 +21,7 @@
 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;
@@ -47,7 +50,7 @@
 /**
  * 璋冨矖鐢宠 Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -69,6 +72,8 @@
     @Resource
     private BpmCategoryService bpmCategoryService;
     @Resource
+    private StorageAttachmentApi storageAttachmentApi;
+    @Resource
     private BpmProcessDefinitionService bpmProcessDefinitionService;
 
     @Override
@@ -82,28 +87,37 @@
         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]鏈缃儴闂紝鏃犳硶纭畾鍘熼儴闂ㄣ�傝鍏堝埌銆屽憳宸ョ鐞嗐�嶇紪杈戣鍛樺伐妗f琛ュ叏閮ㄩ棬锛屽啀閲嶆柊鍙戣捣璋冨矖鐢宠銆�", user.getNickname()));
+        }
+        if (createReqVO.getCurrentPostId() == null) {
+            throw new ServiceException(TRANSFER_APPLICATION_APPLICANT_POST_EMPTY.getCode(),
+                    String.format("璋冨矖鐢宠澶辫触锛氬憳宸%s]鏈缃矖浣嶏紝鏃犳硶纭畾鍘熷矖浣嶃�傝鍏堝埌銆屽憳宸ョ鐞嗐�嶇紪杈戣鍛樺伐妗f琛ュ叏宀椾綅锛屽啀閲嶆柊鍙戣捣璋冨矖鐢宠銆�", 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() {
@@ -129,6 +143,7 @@
         }
         HrmTransferApplicationDO updateObj = BeanUtils.toBean(updateReqVO, HrmTransferApplicationDO.class);
         transferApplicationMapper.updateById(updateObj);
+        storageAttachmentApi.updateAttachments("file", "hrm_transfer_application", updateReqVO.getId(), updateReqVO.getBlobIds());
     }
 
     @Override
@@ -137,6 +152,7 @@
         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);
     }
 
@@ -170,6 +186,7 @@
         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;
     }
 
@@ -249,6 +266,17 @@
         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) {

--
Gitblit v1.9.3