|
@@ -1,5 +1,7 @@
|
|
|
package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
@@ -10,6 +12,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.persagy.ibms.core.data.SceneDataObject;
|
|
|
import com.persagy.ibms.core.data.SceneDataPrimitive;
|
|
|
+import com.persagy.ibms.core.data.SceneDataSet;
|
|
|
import com.persagy.ibms.core.data.SceneDataValue;
|
|
|
import com.persagy.ibms.core.util.ComputeUtil;
|
|
|
|
|
@@ -83,7 +86,7 @@ public class ControlUtil {
|
|
|
}
|
|
|
|
|
|
public static JSONArray set(String userId, String userName, RepositoryImpl Repository, JSONArray path, JSONObject infoValueSet,
|
|
|
- String controlReason,HttpServletRequest request) throws Exception {
|
|
|
+ String controlReason, HttpServletRequest request) throws Exception {
|
|
|
JSONArray result;
|
|
|
Object valueObject = ComputeUtil.getValueObject(Repository, path);
|
|
|
List<SceneDataObject> sdoList = new CopyOnWriteArrayList<SceneDataObject>();
|
|
@@ -191,22 +194,32 @@ public class ControlUtil {
|
|
|
public static void saveBatchOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points,
|
|
|
String controlReason, RepositoryImpl Repository, HttpServletRequest request) {
|
|
|
try {
|
|
|
- String authorization=request.getHeader("Authorization");
|
|
|
+ String authorization = request.getHeader("Authorization");
|
|
|
JSONArray postParamArray = new JSONArray();
|
|
|
+ JSONObject commandRecordParam=new JSONObject();
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String currentTime=dateFormat.format(date);
|
|
|
for (int i = 0; i < sdoList.size(); i++) {
|
|
|
JSONObject postParam;
|
|
|
postParam = new JSONObject();
|
|
|
JSONObject postParam2 = new JSONObject();
|
|
|
postParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
|
|
|
postParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
|
|
|
+ //控制中心保存指令
|
|
|
+ commandRecordParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
|
|
|
+ commandRecordParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
|
|
|
+ commandRecordParam.put("executeTime",currentTime);
|
|
|
+ commandRecordParam.put("commandType",2);
|
|
|
if (userId != null) {
|
|
|
postParam.put("userId", userId);
|
|
|
+ commandRecordParam.put("userId", userId);
|
|
|
}
|
|
|
if (userName != null) {
|
|
|
postParam.put("userName", userName);
|
|
|
+ commandRecordParam.put("creator", userName);
|
|
|
}
|
|
|
- if(authorization!=null)
|
|
|
- {
|
|
|
+ if (authorization != null) {
|
|
|
postParam.put("token", authorization);
|
|
|
}
|
|
|
SceneDataObject sdo = sdoList.get(i);
|
|
@@ -228,7 +241,13 @@ public class ControlUtil {
|
|
|
postParam.put("classCode", classCode);
|
|
|
postParam.put("systemType", "control");
|
|
|
// postParam.put("token", "");
|
|
|
+ //控制中心保存指令
|
|
|
+ Object objectId = sdo.get("id").value_prim.value;
|
|
|
+ commandRecordParam.put("objectId",objectId);
|
|
|
+ commandRecordParam.put("ibmsSceneCode",ibmsSceneCode);
|
|
|
+ commandRecordParam.put("ibmsClassCode",ibmsClassCode);
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
+ StringBuffer sb2 = new StringBuffer();
|
|
|
for (String key : infoValueSet.keySet()) {
|
|
|
Object infoValue = infoValueSet.get(key);
|
|
|
SceneDataObject infoDef = null;
|
|
@@ -240,11 +259,25 @@ public class ControlUtil {
|
|
|
}
|
|
|
}
|
|
|
String infoName = key;
|
|
|
+ String infoCode;
|
|
|
+ String unit;
|
|
|
+ Object ctrlFbCode;
|
|
|
if (infoDef != null) {
|
|
|
infoName = (String) infoDef.get("name").value_prim.value;
|
|
|
+ infoCode = (String) infoDef.get("code").value_prim.value;
|
|
|
+ commandRecordParam.put("infoCode",infoCode);
|
|
|
+ commandRecordParam.put("infoValue",infoValue);
|
|
|
+ sb2.append("" + infoName + ":" + "" + infoValue + "");
|
|
|
+ commandRecordParam.put("commandContent",sb2.toString());
|
|
|
infoValue = ControlUtil.value2CanRead(infoDef, infoValue);
|
|
|
+ SceneDataSet infoPointRelationArray =Repository.InfoPointRelationArray;
|
|
|
+ SceneDataObject infoPointRelation=infoPointRelationArray.set.stream().filter(x -> JSONObject.parseObject(x.toString()).get("ibmsSceneCode").equals(ibmsSceneCode)
|
|
|
+ && JSONObject.parseObject(x.toString()).get("ibmsClassCode").equals(ibmsClassCode)&& JSONObject.parseObject(x.toString()).get("控制点").equals(infoCode))
|
|
|
+ .findFirst().get();
|
|
|
+ ctrlFbCode = infoPointRelation.get("控制反馈点").value_prim.value;
|
|
|
+ commandRecordParam.put("ctrlFbCode",ctrlFbCode);
|
|
|
}
|
|
|
- sb.append("" + infoName + "设为:" + "" + infoValue + "");
|
|
|
+ sb.append("" + infoName + "设为:" + "" + infoValue + "");
|
|
|
if (controlReason != null && !controlReason.isEmpty()) {
|
|
|
if (infoDef.get("code").value_prim.value.equals("manualAutoSet")) {
|
|
|
sb.append(",切换原因:" + controlReason + "");
|
|
@@ -262,14 +295,17 @@ public class ControlUtil {
|
|
|
&& JSONObject.parseObject(x.toString()).get("funcid").equals(funcid))
|
|
|
.findFirst().get();
|
|
|
String status = (String) point.get("status");
|
|
|
+ boolean virtual = (boolean) point.get("virtual");
|
|
|
+ commandRecordParam.put("isVirtual",virtual);
|
|
|
if (status.equals("finish:success")) {
|
|
|
sb.append("*成功;");
|
|
|
+ commandRecordParam.put("executeStatus",1);
|
|
|
} else {
|
|
|
sb.append("*失败;");
|
|
|
+ commandRecordParam.put("executeStatus",2);
|
|
|
}
|
|
|
}
|
|
|
- if(i < sdoList.size()-1)
|
|
|
- {
|
|
|
+ if (i < sdoList.size() - 1) {
|
|
|
sb.append(",");
|
|
|
}
|
|
|
}
|
|
@@ -279,12 +315,13 @@ public class ControlUtil {
|
|
|
postParam2.put("details", "控制:" + ibmsxianshimingcheng + "," + sb.toString());
|
|
|
postParam2.put("logSource", "user");
|
|
|
} else {
|
|
|
- postParam2.put("details", "用户控制日志."+userName+":" + ibmsxianshimingcheng + "," + sb.toString());
|
|
|
+ postParam2.put("details", "用户控制日志." + userName + ":" + ibmsxianshimingcheng + "," + sb.toString());
|
|
|
postParam2.put("logSource", "sys");
|
|
|
}
|
|
|
postParamArray.add(postParam2);
|
|
|
}
|
|
|
}
|
|
|
+ createCommandRecord(commandRecordParam);
|
|
|
saveBatchOperationLog(postParamArray);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
@@ -329,6 +366,16 @@ public class ControlUtil {
|
|
|
log.debug(result.toJSONString());
|
|
|
}
|
|
|
|
|
|
+ //控制中心保存控制命令
|
|
|
+ private static void createCommandRecord(JSONObject postParam) throws Exception {
|
|
|
+ String post_url = Constant.zkt_control_url + "/commandRecord/createCommandRecord";
|
|
|
+ System.out.println("保存控制指令url:" + post_url);
|
|
|
+ System.out.println("控制指令boby:" + postParam.toJSONString());
|
|
|
+ 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)
|
|
|
throws Exception {
|
|
|
JSONArray result;
|