春风项目四线(合箱线、总装线)
yyt
2024-02-17 386e107222d673a1ea2781a03a7b1b1d28212f58
提交 | 用户 | 时间
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);
f0b395 27     public void Transit(String Node, String value) throws Exception {
386e10 28         //log.info(Node+":"+value);
Y 29         String[] parts = Node.split("[.]");
30         ClientHandler clientHandler=new ClientHandler();
31         switch (value) {
32             case "0":   //初始
33                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("0").type("short").build();
34                 Boolean out=clientHandler.write(node);
35                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
36                 break;
37             case "1":   //请求下发进站状态
38                 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("11").type("short").build();
39                 Boolean out1=clientHandler.write(node1);
40                 log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
41                 break;
42             case "2":   //请求记录工位数据
43                 NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
44                 String SNCode=clientHandler.read(SN_node);
45                 log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode);
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);
55
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                 for(int i=0;i<nodeId.size();i++)
63                 {
64                     DaParamCollection Config=new DaParamCollection();
65                     Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
66                     Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
67                     Config.setParamValue(s.get(i).getValue().getValue().toString());
68                     Config.setSfcCode(SNCode);
69                     Config.setParamName(b.get(i).getGatherAddress());
70                     daParamCollectionService.insertDaParamCollection(Config);
71                 }
72                 //记录过站,并计算节拍。
73                 DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
74                 PassingStationCollection.setSfcCode(SNCode);
75                 PassingStationCollection.setLocationCode(parts[1]);
76                 PassingStationCollection.setInboundTime(new Date());
77                 PassingStationCollection.setOutboundTime(new Date());
78                 PassingStationCollection.setCollectionTime(new Date());
79                 PassingStationCollection.setBeatTime("56");
80                 daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
81                 //更新PLC节点状态
82                 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("21").type("short").build();
83                 Boolean out2=clientHandler.write(node2);
84                 log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2);
85                 break;
86             default:
87                 break;
88         }
89     }
90
91     public void Transit2(String Node, String value) throws Exception {
e4c3b0 92         log.info(Node+":"+value);
Y 93         String[] parts = Node.split("[.]");
94         ClientHandler clientHandler=new ClientHandler();
01cb63 95         NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
Y 96         String SNCode=clientHandler.read(SN_node);
97         log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode);
e4c3b0 98         switch (value) {
Y 99             case "0":   //初始
386e10 100                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("0").type("short").build();
e4c3b0 101                 Boolean out=clientHandler.write(node);
Y 102                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
103                 break;
104             case "1":   //请求下发进站状态
386e10 105                 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("11").type("short").build();
e4c3b0 106                 Boolean out1=clientHandler.write(node1);
01cb63 107                 DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
Y 108                 PassingStationCollection.setSfcCode(SNCode);
109                 PassingStationCollection.setLocationCode(parts[1]);
110                 PassingStationCollection.setInboundTime(new Date());
111                 daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
e4c3b0 112                 log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
Y 113                 break;
114             case "2":   //请求记录工位数据
115                 List<DaCollectionParamConf> b;
116                 DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
01cb63 117                 daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
e4c3b0 118                 b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
4c41b4 119
Y 120                 List<NodeId> nodeId = b.stream().map(info -> {
01cb63 121                     NodeId nodeid = new NodeId(2,info.getGatherAddress());
4c41b4 122                     return nodeid;
Y 123                 }).collect(Collectors.toList());
124                 List<DataValue> s=readValues(nodeId);
01cb63 125                 //保存PLC采集数据
4c41b4 126                 for(int i=0;i<nodeId.size();i++)
Y 127                 {
128                     DaParamCollection Config=new DaParamCollection();
129                     Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
130                     Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
131                     Config.setParamValue(s.get(i).getValue().getValue().toString());
01cb63 132                     Config.setSfcCode(SNCode);
Y 133                     Config.setParamName(b.get(i).getGatherAddress());
4c41b4 134                     daParamCollectionService.insertDaParamCollection(Config);
Y 135                 }
01cb63 136                 //更新出站时间,计算节拍。
Y 137                 DaPassingStationCollection PSC=new DaPassingStationCollection();
138                 PSC.setSfcCode(SNCode);
139                 List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
140                 if(LPSC != null && LPSC.size() > 0){
141                     LPSC.get(0).setOutboundTime(new Date());
142                     LPSC.get(0).setCollectionTime(new Date());
143                     LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
144                     daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
145                 }
146                 //更新PLC节点状态
386e10 147                 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("21").type("short").build();
e4c3b0 148                 Boolean out2=clientHandler.write(node2);
Y 149                 log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2);
150                 break;
151             default:
152                 break;
153         }
154     }
f7a995 155
Y 156     public void SNRetrieval(String Node, String value) throws Exception {
157         String[] parts = Node.split("[.]");
158         if(value=="1") {
159             //SN号检索
160             ClientHandler clientHandler=new ClientHandler();
161             NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
162             String SNCode=clientHandler.read(SN_node);
163
164             String a=daPassingStationCollectionService.SelectSN(SNCode);
165
166             // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件)
167             NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".CodeCheckFeed").value(a).type("short").build();
168             Boolean out1=clientHandler.write(node1);
169             DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
170             PassingStationCollection.setSfcCode(SNCode);
171             PassingStationCollection.setLocationCode(parts[1]);
172             PassingStationCollection.setInboundTime(new Date());
173             daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
174         }
175     }
176     public void SaveData(String Node, String value) throws Exception {
177         String[] parts = Node.split("[.]");
178         if(value=="1") {
179             //采集数据最终保存
180             ClientHandler clientHandler=new ClientHandler();
181             NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
182             String SNCode=clientHandler.read(SN_node);
183             List<DaCollectionParamConf> b;
184             DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
185             daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
186             b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
187
188             List<NodeId> nodeId = b.stream().map(info -> {
189                 NodeId nodeid = new NodeId(2,info.getGatherAddress());
190                 return nodeid;
191             }).collect(Collectors.toList());
192             List<DataValue> s=readValues(nodeId);
193             //保存PLC采集数据
194             for(int i=0;i<nodeId.size();i++)
195             {
196                 DaParamCollection Config=new DaParamCollection();
197                 Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
198                 Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
199                 Config.setParamValue(s.get(i).getValue().getValue().toString());
200                 Config.setSfcCode(SNCode);
201                 Config.setParamName(b.get(i).getGatherAddress());
202                 daParamCollectionService.insertDaParamCollection(Config);
203             }
204             //更新出站时间,计算节拍。
205             DaPassingStationCollection PSC=new DaPassingStationCollection();
206             PSC.setSfcCode(SNCode);
207             List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
208             if(LPSC != null && LPSC.size() > 0){
209                 LPSC.get(0).setOutboundTime(new Date());
210                 LPSC.get(0).setCollectionTime(new Date());
211                 LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
212                 daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
213             }
214             //请求最终保存反馈:1 保存完成 2 保存失败 3 保存失败,数据位超长
215             NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SaveFeedLast").value("1").type("short").build();
216             Boolean out1=clientHandler.write(node1);
217         }
218     }
e4c3b0 219 }