|
@@ -2,12 +2,10 @@ package com.persagy.dptool;
|
|
|
|
|
|
import com.persagy.dptool.dto.PhysicalObject;
|
|
|
import com.persagy.dptool.dto.physical.*;
|
|
|
+import com.persagy.dptool.dto.physical.Objects;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class PhysicalCheckUtil {
|
|
|
public static final String[] tipsArray = {"无异常。", "无指定项目数据。", "无数据。"};
|
|
@@ -166,13 +164,25 @@ public class PhysicalCheckUtil {
|
|
|
return tipsArray[2];
|
|
|
}
|
|
|
|
|
|
+ StringBuilder noObjErr = new StringBuilder();
|
|
|
+ Set<String> graphIdSet = new HashSet<>();
|
|
|
List<RelBtwGraphPeriod> relBtwGraphPeriods = new ArrayList<>();
|
|
|
try {
|
|
|
+ String graphType = null, sequenceId = null;
|
|
|
for(String jsonStr : dataList) {
|
|
|
if(jsonStr != null && jsonStr.length() > 2) {
|
|
|
RelBtwGraphPeriod item = CommonUtil.jsonStrToObj(jsonStr, RelBtwGraphPeriod.class);
|
|
|
if(physicalObject.pjId.equals(item.getProject_id())) {
|
|
|
relBtwGraphPeriods.add(item);
|
|
|
+
|
|
|
+ graphType = item.getGraph_type();
|
|
|
+ sequenceId = item.getSequence_id();
|
|
|
+ if(null != graphType && sequenceId != null) {
|
|
|
+ graphIdSet.add(graphType+sequenceId);
|
|
|
+ if(physicalObject.graphIdSet != null && !physicalObject.graphIdSet.contains(graphType+sequenceId)) {
|
|
|
+ noObjErr.append(item.toString() + "记录异常!graph_instance表无对应记录。\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -185,9 +195,17 @@ public class PhysicalCheckUtil {
|
|
|
return tipsArray[1];
|
|
|
}
|
|
|
|
|
|
+ if(!graphIdSet.isEmpty()) {
|
|
|
+ physicalObject.graphIdPeriodSet = new HashSet<>(graphIdSet);
|
|
|
+ }
|
|
|
+
|
|
|
String errorMsg = CommonUtil.annotationFieldCheck(relBtwGraphPeriods, physicalObject);
|
|
|
if(null != errorMsg) {
|
|
|
- return errorMsg;
|
|
|
+ noObjErr.append(errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(noObjErr.length() > 0) {
|
|
|
+ return noObjErr.toString();
|
|
|
}
|
|
|
|
|
|
return tipsArray[0];
|
|
@@ -297,4 +315,261 @@ public class PhysicalCheckUtil {
|
|
|
|
|
|
return tipsArray[0];
|
|
|
}
|
|
|
+
|
|
|
+ public String check_infocode_scheme_detail(File file, PhysicalObject physicalObject) {
|
|
|
+ List<String> dataList = CommonUtil.readFileToList(file);
|
|
|
+ if(dataList.isEmpty()) {
|
|
|
+ return tipsArray[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ List<InfocodeSchemeDetail> infocodeSchemeDetails = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ for(String jsonStr : dataList) {
|
|
|
+ if(jsonStr != null && jsonStr.length() > 2) {
|
|
|
+ InfocodeSchemeDetail item = CommonUtil.jsonStrToObj(jsonStr, InfocodeSchemeDetail.class);
|
|
|
+ if(physicalObject.infoCodeSchemeIdSet != null && physicalObject.infoCodeSchemeIdSet.contains(item.getScheme_id())) {
|
|
|
+ infocodeSchemeDetails.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return "数据格式错误!无法转为Json对象。";
|
|
|
+ }
|
|
|
+
|
|
|
+ if(infocodeSchemeDetails.isEmpty()) {
|
|
|
+ return tipsArray[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ String errorMsg = CommonUtil.annotationFieldCheck(infocodeSchemeDetails, physicalObject);
|
|
|
+ if(null != errorMsg) {
|
|
|
+ return errorMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ return tipsArray[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ public String check_ctm_dict(File file, PhysicalObject physicalObject) {
|
|
|
+ List<String> dataList = CommonUtil.readFileToList(file);
|
|
|
+ if(dataList.isEmpty()) {
|
|
|
+ return tipsArray[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CtmDict> ctmDicts = new ArrayList<>();
|
|
|
+ Set<String> ctmDicIdSet = new HashSet<>();
|
|
|
+ try {
|
|
|
+ for(String jsonStr : dataList) {
|
|
|
+ if(jsonStr != null && jsonStr.length() > 2) {
|
|
|
+ CtmDict item = CommonUtil.jsonStrToObj(jsonStr, CtmDict.class);
|
|
|
+ if(item.getId() != null) {
|
|
|
+ ctmDicIdSet.add(item.getId());
|
|
|
+ }
|
|
|
+ ctmDicts.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return "数据格式错误!无法转为Json对象。";
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ctmDicts.isEmpty()) {
|
|
|
+ return tipsArray[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!ctmDicIdSet.isEmpty()) {
|
|
|
+ physicalObject.ctmDicIdSet = new HashSet<>(ctmDicIdSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ String errorMsg = CommonUtil.annotationFieldCheck(ctmDicts, physicalObject);
|
|
|
+ if(null != errorMsg) {
|
|
|
+ return errorMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ return tipsArray[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ public String check_ctm_dict_follower(File file, PhysicalObject physicalObject) {
|
|
|
+ List<String> dataList = CommonUtil.readFileToList(file);
|
|
|
+ if(dataList.isEmpty()) {
|
|
|
+ return tipsArray[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CtmDictFollower> ctmDictFollowers = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ for(String jsonStr : dataList) {
|
|
|
+ if(jsonStr != null && jsonStr.length() > 2) {
|
|
|
+ CtmDictFollower item = CommonUtil.jsonStrToObj(jsonStr, CtmDictFollower.class);
|
|
|
+ if(physicalObject.pjId.equals(item.getProject_id())) {
|
|
|
+ ctmDictFollowers.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return "数据格式错误!无法转为Json对象。";
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ctmDictFollowers.isEmpty()) {
|
|
|
+ return tipsArray[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ String errorMsg = CommonUtil.annotationFieldCheck(ctmDictFollowers, physicalObject);
|
|
|
+ if(null != errorMsg) {
|
|
|
+ return errorMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ return tipsArray[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ public String check_ctm_node(File file, PhysicalObject physicalObject) {
|
|
|
+ List<String> dataList = CommonUtil.readFileToList(file);
|
|
|
+ if(dataList.isEmpty()) {
|
|
|
+ return tipsArray[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CtmNode> ctmNodes = new ArrayList<>();
|
|
|
+ // 字典id:该字典下的所有ctmNode
|
|
|
+ Map<String, List<CtmNode>> dicId2Nodes = new HashMap<>();
|
|
|
+ // 字典id:该字典下的所有专业编码
|
|
|
+ Map<String, Set<String>> dicId2MajorCode = new HashMap<>();
|
|
|
+ // 字典id:该字典下的所有系统编码
|
|
|
+ Map<String, Set<String>> dicId2SystemCode = new HashMap<>();
|
|
|
+ // 字典id:该字典下的所有设备编码
|
|
|
+ Map<String, Set<String>> dicId2EquipCode = new HashMap<>();
|
|
|
+ // 字典id:该字典下的所有部件编码
|
|
|
+ Map<String, Set<String>> dicId2CompCode = new HashMap<>();
|
|
|
+
|
|
|
+ StringBuilder eqTreeErr = new StringBuilder();
|
|
|
+
|
|
|
+ try {
|
|
|
+ for(String jsonStr : dataList) {
|
|
|
+ if(jsonStr != null && jsonStr.length() > 2) {
|
|
|
+ CtmNode item = CommonUtil.jsonStrToObj(jsonStr, CtmNode.class);
|
|
|
+ ctmNodes.add(item);
|
|
|
+
|
|
|
+ // 对设备岗位数相关数据进行处理
|
|
|
+ String dictId = item.getDict_id();
|
|
|
+ if(dictId != null && "eq".equals(item.getType())) {
|
|
|
+ if(dicId2Nodes.containsKey(dictId)) {
|
|
|
+ dicId2Nodes.get(dictId).add(item);
|
|
|
+ }else {
|
|
|
+ dicId2Nodes.put(dictId, new ArrayList<>(Arrays.asList(item)));
|
|
|
+ }
|
|
|
+
|
|
|
+ String code = item.getCode();
|
|
|
+ if(code != null) {
|
|
|
+ Set<String> majorSet = dicId2MajorCode.get(dictId);
|
|
|
+ if(null == majorSet) {
|
|
|
+ majorSet = new HashSet<>();
|
|
|
+ dicId2MajorCode.put(dictId, majorSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> systemSet = dicId2SystemCode.get(dictId);
|
|
|
+ if(null == systemSet) {
|
|
|
+ systemSet = new HashSet<>();
|
|
|
+ dicId2SystemCode.put(dictId, systemSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> equipSet = dicId2EquipCode.get(dictId);
|
|
|
+ if(null == equipSet) {
|
|
|
+ equipSet = new HashSet<>();
|
|
|
+ dicId2EquipCode.put(dictId, equipSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> compSet = dicId2CompCode.get(dictId);
|
|
|
+ if(null == compSet) {
|
|
|
+ compSet = new HashSet<>();
|
|
|
+ dicId2CompCode.put(dictId, compSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(code.length() == 2) {
|
|
|
+ if(item.getParent() == null) {
|
|
|
+ // 专业码
|
|
|
+ if(majorSet.contains(code)) {
|
|
|
+ eqTreeErr.append(item.toString() + "记录异常!code值重复。\n");
|
|
|
+ }else {
|
|
|
+ majorSet.add(code);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ // 系统码
|
|
|
+ if(systemSet.contains(code)) {
|
|
|
+ eqTreeErr.append(item.toString() + "记录异常!code值重复。\n");
|
|
|
+ }else {
|
|
|
+ systemSet.add(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(code.length() == 4) {
|
|
|
+ // 设备码
|
|
|
+ if(equipSet.contains(code)) {
|
|
|
+ eqTreeErr.append(item.toString() + "记录异常!code值重复。\n");
|
|
|
+ }else {
|
|
|
+ equipSet.add(code);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ // 其他类型
|
|
|
+ if(compSet.contains(code)) {
|
|
|
+ eqTreeErr.append(item.toString() + "记录异常!code值重复。\n");
|
|
|
+ }else {
|
|
|
+ compSet.add(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return "数据格式错误!无法转为Json对象。";
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ctmNodes.isEmpty()) {
|
|
|
+ return tipsArray[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 进行设备编码校验,编码长度,编码去重,父级编码存在性校验
|
|
|
+ if(!dicId2Nodes.isEmpty()) {
|
|
|
+ String code = "";
|
|
|
+ String parent = "";
|
|
|
+ int codeLength = -1;
|
|
|
+ for(String dicId : dicId2Nodes.keySet()) {
|
|
|
+ for(CtmNode node : dicId2Nodes.get(dicId)) {
|
|
|
+ code = node.getCode();
|
|
|
+ if(null == code) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ parent = node.getParent();
|
|
|
+ codeLength = code.length();
|
|
|
+
|
|
|
+ if(codeLength == 2 ) {
|
|
|
+ if(parent != null && !dicId2MajorCode.get(dicId).contains(parent)) {
|
|
|
+ eqTreeErr.append(node.toString() + "记录异常!找不到parent值对应的记录。\n");
|
|
|
+ }
|
|
|
+ }else if(codeLength == 4) {
|
|
|
+ if(!dicId2SystemCode.get(dicId).contains(parent)) {
|
|
|
+ eqTreeErr.append(node.toString() + "记录异常!parent值不能为null且对应记录必须存在。\n");
|
|
|
+ }
|
|
|
+ }else if(codeLength == 6) {
|
|
|
+ if(!dicId2EquipCode.get(dicId).contains(parent)) {
|
|
|
+ eqTreeErr.append(node.toString() + "记录异常!parent值不能为null且对应记录必须存在。\n");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ eqTreeErr.append(node.toString() + "记录异常!code值长度不合法。专业和系统长度为2,设备长度为4,部件长度为6。\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String errorMsg = CommonUtil.annotationFieldCheck(ctmNodes, physicalObject);
|
|
|
+ if(null != errorMsg) {
|
|
|
+ eqTreeErr.append(errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(eqTreeErr.length() > 0) {
|
|
|
+ return eqTreeErr.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ return tipsArray[0];
|
|
|
+ }
|
|
|
+
|
|
|
}
|