From 962f78c8383e7c884ddb08c951c15e5ba6eb4cb8 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期五, 23 十月 2026 15:43:33 +0800
Subject: [PATCH] fix: 完善审批流程与业务状态校验

---
 yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryServiceImpl.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryServiceImpl.java b/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryServiceImpl.java
index da7fea1..3a5025b 100644
--- a/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryServiceImpl.java
+++ b/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmCategoryServiceImpl.java
@@ -2,8 +2,13 @@
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
+import cn.hutool.core.util.StrUtil;
+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.module.bpm.controller.admin.definition.vo.category.BpmCategoryImportExcelVO;
+import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryImportReqVO;
+import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryImportRespVO;
 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryPageReqVO;
 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategorySaveReqVO;
 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
@@ -13,13 +18,16 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
 import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
 
 /**
@@ -137,4 +145,55 @@
         bpmCategoryMapper.updateBatch(updateList);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public BpmCategoryImportRespVO importCategoryList(List<BpmCategoryImportExcelVO> importCategories,
+                                                      BpmCategoryImportReqVO importReqVO) {
+        // 1. 鏍¢獙闈炵┖
+        importCategories = filterList(importCategories, item -> StrUtil.isNotBlank(item.getName()));
+        if (CollUtil.isEmpty(importCategories)) {
+            throw exception(CATEGORY_IMPORT_LIST_IS_EMPTY);
+        }
+        // 2. 閫愭潯澶勭悊
+        BpmCategoryImportRespVO respVO = BpmCategoryImportRespVO.builder()
+                .createCategoryNames(new ArrayList<>())
+                .updateCategoryNames(new ArrayList<>())
+                .failureCategoryNames(new LinkedHashMap<>())
+                .build();
+        importCategories.forEach(importCategory -> {
+            try {
+                // 2.1 鏍¢獙鍞竴锛氬悕瀛椾笌鏍囧織鍒嗗埆鍖归厤锛岃嫢鎾炲埌涓嶅悓璁板綍鍒欐姤閿�
+                BpmCategoryDO byName = bpmCategoryMapper.selectByName(importCategory.getName());
+                BpmCategoryDO byCode = bpmCategoryMapper.selectByCode(importCategory.getCode());
+                BpmCategoryDO existCategory = byCode != null ? byCode : byName;
+                if (byName != null && !byName.getId().equals(existCategory.getId())) {
+                    throw exception(CATEGORY_NAME_DUPLICATE, importCategory.getName());
+                }
+                if (byCode != null && !byCode.getId().equals(existCategory.getId())) {
+                    throw exception(CATEGORY_CODE_DUPLICATE, importCategory.getCode());
+                }
+                // 2.2 鍒ゆ柇鏄惁瀛樺湪
+                if (existCategory == null) {
+                    BpmCategoryDO category = BeanUtils.toBean(importCategory, BpmCategoryDO.class);
+                    bpmCategoryMapper.insert(category);
+                    respVO.getCreateCategoryNames().add(importCategory.getName());
+                    return;
+                }
+                // 2.3 宸插瓨鍦紝鍒ゆ柇鏄惁鍏佽鏇存柊
+                if (!importReqVO.getUpdateSupport()) {
+                    respVO.getFailureCategoryNames().put(importCategory.getName(),
+                            StrUtil.format(CATEGORY_IMPORT_EXISTS.getMsg(), importCategory.getName()));
+                    return;
+                }
+                BpmCategoryDO updateCategory = BeanUtils.toBean(importCategory, BpmCategoryDO.class)
+                        .setId(existCategory.getId());
+                bpmCategoryMapper.updateById(updateCategory);
+                respVO.getUpdateCategoryNames().add(importCategory.getName());
+            } catch (ServiceException ex) {
+                respVO.getFailureCategoryNames().put(importCategory.getName(), ex.getMessage());
+            }
+        });
+        return respVO;
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3