|
@@ -1,6 +1,8 @@
|
|
|
package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -15,24 +17,71 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
@Slf4j
|
|
|
public class ControlUtil {
|
|
|
- public static void setControlValue(JSONArray path, JSONObject infoValueSet) {
|
|
|
- JSONObject exist_value = RepositoryContainer.RepositoryProject.controlValueMap.putIfAbsent(path.toJSONString(), infoValueSet);
|
|
|
- if (exist_value != null) {
|
|
|
+ public static void setControlValue(SceneDataObject object, JSONObject infoValueSet) {
|
|
|
+ String id = (String) object.get("id").value_prim.value;
|
|
|
+ JSONObject existValue = RepositoryContainer.RepositoryProject.ObjCtrlValueMap.putIfAbsent(id, infoValueSet);
|
|
|
+ if (existValue != null) {
|
|
|
for (String info_code : infoValueSet.keySet()) {
|
|
|
- exist_value.put(info_code, infoValueSet.get(info_code));
|
|
|
+ existValue.put(info_code, infoValueSet.get(info_code));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static JSONObject getControlValue(JSONArray path) {
|
|
|
- JSONObject result = RepositoryContainer.RepositoryProject.controlValueMap.get(path.toString());
|
|
|
- if (result == null) {
|
|
|
- result = new JSONObject();
|
|
|
+ public static JSONObject getControlValue(RepositoryImpl Repository, JSONArray path) throws Exception {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ Object valueObject = ComputeUtil.getValueObject(Repository, path);
|
|
|
+ List<SceneDataObject> sdoList = new CopyOnWriteArrayList<SceneDataObject>();
|
|
|
+ if (valueObject instanceof SceneDataValue) {
|
|
|
+ SceneDataValue currData = (SceneDataValue) valueObject;
|
|
|
+ if (currData.value_array != null) {
|
|
|
+ sdoList.addAll(currData.value_array.set);
|
|
|
+ } else if (currData.value_object != null) {
|
|
|
+ sdoList.add(currData.value_object);
|
|
|
+ } else {
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SceneDataObject currData = (SceneDataObject) valueObject;
|
|
|
+ sdoList.add(currData);
|
|
|
+ }
|
|
|
+ Map<String, Boolean> all_info_code = new ConcurrentHashMap<String, Boolean>();
|
|
|
+ for (SceneDataObject object : sdoList) {
|
|
|
+ String id = (String) object.get("id").value_prim.value;
|
|
|
+ if (RepositoryContainer.RepositoryProject.ObjCtrlValueMap.contains(id)) {
|
|
|
+ JSONObject infoValueSet = RepositoryContainer.RepositoryProject.ObjCtrlValueMap.get(id);
|
|
|
+ for (String info_code : infoValueSet.keySet()) {
|
|
|
+ all_info_code.putIfAbsent(info_code, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String info_code : all_info_code.keySet()) {
|
|
|
+ boolean all_exist = true;
|
|
|
+ boolean all_equal = true;
|
|
|
+ Object first_info_value = null;
|
|
|
+ for (SceneDataObject object : sdoList) {
|
|
|
+ if (!object.containsKey(info_code)) {
|
|
|
+ all_exist = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Object info_value = object.get(info_code);
|
|
|
+ if (first_info_value == null) {
|
|
|
+ first_info_value = info_value;
|
|
|
+ } else {
|
|
|
+ if (!first_info_value.equals(info_value)) {
|
|
|
+ all_equal = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (all_exist && all_equal) {
|
|
|
+ result.put(info_code, first_info_value);
|
|
|
+ }
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public static JSONArray set(String userId, String userName, RepositoryImpl Repository, JSONArray path, JSONObject infoValueSet,String controlReason) throws Exception {
|
|
|
+ public static JSONArray set(String userId, String userName, RepositoryImpl Repository, JSONArray path, JSONObject infoValueSet,
|
|
|
+ String controlReason) throws Exception {
|
|
|
JSONArray result;
|
|
|
Object valueObject = ComputeUtil.getValueObject(Repository, path);
|
|
|
List<SceneDataObject> sdoList = new CopyOnWriteArrayList<SceneDataObject>();
|
|
@@ -51,22 +100,8 @@ public class ControlUtil {
|
|
|
result = set(Repository, currData, infoValueSet, sdoList);
|
|
|
}
|
|
|
|
|
|
- boolean all_success = true;
|
|
|
- for (int i = 0; i < result.size(); i++) {
|
|
|
- JSONObject item = result.getJSONObject(i);
|
|
|
- String status = (String) item.get("status");
|
|
|
- if (status == null || !status.endsWith("finish:success")) {
|
|
|
- all_success = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (all_success) {
|
|
|
- setControlValue(path, infoValueSet);
|
|
|
- }
|
|
|
-
|
|
|
- ControlUtil.saveBatchOperationLog(userId, userName, sdoList, infoValueSet, result,controlReason,Repository);
|
|
|
-// ControlUtil.saveOperationLog(userId, userName, sdoList, infoValueSet, result);
|
|
|
+ ControlUtil.saveBatchOperationLog(userId, userName, sdoList, infoValueSet, result, controlReason, Repository);
|
|
|
+ // ControlUtil.saveOperationLog(userId, userName, sdoList, infoValueSet, result);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
@@ -150,11 +185,13 @@ public class ControlUtil {
|
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
- public static void saveBatchOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points,String controlReason,RepositoryImpl Repository) {
|
|
|
+
|
|
|
+ public static void saveBatchOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points,
|
|
|
+ String controlReason, RepositoryImpl Repository) {
|
|
|
try {
|
|
|
- JSONArray postParamArray=new JSONArray();
|
|
|
+ JSONArray postParamArray = new JSONArray();
|
|
|
JSONObject postParam = new JSONObject();
|
|
|
- for (int i = 0; i < sdoList.size();i++) {
|
|
|
+ for (int i = 0; i < sdoList.size(); i++) {
|
|
|
postParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
|
|
|
postParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
|
|
|
if (userId == null || userId.length() == 0) {
|
|
@@ -168,7 +205,7 @@ public class ControlUtil {
|
|
|
postParam.put("userName", userName);
|
|
|
}
|
|
|
{
|
|
|
- SceneDataObject sdo=sdoList.get(i);
|
|
|
+ SceneDataObject sdo = sdoList.get(i);
|
|
|
postParam.put("objId", sdo.get("id").value_prim.value);
|
|
|
Object objType = sdo.get("objType").value_prim.value;
|
|
|
Object objName = sdo.get("ibmsxianshimingcheng").value_prim.value;
|
|
@@ -199,9 +236,8 @@ public class ControlUtil {
|
|
|
}
|
|
|
sb.append("[" + infoName + "]" + "设为:" + "[" + infoValue + "]");
|
|
|
sb.append(";");
|
|
|
- if(infoDef.get("code").value_prim.value.equals("manualAutoSet"))
|
|
|
- {
|
|
|
- sb.append("原因:"+controlReason+";");
|
|
|
+ if (infoDef.get("code").value_prim.value.equals("manualAutoSet")) {
|
|
|
+ sb.append("原因:" + controlReason + ";");
|
|
|
}
|
|
|
String id = (String) sdo.get("id").value_prim.value;
|
|
|
JSONObject obj = Repository.id2object.get(id);
|
|
@@ -210,7 +246,10 @@ public class ControlUtil {
|
|
|
int index_ = objInfoValue.lastIndexOf("-");
|
|
|
String meter = objInfoValue.substring(0, index_);
|
|
|
int funcid = Integer.parseInt(objInfoValue.substring(index_ + 1));
|
|
|
- JSONObject point= (JSONObject) points.stream().filter(x->JSONObject.parseObject(x.toString()).get("meter").equals(meter)&&JSONObject.parseObject(x.toString()).get("funcid").equals(funcid)).findFirst().get();
|
|
|
+ JSONObject point = (JSONObject) points.stream()
|
|
|
+ .filter(x -> JSONObject.parseObject(x.toString()).get("meter").equals(meter)
|
|
|
+ && JSONObject.parseObject(x.toString()).get("funcid").equals(funcid))
|
|
|
+ .findFirst().get();
|
|
|
String status = (String) point.get("status");
|
|
|
if (status.equals("finish:success")) {
|
|
|
sb.append("控制结果:成功;");
|
|
@@ -279,6 +318,7 @@ public class ControlUtil {
|
|
|
private static JSONArray 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);
|
|
@@ -293,6 +333,7 @@ public class ControlUtil {
|
|
|
}
|
|
|
JSONArray points = new JSONArray();
|
|
|
for (SceneDataObject object : objectArray) {
|
|
|
+ setControlValue(object, infoValueSet);
|
|
|
build_points(Repository, (SceneDataObject) object, infoValueSet, points);
|
|
|
sdoList.add(object);
|
|
|
build_object((SceneDataObject) object, infoValueSet);
|