|
@@ -71,6 +71,7 @@ public class RWDDownloadUtil {
|
|
|
// 检查一致性
|
|
|
boolean compare = FileUtil.compareRecursive(dir1, dir2);
|
|
|
log.debug("Compare tmp1" + (compare ? "==" : "!=") + "tmp2");
|
|
|
+ boolean result;
|
|
|
if (compare) {
|
|
|
File valid = null;
|
|
|
if (validPath != null) {
|
|
@@ -80,22 +81,24 @@ public class RWDDownloadUtil {
|
|
|
boolean compare_valid = FileUtil.compareRecursive(valid, dir2);
|
|
|
log.debug("Compare valid" + (compare_valid ? "==" : "!=") + "tmp2");
|
|
|
if (compare_valid) {
|
|
|
- return false;
|
|
|
+ result = false;
|
|
|
} else {
|
|
|
// 移动tmp2
|
|
|
Date currTime = new Date();
|
|
|
dir2.renameTo(new File(Constant.physical_world + Constant.getSeperator() + sdf.format(currTime)));
|
|
|
- return true;
|
|
|
+ result = true;
|
|
|
}
|
|
|
} else {
|
|
|
// 移动tmp2
|
|
|
Date currTime = new Date();
|
|
|
dir2.renameTo(new File(Constant.physical_world + Constant.getSeperator() + sdf.format(currTime)));
|
|
|
- return true;
|
|
|
+ result = true;
|
|
|
}
|
|
|
} else {
|
|
|
- return false;
|
|
|
+ result = false;
|
|
|
}
|
|
|
+ Clear(Constant.physical_world, true);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
public static void LoadPhysicalWorld(String path) throws Exception {
|
|
@@ -135,15 +138,12 @@ public class RWDDownloadUtil {
|
|
|
}
|
|
|
for (int i = 0; i < classArray.size(); i++) {
|
|
|
JSONObject item = (JSONObject) classArray.get(i);
|
|
|
- String objType = item.getString("objType");
|
|
|
String code = item.getString("code");
|
|
|
JSONArray infoArray;
|
|
|
{
|
|
|
JSONObject param = new JSONObject();
|
|
|
JSONObject criteria = new JSONObject();
|
|
|
- criteria.put("objType", objType);
|
|
|
criteria.put("classCode", code);
|
|
|
- criteria.put("valid", 1);
|
|
|
param.put("criteria", criteria);
|
|
|
log.debug("Download info " + code);
|
|
|
String post_result = HttpClientUtil.post(Constant.rwd_url + "rwd/def/funcid?projectId=" + RepositoryContainer.RepositoryBase.projectId
|
|
@@ -207,4 +207,146 @@ public class RWDDownloadUtil {
|
|
|
}
|
|
|
log.debug("Download physical world finish " + path);
|
|
|
}
|
|
|
+
|
|
|
+ public static boolean Process_zkt_physical_world() throws Exception {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ String validPath = Constant.getLatestPath(Constant.zkt_physical_world, true);
|
|
|
+ // 存储临时文件
|
|
|
+ File dir1;
|
|
|
+ {
|
|
|
+ String tmpPath = Constant.zkt_physical_world + Constant.getSeperator() + "tmp1";
|
|
|
+ dir1 = new File(tmpPath);
|
|
|
+ RWDDownloadUtil.LoadZKTPhysicalWorld(tmpPath);
|
|
|
+ }
|
|
|
+ File dir2;
|
|
|
+ {
|
|
|
+ String tmpPath = Constant.zkt_physical_world + Constant.getSeperator() + "tmp2";
|
|
|
+ dir2 = new File(tmpPath);
|
|
|
+ RWDDownloadUtil.LoadZKTPhysicalWorld(tmpPath);
|
|
|
+ }
|
|
|
+ // 检查一致性
|
|
|
+ boolean compare = FileUtil.compareRecursive(dir1, dir2);
|
|
|
+ log.debug("Compare tmp1" + (compare ? "==" : "!=") + "tmp2");
|
|
|
+ boolean result;
|
|
|
+ if (compare) {
|
|
|
+ File valid = null;
|
|
|
+ if (validPath != null) {
|
|
|
+ valid = new File(validPath);
|
|
|
+ }
|
|
|
+ if (valid != null && valid.exists()) {
|
|
|
+ boolean compare_valid = FileUtil.compareRecursive(valid, dir2);
|
|
|
+ log.debug("Compare valid" + (compare_valid ? "==" : "!=") + "tmp2");
|
|
|
+ if (compare_valid) {
|
|
|
+ result = false;
|
|
|
+ } else {
|
|
|
+ // 移动tmp2
|
|
|
+ Date currTime = new Date();
|
|
|
+ dir2.renameTo(new File(Constant.zkt_physical_world + Constant.getSeperator() + sdf.format(currTime)));
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 移动tmp2
|
|
|
+ Date currTime = new Date();
|
|
|
+ dir2.renameTo(new File(Constant.zkt_physical_world + Constant.getSeperator() + sdf.format(currTime)));
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ Clear(Constant.zkt_physical_world, true);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void LoadZKTPhysicalWorld(String path) throws Exception {
|
|
|
+ log.debug("Download zkt physical world refresh dir");
|
|
|
+ FileUtil.deleteRecursive(new File(path));
|
|
|
+ {
|
|
|
+ File root = new File(path);
|
|
|
+ if (!root.exists()) {
|
|
|
+ root.mkdir();
|
|
|
+ }
|
|
|
+ File object = new File(path + Constant.getSeperator() + "object");
|
|
|
+ if (!object.exists()) {
|
|
|
+ object.mkdir();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("Download zkt physical world begin " + path);
|
|
|
+ JSONArray classArray;
|
|
|
+ {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ JSONObject criteria = new JSONObject();
|
|
|
+ criteria.put("ibms", true);
|
|
|
+ param.put("criteria", criteria);
|
|
|
+ String post_result = HttpClientUtil.post(Constant.rwd_url + "rwd/def/class?projectId=" + RepositoryContainer.RepositoryBase.projectId
|
|
|
+ + "&groupCode=" + RepositoryContainer.RepositoryBase.groupCode, param.toJSONString());
|
|
|
+ JSONObject resultJSON = JSON.parseObject(post_result);
|
|
|
+ classArray = resultJSON.getJSONArray("data");
|
|
|
+ classArray = classArray == null ? new JSONArray() : classArray;
|
|
|
+ FileUtil.Save(path + Constant.getSeperator() + "classArray.json", FastJsonUtil.toFormatString(classArray));
|
|
|
+ }
|
|
|
+ for (int i = 0; i < classArray.size(); i++) {
|
|
|
+ JSONObject item = (JSONObject) classArray.get(i);
|
|
|
+ String ibmsSceneCode = item.getString("ibmsSceneCode");
|
|
|
+ String ibmsClassCode = item.getString("ibmsClassCode");
|
|
|
+ JSONArray infoArray;
|
|
|
+ {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ JSONObject criteria = new JSONObject();
|
|
|
+ criteria.put("ibmsSceneCode", ibmsSceneCode);
|
|
|
+ criteria.put("ibmsClassCode", ibmsClassCode);
|
|
|
+ param.put("criteria", criteria);
|
|
|
+ log.debug("Download object " + ibmsSceneCode + "-" + ibmsClassCode);
|
|
|
+ String post_result = HttpClientUtil.post(Constant.rwd_url + "rwd/instance/object/query?projectId="
|
|
|
+ + RepositoryContainer.RepositoryBase.projectId + "&groupCode=" + RepositoryContainer.RepositoryBase.groupCode,
|
|
|
+ param.toJSONString());
|
|
|
+ JSONObject resultJSON = JSON.parseObject(post_result);
|
|
|
+ infoArray = resultJSON.getJSONArray("data");
|
|
|
+ }
|
|
|
+ infoArray = infoArray == null ? new JSONArray() : infoArray;
|
|
|
+ File sceneDir = new File(path + Constant.getSeperator() + "object" + Constant.getSeperator() + ibmsSceneCode);
|
|
|
+ if (!sceneDir.exists()) {
|
|
|
+ sceneDir.mkdir();
|
|
|
+ }
|
|
|
+ FileUtil.Save(path + Constant.getSeperator() + "object" + Constant.getSeperator() + ibmsSceneCode + Constant.getSeperator()
|
|
|
+ + ibmsClassCode + ".json", FastJsonUtil.toFormatString(infoArray));
|
|
|
+ }
|
|
|
+ Map<String, Map<String, Integer>> relDic = new HashMap<String, Map<String, Integer>>();
|
|
|
+ ExcelRelationUtil.ReadRel(Constant.GetPath() + Constant.getSeperator() + "relation.xlsx", relDic);
|
|
|
+ log.debug("Download zkt physical world finish " + path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Clear(String path, boolean is_dir) throws Exception {
|
|
|
+ if (is_dir) {
|
|
|
+ {
|
|
|
+ String tmpPath = path + Constant.getSeperator() + "tmp1";
|
|
|
+ File dir1 = new File(tmpPath);
|
|
|
+ if (dir1.exists()) {
|
|
|
+ FileUtil.deleteRecursive(dir1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ String tmpPath = path + Constant.getSeperator() + "tmp2";
|
|
|
+ File dir2 = new File(tmpPath);
|
|
|
+ if (dir2.exists()) {
|
|
|
+ FileUtil.deleteRecursive(dir2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ String tmpPath = path + Constant.getSeperator() + "tmp" + ".json";
|
|
|
+ File dir1 = new File(tmpPath);
|
|
|
+ if (dir1.exists()) {
|
|
|
+ FileUtil.deleteRecursive(dir1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> pathList = Constant.getValidPath(path, is_dir);
|
|
|
+ if (pathList != null && pathList.size() > 3) {
|
|
|
+ for (int i = 3; i < pathList.size(); i++) {
|
|
|
+ String pathInner = pathList.get(i);
|
|
|
+ File file = new File(path + Constant.getSeperator() + pathInner);
|
|
|
+ FileUtil.deleteRecursive(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|