| | |
| | | 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; |
| | |
| | | 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 实现类 |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | 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())) { |
| | |
| | | fullPathDeptIdMap.put(myFullPath, newDept.getId()); |
| | | } |
| | | |
| | | // 记录导入结果汇总,供 @LogRecord 的 success 文案引用 |
| | | OperateLogUtils.putImportSummary(respVO.getCreateDeptNames(), respVO.getUpdateDeptNames(), |
| | | respVO.getFailureDeptNames()); |
| | | return respVO; |
| | | } |
| | | |