提交 | 用户 | 时间
|
e4c3b0
|
1 |
package com.jcdm.main.da.opcuaconfig.cert; |
Y |
2 |
|
|
3 |
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
|
4 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
|
5 |
import com.jcdm.main.da.opcuaconfig.client.ClientHandler; |
|
6 |
import com.jcdm.main.da.opcuaconfig.domain.NodeEntity; |
|
7 |
import com.jcdm.main.da.opcuaconfig.init.BeanUtils; |
|
8 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
4c41b4
|
9 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
01cb63
|
10 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
Y |
11 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
e4c3b0
|
12 |
import lombok.extern.slf4j.Slf4j; |
Y |
13 |
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; |
|
14 |
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; |
|
15 |
|
01cb63
|
16 |
import java.time.Duration; |
e4c3b0
|
17 |
import java.util.*; |
Y |
18 |
import java.util.stream.Collectors; |
|
19 |
|
|
20 |
import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues; |
|
21 |
|
|
22 |
@Slf4j |
|
23 |
public class MethodName { |
|
24 |
private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class); |
4c41b4
|
25 |
private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class); |
01cb63
|
26 |
private IDaPassingStationCollectionService daPassingStationCollectionService = BeanUtils.getBean(IDaPassingStationCollectionService.class); |
4c41b4
|
27 |
private List<DataValue> s=null; |
e4c3b0
|
28 |
public void getSn(String Node, String value) throws Exception { |
Y |
29 |
log.info(Node+":"+value); |
|
30 |
String[] parts = Node.split("[.]"); |
|
31 |
ClientHandler clientHandler=new ClientHandler(); |
01cb63
|
32 |
NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build(); |
Y |
33 |
String SNCode=clientHandler.read(SN_node); |
|
34 |
log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode); |
e4c3b0
|
35 |
switch (value) { |
Y |
36 |
case "0": //初始 |
|
37 |
NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build(); |
|
38 |
Boolean out=clientHandler.write(node); |
|
39 |
log.info("节点:{},响应结果:{}", node.getIdentifier(),out); |
|
40 |
break; |
|
41 |
case "1": //请求下发进站状态 |
|
42 |
NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build(); |
|
43 |
Boolean out1=clientHandler.write(node1); |
01cb63
|
44 |
DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
Y |
45 |
PassingStationCollection.setSfcCode(SNCode); |
|
46 |
PassingStationCollection.setLocationCode(parts[1]); |
|
47 |
PassingStationCollection.setInboundTime(new Date()); |
|
48 |
daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection); |
e4c3b0
|
49 |
log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1); |
Y |
50 |
break; |
|
51 |
case "2": //请求记录工位数据 |
|
52 |
List<DaCollectionParamConf> b; |
|
53 |
DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); |
01cb63
|
54 |
daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]); |
e4c3b0
|
55 |
b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
4c41b4
|
56 |
|
Y |
57 |
List<NodeId> nodeId = b.stream().map(info -> { |
01cb63
|
58 |
NodeId nodeid = new NodeId(2,info.getGatherAddress()); |
4c41b4
|
59 |
return nodeid; |
Y |
60 |
}).collect(Collectors.toList()); |
|
61 |
List<DataValue> s=readValues(nodeId); |
01cb63
|
62 |
//保存PLC采集数据 |
4c41b4
|
63 |
for(int i=0;i<nodeId.size();i++) |
Y |
64 |
{ |
|
65 |
DaParamCollection Config=new DaParamCollection(); |
|
66 |
Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]); |
|
67 |
Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]); |
|
68 |
Config.setParamValue(s.get(i).getValue().getValue().toString()); |
01cb63
|
69 |
Config.setSfcCode(SNCode); |
Y |
70 |
Config.setParamName(b.get(i).getGatherAddress()); |
4c41b4
|
71 |
daParamCollectionService.insertDaParamCollection(Config); |
Y |
72 |
} |
01cb63
|
73 |
//更新出站时间,计算节拍。 |
Y |
74 |
DaPassingStationCollection PSC=new DaPassingStationCollection(); |
|
75 |
PSC.setSfcCode(SNCode); |
|
76 |
List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC); |
|
77 |
if(LPSC != null && LPSC.size() > 0){ |
|
78 |
LPSC.get(0).setOutboundTime(new Date()); |
|
79 |
LPSC.get(0).setCollectionTime(new Date()); |
|
80 |
LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime()))); |
|
81 |
daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0)); |
|
82 |
} |
|
83 |
//更新PLC节点状态 |
e4c3b0
|
84 |
NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build(); |
Y |
85 |
Boolean out2=clientHandler.write(node2); |
|
86 |
log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2); |
|
87 |
break; |
|
88 |
default: |
|
89 |
break; |
|
90 |
} |
|
91 |
} |
|
92 |
} |