|
@@ -56,9 +56,11 @@ public class OpcDAClient {
|
|
|
* 创建连接
|
|
|
*/
|
|
|
public static void connect() {
|
|
|
+ log.info("获取opc server");
|
|
|
if (server != null && server.getServerState() != null && server.getServerState().getServerState().equals(OPCSERVERSTATE.OPC_STATUS_RUNNING)) {
|
|
|
return;
|
|
|
}
|
|
|
+ log.info("opc server不存在,开始创建");
|
|
|
final ConnectionInformation ci = new ConnectionInformation();
|
|
|
ci.setHost(host);
|
|
|
ci.setDomain(""); // 域 为空
|
|
@@ -136,10 +138,8 @@ public class OpcDAClient {
|
|
|
* @return
|
|
|
*/
|
|
|
public static AddFailedException addGroupList(Map<String, List<RemoteOpc>> listMap) {
|
|
|
- itemArrList = new HashMap<>();
|
|
|
try {
|
|
|
log.info("开始建组...");
|
|
|
- int i = 0;
|
|
|
for (Map.Entry<String, List<RemoteOpc>> entry : listMap.entrySet()) {
|
|
|
Group group = null;
|
|
|
if (!CollectionUtils.isEmpty(groupList)) {
|
|
@@ -151,9 +151,11 @@ public class OpcDAClient {
|
|
|
}
|
|
|
if (group == null) {
|
|
|
group = server.addGroup(entry.getKey() + "");
|
|
|
+ groupList.add(group);
|
|
|
}
|
|
|
} else {
|
|
|
group = server.addGroup(entry.getKey() + "");
|
|
|
+ groupList.add(group);
|
|
|
}
|
|
|
|
|
|
List<RemoteOpc> list = entry.getValue();
|
|
@@ -165,9 +167,8 @@ public class OpcDAClient {
|
|
|
Set itemSet = new HashSet(groupItems.values());
|
|
|
Item[] itemArr = new Item[itemSet.size()];
|
|
|
itemSet.toArray(itemArr);
|
|
|
- groupList.add(group);
|
|
|
|
|
|
- List<Item> arrayList = new ArrayList<Item>(Arrays.asList(itemArr));
|
|
|
+ List<Item> arrayList = new ArrayList<>(Arrays.asList(itemArr));
|
|
|
List<Item> oldList = itemArrList.get(entry.getKey() + "");
|
|
|
if (CollectionUtils.isEmpty(oldList)) {// 第一次追加,新增即可
|
|
|
itemArrList.put(entry.getKey() + "", arrayList);
|
|
@@ -175,7 +176,8 @@ public class OpcDAClient {
|
|
|
oldList.addAll(arrayList);
|
|
|
itemArrList.put(entry.getKey() + "", oldList);
|
|
|
}
|
|
|
- log.info("组建完成,开始查询数据...,分组数量:" + i);
|
|
|
+ log.info("组建完成,开始查询数据...,组key:" + group.getName() + ", 组数量:" + itemArrList.get(entry.getKey() + "").size());
|
|
|
+
|
|
|
}
|
|
|
} catch (AddFailedException e) {
|
|
|
e.printStackTrace();
|
|
@@ -221,17 +223,22 @@ public class OpcDAClient {
|
|
|
for (Item item : items) {
|
|
|
boolean find = false;
|
|
|
for (RemoteOpc remoteOpc : list) {
|
|
|
- if(item.getId().equals(remoteOpc.getPositionNum())){
|
|
|
- find =true;
|
|
|
+ if (item.getId().equals(remoteOpc.getPositionNum())) {
|
|
|
+ find = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if(!find){
|
|
|
+ if (!find) {
|
|
|
itemResults.add(item);
|
|
|
}
|
|
|
}
|
|
|
log.info("取消前数量:" + items.size());
|
|
|
log.info("取消后数量:" + itemResults.size());
|
|
|
+ // 如果该分组下面没有点位了,则删除该分组
|
|
|
+ if(CollectionUtils.isEmpty(itemResults) || itemResults.size()==0){
|
|
|
+ groupList.remove(group);
|
|
|
+ itemArrList.remove(entry.getKey() + "");
|
|
|
+ }
|
|
|
itemArrList.put(entry.getKey() + "", itemResults);
|
|
|
}
|
|
|
}
|
|
@@ -251,10 +258,14 @@ public class OpcDAClient {
|
|
|
public static List<OpcResult> getItemValuesList() {
|
|
|
List<OpcResult> resultList = new ArrayList<>();
|
|
|
try {
|
|
|
- if (!CollectionUtils.isEmpty(groupList)) {
|
|
|
+ if (!CollectionUtils.isEmpty(groupList) || groupList.size() > 0) {
|
|
|
log.info("数据获取总组数:", groupList.size());
|
|
|
for (int i = 0; i < groupList.size(); i++) {
|
|
|
- Map<Item, ItemState> resultMap = groupList.get(i).read(true, itemArrList.get(groupList.get(i).getName()).toArray(new Item[0]));
|
|
|
+ Group group = groupList.get(i);
|
|
|
+ log.info("获取分组的数据: 组名:" + group.getName());
|
|
|
+ Item[] items = itemArrList.get(groupList.get(i).getName()).toArray(new Item[0]);
|
|
|
+ log.info("获取分组的数据数量:" + items.length);
|
|
|
+ Map<Item, ItemState> resultMap = group.read(true, items);
|
|
|
//log.info("数据获取完成。数量:", resultMap.size() + ", 组序号:" + i);
|
|
|
for (Item item : resultMap.keySet()) {
|
|
|
OpcResult result = new OpcResult();
|