gaoluyang
3 天以前 0f4aa5957957d9124e88da4490fac60da5324058
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java
@@ -14,7 +14,9 @@
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils;
import com.google.common.annotations.VisibleForTesting;
import com.mzt.logapi.starter.annotation.LogRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@@ -27,6 +29,7 @@
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.system.enums.LogRecordConstants.*;
/**
 * 部门 Service 实现类
@@ -240,6 +243,8 @@
    }
    @Override
    @LogRecord(type = SYSTEM_DEPT_TYPE, subType = SYSTEM_DEPT_IMPORT_SUB_TYPE, bizNo = "0",
            success = SYSTEM_DEPT_IMPORT_SUCCESS)
    public DeptImportRespVO importDeptList(List<DeptImportExcelVO> importDepts, boolean isUpdateSupport) {
        if (CollUtil.isEmpty(importDepts)) {
            throw exception(DEPT_IMPORT_LIST_IS_EMPTY);
@@ -259,7 +264,24 @@
        importDepts.sort(Comparator.comparingInt(dept -> StrUtil.isEmpty(dept.getParentPath()) ? 0 : dept.getParentPath().split("/").length));
        // 3. 遍历导入
        for (DeptImportExcelVO importDept : importDepts) {
        for (int i = 0; i < importDepts.size(); i++) {
            DeptImportExcelVO importDept = importDepts.get(i);
            // 3.0 校验必填项:名称为空会生成 null 的 Map key,导致响应序列化失败;
            // 顺序、状态为空会触发数据库非空约束,直接抛系统异常
            String rowLabel = StrUtil.blankToDefault(importDept.getName(), "第 " + (i + 1) + " 条记录");
            if (StrUtil.isBlank(importDept.getName())) {
                respVO.getFailureDeptNames().put(rowLabel, "部门名称不能为空,请补全 Excel 的「部门名称」列后重新导入");
                continue;
            }
            if (importDept.getSort() == null) {
                respVO.getFailureDeptNames().put(rowLabel, "显示顺序不能为空,请补全 Excel 的「显示顺序」列后重新导入");
                continue;
            }
            if (importDept.getStatus() == null) {
                respVO.getFailureDeptNames().put(rowLabel, "状态未填写或不是「开启/关闭」,请填写 Excel 的「状态」列后重新导入");
                continue;
            }
            // 3.1 获取父部门 ID
            Long parentId = DeptDO.PARENT_ID_ROOT;
            if (StrUtil.isNotEmpty(importDept.getParentPath())) {
@@ -302,6 +324,9 @@
            fullPathDeptIdMap.put(myFullPath, newDept.getId());
        }
        // 记录导入结果汇总,供 @LogRecord 的 success 文案引用
        OperateLogUtils.putImportSummary(respVO.getCreateDeptNames(), respVO.getUpdateDeptNames(),
                respVO.getFailureDeptNames());
        return respVO;
    }