瀏覽代碼

保存控制指令改为批量保存

lirong 2 年之前
父節點
當前提交
9cda2724d1

+ 2 - 5
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -175,10 +175,6 @@ public class RestUtil {
             JSONObject infoValueSet = (JSONObject) paramObject.get("infoValueSet");
             String controlReason = (String) paramObject.get("controlReason");
             String controlRemark = (String) paramObject.get("controlRemark");
-            log.info("path: " + path);
-            log.info("infoValueSet: " + infoValueSet);
-            log.info("controlReason: " + controlReason);
-            log.info("controlRemark: " + controlRemark);
             for (String key : infoValueSet.keySet()) {
                 Object infoValue = infoValueSet.get(key);
                 if (infoValue == null) {
@@ -199,7 +195,8 @@ public class RestUtil {
                 }
             }
 
-            JSONArray points = ControlUtil.set(userId, userName,ipAddress, Repository, path, infoValueSet, controlReason, request);
+            JSONObject crlresult = ControlUtil.set(userId, userName,ipAddress, Repository, path, infoValueSet, controlReason, request);
+            JSONArray points= (JSONArray) crlresult.get("points");
             JSONArray success_points = new JSONArray();
             JSONArray failure_points = new JSONArray();
             for (int i = 0; i < points.size(); i++) {

+ 34 - 27
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ControlUtil.java

@@ -85,9 +85,9 @@ public class ControlUtil {
         return result;
     }
 
-    public static JSONArray set(String userId, String userName,String ipAddress, RepositoryImpl Repository, JSONArray path, JSONObject infoValueSet,
+    public static JSONObject set(String userId, String userName,String ipAddress, RepositoryImpl Repository, JSONArray path, JSONObject infoValueSet,
                                 String controlReason, HttpServletRequest request) throws Exception {
-        JSONArray result;
+        JSONObject result;
         Object valueObject = ComputeUtil.getValueObject(Repository, path);
         List<SceneDataObject> sdoList = new CopyOnWriteArrayList<SceneDataObject>();
         if (valueObject instanceof SceneDataValue) {
@@ -189,21 +189,23 @@ public class ControlUtil {
         }
     }
 
-    public static void saveBatchOperationLog(String userId, String userName,String ipAddress, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points,
+    public static void saveBatchOperationLog(String userId, String userName,String ipAddress, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONObject result,
                                              String controlReason, RepositoryImpl Repository, HttpServletRequest request) {
         try {
             String authorization = request.getHeader("Authorization");
             JSONArray postParamArray = new JSONArray();
-            JSONObject commandRecordParam=new JSONObject();
-            Date date = new Date();
+            JSONArray commandRecordParamArray = new JSONArray();
             SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            String currentTime=dateFormat.format(date);
-            //控制中心保存指令
-            commandRecordParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
-            commandRecordParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
-            commandRecordParam.put("executeTime",currentTime);
-            commandRecordParam.put("commandType",2);
+            JSONArray points= (JSONArray) result.get("points");
+            String executeTime=dateFormat.format(result.get("receivetime").toString());
             for (int i = 0; i < sdoList.size(); i++) {
+                //控制中心保存指令
+                JSONObject commandRecordParam=new JSONObject();
+                commandRecordParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
+                commandRecordParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
+                commandRecordParam.put("executeTime",executeTime);
+                commandRecordParam.put("commandType",2);
+                //日志记录
                 JSONObject postParam=new JSONObject();
                 JSONObject postParam2 = new JSONObject();
                 postParam.put("ipAddress", ipAddress);
@@ -311,7 +313,7 @@ public class ControlUtil {
                         }
                     }
                 }
-                createCommandRecord(commandRecordParam);
+                commandRecordParamArray.add(commandRecordParam);
                 for (int j = 1; j <= 2; j++) {
                     postParam2 = JSONObject.parseObject(postParam.toJSONString());
                     if (j == 1) {
@@ -324,6 +326,7 @@ public class ControlUtil {
                     postParamArray.add(postParam2);
                 }
             }
+            createCommandRecord(commandRecordParamArray);
             saveBatchOperationLog(postParamArray,request);
         } catch (Exception e) {
             log.error(e.getMessage(), e);
@@ -367,16 +370,16 @@ public class ControlUtil {
     }
 
     //控制中心保存控制命令
-    private static void createCommandRecord(JSONObject postParam) throws Exception {
-        String post_url = Constant.zkt_control_url + "/commandRecord/createCommandRecord";
+    private static void createCommandRecord(JSONArray postParam) throws Exception {
+        String post_url = Constant.zkt_control_url + "/commandRecord/createCommandRecordBatch";
         String post_result = HttpClientUtil.instance("zkt_control").post(post_url, postParam.toJSONString());
         JSONObject result = JSON.parseObject(post_result);
         log.debug(result.toJSONString());
     }
 
-    private static JSONArray set(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, List<SceneDataObject> sdoList)
+    private static JSONObject set(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, List<SceneDataObject> sdoList)
             throws Exception {
-        JSONArray result;
+        JSONObject result;
         if (object.containsKey("清单")) {
             SceneDataValue list = object.get("清单");
             SceneDataValue detail = object.get("详情");
@@ -387,18 +390,18 @@ public class ControlUtil {
         return result;
     }
 
-    private static JSONArray setInner(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, List<SceneDataObject> sdoList)
+    private static JSONObject setInner(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, List<SceneDataObject> sdoList)
             throws Exception {
         JSONArray points = new JSONArray();
         setControlValue(object, infoValueSet);
         build_points(Repository, object, infoValueSet, points);
         sdoList.add(object);
         build_object(object, infoValueSet);
-        JSONArray result = post(points);
+        JSONObject result = post(points);
         return result;
     }
 
-    private static JSONArray setInner(RepositoryImpl Repository, SceneDataValue detail, List<SceneDataObject> objectArray, JSONObject infoValueSet,
+    private static JSONObject setInner(RepositoryImpl Repository, SceneDataValue detail, List<SceneDataObject> objectArray, JSONObject infoValueSet,
                                       List<SceneDataObject> sdoList) throws Exception {
         if (detail != null) {
             build_object(detail.value_object, infoValueSet);
@@ -410,7 +413,7 @@ public class ControlUtil {
             sdoList.add(object);
             build_object((SceneDataObject) object, infoValueSet);
         }
-        JSONArray result = post(points);
+        JSONObject result = post(points);
         return result;
     }
 
@@ -445,7 +448,7 @@ public class ControlUtil {
         }
     }
 
-    private static JSONArray post(JSONArray points) throws Exception {
+    private static JSONObject post(JSONArray points) throws Exception {
         JSONObject postJSON = new JSONObject();
         postJSON.put("building", RepositoryContainer.RepositoryProject.projectId.substring(2));
         postJSON.put("points", points);
@@ -453,22 +456,23 @@ public class ControlUtil {
             String post_url = Constant.iot_project_url + "/sync_pointsetbatch_post";
             log.debug(postJSON.toJSONString());
             System.out.println("url1:" + post_url);
-            System.out.println("boby1:" + postJSON.toJSONString());
             String post_result = HttpClientUtil.instance("iot_project").post(post_url, postJSON.toJSONString());
-            System.out.println("result1:" + postJSON.toJSONString());
             JSONObject result = JSON.parseObject(post_result);
             JSONArray result_points = (JSONArray) result.get("points");
+            String receivetime=result.get("receivetime").toString();
             log.debug(post_result);
-            return result_points;
+            JSONObject res=new JSONObject();
+            res.put("points",result_points);
+            res.put("receivetime",receivetime);
+            return res;
         } else {
             String post_url = Constant.iot_project_url + "/pointsetbatch_post";
             log.debug(postJSON.toJSONString());
             String post_result = HttpClientUtil.instance("iot_project").post(post_url, postJSON.toJSONString());
             System.out.println("url1:" + post_url);
-            System.out.println("boby1:" + postJSON.toJSONString());
-            System.out.println("result2:" + postJSON.toJSONString());
             JSONObject result = JSON.parseObject(post_result);
             JSONArray result_points = (JSONArray) result.get("points");
+            String receivetime=result.get("receivetime").toString();
             for (int i = 0; i < result_points.size(); i++) {
                 JSONObject item = result_points.getJSONObject(i);
                 String status = item.getString("status");
@@ -478,8 +482,11 @@ public class ControlUtil {
                     item.put("status", "finish:success");
                 }
             }
+            JSONObject res=new JSONObject();
+            res.put("points",result_points);
+            res.put("receivetime",receivetime);
             log.debug(post_result);
-            return result_points;
+            return res;
         }
     }
 }