Kaynağa Gözat

rwd: 导数工具

yaoll 4 yıl önce
ebeveyn
işleme
98333306c8

+ 95 - 32
dmp-rwd-datautils/src/main/java/com/persagy/dmp/rwd/datautils/service/TransObjInfoService.java

@@ -51,6 +51,7 @@ public class TransObjInfoService {
 		private String s_value;
 		private Long l_value;
 		private Double d_value;
+		private String json_value;
 		private String time;
 		private String error;
 
@@ -63,23 +64,67 @@ public class TransObjInfoService {
 		}
 	}
 
-	private static final Set<String> baseColumn = new HashSet<>(Arrays.asList(
-			"BuildID",
-			"FloorID",
-			"RoomID",
-			"EquipID",
-			"BuildName",
-			"FloorName",
-			"RoomName",
-			"EquipName",
-			"BuildLocalID",
-			"FloorLocalID",
-			"RoomLocalID",
-			"EquipLocalID",
-			"BuildLocalName",
-			"FloorLocalName",
-			"RoomLocalName",
-			"EquipLocalName"));
+	private static final Map<String, String> baseFuncid = new HashMap<>();
+
+	static {
+		baseFuncid.put("ProjID", "id");
+		baseFuncid.put("ProjName", "name");
+		baseFuncid.put("ProjLocalID", "localId");
+		baseFuncid.put("ProjLocalName", "localName");
+		baseFuncid.put("BuildID", "id");
+		baseFuncid.put("BuildName", "name");
+		baseFuncid.put("BuildLocalID", "localId");
+		baseFuncid.put("BuildLocalName", "localName");
+		baseFuncid.put("FloorID", "id");
+		baseFuncid.put("FloorName", "name");
+		baseFuncid.put("FloorLocalID", "localId");
+		baseFuncid.put("FloorLocalName", "localName");
+		baseFuncid.put("RoomID", "id");
+		baseFuncid.put("RoomName", "name");
+		baseFuncid.put("RoomLocalID", "localId");
+		baseFuncid.put("RoomLocalName", "localName");
+		baseFuncid.put("ShaftID", "id");
+		baseFuncid.put("ShaftName", "name");
+		baseFuncid.put("ShaftLocalID", "localId");
+		baseFuncid.put("ShaftLocalName", "localName");
+		baseFuncid.put("SysID", "id");
+		baseFuncid.put("SysName", "name");
+		baseFuncid.put("SysLocalID", "localId");
+		baseFuncid.put("SysLocalName", "localName");
+		baseFuncid.put("EquipID", "id");
+		baseFuncid.put("EquipName", "name");
+		baseFuncid.put("EquipLocalID", "localId");
+		baseFuncid.put("EquipLocalName", "localName");
+		baseFuncid.put("ToolID", "id");
+		baseFuncid.put("ToolName", "name");
+		baseFuncid.put("ToolLocalID", "localId");
+		baseFuncid.put("ToolLocalName", "localName");
+		baseFuncid.put("ConsumID", "id");
+		baseFuncid.put("ConsumName", "name");
+		baseFuncid.put("ConsumLocalID", "localId");
+		baseFuncid.put("ConsumLocalName", "localName");
+		baseFuncid.put("ECModelID", "id");
+		baseFuncid.put("ECModelName", "name");
+		baseFuncid.put("ECModelLocalID", "localId");
+		baseFuncid.put("ECModelLocalName", "localName");
+		baseFuncid.put("SubentryID", "id");
+		baseFuncid.put("SubentryName", "name");
+		baseFuncid.put("SubentryLocalID", "localId");
+		baseFuncid.put("SubentryLocalName", "localName");
+		baseFuncid.put("BranchID", "id");
+		baseFuncid.put("BranchName", "name");
+		baseFuncid.put("BranchLocalID", "localId");
+		baseFuncid.put("BranchLocalName", "localName");
+		baseFuncid.put("BeaconID", "id");
+		baseFuncid.put("BeaconlName", "name");
+		baseFuncid.put("BeaconLocalID", "localId");
+		baseFuncid.put("BeaconLocalName", "localName");
+		baseFuncid.put("TenantID", "id");
+		baseFuncid.put("TenantName", "name");
+		baseFuncid.put("TenantLocalID", "localId");
+		baseFuncid.put("TenantLocalName", "localName");
+	}
+
 
 	public void trans(TransContext ctx) throws IOException {
 
@@ -118,9 +163,9 @@ public class TransObjInfoService {
 				continue;
 			}
 
-			if ("Ec".equalsIgnoreCase(model.obj_type)) {
-				continue;
-			}
+//			if ("Ec".equalsIgnoreCase(model.obj_type)) {
+//				continue;
+//			}
 
 			String id = model.getId();
 			if (!objectClassCodeCache.containsKey(id)) {
@@ -141,7 +186,7 @@ public class TransObjInfoService {
 			parseBaseColumn(model, obj);
 
 			String infoId = model.info_id;
-			if (baseColumn.contains(infoId)) {
+			if (baseFuncid.containsKey(infoId)) {
 				outWriter.println(JacksonMapper.toSimpleJson(model));
 				continue;
 			}
@@ -163,6 +208,8 @@ public class TransObjInfoService {
 			}
 			ObjectNode temObj = getValueNode(model);
 			if (funcidDefModel.getCategory() == FuncidCategory.STATIC) {
+				Boolean isMultiple = funcidDefModel.getIsMultiple();
+				Boolean isRegion = funcidDefModel.getIsRegion();
 				InfoCodeParser parser = infoCodeParserFactory.getParser(funcidDefModel.getDataType());
 				ParserContext parserContext = new ParserContext(funcidDefModel, temObj.get("value"));
 				parser.checkValue(parserContext);
@@ -171,8 +218,19 @@ public class TransObjInfoService {
 					errorWriter.println(JacksonMapper.toSimpleJson(model));
 				} else {
 					outWriter.println(JacksonMapper.toSimpleJson(model));
-					Object value = parserContext.getValue();
-					obj.putPOJO(code, value);
+					if (isRegion) {
+						if (isMultiple) {
+							obj.putPOJO(code, parserContext.getRegionArray());
+						} else {
+							obj.putPOJO(code, parserContext.getRegionValue());
+						}
+					} else {
+						if (isMultiple) {
+							obj.putPOJO(code, parserContext.getArrayValue());
+						} else {
+							obj.putPOJO(code, parserContext.getValue());
+						}
+					}
 				}
 			} else {
 				// 动态值不需校验
@@ -217,7 +275,7 @@ public class TransObjInfoService {
 	private void initObjectClassCodeCache(TransContext ctx, Map<String, String> objectClassCodeCache) {
 		JacksonCriteria criteria = JacksonCriteria.newInstance();
 		criteria.add("projectId", ctx.getProjectId());
-//		criteria.add("id", "Eq44030700030f77c5713ecd492382f25959fdcce7bd"); // TODO for test
+//		criteria.add("id", "Eq370202000222ec61e4dd0d4b4db59bfcbf04880638"); // TODO for test
 		criteria.addWithColumn("classCode");
 
 		String url = rwdServer + "/rwd/instance/object/query?projectId=" + ctx.getProjectId() + "&groupCode=" + ctx.getGroupCode();
@@ -267,15 +325,14 @@ public class TransObjInfoService {
 
 	private void parseBaseColumn(Model model, ObjectNode obj) {
 		String infoId = model.info_id;
-		if ("BuildID".equals(infoId) || "FloorID".equals(infoId) || "RoomID".equals(infoId) || "EquipID".equals(infoId)) {
+		String infoCode = baseFuncid.get(infoId);
+		if (infoCode == null) {
 			return;
-		} else if ("BuildName".equals(infoId) || "FloorName".equals(infoId) || "RoomName".equals(infoId) || "EquipName".equals(infoId)) {
-			obj.put("name", model.s_value);
-		} else if ("BuildLocalID".equals(infoId) || "FloorLocalID".equals(infoId) || "RoomLocalID".equals(infoId) || "EquipLocalID".equals(infoId)) {
-			obj.put("localId", model.s_value);
-		} else if ("BuildLocalName".equals(infoId) || "FloorLocalName".equals(infoId) || "RoomLocalName".equals(infoId) || "EquipLocalName".equals(infoId)) {
-			obj.put("localName", model.s_value);
 		}
+		if ("id".equals(infoCode)) {
+			return;
+		}
+		obj.put(infoCode, model.s_value);
 	}
 
 	private void initClass(TransContext ctx) {
@@ -284,6 +341,7 @@ public class TransObjInfoService {
 		ctx.getObjTypeMapping().put("Fl", "floor");
 		ctx.getObjTypeMapping().put("Sp", "space");
 		ctx.getObjTypeMapping().put("Eq", "equipment");
+		ctx.getObjTypeMapping().put("Ec", "component");
 
 		ctx.getClassCodeMapping().put("Pj", "project");
 		ctx.getClassCodeMapping().put("Bd", "building");
@@ -294,7 +352,7 @@ public class TransObjInfoService {
 			ObjectNode obj = (ObjectNode) cla;
 			String parentCode = JacksonMapper.getString(obj, "parentCode", "");
 			String code = JacksonMapper.getString(obj, "code");
-			if ("equipment".equals(parentCode) || "system".equals(parentCode)) {
+			if ("equipment".equals(parentCode) || "system".equals(parentCode) || "coomponent".equals(parentCode)) {
 				ctx.getClassCodeMapping().put(code.substring(2), code);
 			} else if ("space".equals(parentCode)) {
 				ctx.getClassCodeMapping().put(code, code);
@@ -327,11 +385,14 @@ public class TransObjInfoService {
 			return model.l_value;
 		} else if (model.d_value != null) {
 			return model.d_value;
+		} else if (model.json_value != null) {
+			return JacksonMapper.toObject(model.json_value, JsonNode.class);
 		}
 		return null;
 	}
 
 	private ObjectNode getValueNode(Model model) {
+
 		ObjectNode obj = JsonNodeFactory.instance.objectNode();
 		if (model.s_value != null) {
 			if ("".equals(model.s_value)) {
@@ -342,6 +403,8 @@ public class TransObjInfoService {
 			return obj.put("value", model.l_value);
 		} else if (model.d_value != null) {
 			return obj.put("value", model.d_value);
+		} else if (model.json_value != null) {
+			return obj.set("value", JacksonMapper.toObject(model.json_value, JsonNode.class));
 		}
 		return obj;
 	}

+ 6 - 5
dmp-rwd-datautils/src/main/java/com/persagy/dmp/rwd/datautils/service/TransObjService.java

@@ -56,7 +56,7 @@ public class TransObjService {
 		}
 
 		public String getClassCode(TransContext ctx) {
-			if ("Eq".equals(this.obj_type) || "Sy".equals(this.obj_type) || "Sp".equals(this.obj_type)) {
+			if ("Eq".equals(this.obj_type) || "Sy".equals(this.obj_type) || "Sp".equals(this.obj_type) || "Ec".equals(this.obj_type)) {
 				return ctx.getClassCodeMapping().get(this.subtype);
 			} else if ("Bd".equals(this.obj_type) || "Fl".equals(this.obj_type)) {
 				return ctx.getClassCodeMapping().get(this.obj_type);
@@ -106,9 +106,9 @@ public class TransObjService {
 			if ("Si".equalsIgnoreCase(model.obj_type)) {
 				continue;
 			}
-			if ("Ec".equalsIgnoreCase(model.obj_type)) {
-				continue;
-			}
+//			if ("Ec".equalsIgnoreCase(model.obj_type)) {
+//				continue;
+//			}
 
 			String id = model.getId();
 			if (objectIds.contains(id)) {
@@ -174,6 +174,7 @@ public class TransObjService {
 		ctx.getObjTypeMapping().put("Fl", "floor");
 		ctx.getObjTypeMapping().put("Sp", "space");
 		ctx.getObjTypeMapping().put("Eq", "equipment");
+		ctx.getObjTypeMapping().put("Ec", "component");
 
 		ctx.getClassCodeMapping().put("Pj", "project");
 		ctx.getClassCodeMapping().put("Bd", "building");
@@ -184,7 +185,7 @@ public class TransObjService {
 			ObjectNode obj = (ObjectNode) cla;
 			String parentCode = JacksonMapper.getString(obj, "parentCode", "");
 			String code = JacksonMapper.getString(obj, "code");
-			if ("equipment".equals(parentCode) || "system".equals(parentCode)) {
+			if ("equipment".equals(parentCode) || "system".equals(parentCode) || "component".equals(parentCode)) {
 				ctx.getClassCodeMapping().put(code.substring(2), code);
 			} else if ("space".equals(parentCode)) {
 				ctx.getClassCodeMapping().put(code, code);

+ 4 - 4
dmp-rwd-datautils/src/main/java/com/persagy/dmp/rwd/datautils/service/TransObjectValidService.java

@@ -53,7 +53,7 @@ public class TransObjectValidService {
 		}
 
 		public String getClassCode(TransContext ctx) {
-			if ("Eq".equals(this.obj_type) || "Sp".equals(this.obj_type)) {
+			if ("Eq".equals(this.obj_type) || "Sp".equals(this.obj_type) || "Ec".equals(this.obj_type)) {
 				return ctx.getClassCodeMapping().get(this.subtype);
 			} else if ("Bd".equals(this.obj_type) || "Fl".equals(this.obj_type)) {
 				return ctx.getClassCodeMapping().get(this.obj_type);
@@ -82,9 +82,9 @@ public class TransObjectValidService {
 			if ("Si".equalsIgnoreCase(model.obj_type)) {
 				continue;
 			}
-			if ("Ec".equalsIgnoreCase(model.obj_type)) {
-				continue;
-			}
+//			if ("Ec".equalsIgnoreCase(model.obj_type)) {
+//				continue;
+//			}
 //			String classCode = model.getClassCode(ctx);
 //			if (classCode == null) {
 //				log.error("obj error: {}", JacksonMapper.toSimpleJson(model));

+ 20 - 16
dmp-rwd-datautils/src/main/java/com/persagy/dmp/rwd/datautils/service/TransRelationService.java

@@ -3,7 +3,6 @@ package com.persagy.dmp.rwd.datautils.service;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.common.json.JacksonMapper;
 import com.persagy.dmp.common.http.HttpUtils;
 import com.persagy.dmp.rwd.datautils.config.GraphMapping;
@@ -45,7 +44,7 @@ public class TransRelationService {
 		private String from_obj_type;
 		private String graph_id;
 
-		public String getGraphCode(){
+		public String getGraphCode() {
 			return this.graph_id.substring(2, this.graph_id.length() - 3);
 		}
 
@@ -66,7 +65,7 @@ public class TransRelationService {
 		}
 	}
 
-	private RelationInstanceModel toRelation(Model model){
+	private RelationInstanceModel toRelation(Model model) {
 		GraphMapping.Item mapping = GraphMapping.getMapping(model.getGraphCode(), model.rel_type);
 		if (mapping == null) {
 			return null;
@@ -87,7 +86,6 @@ public class TransRelationService {
 	public void trans(TransContext ctx) throws IOException {
 		String file = ctx.getBasePath() + "/" + ctx.getDataFile();
 		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
-		ArrayNode objectArray = JsonNodeFactory.instance.arrayNode();
 		String temp;
 		List<RelationInstanceModel> data = new LinkedList<>();
 		while (true) {
@@ -99,33 +97,39 @@ public class TransRelationService {
 			if ("Si".equalsIgnoreCase(model.from_obj_type) || "Si".equals(model.to_obj_type)) {
 				continue;
 			}
-			if ("Ec".equalsIgnoreCase(model.from_obj_type) || "Ec".equals(model.to_obj_type)) {
-				continue;
-			}
+//			if ("Ec".equalsIgnoreCase(model.from_obj_type) || "Ec".equals(model.to_obj_type)) {
+//				continue;
+//			}
 			RelationInstanceModel relation = toRelation(model);
 			if (relation != null) {
 				data.add(relation);
 			} else {
 				log.error("relaton error: {}", temp);
 			}
-
-			ObjectNode obj = objectArray.addObject();
-			obj.put("graphId", model.graph_id);
-			obj.put("relCode", model.rel_type);
-			obj.put("objFrom", model.getFromId());
-			obj.put("objTo", model.getToId());
 		}
 		reader.close();
 
-		if (objectArray.size() > 0) {
+		int size = data.size();
+		int begin = 0;
+		while(true){
+			if(begin >= size){
+				break;
+			}
+			int end = begin + 100000;
+			if (end >= size) {
+				end = size;
+			}
+			List<RelationInstanceModel> params = data.subList(begin, end);
 			String url = rwdServer + "/rwd/instance/relation/create?groupCode=" + ctx.getGroupCode() + "&projectId=" + ctx.getProjectId();
-			HttpUtils.HttpResult response = httpUtils.post(url, JacksonMapper.toSimpleJson(data), 3600000);
+			HttpUtils.HttpResult response = httpUtils.post(url, JacksonMapper.toSimpleJson(params), 3600000);
 			System.out.println(response.getContent());
+			begin = end;
 		}
 	}
 
 	/**
 	 * 拼装SQL
+	 *
 	 * @param ctx
 	 * @throws IOException
 	 */
@@ -138,7 +142,7 @@ public class TransRelationService {
 		PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(ctx.getBasePath() + outFile)));
 
 		String projectId = ctx.getProjectId();
-		String insert = "insert into rwd_relation_"+ctx.getGroupCode().toLowerCase() + "_" + projectId.toLowerCase() + "(id,group_code,project_id,graph_code,graph_id,rel_code,obj_from,obj_to,status,create_time)values";
+		String insert = "insert into rwd_relation_" + ctx.getGroupCode().toLowerCase() + "_" + projectId.toLowerCase() + "(id,group_code,project_id,graph_code,graph_id,rel_code,obj_from,obj_to,status,create_time)values";
 		while (true) {
 			temp = reader.readLine();
 			if (temp == null) {

+ 41 - 0
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/TestList.java

@@ -0,0 +1,41 @@
+package com.persagy.dmp.rwd;
+
+import com.persagy.common.json.JacksonMapper;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @author: yaoll
+ * @date: 2020-12-31
+ * @verison: 1.0
+ */
+public class TestList {
+
+
+	@Test
+	public void test1() {
+
+		List<Integer> list = new ArrayList<>();
+
+		for (int i = 0; i < 100; i++) {
+			list.add(i);
+		}
+		List<Integer> sub = list.subList(10, 20);
+		System.out.println(JacksonMapper.toSimpleJson(sub));
+		System.out.println(JacksonMapper.toSimpleJson(list));
+	}
+
+	@Test
+	public void test2() {
+		List<Integer> list = new LinkedList<>();
+		for (int i = 0; i < 100; i++) {
+			list.add(i);
+		}
+		List<Integer> sub = list.subList(10, 20);
+		System.out.println(JacksonMapper.toSimpleJson(sub));
+		System.out.println(JacksonMapper.toSimpleJson(list));
+	}
+}

+ 107 - 0
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/datautils/TestTransServiceForBT.java

@@ -0,0 +1,107 @@
+package com.persagy.dmp.rwd.datautils;
+
+import com.persagy.dmp.rwd.datautils.model.TransContext;
+import com.persagy.dmp.rwd.datautils.service.TransObjInfoService;
+import com.persagy.dmp.rwd.datautils.service.TransObjService;
+import com.persagy.dmp.rwd.datautils.service.TransObjectValidService;
+import com.persagy.dmp.rwd.datautils.service.TransRelationService;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * @author: yaoll
+ * @date: 2020-10-14
+ * @verison: 1.0
+ */
+@Slf4j
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class TestTransServiceForBT {
+
+	@Autowired
+	private TransObjInfoService transObjInfoService;
+
+	@Autowired
+	private TransObjService transObjervice;
+
+	@Autowired
+	private TransRelationService transRelationService;
+
+	@Autowired
+	private TransObjectValidService transObjectValidService;
+
+	private String groupCode = "BT";
+	private String projectId = "Pj1101050013";
+	private String basePath = "/Users/devsaga/trans/1101050013-20201228";
+
+	@Test
+	public void all() throws Exception {
+		transObjects();
+		transObjInfos();
+		transRelation();
+		transObjectValid();
+	}
+
+	@Test
+	public void transObjects() throws Exception {
+
+		TransContext ctx = new TransContext();
+		ctx.setGroupCode(groupCode);
+		ctx.setProjectId(projectId);
+		ctx.setBasePath(basePath);
+		ctx.setDataFile("objects.json");
+		transObjervice.trans(ctx);
+	}
+
+	@Test
+	public void transObjInfos() throws Exception {
+
+		String fileName = "obj_infos.json";
+		TransContext ctx = new TransContext();
+		ctx.setGroupCode(groupCode);
+		ctx.setProjectId(projectId);
+		ctx.setBasePath(basePath);
+		ctx.setDataFile(fileName);
+		transObjInfoService.trans(ctx);
+	}
+
+
+	/**
+	 * 导入前要清除掉关系数据
+	 *
+	 * @throws Exception
+	 */
+	@Test
+	public void transRelation() throws Exception {
+
+		String fileName = "rel_btw_objs.json";
+		TransContext ctx = new TransContext();
+		ctx.setGroupCode(groupCode);
+		ctx.setProjectId(projectId);
+		ctx.setBasePath(basePath);
+		ctx.setDataFile(fileName);
+		transRelationService.trans(ctx);
+	}
+
+	/**
+	 * 清理失效对象
+	 *
+	 * @throws Exception
+	 */
+	@Test
+	public void transObjectValid() throws Exception {
+
+		TransContext ctx = new TransContext();
+		ctx.setGroupCode(groupCode);
+		ctx.setProjectId(projectId);
+		ctx.setBasePath(basePath);
+		ctx.setDataFile("objects.json");
+		transObjectValidService.trans(ctx);
+	}
+
+
+}

+ 3 - 3
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/datautils/TestTransServiceForGX.java

@@ -36,12 +36,12 @@ public class TestTransServiceForGX {
 
 	private String groupCode = "GX";
 	private String projectId = "Pj3702020002";
-	private String basePath = "/Users/devsaga/trans/3702020002-20201220";
+	private String basePath = "/Users/devsaga/trans/3702020002-20201228";
 
 	@Test
 	public void all() throws Exception {
-		transObjects();
-		transObjInfos();
+//		transObjects();
+//		transObjInfos();
 		transRelation();
 		transObjectValid();
 	}

+ 1 - 3
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/datautils/TestTransServiceForWD.java

@@ -37,7 +37,7 @@ public class TestTransServiceForWD {
 	private String groupCode = "WD";
 	private String projectId = "Pj4403070003";
 //	private String basePath = "/Users/devsaga/persagy/4403070003-1128龙岗万达";
-	private String basePath = "/Users/devsaga/trans/4403070003-20201220";
+	private String basePath = "/Users/devsaga/trans/4403070003-20201229";
 
 
 	@Test
@@ -63,8 +63,6 @@ public class TestTransServiceForWD {
 	public void transObjInfos() throws Exception {
 
 		String fileName = "obj_infos.json";
-//		String fileName = "obj_infos3.json";
-//		String fileName = "obj_infos-change.json";
 		TransContext ctx = new TransContext();
 		ctx.setGroupCode(groupCode);
 		ctx.setProjectId(projectId);

+ 2 - 2
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/datautils/TestTransServiceForXG.java

@@ -36,7 +36,7 @@ public class TestTransServiceForXG {
 
 	private String groupCode = "XG";
 	private String projectId = "Pj5001120003";
-	private String basePath = "/Users/devsaga/trans/5001120003-20201221";
+	private String basePath = "/Users/devsaga/trans/5001120003-20210104";
 
 	@Test
 	public void all() throws Exception {
@@ -60,7 +60,7 @@ public class TestTransServiceForXG {
 	@Test
 	public void transObjInfos() throws Exception {
 
-		String fileName = "obj_infos.json";
+		String fileName = "obj_infos2.json";
 		TransContext ctx = new TransContext();
 		ctx.setGroupCode(groupCode);
 		ctx.setProjectId(projectId);

+ 1 - 0
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/FuncidUtils.java

@@ -80,6 +80,7 @@ public class FuncidUtils {
 		baseFuncid.add("TenantName");
 		baseFuncid.add("TenantLocalID");
 		baseFuncid.add("TenantLocalName");
+
 	}
 
 	public static boolean isBase(String code) {

+ 362 - 0
dmp-rwd-datautils/src/test/java/com/persagy/dmp/rwd/dic/UpdateInfoCodeTag.java

@@ -0,0 +1,362 @@
+package com.persagy.dmp.rwd.dic;
+
+import com.persagy.common.date.DateUtils;
+import com.persagy.common.json.JacksonMapper;
+import com.persagy.dmp.rwd.enums.FuncidDataType;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Test;
+
+import java.io.*;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @author: yaoll
+ * @date: 2020-11-30
+ * @verison: 1.0
+ */
+@Slf4j
+public class UpdateInfoCodeTag {
+
+	private String basepath = "/Users/devsaga/trans";
+
+	private String outPath = "/Users/devsaga/trans/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
+
+	@Test
+	public void test1() throws IOException {
+		String majorCode = "OT";
+		String file = basepath + "/85-传感器.xlsx";
+
+		FileInputStream inputStream = new FileInputStream(file);
+		Workbook workbook = new XSSFWorkbook(inputStream);
+
+		int numberOfSheets = workbook.getNumberOfSheets();
+
+		List<FuncidDefModel> data = new LinkedList<>();
+
+		for (int i = 0; i < numberOfSheets; i++) {
+			Sheet sheet = workbook.getSheetAt(i);
+			String sheetName = sheet.getSheetName();
+			System.out.println(sheetName);
+
+			String classCode = majorCode + sheetName.substring(0, 4);
+
+
+			int startRowNum = 2;
+			int lastRowNum = sheet.getLastRowNum();
+			CacheModel cache = new CacheModel();
+			for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
+				Row row = sheet.getRow(rowIndex);
+				if (row == null) {
+					log.info("file: {}, sheet: {}, row[{}] is null", null, sheetName, rowIndex);
+					continue;
+				}
+				// 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
+				CacheModel target = new CacheModel();
+				target.classCode = classCode;
+				target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
+				target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
+				target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
+				target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
+				target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
+				target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
+				target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
+				target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
+				target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
+				target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
+
+				if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
+					continue;
+				}
+				if (FuncidUtils.isBase(target.origCode)) {
+					continue;
+				}
+
+				// firstTag不为空
+				if (target.firstTag != null) {
+					cache.firstTag = target.firstTag;
+					cache.secondTag = null;
+				} else {
+					target.firstTag = cache.firstTag;
+				}
+
+				// secondTag
+				if (target.secondTag != null) {
+					cache.secondTag = target.secondTag;
+				} else {
+					target.secondTag = cache.secondTag;
+				}
+				FuncidDefModel funcidDefModel = toFuncidDefModel(target);
+				if (funcidDefModel == null) {
+					log.info("file: {}, sheet: {}, row: {} data type [{}] error", null, sheetName, rowIndex, target.origDataType);
+				} else {
+					data.add(funcidDefModel);
+				}
+			}
+		}
+
+		List<String> sqls = new LinkedList<>();
+		for (FuncidDefModel funcid : data) {
+			//System.out.println(funcid.getClassCode() + "\t" + funcid.getFirstTag() + "\t" + funcid.getSecondTag() + "\t" + funcid.getOrigCode() + "\t" + funcid.getName());
+			// update rwd_def_funcid set first_tag = '', second_tag = '' where class_code = '' and orig_code = '';
+			StringBuilder sql = new StringBuilder();
+			sql.append("update rwd_def_funcid set first_tag = ")
+					.append(funcid.getFirstTag() == null ? null : "'" + funcid.getFirstTag().trim() + "'")
+					.append(", ")
+					.append("second_tag = ")
+					.append(funcid.getSecondTag() == null ? null : "'" + funcid.getSecondTag().trim() + "'")
+					.append(" where class_code = '").append(funcid.getClassCode()).append("'")
+					.append(" and orig_code = '").append(funcid.getOrigCode()).append("';")
+					;
+
+			sqls.add(sql.toString());
+		}
+
+		for (String sql : sqls) {
+			System.out.println(sql);
+		}
+
+		workbook.close();
+		inputStream.close();
+
+	}
+
+	@Test
+	public void importFuncidDef() throws IOException {
+		List<FuncidDefModel> funcids = new LinkedList<>();
+		importEquipment(funcids);
+
+		FileOutputStream fos = new FileOutputStream(outPath);
+		PrintWriter writer = new PrintWriter(new BufferedOutputStream(fos));
+		writer.println("commit;");
+		funcids.forEach(item -> {
+//			System.out.println(JacksonMapper.toSimpleJson(item));
+			writer.println(toSql(item));
+		});
+		writer.println("commit;");
+		writer.flush();
+		writer.close();
+	}
+
+	private String toSql(FuncidDefModel model) {
+		StringBuilder buff = new StringBuilder("");
+		buff.append("insert into rwd_def_funcid ");
+		buff.append("(id,code,orig_code,name,alias_code,alias_name,class_code,type,group_code,project_id,category,");
+		buff.append("first_tag,second_tag,priority,input_mode,unit,data_type,orig_data_type,is_multiple,is_region,formater,data_source,orig_data_source,note,sub_flag,weak_point) ");
+		buff.append("values (");
+		buff.append("'").append(UUID.randomUUID().toString().replace("-", "")).append("',"); // id
+		buff.append("'").append(model.getCode()).append("',"); // code
+		buff.append("'").append(model.getOrigCode()).append("',"); // orig_code
+		buff.append("'").append(model.getName()).append("',"); // name
+		buff.append("'").append(model.getAliasCode()).append("',"); // alias_code
+		buff.append("'").append(model.getAliasName()).append("',"); // alias_name
+		buff.append("'").append(model.getClassCode()).append("',"); // class_code
+		buff.append("'").append(model.getType()).append("',"); // type
+		buff.append("'").append(model.getGroupCode()).append("',"); // group_code
+		buff.append("'").append(model.getProjectId()).append("',"); // project_id
+		buff.append("'").append(model.getCategory().name()).append("',"); // category
+		if (model.getFirstTag() != null) {
+			buff.append("'").append(model.getFirstTag()).append("',"); // first_tag
+		} else {
+			buff.append("null,");
+		}
+		if (model.getSecondTag() != null) {
+			buff.append("'").append(model.getSecondTag()).append("',"); // second_tag
+		} else {
+			buff.append("null,");
+		}
+		if (model.getPriority() != null) {
+			buff.append("'").append(model.getPriority()).append("',"); // priority
+		} else {
+			buff.append("null,");
+		}
+		if (model.getInputMode() != null) {
+			buff.append("'").append(model.getInputMode()).append("',"); // input_mode
+		} else {
+			buff.append("null,");
+		}
+		if (model.getUnit() != null) {
+			buff.append("'").append(model.getUnit()).append("',"); // unit
+		} else {
+			buff.append("null,");
+		}
+
+		buff.append("'").append(model.getDataType().name()).append("',"); // data_type
+		buff.append("'").append(model.getOrigDataType()).append("',"); // orig_data_type
+		buff.append(model.getIsMultiple() ? 1 : 0).append(","); // is_multiple
+		buff.append(model.getIsRegion() ? 1 : 0).append(","); // is_region
+		if (model.getFormater() != null) {
+			buff.append("'").append(model.getFormater()).append("',"); // formater
+		} else {
+			buff.append("null,");
+		}
+		if (model.getDataSource() != null) {
+			buff.append("'").append(model.getDataSource().toString()).append("',"); // data_source
+		} else {
+			buff.append("null,");
+		}
+		if (model.getOrigDataSource() != null) { // orig_data_source
+			buff.append("'").append(model.getOrigDataSource()).append("',"); // data_source
+		} else {
+			buff.append("null,");
+		}
+		if (model.getNote() != null) {
+			buff.append("'").append(model.getNote()).append("',"); // note}
+		} else {
+			buff.append("null,");
+		}
+		buff.append(model.getSubFlag() ? 1 : 0).append(","); // sub_flag
+		buff.append(model.getWeakPoint() ? 1 : 0).append(","); // weak_point
+		buff.deleteCharAt(buff.length() - 1);
+		buff.append(");");
+		return buff.toString();
+	}
+
+	private FuncidDefModel toFuncidDefModel(CacheModel model) {
+		FuncidDefModel funcid = new FuncidDefModel();
+		funcid.setGroupCode("0");
+		funcid.setProjectId("0");
+		funcid.setType("common");
+		funcid.setClassCode(model.classCode);
+		funcid.setFirstTag(model.firstTag != null ? model.firstTag.replace("\n", "") : null);
+		funcid.setSecondTag(model.secondTag != null ? model.secondTag.replace("\n", "") : null);
+		funcid.setCode(model.origCode.substring(0, 1).toLowerCase() + model.origCode.substring(1));
+		funcid.setOrigCode(model.origCode);
+		funcid.setAliasCode(model.origCode);
+		if (model.name != null) {
+			funcid.setName(model.name.replace("\n", ""));
+			funcid.setAliasName(model.name.replace("\n", ""));
+		} else {
+			log.error("funcid name is null : {}", JacksonMapper.toSimpleJson(funcid));
+		}
+		funcid.setUnit(model.unit);
+		funcid.setPriority(model.priority);
+		funcid.setInputMode(model.inputMode);
+		funcid.setOrigDataType(model.origDataType);
+		funcid.setSubFlag(false);
+		funcid.setWeakPoint(false);
+		FuncidDefModel dataType = DataTypeMapping.getDataType(model.origDataType);
+		if (dataType != null) {
+			funcid.setCategory(dataType.getCategory());
+			funcid.setDataType(dataType.getDataType());
+			funcid.setIsMultiple(dataType.getIsMultiple());
+			funcid.setIsRegion(dataType.getIsRegion());
+		} else {
+			return null;
+		}
+		funcid.setSubFlag(false);
+		if (model.remark != null) {
+			funcid.setNote(model.remark.replace("\n", ""));
+		}
+
+		if (model.origDataSource != null) {
+			funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
+		}
+		if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
+			funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
+		}
+		return funcid;
+	}
+
+	private void importEquipment(List<FuncidDefModel> funcids) throws IOException {
+
+		funcids.addAll(readSheet("SELTLT", "/85-传感器.xlsx", "LTLT照明灯具"));
+
+		funcids.addAll(readSheet("SELTCC", "/17-照明系统设备.xlsx", "LTCC照明回路"));
+		funcids.addAll(readSheet("SELTLG", "/17-照明系统设备.xlsx", "LTLG照明灯组"));
+
+		funcids.addAll(readSheet("SELTCU", "/17-照明系统设备.xlsx", "LTCU照明控制箱"));
+		funcids.addAll(readSheet("SELTCP", "/17-照明系统设备.xlsx", "LTCP照明控制面板"));
+
+
+	}
+
+	@Data
+	private static class CacheModel {
+		private String classCode;
+		private String firstTag;
+		private String secondTag;
+		private String origCode;
+		private String name;
+		private String unit;
+		private String origDataType;
+		private String priority; // 优先级
+		private String inputMode;
+		private String origDataSource; // 字典选择
+		private String remark; // 备注
+	}
+
+	private List<FuncidDefModel> readSheet(String classCode, String fileName, String sheetName) throws IOException {
+		List<FuncidDefModel> data = new LinkedList<>();
+		String classFile = basepath + fileName;
+		FileInputStream inputStream = new FileInputStream(classFile);
+		Workbook workbook = new XSSFWorkbook(inputStream);
+		Sheet sheet = workbook.getSheet(sheetName);
+		if (sheet == null) {
+			return data;
+		}
+
+		// 行号从0开始, 从第2行开始读数据
+		int startRowNum = 2;
+		int lastRowNum = sheet.getLastRowNum();
+		CacheModel cache = new CacheModel();
+		for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
+			Row row = sheet.getRow(rowIndex);
+			if (row == null) {
+				log.info("file: {}, sheet: {}, row[{}] is null", fileName, sheetName, rowIndex);
+				continue;
+			}
+			// 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
+			CacheModel target = new CacheModel();
+			target.classCode = classCode;
+			target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
+			target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
+			target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
+			target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
+			target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
+			target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
+			target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
+			target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
+			target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
+			target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
+
+			if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
+				continue;
+			}
+			if (FuncidUtils.isBase(target.origCode)) {
+				continue;
+			}
+
+			// firstTag不为空
+			if (target.firstTag != null) {
+				cache.firstTag = target.firstTag;
+				cache.secondTag = null;
+			} else {
+				target.firstTag = cache.firstTag;
+			}
+
+			// secondTag
+			if (target.secondTag != null) {
+				cache.secondTag = target.secondTag;
+			} else {
+				target.secondTag = cache.secondTag;
+			}
+			FuncidDefModel funcidDefModel = toFuncidDefModel(target);
+			if (funcidDefModel == null) {
+				log.info("file: {}, sheet: {}, row: {} data type [{}] error", fileName, sheetName, rowIndex, target.origDataType);
+			} else {
+				data.add(funcidDefModel);
+			}
+		}
+		return data;
+	}
+
+}
+