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