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