|
@@ -17,6 +17,7 @@ import org.jinterop.dcom.core.JIVariant;
|
|
|
import org.openscada.opc.dcom.da.OPCSERVERSTATE;
|
|
|
import org.openscada.opc.dcom.list.ClassDetails;
|
|
|
import org.openscada.opc.lib.common.ConnectionInformation;
|
|
|
+import org.openscada.opc.lib.da.AddFailedException;
|
|
|
import org.openscada.opc.lib.da.Group;
|
|
|
import org.openscada.opc.lib.da.ItemState;
|
|
|
import org.openscada.opc.lib.da.Server;
|
|
@@ -253,10 +254,8 @@ public class OpcDaUtil {
|
|
|
}
|
|
|
|
|
|
public static List<JSONObject> opcReadItemListValue(DataSource dataSource, String[] items, List<Item> itemList, Map<String, DataModel> dmMap) {
|
|
|
- Server server = null;
|
|
|
try {
|
|
|
- server = createServer(dataSource);
|
|
|
- server.connect();
|
|
|
+ Server server = getServer(dataSource);
|
|
|
if (null == server.getServerState()) {
|
|
|
throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
|
|
|
}
|
|
@@ -316,19 +315,14 @@ public class OpcDaUtil {
|
|
|
.sorted(Comparator.comparing((JSONObject jsonObject) -> jsonObject.getInteger("eventMode"), Comparator.nullsFirst(Integer::compareTo).reversed())
|
|
|
.thenComparing(jsonObject -> jsonObject.getString("itemName")
|
|
|
)).collect(Collectors.toList());
|
|
|
-// jsonObjectList.stream()
|
|
|
-// .sorted(Comparator.comparing((JSONObject jsonObject) -> jsonObject.getString("itemName"))
|
|
|
-// .thenComparing(jsonObject -> jsonObject.getInteger("eventMode"), Comparator.nullsFirst(Integer::compareTo).reversed()
|
|
|
-// )).collect(Collectors.toList());
|
|
|
return jsonObjectList;
|
|
|
}
|
|
|
+ } catch (AddFailedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "数据项通信异常");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), genException(e.getMessage()));
|
|
|
- } finally {
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -400,37 +394,6 @@ public class OpcDaUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static Result readItemValue(DataSource dataSource, String itemStr) {
|
|
|
- Server server = null;
|
|
|
- try {
|
|
|
- server = createServer(dataSource);
|
|
|
- server.connect();
|
|
|
- if (null == server.getServerState()) {
|
|
|
- throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
|
|
|
- }
|
|
|
- if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
|
|
|
- Group group = server.addGroup();
|
|
|
- org.openscada.opc.lib.da.Item item = group.addItem(itemStr);
|
|
|
- Map<org.openscada.opc.lib.da.Item, ItemState> read = group.read(true, item);
|
|
|
- ItemState itemState = read.get(item);
|
|
|
- Map<String, Object> val = getVal(itemState.getValue());
|
|
|
- String javaType = val.get("javaType").toString();
|
|
|
- Object value = val.get("value");
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("javaType", javaType);
|
|
|
- map.put("value", value);
|
|
|
- return Result.ok(map);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), genException(e.getMessage()));
|
|
|
- } finally {
|
|
|
- if (Blank.isNotEmpty(server)) {
|
|
|
- server.dispose();
|
|
|
- }
|
|
|
- }
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
- }
|
|
|
-
|
|
|
public static Result getNextAllItem(DataSource dataSource, String itemStr) {
|
|
|
try {
|
|
|
Server server = getServer(dataSource);
|
|
@@ -453,36 +416,6 @@ public class OpcDaUtil {
|
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
}
|
|
|
|
|
|
-// public static JSONObject getNextItem(TreeBrowser treeBrowser, String itemStr) {
|
|
|
-// if (Blank.isEmpty(itemStr)) {
|
|
|
-// return browserTree(treeBrowser, new Branch());
|
|
|
-// } else {
|
|
|
-// JSONObject jsonObject = new JSONObject();
|
|
|
-// String[] split = itemStr.split("!@");
|
|
|
-// Branch branch = new Branch();
|
|
|
-// List<Branch> branchList = getBranch(treeBrowser, branch);
|
|
|
-// for (int i = 0; i < split.length; i++) {
|
|
|
-// String itemId = split[i];
|
|
|
-// if (i == split.length - 1) {
|
|
|
-// for (Branch branch1 : branchList) {
|
|
|
-// if (itemId.equals(branch1.getName())) {
|
|
|
-// jsonObject = browserTree(treeBrowser, branch1);
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// for (Branch branch1 : branchList) {
|
|
|
-// if (itemId.equals(branch1.getName())) {
|
|
|
-// branchList = getBranch(treeBrowser, branch1);
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return jsonObject;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 优化之后获取下级节点
|
|
|
*
|
|
@@ -509,31 +442,6 @@ public class OpcDaUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static List<Branch> getBranch(TreeBrowser treeBrowser, Branch branch) {
|
|
|
- try {
|
|
|
- treeBrowser.fillBranches(branch);
|
|
|
- } catch (Exception ignored) {
|
|
|
- }
|
|
|
- try {
|
|
|
- treeBrowser.fillLeaves(branch);
|
|
|
- } catch (Exception ignored) {
|
|
|
- }
|
|
|
-// Iterator iter = branch.getLeaves().iterator();
|
|
|
-// while (iter.hasNext()) {
|
|
|
-// Leaf leaf = (Leaf) iter.next();
|
|
|
-// //key是leaf.getName(),value是leaf.getItemId()
|
|
|
-// tree.addTree(new MapTree(leaf.getName(), leaf.getItemId()));
|
|
|
-// //this.itemList.put(leaf.getName(),leaf.getItemId())
|
|
|
-// }
|
|
|
- Iterator iter = branch.getBranches().iterator();
|
|
|
- List<Branch> branchList = new ArrayList<>();
|
|
|
- while (iter.hasNext()) {
|
|
|
- branch = (Branch) iter.next();
|
|
|
- branchList.add(branch);
|
|
|
- }
|
|
|
- return branchList;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 通过上一级,获取下一次的所有item
|
|
|
*
|