From 7591ba21194595cc8d9a1293dfdbfa945bc9948f Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期一, 17 八月 2026 16:36:54 +0800
Subject: [PATCH] Merge branch 'dev_business' of http://114.132.189.42:9002/r/mom-pro2-after into dev_business
---
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 55 insertions(+), 1 deletions(-)
diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
index c90308a..79afd74 100644
--- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
+++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
@@ -16,6 +16,12 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportExcelVO;
+import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostImportRespVO;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
@@ -24,7 +30,7 @@
/**
* 宀椾綅 Service 瀹炵幇绫�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
@@ -155,4 +161,52 @@
}
});
}
+
+ @Override
+ public PostImportRespVO importPostList(List<PostImportExcelVO> importPosts, boolean isUpdateSupport) {
+ if (CollUtil.isEmpty(importPosts)) {
+ throw exception(POST_IMPORT_LIST_IS_EMPTY);
+ }
+ PostImportRespVO respVO = PostImportRespVO.builder().createPostNames(new ArrayList<>())
+ .updatePostNames(new ArrayList<>()).failurePostNames(new LinkedHashMap<>()).build();
+ importPosts.forEach(importPost -> {
+ // 鏍¢獙锛屽垽鏂槸鍚︽湁涓嶇鍚堢殑鍘熷洜
+ try {
+ validatePostForCreateOrUpdate(null, importPost.getName(), importPost.getCode());
+ } catch (ServiceException ex) {
+ // 濡傛灉鏄噸澶嶅紓甯革紝鑰屼笖鏀寔鏇存柊
+ if (isUpdateSupport && (POST_NAME_DUPLICATE.getCode().equals(ex.getCode()) || POST_CODE_DUPLICATE.getCode().equals(ex.getCode()))) {
+ // ignore
+ } else {
+ respVO.getFailurePostNames().put(importPost.getName(), ex.getMessage());
+ return;
+ }
+ }
+
+ // 鍒ゆ柇濡傛灉瀛樺湪锛屽湪杩涜鏇存柊
+ PostDO existPost = postMapper.selectByName(importPost.getName());
+ if (existPost == null) {
+ existPost = postMapper.selectByCode(importPost.getCode());
+ }
+ if (existPost == null) {
+ PostDO post = BeanUtils.toBean(importPost, PostDO.class);
+ postMapper.insert(post);
+ respVO.getCreatePostNames().add(importPost.getName());
+ return;
+ }
+
+ // 濡傛灉瀛樺湪锛屽垽鏂槸鍚﹀厑璁告洿鏂�
+ if (!isUpdateSupport) {
+ respVO.getFailurePostNames().put(importPost.getName(), "宀椾綅鍚嶆垨缂栫爜宸茬粡瀛樺湪");
+ return;
+ }
+
+ // 鏇存柊宀椾綅
+ PostDO updatePost = BeanUtils.toBean(importPost, PostDO.class);
+ updatePost.setId(existPost.getId());
+ postMapper.updateById(updatePost);
+ respVO.getUpdatePostNames().add(importPost.getName());
+ });
+ return respVO;
+ }
}
--
Gitblit v1.9.3