Browse Source

优化:优化graphic/import/point接口
fix bug:graphic/import/point接口上传静态信息点存在问题
fix bug:/object/equip/import接口上传时显示classCode非信息点的问题

lijie 3 years ago
parent
commit
261dc2d436

+ 5 - 121
src/main/java/com/persagy/proxy/object/controller/AdmEquipmentController.java

@@ -743,15 +743,15 @@ public class AdmEquipmentController {
 				return AdmExcelUtil.getImportSuccessResult(fileName, successCount, listList.size());
 			}
 			// 1.根据设备类型code集合查询定义
-			Map<String,ObjectTypeDefine> defineMap = queryDefineTypeMapByClassCodes(classCodes);
+			Map<String,ObjectTypeDefine> defineMap = relationReportService.queryDefineTypeMapByClassCodes(classCodes);
 			// 2.根据设备类型code集合查询设备类的信息点
-			Map<String,List<ObjectInfoDefine>> defineInfoMap = queryDefineInfoMapByClassCodes(classCodes);
+			Map<String,List<ObjectInfoDefine>> defineInfoMap = relationReportService.queryDefineInfoMapByClassCodes(classCodes);
 			// 3.根据是否根据设备类型code上传来区分处理
 			Map<String,List<ObjectNode>> objectDigitalMap = CollUtil.newHashMap();
 			if (isClassCode){
-				objectDigitalMap=queryEquipsByClassCodes(classCodes);
+				objectDigitalMap=relationReportService.queryEquipsByClassCodes(classCodes);
 			}else {
-				objectDigitalMap=queryEquipsByConditions(primaryKey,primaryMess,classCodes);
+				objectDigitalMap=relationReportService.queryEquipsByConditions(primaryKey,primaryMess,classCodes);
 			}
 			List<ObjectNode> updateObjs = new ArrayList<>();
 			ObjectNode equipment = null;
@@ -792,7 +792,7 @@ public class AdmEquipmentController {
 					}
 				}
 				boolean changeFlag = true;
