提交 | 用户 | 时间
|
d3409e
|
1 |
package com.jcdm.main.da.opcuaconfig.init; |
懒 |
2 |
|
|
3 |
import com.google.common.collect.Lists; |
|
4 |
import com.jcdm.main.da.opcuaconfig.client.ClientHandler; |
|
5 |
import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig; |
|
6 |
import com.jcdm.main.da.opcuaconfig.domain.NodeEntity; |
|
7 |
import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService; |
|
8 |
import lombok.extern.slf4j.Slf4j; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.boot.CommandLineRunner; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
|
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
@Component |
|
16 |
@Slf4j |
|
17 |
public class OpcusConfigInit implements CommandLineRunner { |
|
18 |
|
|
19 |
@Autowired |
|
20 |
private ClientHandler clientHandler; |
|
21 |
|
|
22 |
@Autowired |
|
23 |
private IDaOpcuaConfigService daOpcuaConfigService; |
|
24 |
|
|
25 |
@Override |
|
26 |
public void run(String... args) throws Exception { |
|
27 |
try { |
|
28 |
DaOpcuaConfig daOpcuaConfig=new DaOpcuaConfig(); |
|
29 |
daOpcuaConfig.setSubscribe("Y"); //设置查询条件,是否订阅状态为Y的所有数据. |
|
30 |
List<DaOpcuaConfig> nodeslist=daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig); |
|
31 |
clientHandler.connect(); |
|
32 |
if (nodeslist != null && nodeslist.size() > 0) { |
|
33 |
List<NodeEntity> NodeList = Lists.transform(nodeslist, (DaOpcuaConfig) -> { |
|
34 |
NodeEntity nodeEntity = new NodeEntity(); |
|
35 |
nodeEntity.setIndex(2); |
|
36 |
nodeEntity.setIdentifier(DaOpcuaConfig.getNode()); |
|
37 |
return nodeEntity; |
|
38 |
}); |
|
39 |
clientHandler.subscribe(NodeList); |
|
40 |
log.info("初始化OPC订阅" + nodeslist.size() + "条!"); |
|
41 |
} |
|
42 |
log.info("系统提示,OPCUA订阅成功!"); |
|
43 |
} catch (Exception e) { |
|
44 |
e.printStackTrace(); |
|
45 |
log.info("系统提示,OPCUA订阅失败!"); |
|
46 |
} |
|
47 |
} |
|
48 |
} |