|
@@ -17,412 +17,414 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
@Slf4j
|
|
|
public class ControlUtil {
|
|
|
- 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()) {
|
|
|
- existValue.put(info_code, infoValueSet.get(info_code));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ 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()) {
|
|
|
+ existValue.put(info_code, infoValueSet.get(info_code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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.containsKey(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).value_prim.value;
|
|
|
- if (first_info_value == null) {
|
|
|
- first_info_value = info_value;
|
|
|
- } else {
|
|
|
- if (!first_info_value.toString().equals(info_value)) {
|
|
|
- all_equal = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (all_exist && all_equal) {
|
|
|
- result.put(info_code, first_info_value);
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
+ 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.containsKey(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).value_prim.value;
|
|
|
+ if (first_info_value == null) {
|
|
|
+ first_info_value = info_value;
|
|
|
+ } else {
|
|
|
+ if (!first_info_value.toString().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 {
|
|
|
- JSONArray result;
|
|
|
- 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) {
|
|
|
- SceneDataValue detail = currData.parentObjectData.get("详情");
|
|
|
- result = setInner(Repository, detail, currData.value_array.set, infoValueSet, sdoList);
|
|
|
- } else if (currData.value_object != null) {
|
|
|
- result = set(Repository, currData.value_object, infoValueSet, sdoList);
|
|
|
- } else {
|
|
|
- throw new Exception();
|
|
|
- }
|
|
|
- } else {
|
|
|
- SceneDataObject currData = (SceneDataObject) valueObject;
|
|
|
- result = set(Repository, currData, infoValueSet, sdoList);
|
|
|
- }
|
|
|
+ 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>();
|
|
|
+ if (valueObject instanceof SceneDataValue) {
|
|
|
+ SceneDataValue currData = (SceneDataValue) valueObject;
|
|
|
+ if (currData.value_array != null) {
|
|
|
+ SceneDataValue detail = currData.parentObjectData.get("详情");
|
|
|
+ result = setInner(Repository, detail, currData.value_array.set, infoValueSet, sdoList);
|
|
|
+ } else if (currData.value_object != null) {
|
|
|
+ result = set(Repository, currData.value_object, infoValueSet, sdoList);
|
|
|
+ } else {
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SceneDataObject currData = (SceneDataObject) valueObject;
|
|
|
+ result = set(Repository, currData, infoValueSet, sdoList);
|
|
|
+ }
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- public static void saveOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points) {
|
|
|
- try {
|
|
|
- JSONObject postParam = new JSONObject();
|
|
|
- postParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
|
|
|
- postParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
|
|
|
- if (userId == null || userId.length() == 0) {
|
|
|
- postParam.put("userId", "systemId");
|
|
|
- } else {
|
|
|
- postParam.put("userId", userId);
|
|
|
- }
|
|
|
- if (userName == null || userName.length() == 0) {
|
|
|
- postParam.put("userName", "系统");
|
|
|
- } else {
|
|
|
- postParam.put("userName", userName);
|
|
|
- }
|
|
|
- if (sdoList.size() == 1) {
|
|
|
- SceneDataObject sdo = sdoList.get(0);
|
|
|
- postParam.put("objId", sdo.get("id").value_prim.value);
|
|
|
- } else {
|
|
|
- JSONArray objs = new JSONArray();
|
|
|
- for (SceneDataObject sdo : sdoList) {
|
|
|
- objs.add(sdo.get("id").value_prim.value);
|
|
|
- }
|
|
|
- postParam.put("objs", objs);
|
|
|
- }
|
|
|
- {
|
|
|
- SceneDataObject sdo = sdoList.get(0);
|
|
|
- Object objType = sdo.get("objType").value_prim.value;
|
|
|
- Object objName = sdo.get("ibmsxianshimingcheng").value_prim.value;
|
|
|
- Object systemCode = null;
|
|
|
- String classCode = (String) sdo.get("classCode").value_prim.value;
|
|
|
- Object belongSystem = sdo.get("所属场景").value_prim.value;
|
|
|
+ public static void saveOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points) {
|
|
|
+ try {
|
|
|
+ JSONObject postParam = new JSONObject();
|
|
|
+ postParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
|
|
|
+ postParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
|
|
|
+ if (userId == null || userId.length() == 0) {
|
|
|
+ postParam.put("userId", "systemId");
|
|
|
+ } else {
|
|
|
+ postParam.put("userId", userId);
|
|
|
+ }
|
|
|
+ if (userName == null || userName.length() == 0) {
|
|
|
+ postParam.put("userName", "系统");
|
|
|
+ } else {
|
|
|
+ postParam.put("userName", userName);
|
|
|
+ }
|
|
|
+ if (sdoList.size() == 1) {
|
|
|
+ SceneDataObject sdo = sdoList.get(0);
|
|
|
+ postParam.put("objId", sdo.get("id").value_prim.value);
|
|
|
+ } else {
|
|
|
+ JSONArray objs = new JSONArray();
|
|
|
+ for (SceneDataObject sdo : sdoList) {
|
|
|
+ objs.add(sdo.get("id").value_prim.value);
|
|
|
+ }
|
|
|
+ postParam.put("objs", objs);
|
|
|
+ }
|
|
|
+ {
|
|
|
+ SceneDataObject sdo = sdoList.get(0);
|
|
|
+ Object objType = sdo.get("objType").value_prim.value;
|
|
|
+ Object objName = sdo.get("ibmsxianshimingcheng").value_prim.value;
|
|
|
+ Object systemCode = null;
|
|
|
+ String classCode = (String) sdo.get("classCode").value_prim.value;
|
|
|
+ Object belongSystem = sdo.get("所属场景").value_prim.value;
|
|
|
|
|
|
- List<SceneDataObject> infoList = RepositoryContainer.instance.infoArrayDic.get(classCode).set;
|
|
|
- postParam.put("objType", objType);
|
|
|
- postParam.put("objName", objName);
|
|
|
- postParam.put("systemCode", systemCode);
|
|
|
- postParam.put("classCode", classCode);
|
|
|
- postParam.put("functionType", "remoteControl");
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- for (String key : infoValueSet.keySet()) {
|
|
|
- Object infoValue = infoValueSet.get(key);
|
|
|
- SceneDataObject infoDef = null;
|
|
|
- for (SceneDataObject infoDefInner : infoList) {
|
|
|
- String code = (String) infoDefInner.get("code").value_prim.value;
|
|
|
- if (code.equals(key)) {
|
|
|
- infoDef = infoDefInner;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- String infoName = key;
|
|
|
- if (infoDef != null) {
|
|
|
- infoName = (String) infoDef.get("name").value_prim.value;
|
|
|
- infoValue = ControlUtil.value2CanRead(infoDef, infoValue);
|
|
|
- }
|
|
|
- sb.append("[" + infoName + "]" + "设为:" + "[" + infoValue + "]");
|
|
|
- sb.append(";");
|
|
|
- }
|
|
|
- JSONArray success_points = new JSONArray();
|
|
|
- JSONArray failure_points = new JSONArray();
|
|
|
- for (int i = 0; i < points.size(); i++) {
|
|
|
- JSONObject point = points.getJSONObject(i);
|
|
|
- String status = (String) point.get("status");
|
|
|
- if (status.equals("finish:success")) {
|
|
|
- success_points.add(point);
|
|
|
- } else {
|
|
|
- failure_points.add(point);
|
|
|
- }
|
|
|
- }
|
|
|
- sb.append("控制结果:" + points.size() + "个控制指令" + (success_points.size() > 0 ? ("," + success_points.size() + "个成功") : "")
|
|
|
- + (failure_points.size() > 0 ? ("," + failure_points.size() + "个失败") : ""));
|
|
|
- postParam.put("operateDetail", "【" + belongSystem + "】:" + objName + "-" + sb.toString());
|
|
|
- postParam.put("sourceType", 1);
|
|
|
- }
|
|
|
- saveOperationLog(postParam);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
+ List<SceneDataObject> infoList = RepositoryContainer.instance.infoArrayDic.get(classCode).set;
|
|
|
+ postParam.put("objType", objType);
|
|
|
+ postParam.put("objName", objName);
|
|
|
+ postParam.put("systemCode", systemCode);
|
|
|
+ postParam.put("classCode", classCode);
|
|
|
+ postParam.put("functionType", "remoteControl");
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (String key : infoValueSet.keySet()) {
|
|
|
+ Object infoValue = infoValueSet.get(key);
|
|
|
+ SceneDataObject infoDef = null;
|
|
|
+ for (SceneDataObject infoDefInner : infoList) {
|
|
|
+ String code = (String) infoDefInner.get("code").value_prim.value;
|
|
|
+ if (code.equals(key)) {
|
|
|
+ infoDef = infoDefInner;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String infoName = key;
|
|
|
+ if (infoDef != null) {
|
|
|
+ infoName = (String) infoDef.get("name").value_prim.value;
|
|
|
+ infoValue = ControlUtil.value2CanRead(infoDef, infoValue);
|
|
|
+ }
|
|
|
+ sb.append("[" + infoName + "]" + "设为:" + "[" + infoValue + "]");
|
|
|
+ sb.append(";");
|
|
|
+ }
|
|
|
+ JSONArray success_points = new JSONArray();
|
|
|
+ JSONArray failure_points = new JSONArray();
|
|
|
+ for (int i = 0; i < points.size(); i++) {
|
|
|
+ JSONObject point = points.getJSONObject(i);
|
|
|
+ String status = (String) point.get("status");
|
|
|
+ if (status.equals("finish:success")) {
|
|
|
+ success_points.add(point);
|
|
|
+ } else {
|
|
|
+ failure_points.add(point);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sb.append("控制结果:" + points.size() + "个控制指令" + (success_points.size() > 0 ? ("," + success_points.size() + "个成功") : "")
|
|
|
+ + (failure_points.size() > 0 ? ("," + failure_points.size() + "个失败") : ""));
|
|
|
+ postParam.put("operateDetail", "【" + belongSystem + "】:" + objName + "-" + sb.toString());
|
|
|
+ postParam.put("sourceType", 1);
|
|
|
+ }
|
|
|
+ saveOperationLog(postParam);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- public static void saveBatchOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points,
|
|
|
- String controlReason, RepositoryImpl Repository) {
|
|
|
- try {
|
|
|
- JSONArray postParamArray = new JSONArray();
|
|
|
- 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);
|
|
|
- if (userId != null) {
|
|
|
- postParam.put("userId", userId);
|
|
|
- }
|
|
|
- if (userName != null) {
|
|
|
- postParam.put("userName", userName);
|
|
|
- }
|
|
|
- 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;
|
|
|
- Object localId = sdo.get("localId").value_prim.value;
|
|
|
- Object systemCode = sdo.get("ibmsSceneCode").value_prim.value;
|
|
|
- String classCode = (String) sdo.get("classCode").value_prim.value;
|
|
|
- Object belongSystem = sdo.get("所属场景").value_prim.value;
|
|
|
- List<SceneDataObject> infoList = RepositoryContainer.instance.infoArrayDic.get(classCode).set;
|
|
|
- postParam.put("objType", objType);
|
|
|
- postParam.put("objName", objName);
|
|
|
- postParam.put("localId", localId);
|
|
|
- postParam.put("systemCode", systemCode);
|
|
|
- postParam.put("systemName", belongSystem);
|
|
|
- postParam.put("classCode", classCode);
|
|
|
- postParam.put("functionType", "remoteControl");
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- for (String key : infoValueSet.keySet()) {
|
|
|
- Object infoValue = infoValueSet.get(key);
|
|
|
- SceneDataObject infoDef = null;
|
|
|
- for (SceneDataObject infoDefInner : infoList) {
|
|
|
- String code = (String) infoDefInner.get("code").value_prim.value;
|
|
|
- if (code.equals(key)) {
|
|
|
- infoDef = infoDefInner;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- String infoName = key;
|
|
|
- if (infoDef != null) {
|
|
|
- infoName = (String) infoDef.get("name").value_prim.value;
|
|
|
- infoValue = ControlUtil.value2CanRead(infoDef, infoValue);
|
|
|
- }
|
|
|
- sb.append("[" + infoName + "]" + "设为:" + "[" + infoValue + "]");
|
|
|
- sb.append(";");
|
|
|
- if(controlReason!=null&&!controlReason.isEmpty())
|
|
|
- {
|
|
|
- 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);
|
|
|
- String objInfoValue = (String) obj.get(key);
|
|
|
- if (objInfoValue != null && objInfoValue.length() > 0) {
|
|
|
- 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();
|
|
|
- String status = (String) point.get("status");
|
|
|
- if (status.equals("finish:success")) {
|
|
|
- sb.append("控制结果:成功;");
|
|
|
- } else {
|
|
|
- sb.append("控制结果:失败;");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for (int j=1;j<=2;j++){
|
|
|
- postParam2=JSONObject.parseObject(postParam.toJSONString());
|
|
|
- if(j==1)
|
|
|
- {
|
|
|
- postParam2.put("operateDetail", "【" + belongSystem + "】:" + objName + "-" + sb.toString());
|
|
|
- postParam2.put("sourceType", j);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- postParam2.put("operateDetail", sb.toString());
|
|
|
- postParam2.put("sourceType", j);
|
|
|
- }
|
|
|
- postParamArray.add(postParam2);
|
|
|
- }
|
|
|
- }
|
|
|
- saveBatchOperationLog(postParamArray);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
+ public static void saveBatchOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points,
|
|
|
+ String controlReason, RepositoryImpl Repository) {
|
|
|
+ try {
|
|
|
+ JSONArray postParamArray = new JSONArray();
|
|
|
+ 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);
|
|
|
+ if (userId != null) {
|
|
|
+ postParam.put("userId", userId);
|
|
|
+ }
|
|
|
+ if (userName != null) {
|
|
|
+ postParam.put("userName", userName);
|
|
|
+ }
|
|
|
+ SceneDataObject sdo = sdoList.get(i);
|
|
|
+ Object ibmsxianshimingcheng = sdo.get("ibmsxianshimingcheng").value_prim.value;
|
|
|
+ Object ibmsxianshibianma = sdo.get("ibmsxianshibianma").value_prim.value;
|
|
|
+ Object ibmsSceneCode = sdo.get("ibmsSceneCode").value_prim.value;
|
|
|
+ Object ibmsClassCode = sdo.get("ibmsClassCode").value_prim.value;
|
|
|
+ String classCode = (String) sdo.get("classCode").value_prim.value;
|
|
|
+ Object ibmsSceneName = sdo.get("所属场景").value_prim.value;
|
|
|
+ Object ibmsClassName = sdo.get("对象类型").value_prim.value;
|
|
|
+ List<SceneDataObject> infoList = RepositoryContainer.instance.infoArrayDic.get(classCode).set;
|
|
|
+ postParam.put("deviceName", ibmsxianshimingcheng);
|
|
|
+ postParam.put("deviceCode", ibmsxianshibianma);
|
|
|
+ postParam.put("ibmsSceneCode", ibmsSceneCode);
|
|
|
+ postParam.put("ibmsSceneName", ibmsSceneName);
|
|
|
+ postParam.put("ibmsClassCode", ibmsClassCode);
|
|
|
+ postParam.put("ibmsClassName", ibmsClassName);
|
|
|
+ postParam.put("module", "general");
|
|
|
+ postParam.put("classCode", classCode);
|
|
|
+ postParam.put("systemType", "control");
|
|
|
+// postParam.put("token", "");
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (String key : infoValueSet.keySet()) {
|
|
|
+ Object infoValue = infoValueSet.get(key);
|
|
|
+ SceneDataObject infoDef = null;
|
|
|
+ for (SceneDataObject infoDefInner : infoList) {
|
|
|
+ String code = (String) infoDefInner.get("code").value_prim.value;
|
|
|
+ if (code.equals(key)) {
|
|
|
+ infoDef = infoDefInner;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String infoName = key;
|
|
|
+ if (infoDef != null) {
|
|
|
+ infoName = (String) infoDef.get("name").value_prim.value;
|
|
|
+ infoValue = ControlUtil.value2CanRead(infoDef, infoValue);
|
|
|
+ }
|
|
|
+ sb.append("[" + infoName + "]" + "设为:" + "[" + infoValue + "]");
|
|
|
+ sb.append(";");
|
|
|
+ if (controlReason != null && !controlReason.isEmpty()) {
|
|
|
+ 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);
|
|
|
+ String objInfoValue = (String) obj.get(key);
|
|
|
+ if (objInfoValue != null && objInfoValue.length() > 0) {
|
|
|
+ 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();
|
|
|
+ String status = (String) point.get("status");
|
|
|
+ if (status.equals("finish:success")) {
|
|
|
+ sb.append("控制结果:成功;");
|
|
|
+ } else {
|
|
|
+ sb.append("控制结果:失败;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int j = 1; j <= 2; j++) {
|
|
|
+ postParam2 = JSONObject.parseObject(postParam.toJSONString());
|
|
|
+ if (j == 1) {
|
|
|
+ postParam2.put("details", "【" + ibmsSceneName + "】:" + ibmsxianshimingcheng + "-" + sb.toString());
|
|
|
+ postParam2.put("logSource", "user");
|
|
|
+ } else {
|
|
|
+ postParam2.put("details", sb.toString());
|
|
|
+ postParam2.put("logSource", "sys");
|
|
|
+ }
|
|
|
+ postParamArray.add(postParam2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveBatchOperationLog(postParamArray);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- public static Object value2CanRead(SceneDataObject infoDef, Object infoValue) {
|
|
|
- if (infoDef.containsKey("dataSource")) {
|
|
|
- JSONArray dataSource = (JSONArray) infoDef.get("dataSource").value_prim.value;
|
|
|
- for (int i = 0; i < dataSource.size(); i++) {
|
|
|
- JSONObject item = (JSONObject) dataSource.get(i);
|
|
|
- String code = item.getString("code");
|
|
|
- double value1 = Double.parseDouble(infoValue.toString());
|
|
|
- double value2 = Double.parseDouble(code);
|
|
|
- if (value1 == value2) {
|
|
|
- String name = item.getString("name");
|
|
|
- return name;
|
|
|
- }
|
|
|
- }
|
|
|
- return infoValue;
|
|
|
- } else {
|
|
|
- return infoValue;
|
|
|
- }
|
|
|
- }
|
|
|
+ public static Object value2CanRead(SceneDataObject infoDef, Object infoValue) {
|
|
|
+ if (infoDef.containsKey("dataSource")) {
|
|
|
+ JSONArray dataSource = (JSONArray) infoDef.get("dataSource").value_prim.value;
|
|
|
+ for (int i = 0; i < dataSource.size(); i++) {
|
|
|
+ JSONObject item = (JSONObject) dataSource.get(i);
|
|
|
+ String code = item.getString("code");
|
|
|
+ double value1 = Double.parseDouble(infoValue.toString());
|
|
|
+ double value2 = Double.parseDouble(code);
|
|
|
+ if (value1 == value2) {
|
|
|
+ String name = item.getString("name");
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return infoValue;
|
|
|
+ } else {
|
|
|
+ return infoValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- private static void saveOperationLog(JSONObject postParam) throws Exception {
|
|
|
- String post_url = Constant.zkt_control_url + "/operationLog/saveOperationLog";
|
|
|
- String post_result = HttpClientUtil.instance("zkt_control").post(post_url, postParam.toJSONString());
|
|
|
- JSONObject result = JSON.parseObject(post_result);
|
|
|
- log.debug(result.toJSONString());
|
|
|
- }
|
|
|
+ public static void saveOperationLog(JSONObject postParam) throws Exception {
|
|
|
+ String post_url = Constant.zkt_monitor_url + "/operatorLog/save";
|
|
|
+ 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 void saveBatchOperationLog(JSONArray postParam) throws Exception {
|
|
|
- String post_url = Constant.zkt_control_url + "/operationLog/saveBatchOperationLog";
|
|
|
- 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 void saveBatchOperationLog(JSONArray postParam) throws Exception {
|
|
|
+ String post_url = Constant.zkt_monitor_url + "/operatorLog/saveBatch";
|
|
|
+ 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;
|
|
|
- if (object.containsKey("清单")) {
|
|
|
- SceneDataValue list = object.get("清单");
|
|
|
- SceneDataValue detail = object.get("详情");
|
|
|
- result = setInner(Repository, detail, list.value_array.set, infoValueSet, sdoList);
|
|
|
- } else {
|
|
|
- result = setInner(Repository, object, infoValueSet, sdoList);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
+ private static JSONArray set(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, List<SceneDataObject> sdoList)
|
|
|
+ throws Exception {
|
|
|
+ JSONArray result;
|
|
|
+ if (object.containsKey("清单")) {
|
|
|
+ SceneDataValue list = object.get("清单");
|
|
|
+ SceneDataValue detail = object.get("详情");
|
|
|
+ result = setInner(Repository, detail, list.value_array.set, infoValueSet, sdoList);
|
|
|
+ } else {
|
|
|
+ result = setInner(Repository, object, infoValueSet, sdoList);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
- JSONArray result = post(points);
|
|
|
- return result;
|
|
|
- }
|
|
|
+ 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);
|
|
|
+ JSONArray result = post(points);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- private static JSONArray setInner(RepositoryImpl Repository, SceneDataValue detail, List<SceneDataObject> objectArray, JSONObject infoValueSet,
|
|
|
- List<SceneDataObject> sdoList) throws Exception {
|
|
|
- if (detail != null) {
|
|
|
- build_object(detail.value_object, infoValueSet);
|
|
|
- }
|
|
|
- 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);
|
|
|
- }
|
|
|
- JSONArray result = post(points);
|
|
|
- return result;
|
|
|
- }
|
|
|
+ private static JSONArray setInner(RepositoryImpl Repository, SceneDataValue detail, List<SceneDataObject> objectArray, JSONObject infoValueSet,
|
|
|
+ List<SceneDataObject> sdoList) throws Exception {
|
|
|
+ if (detail != null) {
|
|
|
+ build_object(detail.value_object, infoValueSet);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ JSONArray result = post(points);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- private static void build_points(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, JSONArray points) {
|
|
|
- String id = (String) object.get("id").value_prim.value;
|
|
|
- JSONObject obj = Repository.id2object.get(id);
|
|
|
- for (String key : infoValueSet.keySet()) {
|
|
|
- String infoValue = (String) obj.get(key);
|
|
|
- if (infoValue != null && infoValue.length() > 0) {
|
|
|
- int index_ = infoValue.lastIndexOf("-");
|
|
|
- String meter = infoValue.substring(0, index_);
|
|
|
- int funcid = Integer.parseInt(infoValue.substring(index_ + 1));
|
|
|
- JSONObject point = new JSONObject();
|
|
|
- if (key.equals("manualAutoSet")) {
|
|
|
- point.put("virtual", true);
|
|
|
- }
|
|
|
- point.put("meter", meter);
|
|
|
- point.put("funcid", funcid);
|
|
|
- point.put("data", infoValueSet.get(key));
|
|
|
- points.add(point);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ private static void build_points(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, JSONArray points) {
|
|
|
+ String id = (String) object.get("id").value_prim.value;
|
|
|
+ JSONObject obj = Repository.id2object.get(id);
|
|
|
+ for (String key : infoValueSet.keySet()) {
|
|
|
+ String infoValue = (String) obj.get(key);
|
|
|
+ if (infoValue != null && infoValue.length() > 0) {
|
|
|
+ int index_ = infoValue.lastIndexOf("-");
|
|
|
+ String meter = infoValue.substring(0, index_);
|
|
|
+ int funcid = Integer.parseInt(infoValue.substring(index_ + 1));
|
|
|
+ JSONObject point = new JSONObject();
|
|
|
+ if (key.equals("manualAutoSet")) {
|
|
|
+ point.put("virtual", true);
|
|
|
+ }
|
|
|
+ point.put("meter", meter);
|
|
|
+ point.put("funcid", funcid);
|
|
|
+ point.put("data", infoValueSet.get(key));
|
|
|
+ points.add(point);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- private static void build_object(SceneDataObject object, JSONObject infoValueSet) {
|
|
|
- for (String key : infoValueSet.keySet()) {
|
|
|
- SceneDataValue sdv = object.get(key);
|
|
|
- if (sdv != null) {
|
|
|
- sdv.value_prim = new SceneDataPrimitive();
|
|
|
- sdv.value_prim.value = infoValueSet.get(key);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ private static void build_object(SceneDataObject object, JSONObject infoValueSet) {
|
|
|
+ for (String key : infoValueSet.keySet()) {
|
|
|
+ SceneDataValue sdv = object.get(key);
|
|
|
+ if (sdv != null) {
|
|
|
+ sdv.value_prim = new SceneDataPrimitive();
|
|
|
+ sdv.value_prim.value = infoValueSet.get(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- private static JSONArray post(JSONArray points) throws Exception {
|
|
|
- JSONObject postJSON = new JSONObject();
|
|
|
- postJSON.put("building", RepositoryContainer.RepositoryProject.projectId.substring(2));
|
|
|
- postJSON.put("points", points);
|
|
|
- if (Constant.control_mode.equals("sync")) {
|
|
|
- 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");
|
|
|
- log.debug(post_result);
|
|
|
- return result_points;
|
|
|
- } 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");
|
|
|
- for (int i = 0; i < result_points.size(); i++) {
|
|
|
- JSONObject item = result_points.getJSONObject(i);
|
|
|
- String status = item.getString("status");
|
|
|
- if (status.endsWith("start:sent")) {
|
|
|
- item.put("status", "finish:success");
|
|
|
- }else if (status.endsWith("success")) {
|
|
|
- item.put("status", "finish:success");
|
|
|
- }
|
|
|
- }
|
|
|
- log.debug(post_result);
|
|
|
- return result_points;
|
|
|
- }
|
|
|
- }
|
|
|
+ private static JSONArray post(JSONArray points) throws Exception {
|
|
|
+ JSONObject postJSON = new JSONObject();
|
|
|
+ postJSON.put("building", RepositoryContainer.RepositoryProject.projectId.substring(2));
|
|
|
+ postJSON.put("points", points);
|
|
|
+ if (Constant.control_mode.equals("sync")) {
|
|
|
+ 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");
|
|
|
+ log.debug(post_result);
|
|
|
+ return result_points;
|
|
|
+ } 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");
|
|
|
+ for (int i = 0; i < result_points.size(); i++) {
|
|
|
+ JSONObject item = result_points.getJSONObject(i);
|
|
|
+ String status = item.getString("status");
|
|
|
+ if (status.endsWith("start:sent")) {
|
|
|
+ item.put("status", "finish:success");
|
|
|
+ } else if (status.endsWith("success")) {
|
|
|
+ item.put("status", "finish:success");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.debug(post_result);
|
|
|
+ return result_points;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|