提交 | 用户 | 时间
|
e4c3b0
|
1 |
package com.jcdm.main.da.opcuaconfig.cert; |
Y |
2 |
|
a9406b
|
3 |
import cn.hutool.core.date.StopWatch; |
e4c3b0
|
4 |
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
Y |
5 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
|
6 |
import com.jcdm.main.da.opcuaconfig.client.ClientHandler; |
|
7 |
import com.jcdm.main.da.opcuaconfig.domain.NodeEntity; |
|
8 |
import com.jcdm.main.da.opcuaconfig.init.BeanUtils; |
|
9 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
4c41b4
|
10 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
01cb63
|
11 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
Y |
12 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
e4c3b0
|
13 |
import lombok.extern.slf4j.Slf4j; |
Y |
14 |
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; |
|
15 |
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; |
|
16 |
|
01cb63
|
17 |
import java.time.Duration; |
e4c3b0
|
18 |
import java.util.*; |
Y |
19 |
import java.util.stream.Collectors; |
|
20 |
|
|
21 |
import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues; |
|
22 |
|
|
23 |
@Slf4j |
|
24 |
public class MethodName { |
|
25 |
private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class); |
4c41b4
|
26 |
private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class); |
01cb63
|
27 |
private IDaPassingStationCollectionService daPassingStationCollectionService = BeanUtils.getBean(IDaPassingStationCollectionService.class); |
f0b395
|
28 |
public void Transit(String Node, String value) throws Exception { |
386e10
|
29 |
//log.info(Node+":"+value); |
Y |
30 |
String[] parts = Node.split("[.]"); |
|
31 |
ClientHandler clientHandler=new ClientHandler(); |
|
32 |
switch (value) { |
|
33 |
case "0": //初始 |
|
34 |
NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("0").type("short").build(); |
|
35 |
Boolean out=clientHandler.write(node); |
|
36 |
log.info("节点:{},响应结果:{}", node.getIdentifier(),out); |
|
37 |
break; |
|
38 |
case "1": //请求下发进站状态 |
|
39 |
NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("11").type("short").build(); |
|
40 |
Boolean out1=clientHandler.write(node1); |
|
41 |
log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1); |
|
42 |
break; |
|
43 |
case "2": //请求记录工位数据 |
|
44 |
NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build(); |
|
45 |
String SNCode=clientHandler.read(SN_node); |
|
46 |
if(SNCode==null){ |
|
47 |
NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("22").type("short").build(); |
|
48 |
Boolean out2=clientHandler.write(node2); |
|
49 |
break; |
|
50 |
} |
|
51 |
List<DaCollectionParamConf> b; |
|
52 |
DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); |
|
53 |
daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]); |
|
54 |
b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
a9406b
|
55 |
if(b!=null&&b.size()>0){ |
Y |
56 |
List<NodeId> nodeId = b.stream().map(info -> { |
|
57 |
NodeId nodeid = new NodeId(2,info.getGatherAddress()); |
|
58 |
return nodeid; |
|
59 |
}).collect(Collectors.toList()); |
|
60 |
List<DataValue> s=readValues(nodeId); |
|
61 |
//保存PLC采集数据 |
|
62 |
// StopWatch stopWatch = new StopWatch(); |
|
63 |
// stopWatch.start(); |
220f7b
|
64 |
List<DaParamCollection> ParamCollectionlist = new ArrayList<>(); |
a9406b
|
65 |
for(int i=0;i<nodeId.size();i++){ |
Y |
66 |
DaParamCollection ParamCollection = new DaParamCollection(); |
|
67 |
ParamCollection.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]); |
|
68 |
ParamCollection.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]); |
|
69 |
ParamCollection.setParamValue(s.get(i).getValue().getValue().toString()); |
|
70 |
ParamCollection.setSfcCode(SNCode); |
|
71 |
ParamCollection.setParamName(b.get(i).getGatherAddress()); |
220f7b
|
72 |
ParamCollectionlist.add(ParamCollection); |
a9406b
|
73 |
} |
220f7b
|
74 |
daParamCollectionService.saveBeachDaParamCollection(ParamCollectionlist); |
a9406b
|
75 |
// stopWatch.stop(); |
Y |
76 |
// System.out.println("使用sqlSessionFactory实现批量插入耗时:" + stopWatch.getTotalTimeMillis()); |
386e10
|
77 |
} |
Y |
78 |
//记录过站,并计算节拍。 |
|
79 |
DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
|
80 |
PassingStationCollection.setSfcCode(SNCode); |
|
81 |
PassingStationCollection.setLocationCode(parts[1]); |
|
82 |
PassingStationCollection.setInboundTime(new Date()); |
|
83 |
PassingStationCollection.setOutboundTime(new Date()); |
|
84 |
PassingStationCollection.setCollectionTime(new Date()); |
|
85 |
PassingStationCollection.setBeatTime("56"); |
|
86 |
daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection); |
|
87 |
//更新PLC节点状态 |
|
88 |
NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("21").type("short").build(); |
|
89 |
Boolean out2=clientHandler.write(node2); |
|
90 |
log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2); |
|
91 |
break; |
|
92 |
default: |
|
93 |
break; |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
public void Transit2(String Node, String value) throws Exception { |
e4c3b0
|
98 |
log.info(Node+":"+value); |
Y |
99 |
String[] parts = Node.split("[.]"); |
|
100 |
ClientHandler clientHandler=new ClientHandler(); |
01cb63
|
101 |
NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build(); |
Y |
102 |
String SNCode=clientHandler.read(SN_node); |
|
103 |
log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode); |
e4c3b0
|
104 |
switch (value) { |
Y |
105 |
case "0": //初始 |
386e10
|
106 |
NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("0").type("short").build(); |
e4c3b0
|
107 |
Boolean out=clientHandler.write(node); |
Y |
108 |
log.info("节点:{},响应结果:{}", node.getIdentifier(),out); |
|
109 |
break; |
|
110 |
case "1": //请求下发进站状态 |
386e10
|
111 |
NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("11").type("short").build(); |
e4c3b0
|
112 |
Boolean out1=clientHandler.write(node1); |
01cb63
|
113 |
DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
Y |
114 |
PassingStationCollection.setSfcCode(SNCode); |
|
115 |
PassingStationCollection.setLocationCode(parts[1]); |
|
116 |
PassingStationCollection.setInboundTime(new Date()); |
|
117 |
daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection); |
e4c3b0
|
118 |
log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1); |
Y |
119 |
break; |
|
120 |
case "2": //请求记录工位数据 |
|
121 |
List<DaCollectionParamConf> b; |
|
122 |
DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); |
01cb63
|
123 |
daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]); |
e4c3b0
|
124 |
b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
4c41b4
|
125 |
|
Y |
126 |
List<NodeId> nodeId = b.stream().map(info -> { |
01cb63
|
127 |
NodeId nodeid = new NodeId(2,info.getGatherAddress()); |
4c41b4
|
128 |
return nodeid; |
Y |
129 |
}).collect(Collectors.toList()); |
|
130 |
List<DataValue> s=readValues(nodeId); |
01cb63
|
131 |
//保存PLC采集数据 |
4c41b4
|
132 |
for(int i=0;i<nodeId.size();i++) |
Y |
133 |
{ |
|
134 |
DaParamCollection Config=new DaParamCollection(); |
|
135 |
Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]); |
|
136 |
Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]); |
|
137 |
Config.setParamValue(s.get(i).getValue().getValue().toString()); |
01cb63
|
138 |
Config.setSfcCode(SNCode); |
Y |
139 |
Config.setParamName(b.get(i).getGatherAddress()); |
4c41b4
|
140 |
daParamCollectionService.insertDaParamCollection(Config); |
Y |
141 |
} |
01cb63
|
142 |
//更新出站时间,计算节拍。 |
Y |
143 |
DaPassingStationCollection PSC=new DaPassingStationCollection(); |
|
144 |
PSC.setSfcCode(SNCode); |
|
145 |
List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC); |
|
146 |
if(LPSC != null && LPSC.size() > 0){ |
|
147 |
LPSC.get(0).setOutboundTime(new Date()); |
|
148 |
LPSC.get(0).setCollectionTime(new Date()); |
|
149 |
LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime()))); |
|
150 |
daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0)); |
|
151 |
} |
|
152 |
//更新PLC节点状态 |
386e10
|
153 |
NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("21").type("short").build(); |
e4c3b0
|
154 |
Boolean out2=clientHandler.write(node2); |
Y |
155 |
log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2); |
|
156 |
break; |
|
157 |
default: |
|
158 |
break; |
|
159 |
} |
|
160 |
} |
f7a995
|
161 |
|
Y |
162 |
public void SNRetrieval(String Node, String value) throws Exception { |
|
163 |
String[] parts = Node.split("[.]"); |
|
164 |
if(value=="1") { |
|
165 |
//SN号检索 |
|
166 |
ClientHandler clientHandler=new ClientHandler(); |
|
167 |
NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build(); |
|
168 |
String SNCode=clientHandler.read(SN_node); |
|
169 |
|
|
170 |
String a=daPassingStationCollectionService.SelectSN(SNCode); |
|
171 |
|
|
172 |
// 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件) |
|
173 |
NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".CodeCheckFeed").value(a).type("short").build(); |
|
174 |
Boolean out1=clientHandler.write(node1); |
|
175 |
DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
|
176 |
PassingStationCollection.setSfcCode(SNCode); |
|
177 |
PassingStationCollection.setLocationCode(parts[1]); |
|
178 |
PassingStationCollection.setInboundTime(new Date()); |
|
179 |
daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection); |
|
180 |
} |
|
181 |
} |
|
182 |
public void SaveData(String Node, String value) throws Exception { |
|
183 |
String[] parts = Node.split("[.]"); |
|
184 |
if(value=="1") { |
|
185 |
//采集数据最终保存 |
|
186 |
ClientHandler clientHandler=new ClientHandler(); |
|
187 |
NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build(); |
|
188 |
String SNCode=clientHandler.read(SN_node); |
|
189 |
List<DaCollectionParamConf> b; |
|
190 |
DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); |
|
191 |
daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]); |
|
192 |
b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
|
193 |
|
|
194 |
List<NodeId> nodeId = b.stream().map(info -> { |
|
195 |
NodeId nodeid = new NodeId(2,info.getGatherAddress()); |
|
196 |
return nodeid; |
|
197 |
}).collect(Collectors.toList()); |
|
198 |
List<DataValue> s=readValues(nodeId); |
|
199 |
//保存PLC采集数据 |
|
200 |
for(int i=0;i<nodeId.size();i++) |
|
201 |
{ |
|
202 |
DaParamCollection Config=new DaParamCollection(); |
|
203 |
Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]); |
|
204 |
Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]); |
|
205 |
Config.setParamValue(s.get(i).getValue().getValue().toString()); |
|
206 |
Config.setSfcCode(SNCode); |
|
207 |
Config.setParamName(b.get(i).getGatherAddress()); |
|
208 |
daParamCollectionService.insertDaParamCollection(Config); |
|
209 |
} |
|
210 |
//更新出站时间,计算节拍。 |
|
211 |
DaPassingStationCollection PSC=new DaPassingStationCollection(); |
|
212 |
PSC.setSfcCode(SNCode); |
|
213 |
List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC); |
|
214 |
if(LPSC != null && LPSC.size() > 0){ |
|
215 |
LPSC.get(0).setOutboundTime(new Date()); |
|
216 |
LPSC.get(0).setCollectionTime(new Date()); |
|
217 |
LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime()))); |
|
218 |
daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0)); |
|
219 |
} |
|
220 |
//请求最终保存反馈:1 保存完成 2 保存失败 3 保存失败,数据位超长 |
|
221 |
NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SaveFeedLast").value("1").type("short").build(); |
|
222 |
Boolean out1=clientHandler.write(node1); |
|
223 |
} |
|
224 |
} |
e4c3b0
|
225 |
} |