提交 | 用户 | 时间
|
e4c3b0
|
1 |
package com.jcdm.main.da.opcuaconfig.init; |
Y |
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 |
import java.util.List; |
|
13 |
|
|
14 |
@Component |
|
15 |
@Slf4j |
|
16 |
public class OpcusConfigInit implements CommandLineRunner { |
|
17 |
|
|
18 |
@Autowired |
|
19 |
private ClientHandler clientHandler; |
|
20 |
|
|
21 |
@Autowired |
|
22 |
private IDaOpcuaConfigService daOpcuaConfigService; |
|
23 |
|
|
24 |
@Override |
|
25 |
public void run(String... args) throws Exception { |
|
26 |
try { |
|
27 |
DaOpcuaConfig daOpcuaConfig=new DaOpcuaConfig(); |
f7a995
|
28 |
daOpcuaConfig.setSubscribe("Y"); //设置查询条件,订阅状态的所有数据. |
Y |
29 |
daOpcuaConfig.setState(Long.valueOf("0")); //设置查询条件,正常状态. |
e4c3b0
|
30 |
List<DaOpcuaConfig> nodeslist=daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig); |
Y |
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 |
} |
f0b395
|
41 |
log.info("OPCUA初始化成功,并完成"+ nodeslist.size() +"个节点订阅"); |
e4c3b0
|
42 |
} catch (Exception e) { |
Y |
43 |
e.printStackTrace(); |
|
44 |
log.info("系统提示,OPCUA订阅失败!"); |
|
45 |
} |
|
46 |
} |
|
47 |
} |