修改导入
parent
9e1709242c
commit
e7089aebb2
|
|
@ -46,7 +46,7 @@ public class FireDeviceController {
|
|||
|
||||
@ApiOperation("消防器材分页")
|
||||
@PostMapping("/list")
|
||||
@PreAuthorize("@pms.hasAnyPermission('xfqcgl')")
|
||||
// @PreAuthorize("@pms.hasAnyPermission('xfqcgl')")
|
||||
public PageResponse<FireDeviceCO> page(@RequestBody FireDevicePageQry qry) {
|
||||
return fireDeviceService.listPage(qry);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,6 +180,9 @@ public class FireCheckRecordQueryExe {
|
|||
Map<String, Object> params = PageQueryHelper.toHashMap(qry);
|
||||
PageResponse<FireCheckRecordDO> pageResponse = fireCheckRecordRepository.getCheckRecordPageH5(params);
|
||||
List<FireCheckRecordCO> examCenterCOS = fireCheckRecordCoConvertor.converDOsToCOs(pageResponse.getData());
|
||||
if(CollUtil.isEmpty(examCenterCOS)){
|
||||
return PageResponse.of(null, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
|
||||
}
|
||||
//组装点位名称 和区域名称
|
||||
List<String> fireCheckRecordIdList = examCenterCOS.stream().map(FireCheckRecordCO::getFireRecordId).collect(Collectors.toList());
|
||||
List<FireCheckRecordPointDO> fireCheckRecordPointDOList =fireCheckRecordPointRepository.getCheckRecordPointListByCheckRecordIds(fireCheckRecordIdList);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alibaba.cola.exception.BizException;
|
|||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
||||
import com.jjb.saas.framework.domain.model.BaseE;
|
||||
import com.zcloud.fire.check.domain.enums.FireDeviceTypeEnum;
|
||||
import com.zcloud.fire.check.domain.utils.DepartmentPathUtil;
|
||||
import com.zcloud.gbscommon.excelEntity.*;
|
||||
import com.zcloud.gbscommon.utils.ExcelUtils;
|
||||
import com.zcloud.gbscommon.utils.Tools;
|
||||
|
|
@ -112,7 +113,9 @@ public class FireDeviceE extends BaseE {
|
|||
throw new BizException("该企业不存在部门信息,请添加部门后重新导入");
|
||||
}
|
||||
|
||||
Map<String, DepartmentE> departmentEMap = departmentEList.stream().collect(Collectors.toMap(DepartmentE::getName, DepartmentE -> DepartmentE));
|
||||
// Map<String, DepartmentE> departmentEMap = departmentEList.stream().collect(Collectors.toMap(DepartmentE::getName, DepartmentE -> DepartmentE));
|
||||
Map<String, DepartmentE> departmentEMap = DepartmentPathUtil.buildDepartmentPathMap(departmentEList);
|
||||
|
||||
Map<String, FireDeviceE> fireDeviceEMap = fireDeviceEList.stream().collect(Collectors.toMap(FireDeviceE::getFireDeviceCode, FireDeviceE -> FireDeviceE));
|
||||
Map<String, FireRegionE> fireRegionEMap = fireRegionEList.stream().collect(Collectors.toMap(FireRegionE::getFireRegionCode, FireRegionE -> FireRegionE));
|
||||
Map<String, FirePointE> firePointEMap = firePointEList.stream().collect(Collectors.toMap(FirePointE::getFirePointCode, FirePointE -> FirePointE));
|
||||
|
|
@ -163,36 +166,53 @@ public class FireDeviceE extends BaseE {
|
|||
continue;
|
||||
}
|
||||
|
||||
|
||||
// 部门和负责人校验
|
||||
if (StringUtils.isEmpty(entity.getDepartmentName())) {
|
||||
errList.add("第" + (i + 2) + "行责任部门不能为空。");
|
||||
continue;
|
||||
if(StringUtils.isEmpty(entity.getDepartmentName1()) &&
|
||||
StringUtils.isEmpty(entity.getDepartmentName2()) &&
|
||||
StringUtils.isEmpty(entity.getDepartmentName3()) &&
|
||||
StringUtils.isEmpty(entity.getDepartmentName4()) &&
|
||||
StringUtils.isEmpty(entity.getDepartmentName5())){
|
||||
errList.add("第" + (i+3) + "行责任部门不能全部为空。");
|
||||
}else{
|
||||
DepartmentE department = departmentEMap.get(entity.getDepartmentName());
|
||||
String departmentName = entity.getDepartmentName1();
|
||||
if(StringUtils.isNotEmpty(entity.getDepartmentName2())){
|
||||
departmentName += "=" + entity.getDepartmentName2();
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getDepartmentName3())){
|
||||
departmentName += "=" + entity.getDepartmentName3();
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getDepartmentName4())){
|
||||
departmentName += "=" + entity.getDepartmentName4();
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getDepartmentName5())){
|
||||
departmentName += "=" + entity.getDepartmentName5();
|
||||
}
|
||||
|
||||
DepartmentE department = departmentEMap.get(departmentName);
|
||||
if (department == null) {
|
||||
errList.add("第" + (i + 2) + "行:未找到名称为“" + entity.getDepartmentName() + "”的责任部门。");
|
||||
errList.add("第" + (i + 2) + "行:未找到名称为“" + departmentName + "”的责任部门。");
|
||||
continue;
|
||||
} else {
|
||||
fireDeviceE.setDepartmentId(department.getId());
|
||||
// 负责人校验
|
||||
if (StringUtils.isEmpty(entity.getUserName())) {
|
||||
errList.add("第" + (i + 2) + "行负责人不能为空。");
|
||||
if (StringUtils.isEmpty(entity.getUserPhone())) {
|
||||
errList.add("第" + (i + 2) + "行负责人手机号不能为空。");
|
||||
continue;
|
||||
} else {
|
||||
UserE user = userEMapByPhone.get(entity.getUserPhone());
|
||||
List<UserE> usersInDept = userEMap.get(department.getId());
|
||||
if (user == null) {
|
||||
errList.add("第" + (i + 2) + "行:未找到名称为“" + entity.getUserName() + "”的负责人。");
|
||||
errList.add("第" + (i + 2) + "行:未找到名称为“" + entity.getUserPhone() + "”的负责人手机号");
|
||||
continue;
|
||||
} else if (usersInDept == null || !usersInDept.contains(user)) {
|
||||
errList.add("第" + (i + 2) + "行:部门“" + entity.getDepartmentName() + "”下未找到负责人“" + entity.getUserName() + "”。");
|
||||
errList.add("第" + (i + 2) + "行:部门“" + departmentName + "”下未找到负责人“" + departmentName + "”。");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 时间校验
|
||||
|
||||
/* // 时间校验
|
||||
if (StringUtils.isNotEmpty(entity.getValidityStartTime())) {
|
||||
try {
|
||||
// 定义输入格式
|
||||
|
|
@ -216,7 +236,7 @@ public class FireDeviceE extends BaseE {
|
|||
errList.add("第" + (i + 2) + "行有效期结束时间格式错误");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// 验证器材类型
|
||||
if (StringUtils.isEmpty(entity.getFireDeviceTypeName())) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,161 @@
|
|||
package com.zcloud.fire.check.domain.utils;
|
||||
|
||||
|
||||
import com.zcloud.fire.check.domain.model.DepartmentE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author SondonYong
|
||||
* @description
|
||||
* @date 2025/12/12/周五 15:29
|
||||
*/
|
||||
public class DepartmentPathUtil {
|
||||
|
||||
/**
|
||||
* 构建部门路径映射
|
||||
* @param departmentList 部门列表
|
||||
* @return Map<部门路径, 部门对象>
|
||||
*/
|
||||
public static Map<String, DepartmentE> buildDepartmentPathMap(List<DepartmentE> departmentList) {
|
||||
if (departmentList == null || departmentList.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
// 创建id到部门的映射
|
||||
Map<Long, DepartmentE> idToDepartmentMap = departmentList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
DepartmentE::getId,
|
||||
dept -> dept,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
// 创建结果映射
|
||||
Map<String, DepartmentE> result = new HashMap<>();
|
||||
|
||||
for (DepartmentE department : departmentList) {
|
||||
String path = buildDepartmentPath(department, idToDepartmentMap);
|
||||
result.put(path, department);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建单个部门的完整路径
|
||||
* @param department 当前部门
|
||||
* @param idToDepartmentMap ID到部门的映射
|
||||
* @return 部门路径字符串
|
||||
*/
|
||||
private static String buildDepartmentPath(DepartmentE department, Map<Long, DepartmentE> idToDepartmentMap) {
|
||||
List<String> pathNames = new ArrayList<>();
|
||||
DepartmentE current = department;
|
||||
|
||||
// 向上遍历父部门,直到根节点
|
||||
while (current != null) {
|
||||
pathNames.add(0, current.getName()); // 在列表头部添加,保持顺序
|
||||
Long parentId = current.getParentId();
|
||||
|
||||
// 如果没有父ID或父部门不在列表中,结束遍历
|
||||
if (parentId == null || !idToDepartmentMap.containsKey(parentId)) {
|
||||
break;
|
||||
}
|
||||
|
||||
current = idToDepartmentMap.get(parentId);
|
||||
}
|
||||
|
||||
// 使用连字符连接路径
|
||||
return String.join("=", pathNames);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
/**
|
||||
* 构建部门ID到名称路径的映射
|
||||
* 格式:上级部门-当前部门
|
||||
* 示例:A-B, A-B-D
|
||||
*
|
||||
* @param departmentList 部门列表
|
||||
* @return Map<部门ID, 部门完整路径>
|
||||
*/
|
||||
public static Map<Long, String> buildDepartmentIdToPathMap(List<DepartmentE> departmentList) {
|
||||
if (departmentList == null || departmentList.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
// 创建ID到部门的映射,便于快速查找
|
||||
Map<Long, DepartmentE> idToDeptMap = departmentList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
DepartmentE::getId,
|
||||
dept -> dept,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
// 缓存已计算的路径,避免重复计算
|
||||
Map<Long, String> pathCache = new HashMap<>();
|
||||
|
||||
// 结果映射:部门ID -> 完整路径
|
||||
Map<Long, String> result = new HashMap<>();
|
||||
|
||||
for (DepartmentE department : departmentList) {
|
||||
String path = buildPathForDepartment(department.getId(), idToDeptMap, pathCache);
|
||||
result.put(department.getId(), path);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为指定部门构建完整路径(递归实现)
|
||||
*
|
||||
* @param departmentId 当前部门ID
|
||||
* @param idToDeptMap ID到部门的映射
|
||||
* @param pathCache 路径缓存
|
||||
* @return 完整路径字符串
|
||||
*/
|
||||
private static String buildPathForDepartment(Long departmentId,
|
||||
Map<Long, DepartmentE> idToDeptMap,
|
||||
Map<Long, String> pathCache) {
|
||||
// 检查缓存
|
||||
if (pathCache.containsKey(departmentId)) {
|
||||
return pathCache.get(departmentId);
|
||||
}
|
||||
|
||||
DepartmentE department = idToDeptMap.get(departmentId);
|
||||
if (department == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 获取部门名称(处理可能的空值)
|
||||
String departmentName = department.getName() != null ? department.getName() : "";
|
||||
|
||||
// 如果没有父部门或父部门不在列表中,返回当前部门名称
|
||||
Long parentId = department.getParentId();
|
||||
if (parentId == null || !idToDeptMap.containsKey(parentId)) {
|
||||
String path = departmentName;
|
||||
pathCache.put(departmentId, path);
|
||||
return path;
|
||||
}
|
||||
|
||||
// 递归构建父部门路径
|
||||
String parentPath = buildPathForDepartment(parentId, idToDeptMap, pathCache);
|
||||
|
||||
// 拼接完整路径
|
||||
String fullPath;
|
||||
if (parentPath.isEmpty()) {
|
||||
fullPath = departmentName;
|
||||
} else {
|
||||
fullPath = parentPath + "=" + departmentName;
|
||||
}
|
||||
|
||||
// 缓存结果
|
||||
pathCache.put(departmentId, fullPath);
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue