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-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java |   85 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 1 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
index dabb8db..1fcd864 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemTypeServiceImpl.java
@@ -2,14 +2,19 @@
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils;
 import cn.iocoder.yudao.module.mdm.api.category.MdmItemCategoryApi;
 import cn.iocoder.yudao.module.mdm.api.category.dto.MdmItemCategoryRespDTO;
+import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportExcelVO;
+import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeImportRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeListReqVO;
 import cn.iocoder.yudao.module.mes.controller.admin.md.item.vo.type.MesMdItemTypeSaveReqVO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemTypeDO;
 import cn.iocoder.yudao.module.mes.dal.mysql.md.item.MesMdItemTypeMapper;
+import com.mzt.logapi.starter.annotation.LogRecord;
 import jakarta.annotation.Resource;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -19,6 +24,7 @@
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
+import static cn.iocoder.yudao.module.mes.enums.LogRecordConstants.*;
 
 /**
  * MES 鐗╂枡浜у搧鍒嗙被 Service 瀹炵幇绫�
@@ -26,7 +32,7 @@
  * 鍏煎灞傚疄鐜帮細鏁版嵁瀛樺偍鍦� mes_md_item_type 琛紝浣嗕紭鍏堜粠 MDM 鍒嗙被 API 鑾峰彇
  * 瀹為檯鍒嗙被鏁版嵁宸茶縼绉诲埌 mdm_item_category 琛�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -230,4 +236,81 @@
         return mesDO;
     }
 
+    @Override
+    @org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
+    @LogRecord(type = MES_MD_ITEM_TYPE_TYPE, subType = MES_MD_ITEM_TYPE_IMPORT_SUB_TYPE, bizNo = "0",
+            success = MES_MD_ITEM_TYPE_IMPORT_SUCCESS)
+    public MesMdItemTypeImportRespVO importItemTypeList(List<MesMdItemTypeImportExcelVO> importList, Boolean isUpdateSupport) {
+        if (CollUtil.isEmpty(importList)) {
+            throw exception(MD_ITEM_TYPE_IMPORT_LIST_IS_EMPTY);
+        }
+        MesMdItemTypeImportRespVO respVO = MesMdItemTypeImportRespVO.builder()
+                .createList(new ArrayList<>()).updateList(new ArrayList<>())
+                .failureList(new LinkedHashMap<>()).build();
+
+        // 1. 寤虹珛缂栫爜 -> ID 鏄犲皠锛堢幇鏈夊垎绫� + 鏈鏂板缓鍒嗙被锛夛紝鐢ㄤ簬瑙f瀽"鐖跺垎绫荤紪鐮�"鍒�
+        Map<String, Long> codeIdMap = new HashMap<>();
+        for (MesMdItemTypeDO itemType : itemTypeMapper.selectList()) {
+            codeIdMap.put(itemType.getCode(), itemType.getId());
+        }
+        Map<String, Long> importedCodeIdMap = new HashMap<>();
+
+        // 2. 閬嶅巻瀵煎叆
+        for (MesMdItemTypeImportExcelVO importVO : importList) {
+            // 2.1 鍩虹鏍¢獙
+            if (StrUtil.isBlank(importVO.getCode()) || StrUtil.isBlank(importVO.getName())) {
+                respVO.getFailureList().put(StrUtil.blankToDefault(importVO.getName(), importVO.getCode()), "鍒嗙被缂栫爜鍜屽垎绫诲悕绉颁笉鑳戒负绌�");
+                continue;
+            }
+            // 2.2 瑙f瀽鐖跺垎绫� ID
+            Long parentId = MesMdItemTypeDO.PARENT_ID_ROOT;
+            if (StrUtil.isNotBlank(importVO.getParentCode())) {
+                Long pid = importedCodeIdMap.get(importVO.getParentCode()) != null
+                        ? importedCodeIdMap.get(importVO.getParentCode())
+                        : codeIdMap.get(importVO.getParentCode());
+                if (pid == null) {
+                    respVO.getFailureList().put(importVO.getName(), "鐖跺垎绫荤紪鐮佷笉瀛樺湪锛�" + importVO.getParentCode());
+                    continue;
+                }
+                parentId = pid;
+            }
+
+            // 2.3 宸插瓨鍦紙鎸夌紪鐮佸垽鏂級
+            MesMdItemTypeDO existByCode = itemTypeMapper.selectByCode(importVO.getCode());
+            if (existByCode != null) {
+                if (!Boolean.TRUE.equals(isUpdateSupport)) {
+                    respVO.getFailureList().put(importVO.getName(), "鍒嗙被缂栫爜宸插瓨鍦�");
+                    continue;
+                }
+                MesMdItemTypeDO updateObj = BeanUtils.toBean(importVO, MesMdItemTypeDO.class);
+                updateObj.setId(existByCode.getId());
+                updateObj.setParentId(parentId);
+                itemTypeMapper.updateById(updateObj);
+                respVO.getUpdateList().add(importVO.getName());
+            } else {
+                // 2.4 鏍¢獙鍚屼竴鐖跺垎绫讳笅鍚嶇О鍞竴
+                MesMdItemTypeDO existByName = itemTypeMapper.selectByParentIdAndName(parentId, importVO.getName());
+                if (existByName != null) {
+                    respVO.getFailureList().put(importVO.getName(), "鍚屼竴鐖跺垎绫讳笅宸插瓨鍦ㄨ鍚嶇О鐨勫垎绫�");
+                    continue;
+                }
+                // 2.5 鏍¢獙鍚屼竴鐖跺垎绫讳笅缂栫爜鍞竴
+                MesMdItemTypeDO existByParentCode = itemTypeMapper.selectByParentIdAndCode(parentId, importVO.getCode());
+                if (existByParentCode != null) {
+                    respVO.getFailureList().put(importVO.getName(), "鍚屼竴鐖跺垎绫讳笅宸插瓨鍦ㄨ缂栫爜鐨勫垎绫�");
+                    continue;
+                }
+                // 2.6 鏂板
+                MesMdItemTypeDO newObj = BeanUtils.toBean(importVO, MesMdItemTypeDO.class);
+                newObj.setParentId(parentId);
+                itemTypeMapper.insert(newObj);
+                respVO.getCreateList().add(importVO.getName());
+                importedCodeIdMap.put(importVO.getCode(), newObj.getId());
+            }
+        }
+        // 璁板綍瀵煎叆缁撴灉姹囨�伙紝渚� @LogRecord 鐨� success 鏂囨寮曠敤
+        OperateLogUtils.putImportSummary(respVO.getCreateList(), respVO.getUpdateList(), respVO.getFailureList());
+        return respVO;
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3