|
@@ -1,8 +1,10 @@
|
|
|
package com.platform.opc.util;
|
|
|
|
|
|
+import com.platform.common.util.DateUtils;
|
|
|
import com.platform.common.util.RedisUtils;
|
|
|
import com.platform.dao.entity.remote.RemoteOpc;
|
|
|
import com.platform.dao.vo.SysUserVO;
|
|
|
+import com.platform.opc.entity.OpcResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jinterop.dcom.common.JIErrorCodes;
|
|
|
import org.jinterop.dcom.common.JIException;
|
|
@@ -16,6 +18,8 @@ import org.openscada.opc.lib.da.browser.FlatBrowser;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -213,23 +217,22 @@ public class OpcDAClient {
|
|
|
|
|
|
/**
|
|
|
* 获取多组数据
|
|
|
- *
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<Map<String, Object>> getItemValuesList() {
|
|
|
- List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
+ /*public static List<Map<String, String>> getItemValuesList() {
|
|
|
+ List<Map<String, String>> resultList = new ArrayList<>();
|
|
|
try {
|
|
|
if (!CollectionUtils.isEmpty(groupItemsList)) {
|
|
|
log.info("数据获取总组数:", groupItemsList.size());
|
|
|
for (int i = 0; i < groupItemsList.size(); i++) {
|
|
|
Map<Item, ItemState> resultMap = groupList.get(i).read(true, itemArrList[i]);
|
|
|
log.info("数据获取完成。数量:", resultMap.size() + ", 组序号:" + i);
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
for (Item item : resultMap.keySet()) {
|
|
|
ItemState itemMap = resultMap.get(item);
|
|
|
- Object value = getVal(itemMap.getValue());
|
|
|
+ String value = getVal(itemMap.getValue());
|
|
|
result.put(item.getId(), value);
|
|
|
- log.info("id: " + item.getId() + ", value: " + value);
|
|
|
+ log.info("id: " + item.getId() + ", value: " + value + ", timestamp: " + itemMap.getTimestamp());
|
|
|
}
|
|
|
resultList.add(result);
|
|
|
}
|
|
@@ -239,6 +242,37 @@ public class OpcDAClient {
|
|
|
log.error("批量获取数据异常:", e);
|
|
|
}
|
|
|
return resultList;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取多组数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<OpcResult> getItemValuesList() {
|
|
|
+ List<OpcResult> resultList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ if (!CollectionUtils.isEmpty(groupItemsList)) {
|
|
|
+ log.info("数据获取总组数:", groupItemsList.size());
|
|
|
+ for (int i = 0; i < groupItemsList.size(); i++) {
|
|
|
+ Map<Item, ItemState> resultMap = groupList.get(i).read(true, itemArrList[i]);
|
|
|
+ //log.info("数据获取完成。数量:", resultMap.size() + ", 组序号:" + i);
|
|
|
+ OpcResult result = new OpcResult();
|
|
|
+ for (Item item : resultMap.keySet()) {
|
|
|
+ ItemState itemMap = resultMap.get(item);
|
|
|
+ String value = getVal(itemMap.getValue());
|
|
|
+ result.setId(item.getId());
|
|
|
+ result.setValue(value);
|
|
|
+ result.setTime(DateUtils.dateToString(itemMap.getTimestamp().getTime()));
|
|
|
+ // log.info("id: " + item.getId() + ", value: " + value + ", timestamp: " + itemMap.getTimestamp());
|
|
|
+ resultList.add(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("批量获取数据异常:", e);
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -248,34 +282,34 @@ public class OpcDAClient {
|
|
|
* @return
|
|
|
* @throws JIException
|
|
|
*/
|
|
|
- private static Object getVal(JIVariant var) throws JIException {
|
|
|
- Object value;
|
|
|
+ private static String getVal(JIVariant var) throws JIException {
|
|
|
+ String value;
|
|
|
int type = var.getType();
|
|
|
switch (type) {
|
|
|
case JIVariant.VT_I2:
|
|
|
- value = var.getObjectAsShort();
|
|
|
+ value = var.getObjectAsShort() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_I4:
|
|
|
- value = var.getObjectAsInt();
|
|
|
+ value = var.getObjectAsInt() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_I8:
|
|
|
- value = var.getObjectAsLong();
|
|
|
+ value = var.getObjectAsLong() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_R4:
|
|
|
- value = var.getObjectAsFloat();
|
|
|
+ value = var.getObjectAsFloat() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_R8:
|
|
|
- value = var.getObjectAsDouble();
|
|
|
+ value = var.getObjectAsDouble() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_BSTR:
|
|
|
- value = var.getObjectAsString2();
|
|
|
+ value = var.getObjectAsString2() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_BOOL:
|
|
|
- value = var.getObjectAsBoolean();
|
|
|
+ value = var.getObjectAsBoolean() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_UI2:
|
|
|
case JIVariant.VT_UI4:
|
|
|
- value = var.getObjectAsUnsigned().getValue();
|
|
|
+ value = var.getObjectAsUnsigned().getValue() + "";
|
|
|
break;
|
|
|
case JIVariant.VT_EMPTY:
|
|
|
throw new JIException(JIErrorCodes.JI_VARIANT_IS_NULL, "Variant is Empty.");
|