-				for (int j = 0; j < objects.size(); j++) {
+				for (int j = 2; j < objects.size(); j++) {
 					// 剩余列数据处理
 					if (!infoMap.containsKey(j)) {
 						continue;
@@ -923,122 +923,6 @@ public class AdmEquipmentController {
 		}
 		return AdmResponse.failure(failure);
 	}
-	/***
-	 * Description:
-	 * @param primaryKey :
-	 * @param primaryMess :
-     * @param classCodes :
-	 * @return : java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.node.ObjectNode>>
-	 * @author : lijie
-	 * @date :2021/11/16 16:34
-	 * Update By lijie 2021/11/16 16:34
-	 */
-	private Map<String, List<ObjectNode>> queryEquipsByConditions(String primaryKey, Set<String> primaryMess,
-																  Set<String> classCodes) throws Exception{
-		if (CollUtil.isEmpty(primaryMess) || CollUtil.isEmpty(classCodes)){
-			return new HashMap<>();
-		}
-		QueryCriteria queryCriteria = new QueryCriteria();
-		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
-		ObjectNode criteria = objectMapper.createObjectNode();
-		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
-		criteria.put(ObjectDigital.CLASS_CODE_HUM,objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
-		criteria.put(primaryKey,objectMapper.readTree(objectMapper.writeValueAsString(primaryMess)));
-		queryCriteria.setCriteria(criteria);
-		List<ObjectNode> objectNodes = DigitalObjectFacade.query(AppContext.getContext().getGroupCode(),
-				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
-				AppContext.getContext().getAccountId(), queryCriteria);
-		if (CollUtil.isEmpty(objectNodes)){
-			return new HashMap<>();
-		}
-		return objectNodes.stream().filter(obj->obj.has("classCode")
-				&& obj.has(primaryKey)
-				&& obj.get("classCode").isTextual()
-				&& obj.get(primaryKey).isTextual())
-				.collect(Collectors.groupingBy(obj->obj.get(primaryKey).asText()+StrUtil.UNDERLINE+obj.get("classCode").asText()));
-	}
-
-	/***
-	 * Description: 根据设备类型编码集合查询映射关系
-	 * @param classCodes : 设备类型编码集合
-	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.digital.entity.ObjectDigital>>
-	 * @author : lijie
-	 * @date :2021/11/16 16:25
-	 * Update By lijie 2021/11/16 16:25
-	 */
-	private Map<String, List<ObjectNode>> queryEquipsByClassCodes(Set<String> classCodes) {
-		if (CollUtil.isEmpty(classCodes)){
-			return new HashMap<>();
-		}
-		Map<String, List<ObjectNode>> result = new HashMap<>();
-		for (String classCode : classCodes) {
-			QueryCriteria queryCriteria = new QueryCriteria();
-			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
-			ObjectNode criteria = objectMapper.createObjectNode();
-			criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
-			criteria.put(ObjectDigital.CLASS_CODE_HUM,classCode);
-			List<ObjectNode> objectNodes = DigitalObjectFacade.query(AppContext.getContext().getGroupCode(),
-					AppContext.getContext().getProjectId(),
-					AppContext.getContext().getAppId(), AppContext.getContext().getAccountId(), queryCriteria);
-			result.put(classCode,CollUtil.defaultIfEmpty(objectNodes,
-					CollUtil.newArrayList()));
-		}
-		return result;
-	}
-
-	/***
-	 * Description: 根据设备类型code集合查询信息点定义
-	 * @param classCodes : 设备类型code集合
-	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.define.entity.ObjectInfoDefine>>
-	 * @author : lijie
-	 * @date :2021/11/16 16:18
-	 * Update By lijie 2021/11/16 16:18
-	 */
-	private Map<String, List<ObjectInfoDefine>> queryDefineInfoMapByClassCodes(Set<String> classCodes) throws Exception {
-		if (CollUtil.isEmpty(classCodes)){
-			return new HashMap<>();
-		}
-		QueryCriteria queryCriteria = new QueryCriteria();
-		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
-		ObjectNode criteria = objectMapper.createObjectNode();
-		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
-		criteria.set(ObjectDigital.CLASS_CODE_HUM,objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
-		queryCriteria.setCriteria(criteria);
-		List<ObjectInfoDefine> objectInfoDefines = DigitalObjectInfoFacade.query(AppContext.getContext().getGroupCode(),
-				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
-				AppContext.getContext().getAccountId(), queryCriteria);
-		if (CollUtil.isEmpty(objectInfoDefines)){
-			return new HashMap<>();
-		}
-		return objectInfoDefines.stream().collect(Collectors.groupingBy(ObjectInfoDefine::getClassCode));
-	}
-
-	/***
-	 * Description: 根据设备类型code集合查询类型定义
-	 * @param classCodes : 设备类型code集合
-	 * @return : java.util.Map<java.lang.String,com.persagy.dmp.define.entity.ObjectTypeDefine>
-	 * @author : lijie
-	 * @date :2021/11/16 16:00
-	 * Update By lijie 2021/11/16 16:00
-	 */
-	private Map<String, ObjectTypeDefine> queryDefineTypeMapByClassCodes(Set<String> classCodes) throws Exception {
-		if (CollUtil.isEmpty(classCodes)){
-			return new HashMap<>();
-		}
-		QueryCriteria queryCriteria = new QueryCriteria();
-		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
-		ObjectNode criteria = objectMapper.createObjectNode();
-		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
-		criteria.set("code",objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
-		queryCriteria.setCriteria(criteria);
-		List<ObjectTypeDefine> objectTypeDefines = DigitalDefineFacade.queryObjectType(AppContext.getContext().getGroupCode(),
-				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
-				AppContext.getContext().getAccountId(), queryCriteria);
-		if (CollUtil.isEmpty(objectTypeDefines)){
-			return new HashMap<>();
-		}
-		return objectTypeDefines.stream().collect(Collectors.toMap(ObjectTypeDefine::getCode, def->def,(k1, k2)->k1));
-	}
 
 	/**
 	 * 更新设备信息

+ 82 - 60
src/main/java/com/persagy/proxy/report/controller/RelationReportController.java

@@ -5,15 +5,18 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.poi.ss.usermodel.CellType;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.RowUtil;
+import cn.hutool.poi.excel.WorkbookUtil;
+import cn.hutool.poi.excel.cell.CellUtil;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -86,11 +89,10 @@ public class RelationReportController {
 	private final RelationObjectContext relationObjectContext;
 	
 	private final IRelationReportService relationReportService;
-	
+
 	/**
 	 * 查询总数量
 	 * 
-	 * @param queryCriteria
 	 * @param request
 	 * @return
 	 */
@@ -132,7 +134,6 @@ public class RelationReportController {
 	 * 项目关系类型查询
 	 * {"filters":"relationType in [\"bd2sp\",\"fl2sp\"];computationalState>1"}
 	 * 
-	 * @param queryCriteria
 	 * @param request
 	 * @return
 	 */
@@ -271,7 +272,6 @@ public class RelationReportController {
 	 * 下载报告-统计项目下已有的设备,以及静态和iot 信息点使用情况
 	 * 设备.xlsx 是个空模板,所以这里未使用 
 	 * 
-	 * @param projectId
 	 * @param request
 	 * @param response
 	 * @return
@@ -480,7 +480,6 @@ public class RelationReportController {
 	 * 文件导入,这里由于需要回写文件,且存储到本地,采用原始POI文件解析、上传、回写、存储
 	 * 
 	 * @param relType
-	 * @param code
 	 * @param zoneType
 	 * @param request
 	 * @param response
@@ -624,7 +623,7 @@ public class RelationReportController {
 		int failCount = 0;
 		int successCount = 0;
 		String failure = null;
-		XSSFWorkbook workbook = null;
+		Workbook workbook = null;
 		String groupCode = AppContext.getContext().getGroupCode();
 		String projectId = AppContext.getContext().getProjectId();
 		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
@@ -632,37 +631,33 @@ public class RelationReportController {
 			if (file == null) {
 				return AdmResponse.failure("未选择文件");
 			}
-			
-			workbook = new XSSFWorkbook(file.getInputStream());
-		    XSSFSheet sheet = workbook.getSheetAt(0);
-		    XSSFRow row = sheet.getRow(0);
+			workbook = ExcelUtil.getReader(file.getInputStream()).getWorkbook();
+		    Sheet sheet = WorkbookUtil.getOrCreateSheet(workbook,0);
+		    Row row = RowUtil.getOrCreateRow(sheet,0);
 		    if (row == null) {
 		    	return AdmResponse.failure("文件标题行不存在");
 			}
-		    
-		    int identificationCode = -1, infosCode = -1, tableCode = -1, functionCode = -1, infosFeedback = -1, 
+		    int identificationCode = -1, infosCode = -1, tableCode = -1, functionCode = -1, infosFeedback = -1,
 		    		classCodeIndexes = -1, bimIdIndexes = -1;
-		    
 		    short lastCellNum = row.getLastCellNum();
 		    for (int i = 0; i <= lastCellNum; i++) {
-				XSSFCell cell = row.getCell(i);
-				if (cell != null && cell.getStringCellValue() != null && "本地编码".equals(cell.getStringCellValue().trim())) {
+				String cellValue = StrUtil.str(CellUtil.getCellValue(CellUtil.getOrCreateCell(row,i),true), StandardCharsets.UTF_8);
+				if (StrUtil.isNotBlank(cellValue) && "本地编码".equals(cellValue)) {
                     identificationCode = i;
-                } else if (cell != null && cell.getStringCellValue() != null && "信息点编码".equals(cell.getStringCellValue().trim())) {
+                } else if (StrUtil.isNotBlank(cellValue) && "信息点编码".equals(cellValue)) {
                     infosCode = i;
-                } else if (cell != null && cell.getStringCellValue() != null && "表号".equals(cell.getStringCellValue().trim())) {
+                } else if (StrUtil.isNotBlank(cellValue) && "表号".equals(cellValue)) {
                     tableCode = i;
-                } else if (cell != null && cell.getStringCellValue() != null && "功能号".equals(cell.getStringCellValue().trim())) {
+                } else if (StrUtil.isNotBlank(cellValue) && "功能号".equals(cellValue)) {
                     functionCode = i;
-                } else if (cell != null && cell.getStringCellValue() != null && "反馈信息".equals(cell.getStringCellValue().trim())) {
+                } else if (StrUtil.isNotBlank(cellValue) && "反馈信息".equals(cellValue)) {
                     infosFeedback = i;
-                } else if (cell != null && cell.getStringCellValue() != null && "设备类型".equals(cell.getStringCellValue().trim())) {
+                } else if (StrUtil.isNotBlank(cellValue) && "设备类型".equals(cellValue)) {
                     classCodeIndexes = i;
-                } else if (cell != null && cell.getStringCellValue() != null && "BIMID".equals(cell.getStringCellValue().trim())) {
+                } else if (StrUtil.isNotBlank(cellValue) && "BIMID".equals(cellValue)) {
                     bimIdIndexes = i;
                 }
 			}
-		    
 			if (identificationCode == -1) {
 				failure = "缺少识别码:本地编码";
 			} else if (infosCode == -1) {
@@ -681,44 +676,67 @@ public class RelationReportController {
 			if (StrUtil.isNotBlank(failure)) {
 				return AdmExcelUtil.getImportFailResult(failure, "3", 0, 0);
 			}
-			
+			// 表中的设备编码code集合
+			Set<String> classCodes = CollUtil.newHashSet();
+			// 表中的设备本地编码集合
+			Set<String> equipLocalIds = CollUtil.newHashSet();
 			// 业务数据获取
-		    int lastRowNum = sheet.getLastRowNum();
+			int lastRowNum = sheet.getLastRowNum();
+			for (int i = 1; i < lastRowNum; i++) {
+				String classCode = StrUtil.str(CellUtil
+						.getCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(sheet,i),classCodeIndexes),true), StandardCharsets.UTF_8);
+				String localId = StrUtil.str(CellUtil
+						.getCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(sheet,i),identificationCode),true), StandardCharsets.UTF_8);
+				if (StrUtil.isNotBlank(classCode)){
+					classCodes.add(classCode);
+				}
+				if (StrUtil.isNotBlank(localId)){
+					equipLocalIds.add(localId);
+				}
+			}
+			// 1.根据设备类型code集合查询定义
+			Map<String,ObjectTypeDefine> defineMap = relationReportService.queryDefineTypeMapByClassCodes(classCodes);
+			// 2.根据设备类型code集合查询设备类的信息点
+			Map<String,List<ObjectInfoDefine>> defineInfoMap = relationReportService.queryDefineInfoMapByClassCodes(classCodes);
+			// 3.根据是否根据设备类型code上传来区分处理
+			Map<String,List<ObjectNode>> objectDigitalMap = relationReportService.queryEquipsByConditions("localId",equipLocalIds,classCodes);
+			List<ObjectNode> updateObjs = new ArrayList<>();
+			Set<String> addEquipIds = new HashSet<>();
 		    for (int i = 1; i <= lastRowNum; i++) {
-		    	XSSFRow xssfRow = sheet.getRow(i);
+		    	Row xssfRow = sheet.getRow(i);
 		    	if (xssfRow == null) {
 		    		sheet.getRow(0).createCell(16).setCellValue("第" + i + " 行数据为空");
 					continue;
 				}
-		    	XSSFCell identificationCodeCell = xssfRow.getCell(identificationCode);
+		    	Cell identificationCodeCell = xssfRow.getCell(identificationCode);
 		    	if (identificationCodeCell == null || StrUtil.isBlank(identificationCodeCell.getStringCellValue())) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("本地编码不可以为空");
                     continue;
 				}
 		    	identificationCodeCell.setCellType(CellType.STRING);
-		    	XSSFCell infosCodeCell = xssfRow.getCell(infosCode);
+		    	Cell infosCodeCell = xssfRow.getCell(infosCode);
 		    	if (infosCodeCell == null || StrUtil.isBlank(infosCodeCell.getStringCellValue())) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("信息点编码不可以为空");
                     continue;
 				}
 		    	infosCodeCell.setCellType(CellType.STRING);
-		    	XSSFCell tableCodeCell = xssfRow.getCell(tableCode);
-		    	if (tableCodeCell == null || StrUtil.isBlank(tableCodeCell.getRawValue())) {
+		    	Cell tableCodeCell = xssfRow.getCell(tableCode);
+		    	if (tableCodeCell == null || StrUtil.isBlank(StrUtil.str(CellUtil.getCellValue(tableCodeCell,true), StandardCharsets.UTF_8))) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("表号不可以为空");
                     continue;
 				}
 		    	tableCodeCell.setCellType(CellType.STRING);
-		    	XSSFCell functionCodeCell = xssfRow.getCell(functionCode);
-		    	if (functionCodeCell == null || StrUtil.isBlank(functionCodeCell.getRawValue())) {
+		    	Cell functionCodeCell = xssfRow.getCell(functionCode);
+		    	if (functionCodeCell == null || StrUtil.isBlank(StrUtil.str(CellUtil.getCellValue(functionCodeCell,true), StandardCharsets.UTF_8))) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("功能号不可以为空");
                     continue;
 				}
 		    	functionCodeCell.setCellType(CellType.STRING);
-		    	XSSFCell classCodeIndexesCell = xssfRow.getCell(classCodeIndexes);
+		    	Cell classCodeIndexesCell = xssfRow.getCell(classCodeIndexes);
 		    	if (classCodeIndexesCell == null || StrUtil.isBlank(classCodeIndexesCell.getStringCellValue())) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("设备类型不可以为空");
@@ -727,24 +745,24 @@ public class RelationReportController {
 		    	classCodeIndexesCell.setCellType(CellType.STRING);
 		    	String classCode = classCodeIndexesCell.getStringCellValue().trim();
 		    	// 验证此classCode是否存在
-		    	ObjectTypeDefine typeDefine = this.queryClassList(groupCode, projectId, classCode, AdmObjectType.SYSTEM.getIndex());
+		    	ObjectTypeDefine typeDefine = defineMap.get(classCode);
 		    	if (typeDefine == null) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("设备类型未在数据字典定义范围");
                     continue;
 				}
-		    	
+
 		    	// 获取实际cell值
 		    	String val0 = identificationCodeCell.getStringCellValue().trim();
 		    	String val1 = infosCodeCell.getStringCellValue().trim();
 		    	String val2 = tableCodeCell.getStringCellValue().trim();
 		    	String val3 = functionCodeCell.getStringCellValue().trim();
-		    	
+
 		    	// 获取设备信息
 		    	ObjectNode criteria = objectMapper.createObjectNode();
 		    	criteria.put("localId", val0);
 		    	criteria.put("classCode", classCode);
-		    	List<ObjectNode> equipments = this.relationReportService.getObjectNode(criteria, groupCode, projectId, null);
+		    	List<ObjectNode> equipments = objectDigitalMap.getOrDefault(val0+StrUtil.UNDERLINE+classCode,new ArrayList<>());
 		    	if (CollectionUtil.isEmpty(equipments)) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("设备类型下本地编码不存在");
@@ -764,35 +782,39 @@ public class RelationReportController {
 					}
                     continue;
 				}
-		    	
+
 		    	// 获取信息点定义
-		    	List<ObjectInfoDefine> funidList = this.relationReportService.queryFunidList(groupCode, projectId, Sets.newHashSet(classCode), val1, null);
+		    	List<ObjectInfoDefine> funidList = defineInfoMap.getOrDefault(classCode,new ArrayList<>())
+						.stream()
+						.filter(obj->val1.equals(obj.getAliasCode()))
+						.collect(Collectors.toList());;
 		    	if (CollectionUtil.isEmpty(funidList)) {
 		    		failCount++;
 		    		xssfRow.createCell(infosFeedback).setCellValue("信息点不存在");
                     continue;
 				}
-		    	ObjectInfoDefine infoDefine = funidList.get(0);
-		    	
+				ObjectInfoDefine infoDefine = funidList.get(0);
+				if ("STATIC".equals(infoDefine.getCategory())) {
+					failCount++;
+					xssfRow.createCell(infosFeedback).setCellValue("该信息点为静态信息点");
+					continue;
+				}
 		    	 // 数据更新,更新对应code值为,表号和功能号
-		    	ObjectNode objectNode = objectMapper.createObjectNode();
-		    	objectNode.put("id", equipments.get(0).get("id").asText());
+		    	ObjectNode objectNode = equipments.get(0);
 		    	objectNode.put(infoDefine.getCode(), val2 + "-" +val3);
-		    	
-		    	ObjectDigital updateOne = DigitalObjectFacade.updateOne(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, objectNode);
-		    	if (updateOne == null) {
-		    		failCount++;
-		    		xssfRow.createCell(infosFeedback).setCellValue("失败");
-		    		String bimId = this.getObjectBimId(equipments.get(0));
-		    		if (StrUtil.isNotBlank(bimId)) {
-		    			xssfRow.createCell(bimIdIndexes).setCellValue(bimId);
-					}
-				} else {
-					xssfRow.createCell(infosFeedback).setCellValue("成功");
-					successCount++;
+				successCount++;
+				if (!addEquipIds.contains(objectNode.get("id").asText())){
+					addEquipIds.add(objectNode.get("id").asText());
+					updateObjs.add(objectNode);
 				}
 			}
-
+		    if (CollUtil.isNotEmpty(updateObjs)){
+		    	DigitalObjectFacade.update(AppContext.getContext().getGroupCode(),
+						AppContext.getContext().getProjectId(),
+						AppContext.getContext().getAppId(),
+						AppContext.getContext().getAccountId(),
+						updateObjs);
+			}
 		    // 文件存储及返回
 		    String fileName = AdmExcelUtil.writeFile2Local(workbook, projectId, AdmCommonConstant.SERVER_ROOT_PATH + AdmExcelUtil.TEMP_UPLOAD_PAHT, file.getOriginalFilename());
 		    return AdmExcelUtil.getImportSuccessResult(fileName, successCount, failCount);

+ 40 - 1
src/main/java/com/persagy/proxy/report/service/IRelationReportService.java

@@ -14,6 +14,7 @@ import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.define.entity.RelationDefine;
 import com.persagy.dmp.digital.entity.ObjectRelation;
+import lombok.SneakyThrows;
 
 /**
  * 报表/模板下载
@@ -220,5 +221,43 @@ public interface IRelationReportService {
 	 * @return
 	 */
 	boolean createRelationProjectCal(String groupCode, String projectId) throws JsonProcessingException;
-
+	/***
+	 * Description: 根据对象类型编码集合查询类型定义映射
+	 * @param classCodes : 对象类型编码集合
+	 * @return : java.util.Map<java.lang.String,com.persagy.dmp.define.entity.ObjectTypeDefine>
+	 * @author : lijie
+	 * @date :2021/11/17 15:24
+	 * Update By lijie 2021/11/17 15:24
+	 */
+    Map<String, ObjectTypeDefine> queryDefineTypeMapByClassCodes(Set<String> classCodes);
+	/***
+	 * Description:
+	 * @param primaryKey : 信息点key
+	 * @param primaryMess : 信息点的值
+	 * @param classCodes : 对象类型code集合
+	 * @return : java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.node.ObjectNode>>
+	 * @author : lijie
+	 * @date :2021/11/16 16:34
+	 * Update By lijie 2021/11/16 16:34
+	 */
+	Map<String, List<ObjectNode>> queryEquipsByConditions(String primaryKey, Set<String> primaryMess,
+														  Set<String> classCodes);
+	/***
+	 * Description: 根据设备类型编码集合查询映射关系
+	 * @param classCodes : 设备类型编码集合
+	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.digital.entity.ObjectDigital>>
+	 * @author : lijie
+	 * @date :2021/11/16 16:25
+	 * Update By lijie 2021/11/16 16:25
+	 */
+	Map<String, List<ObjectNode>> queryEquipsByClassCodes(Set<String> classCodes);
+	/***
+	 * Description: 根据设备类型code集合查询信息点定义
+	 * @param classCodes : 设备类型code集合
+	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.define.entity.ObjectInfoDefine>>
+	 * @author : lijie
+	 * @date :2021/11/16 16:18
+	 * Update By lijie 2021/11/16 16:18
+	 */
+	Map<String, List<ObjectInfoDefine>> queryDefineInfoMapByClassCodes(Set<String> classCodes);
 }

+ 127 - 1
src/main/java/com/persagy/proxy/report/service/impl/RelationReportService.java

@@ -7,6 +7,8 @@ import java.util.stream.Collectors;
 import cn.hutool.core.lang.intern.InternUtil;
 import cn.hutool.core.util.NumberUtil;
 import com.persagy.dmp.common.constant.CommonConstant;
+import com.persagy.dmp.digital.entity.ObjectDigital;
+import lombok.SneakyThrows;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -588,7 +590,131 @@ public class RelationReportService implements IRelationReportService {
 		result.put("total", parentList.size());
 		return result;
 	}
-	
+	/***
+	 * Description: 根据设备类型code集合查询类型定义
+	 * @param classCodes : 设备类型code集合
+	 * @return : java.util.Map<java.lang.String,com.persagy.dmp.define.entity.ObjectTypeDefine>
+	 * @author : lijie
+	 * @date :2021/11/16 16:00
+	 * Update By lijie 2021/11/16 16:00
+	 */
+	@SneakyThrows
+	@Override
+	public Map<String, ObjectTypeDefine> queryDefineTypeMapByClassCodes(Set<String> classCodes) {
+		if (CollUtil.isEmpty(classCodes)){
+			return new HashMap<>();
+		}
+		QueryCriteria queryCriteria = new QueryCriteria();
+		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+		ObjectNode criteria = objectMapper.createObjectNode();
+		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
+		criteria.set("code",objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
+		queryCriteria.setCriteria(criteria);
+		List<ObjectTypeDefine> objectTypeDefines = DigitalDefineFacade.queryObjectType(AppContext.getContext().getGroupCode(),
+				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
+				AppContext.getContext().getAccountId(), queryCriteria);
+		if (CollUtil.isEmpty(objectTypeDefines)){
+			return new HashMap<>();
+		}
+		return objectTypeDefines.stream().collect(Collectors.toMap(ObjectTypeDefine::getCode, def->def,(k1, k2)->k1));
+	}
+
+	/***
+	 * Description:
+	 * @param primaryKey : 信息点key
+	 * @param primaryMess : 信息点的值
+	 * @param classCodes : 对象类型code集合
+	 * @return : java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.node.ObjectNode>>
+	 * @author : lijie
+	 * @date :2021/11/16 16:34
+	 * Update By lijie 2021/11/16 16:34
+	 */
+	@SneakyThrows
+	@Override
+	public Map<String, List<ObjectNode>> queryEquipsByConditions(String primaryKey, Set<String> primaryMess,
+																 Set<String> classCodes){
+		if (CollUtil.isEmpty(primaryMess) || CollUtil.isEmpty(classCodes)){
+			return new HashMap<>();
+		}
+		QueryCriteria queryCriteria = new QueryCriteria();
+		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+		ObjectNode criteria = objectMapper.createObjectNode();
+		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
+		criteria.put(ObjectDigital.CLASS_CODE_HUM,objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
+		criteria.put(primaryKey,objectMapper.readTree(objectMapper.writeValueAsString(primaryMess)));
+		queryCriteria.setCriteria(criteria);
+		List<ObjectNode> objectNodes = DigitalObjectFacade.query(AppContext.getContext().getGroupCode(),
+				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
+				AppContext.getContext().getAccountId(), queryCriteria);
+		if (CollUtil.isEmpty(objectNodes)){
+			return new HashMap<>();
+		}
+		return objectNodes.stream().filter(obj->obj.has("classCode")
+				&& obj.has(primaryKey)
+				&& obj.get("classCode").isTextual()
+				&& obj.get(primaryKey).isTextual())
+				.collect(Collectors.groupingBy(obj->obj.get(primaryKey).asText()+StrUtil.UNDERLINE+obj.get("classCode").asText()));
+	}
+
+	/***
+	 * Description: 根据设备类型编码集合查询映射关系
+	 * @param classCodes : 设备类型编码集合
+	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.digital.entity.ObjectDigital>>
+	 * @author : lijie
+	 * @date :2021/11/16 16:25
+	 * Update By lijie 2021/11/16 16:25
+	 */
+	@SneakyThrows
+	@Override
+	public Map<String, List<ObjectNode>> queryEquipsByClassCodes(Set<String> classCodes) {
+		if (CollUtil.isEmpty(classCodes)){
+			return new HashMap<>();
+		}
+		Map<String, List<ObjectNode>> result = new HashMap<>();
+		for (String classCode : classCodes) {
+			QueryCriteria queryCriteria = new QueryCriteria();
+			ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+			ObjectNode criteria = objectMapper.createObjectNode();
+			criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
+			criteria.put(ObjectDigital.CLASS_CODE_HUM,classCode);
+			List<ObjectNode> objectNodes = DigitalObjectFacade.query(AppContext.getContext().getGroupCode(),
+					AppContext.getContext().getProjectId(),
+					AppContext.getContext().getAppId(), AppContext.getContext().getAccountId(), queryCriteria);
+			result.put(classCode,CollUtil.defaultIfEmpty(objectNodes,
+					CollUtil.newArrayList()));
+		}
+		return result;
+	}
+
+	/***
+	 * Description: 根据设备类型code集合查询信息点定义
+	 * @param classCodes : 设备类型code集合
+	 * @return : java.util.Map<java.lang.String,java.util.List<com.persagy.dmp.define.entity.ObjectInfoDefine>>
+	 * @author : lijie
+	 * @date :2021/11/16 16:18
+	 * Update By lijie 2021/11/16 16:18
+	 */
+	@SneakyThrows
+	@Override
+	public Map<String, List<ObjectInfoDefine>> queryDefineInfoMapByClassCodes(Set<String> classCodes){
+		if (CollUtil.isEmpty(classCodes)){
+			return new HashMap<>();
+		}
+		QueryCriteria queryCriteria = new QueryCriteria();
+		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+		ObjectNode criteria = objectMapper.createObjectNode();
+		criteria.put(ObjectTypeDefine.PROP_VALID,Boolean.TRUE);
+		criteria.set(ObjectDigital.CLASS_CODE_HUM,objectMapper.readTree(objectMapper.writeValueAsString(classCodes)));
+		queryCriteria.setCriteria(criteria);
+		List<ObjectInfoDefine> objectInfoDefines = DigitalObjectInfoFacade.query(AppContext.getContext().getGroupCode(),
+				AppContext.getContext().getProjectId(), AppContext.getContext().getAppId(),
+				AppContext.getContext().getAccountId(), queryCriteria);
+		if (CollUtil.isEmpty(objectInfoDefines)){
+			return new HashMap<>();
+		}
+		return objectInfoDefines.stream().collect(Collectors.groupingBy(ObjectInfoDefine::getClassCode));
+	}
+
 	/***
 	 * Description: 创建存储的对象
 	 * @param groupCode : 集团编码