| | |
| | | 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())) { |