浏览代码

适配恒河和pas300驱动,修改opcda手动停止机制

zhoupeng 2 年之前
父节点
当前提交
73cdbdc4f1

+ 2 - 1
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/enums/OpcDaDriverEnum.java

@@ -5,7 +5,8 @@ public enum OpcDaDriverEnum {
     OPCIFIX("3C5702A2-EB8E-11D4-83A4-00105A984CBD"),
     OPCIFIX("3C5702A2-EB8E-11D4-83A4-00105A984CBD"),
     WINCC("75D00BBB-DDA5-11D1-B944-9E614D000000"),
     WINCC("75D00BBB-DDA5-11D1-B944-9E614D000000"),
     SCADA("04524449-C6B2-4D62-8471-C64FA1DDF64F"),
     SCADA("04524449-C6B2-4D62-8471-C64FA1DDF64F"),
-    YOKOGAWA("E6C32641-F1CF-11D0-B0E4-080009CCD384");
+    YOKOGAWA("E6C32641-F1CF-11D0-B0E4-080009CCD384"),
+    PAS300("4EA2713D-CA07-11D4-BEF5-00002120DB5E");
 
 
     private String value;
     private String value;
 
 

+ 2 - 2
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/annotation/PermissionControlAspect.java

@@ -99,8 +99,8 @@ public class PermissionControlAspect {
                 for (int i = 0; i < keys.length; i++) {
                 for (int i = 0; i < keys.length; i++) {
                     params.put(keys[i], args[i]);
                     params.put(keys[i], args[i]);
                 }
                 }
-                log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
-                log.info("请求的参数有: {}", params.toString());
+//                log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
+//                log.info("请求的参数有: {}", params.toString());
                 return joinPoint.proceed();
                 return joinPoint.proceed();
             }
             }
         }
         }

+ 4 - 4
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/annotation/WebLogAspect.java

@@ -77,19 +77,19 @@ public class WebLogAspect {
         }
         }
         methodName = declaringTypeName + "." + funcName;
         methodName = declaringTypeName + "." + funcName;
         requestArgs = params.toString();
         requestArgs = params.toString();
-        log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
-        log.info("请求的参数有: {}", params.toString());
+//        log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
+//        log.info("请求的参数有: {}", params.toString());
         return joinPoint.proceed();
         return joinPoint.proceed();
     }
     }
 
 
     @Before(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)")
     @Before(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)")
     public void before(JoinPoint joinPoint) {
     public void before(JoinPoint joinPoint) {
-        System.out.println("Before");
+//        System.out.println("Before");
     }
     }
 
 
     @After(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)")
     @After(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)")
     public void after() {
     public void after() {
-        System.out.println("After");
+//        System.out.println("After");
     }
     }
 
 
     @AfterReturning(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)", returning = "result")
     @AfterReturning(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)", returning = "result")

+ 7 - 3
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcAsyncTask.java

@@ -129,9 +129,13 @@ public class OpcAsyncTask {
                     List<JSONObject> jsonObjectList = OpcDaUtil.generServerTree(server);
                     List<JSONObject> jsonObjectList = OpcDaUtil.generServerTree(server);
                     redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
                     redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
                 } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.WINCC.getValue()) ||
                 } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.WINCC.getValue()) ||
-                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue())) {
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue()) ||
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.YOKOGAWA.getValue())) {
                     List<JSONObject> jsonObjectList = OpcDaUtil.generWinccTree(server);
                     List<JSONObject> jsonObjectList = OpcDaUtil.generWinccTree(server);
                     redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
                     redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
+                } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.PAS300.getValue())) {
+                    List<JSONObject> jsonObjectList = OpcDaUtil.generPAS300Tree(server);
+                    redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
                 } else {
                 } else {
                     log.info("目前未适配此种驱动类型");
                     log.info("目前未适配此种驱动类型");
                 }
                 }
