yantian yue
2023-10-20 a7c91f14d9a671a5ad1def32e2a88d4938ecba33
OPCUA更新
已修改2个文件
39 ■■■■ 文件已修改
guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/mapper/mapping/OpcuaConfMapper.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java
@@ -51,6 +51,8 @@
    // 客户端实例
    private OpcUaClient client = null;
    public List<OpcuaConfResult> b = null;
    @Autowired
    private ClientRunner clientRunner;
@@ -113,8 +115,6 @@
            return "找不到客户端,操作失败";
        }
//        List<Node> ns = client.getAddressSpace().browse(new NodeId(2, "模拟通道一.模拟设备一")).get();
        // 查询订阅对象,没有则创建
        UaSubscription subscription = null;
        ImmutableList<UaSubscription> subscriptionList = client.getSubscriptionManager().getSubscriptions();
@@ -148,7 +148,7 @@
        // 创建监控项,并且注册变量值改变时候的回调函数
        subscription.createMonitoredItems(TimestampsToReturn.Both, requests, (item, id) -> {
            item.setValueConsumer((i, v) -> {
                handle(i.getReadValueId().getNodeId(), v.getValue());
                handle2(i.getReadValueId().getNodeId(), v.getValue());
            });
        }).get();
@@ -161,13 +161,13 @@
     * @CreateTime 2023年10月13日
     */
    public void handle(NodeId id, Variant value){
    /*public void handle(NodeId id, Variant value){
        long startTime = System.currentTimeMillis();
        OpcuaConfParam opcuaConfParam=new OpcuaConfParam();
        opcuaConfParam.setNode(id.getIdentifier().toString());
        List<OpcuaConfResult> a=opcuaConfController.mylist(opcuaConfParam);
        log.info("数据库访问代码执行时间:" + (System.currentTimeMillis() - startTime) + "毫秒");
        String str1 = id.getIdentifier().toString()+":"+value.getValue().toString();
        try {
            Class<?> clazz = Class.forName(a.get(0).getRModule());
@@ -179,8 +179,34 @@
            e.printStackTrace();
        }
        log.info("代码执行时间:" + (System.currentTimeMillis() - startTime) + "毫秒");
    }*/
    public void handle2(NodeId id, Variant value){
        long sTime = System.currentTimeMillis();
        if (b == null || 0 > b.size()) {
            OpcuaConfParam opcuaConfParam=new OpcuaConfParam();
            opcuaConfParam.setSubscribe(1);
            b=opcuaConfController.mylist(opcuaConfParam);
        }
        log.info("数据库访问代码执行时间:" + (System.currentTimeMillis() - sTime) + "毫秒");
        String str1 = id.getIdentifier().toString()+":"+value.getValue().toString();
        OpcuaConfResult opcuaConfResult = b.stream()
                .filter(customer ->id.getIdentifier().toString().equals(customer.getNode()))
                .findAny()
                .orElse(null);
        try {
            Class<?> clazz = Class.forName(opcuaConfResult.getRModule());
            Method method = clazz.getMethod(opcuaConfResult.getRFunction(), String.class);
            method.invoke(clazz.newInstance(), str1);
        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException |
                 InvocationTargetException e) {
            e.printStackTrace();
        }
        log.info("代码执行时间:" + (System.currentTimeMillis() - sTime) + "毫秒");
    }
    /**
     * @MethodName: write
     * @Description: 变节点量写入
guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/mapper/mapping/OpcuaConfMapper.xml
@@ -29,6 +29,9 @@
        <if test="paramCondition.node != null and paramCondition.node != ''">
            and node like CONCAT('%',#{paramCondition.node},'%')
        </if>
        <if test="paramCondition.subscribe != null and paramCondition.subscribe != ''">
            and subscribe like CONCAT('%',#{paramCondition.subscribe},'%')
        </if>
    </select>
    <select id="customMapList" resultType="map" parameterType="cn.stylefeng.guns.opcua.model.params.OpcuaConfParam">