From feedd62ec46b9faada80505387526acf914cf4c5 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期日, 11 十月 2026 22:49:44 +0800
Subject: [PATCH] 海西州-同仁堂 1.添加操作日志生成

---
 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java |   62 +++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 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 36aeaec..04ae90f 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,10 +16,19 @@
 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.framework.operatelog.core.util.OperateLogUtils;
+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 com.mzt.logapi.starter.annotation.LogRecord;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
 import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
+import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*;
 
 /**
  * 宀椾綅 Service 瀹炵幇绫�
@@ -155,4 +164,57 @@
             }
         });
     }
+
+    @Override
+    @LogRecord(type = SYSTEM_POST_TYPE, subType = SYSTEM_POST_IMPORT_SUB_TYPE, bizNo = "0",
+            success = SYSTEM_POST_IMPORT_SUCCESS)
+    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());
+        });
+        // 璁板綍瀵煎叆缁撴灉姹囨�伙紝渚� @LogRecord 鐨� success 鏂囨寮曠敤
+        OperateLogUtils.putImportSummary(respVO.getCreatePostNames(), respVO.getUpdatePostNames(),
+                respVO.getFailurePostNames());
+        return respVO;
+    }
 }

--
Gitblit v1.9.3