@@ -168,12 +172,12 @@ public class OpcAsyncTask {
         }
         }
     }
     }
 
 
-    public void addEventTable(Integer tableReportId,List<BigDecimal> eventDataValueList, List<String> eventDataValueTimeList){
+    public void addEventTable(Integer tableReportId, List<BigDecimal> eventDataValueList, List<String> eventDataValueTimeList) {
         ReportTable reportTable = reportTableDao.getReportTableById(tableReportId);
         ReportTable reportTable = reportTableDao.getReportTableById(tableReportId);
         String reportTableData = reportTable.getReportTableData();
         String reportTableData = reportTable.getReportTableData();
         JSONObject jsonObject = JSONObject.parseObject(reportTableData);
         JSONObject jsonObject = JSONObject.parseObject(reportTableData);
         JSONArray objects = jsonObject.getJSONArray("tables");
         JSONArray objects = jsonObject.getJSONArray("tables");
-        if (Blank.isEmpty(objects)){
+        if (Blank.isEmpty(objects)) {
             ReportTable reportTable1 = new ReportTable();
             ReportTable reportTable1 = new ReportTable();
             reportTable1.setTableTemplateId(reportTable.getTableTemplateId());
             reportTable1.setTableTemplateId(reportTable.getTableTemplateId());
             reportTable1.setUserId(reportTable.getUserId());
             reportTable1.setUserId(reportTable.getUserId());

+ 7 - 7
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaChangeTask.java

@@ -2,19 +2,19 @@ package com.example.opc_da.task;
 
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.example.opc_common.entity.*;
 import com.example.opc_common.entity.*;
-import com.example.opc_common.enums.ResultEnum;
-import com.example.opc_common.exception.CustomException;
 import com.example.opc_common.util.*;
 import com.example.opc_common.util.*;
 import com.example.opc_da.dao.ItemGroupDao;
 import com.example.opc_da.dao.ItemGroupDao;
 import com.example.opc_da.dao.MessageNoticeDao;
 import com.example.opc_da.dao.MessageNoticeDao;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.RedisUtil;
 import com.example.opc_da.util.RedisUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.openscada.opc.lib.da.Item;
 import org.openscada.opc.lib.da.Item;
 import org.openscada.opc.lib.da.*;
 import org.openscada.opc.lib.da.*;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.*;
 
 
+@Slf4j
 public class OpcDaChangeTask extends TimerTask {
 public class OpcDaChangeTask extends TimerTask {
 
 
     private final RedisUtil redisUtil;
     private final RedisUtil redisUtil;
@@ -73,7 +73,7 @@ public class OpcDaChangeTask extends TimerTask {
                 Integer tableReportId = item.getTableReportId();
                 Integer tableReportId = item.getTableReportId();
                 access.addItem(itemId, new DataCallback() {
                 access.addItem(itemId, new DataCallback() {
                     private Map<String, Object> valueMap;
                     private Map<String, Object> valueMap;
-                    private long timeLong = 0;
+//                    private long timeLong = 0;
 
 
                     @Override
                     @Override
                     public void changed(Item item, ItemState itemState) {
                     public void changed(Item item, ItemState itemState) {
@@ -87,10 +87,10 @@ public class OpcDaChangeTask extends TimerTask {
                             //值对应取值的时间
                             //值对应取值的时间
                             Date time = itemState.getTimestamp().getTime();
                             Date time = itemState.getTimestamp().getTime();
                             long time1 = time.getTime();
                             long time1 = time.getTime();
-                            if (timeLong == time1) {
-                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                            }
-                            timeLong = time1;
+//                            if (timeLong == time1) {
+//                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
+//                            }
+//                            timeLong = time1;
                             //归属时间
                             //归属时间
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);

+ 5 - 5
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaExceedTask.java

@@ -72,7 +72,7 @@ public class OpcDaExceedTask extends TimerTask {
                 Double eventValue = item.getEventValue();
                 Double eventValue = item.getEventValue();
                 Integer tableReportId = item.getTableReportId();
                 Integer tableReportId = item.getTableReportId();
                 access.addItem(itemId, new DataCallback() {
                 access.addItem(itemId, new DataCallback() {
-                    private long timeLong = 0;
+//                    private long timeLong = 0;
 
 
                     @Override
                     @Override
                     public void changed(Item item, ItemState itemState) {
                     public void changed(Item item, ItemState itemState) {
@@ -88,10 +88,10 @@ public class OpcDaExceedTask extends TimerTask {
                             //值对应取值的时间
                             //值对应取值的时间
                             Date time = itemState.getTimestamp().getTime();
                             Date time = itemState.getTimestamp().getTime();
                             long time1 = time.getTime();
                             long time1 = time.getTime();
-                            if (timeLong == time1) {
-                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                            }
-                            timeLong = time1;
+//                            if (timeLong == time1) {
+//                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
+//                            }
+//                            timeLong = time1;
                             //归属时间
                             //归属时间
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);

+ 5 - 5
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaFrequencyTask.java

@@ -71,7 +71,7 @@ public class OpcDaFrequencyTask extends TimerTask {
                 Double eventValue = item.getEventValue();
                 Double eventValue = item.getEventValue();
                 Integer tableReportId = item.getTableReportId();
                 Integer tableReportId = item.getTableReportId();
                 access.addItem(itemId, new DataCallback() {
                 access.addItem(itemId, new DataCallback() {
-                    private long timeLong = 0;
+//                    private long timeLong = 0;
 
 
                     @Override
                     @Override
                     public void changed(Item item, ItemState itemState) {
                     public void changed(Item item, ItemState itemState) {
@@ -85,10 +85,10 @@ public class OpcDaFrequencyTask extends TimerTask {
                             //值对应取值的时间
                             //值对应取值的时间
                             Date time = itemState.getTimestamp().getTime();
                             Date time = itemState.getTimestamp().getTime();
                             long time1 = time.getTime();
                             long time1 = time.getTime();
-                            if (timeLong == time1) {
-                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                            }
-                            timeLong = time1;
+//                            if (timeLong == time1) {
+//                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
+//                            }
+//                            timeLong = time1;
                             //归属时间
                             //归属时间
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);

+ 5 - 7
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaLowseTask.java

@@ -2,8 +2,6 @@ package com.example.opc_da.task;
 
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.example.opc_common.entity.*;
 import com.example.opc_common.entity.*;
-import com.example.opc_common.enums.ResultEnum;
-import com.example.opc_common.exception.CustomException;
 import com.example.opc_common.util.*;
 import com.example.opc_common.util.*;
 import com.example.opc_da.dao.ItemGroupDao;
 import com.example.opc_da.dao.ItemGroupDao;
 import com.example.opc_da.dao.MessageNoticeDao;
 import com.example.opc_da.dao.MessageNoticeDao;
@@ -72,7 +70,7 @@ public class OpcDaLowseTask extends TimerTask {
                 Double eventValue = item.getEventValue();
                 Double eventValue = item.getEventValue();
                 Integer tableReportId = item.getTableReportId();
                 Integer tableReportId = item.getTableReportId();
                 access.addItem(itemId, new DataCallback() {
                 access.addItem(itemId, new DataCallback() {
-                    private long timeLong = 0;
+//                    private long timeLong = 0;
 
 
                     @Override
                     @Override
                     public void changed(Item item, ItemState itemState) {
                     public void changed(Item item, ItemState itemState) {
@@ -88,10 +86,10 @@ public class OpcDaLowseTask extends TimerTask {
                             //值对应取值的时间
                             //值对应取值的时间
                             Date time = itemState.getTimestamp().getTime();
                             Date time = itemState.getTimestamp().getTime();
                             long time1 = time.getTime();
                             long time1 = time.getTime();
-                            if (timeLong == time1) {
-                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                            }
-                            timeLong = time1;
+//                            if (timeLong == time1) {
+//                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
+//                            }
+//                            timeLong = time1;
                             //归属时间
                             //归属时间
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
                             String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);

+ 28 - 3
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/util/OpcDaUtil.java

@@ -187,6 +187,25 @@ public class OpcDaUtil {
         return jsonList;
         return jsonList;
     }
     }
 
 
+    public static List<JSONObject> generPAS300Tree(Server server) throws JIException, UnknownHostException {
+        List<JSONObject> jsonList = new ArrayList<>();
+        //获取服务器下所有ITEM列表,树形展示
+        TreeBrowser treeBrowser = server.getTreeBrowser();
+        Branch browse = treeBrowser.browse();
+        if (Blank.isEmpty(browse)) {
+            return null;
+        }
+        Collection<Leaf> leaves = browse.getLeaves();
+        List<String> leafNameList = new ArrayList<>();
+        if (Blank.isNotEmpty(leaves)) {
+            for (Leaf leaf : leaves) {
+                leafNameList.add(leaf.getName());
+            }
+            Collections.reverse(leafNameList);
+        }
+        return jsonList;
+    }
+
     public static List<JSONObject> recursionServerChildren(Collection<Branch> branchCollection) {
     public static List<JSONObject> recursionServerChildren(Collection<Branch> branchCollection) {
         List<JSONObject> jsonList = new ArrayList<>();
         List<JSONObject> jsonList = new ArrayList<>();
         for (Branch branch : branchCollection) {
         for (Branch branch : branchCollection) {
@@ -266,11 +285,16 @@ public class OpcDaUtil {
 
 
     public static List<Item> genReadNameDa(DataSource dataSource, List<Item> itemList) {
     public static List<Item> genReadNameDa(DataSource dataSource, List<Item> itemList) {
         if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.KEPSERVER.getValue()) ||
         if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.KEPSERVER.getValue()) ||
-                dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue())
+                dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue()) ||
+                dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.PAS300.getValue())
         ) {
         ) {
             for (int i = 0; i < itemList.size(); i++) {
             for (int i = 0; i < itemList.size(); i++) {
                 itemList.get(i).setItemReadName(itemList.get(i).getItemName());
                 itemList.get(i).setItemReadName(itemList.get(i).getItemName());
             }
             }
+        } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.YOKOGAWA.getValue())) {
+            for (int i = 0; i < itemList.size(); i++) {
+                itemList.get(i).setItemReadName(itemList.get(i).getItemName().replace(".", "!"));
+            }
         } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue())) {
         } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue())) {
             for (int i = 0; i < itemList.size(); i++) {
             for (int i = 0; i < itemList.size(); i++) {
                 String itemName = itemList.get(i).getItemName();
                 String itemName = itemList.get(i).getItemName();
@@ -437,14 +461,15 @@ public class OpcDaUtil {
     }
     }
 
 
     public static String genException(String message) {
     public static String genException(String message) {
-        if (Blank.isEmpty(message)){
+        if (Blank.isEmpty(message)) {
             return "";
             return "";
         }
         }
         if (message.contains("0x00000005")) {
         if (message.contains("0x00000005")) {
             return "账号或密码错误";
             return "账号或密码错误";
         } else if (message.contains("0x8001FFFF")) {
         } else if (message.contains("0x8001FFFF")) {
             return "ip连接不可用";
             return "ip连接不可用";
-        } else if (message.contains("Index 16 out of bounds for length 16")) {
+        } else if (message.contains("Index 16 out of bounds for length 16") ||
+                message.contains("java.lang.ArrayIndexOutOfBoundsException: 16")) {
             return "服务未启动";
             return "服务未启动";
         } else if (message.contains("0x80070005")) {
         } else if (message.contains("0x80070005")) {
             return "访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置";
             return "访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置";