春风项目四线(合箱线、总装线)
yyt
2024-02-17 f7a99591d83efd59af37b257e30d12f10291f4ef
提交 | 用户 | 时间
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 {
e4c3b0 28         log.info(Node+":"+value);
Y 29         String[] parts = Node.split("[.]");
30         ClientHandler clientHandler=new ClientHandler();
01cb63 31         NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
Y 32         String SNCode=clientHandler.read(SN_node);
33         log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode);
e4c3b0 34         switch (value) {
Y 35             case "0":   //初始
36                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build();
37                 Boolean out=clientHandler.write(node);
38                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
39                 break;
40             case "1":   //请求下发进站状态
41                 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build();
42                 Boolean out1=clientHandler.write(node1);
01cb63 43                 DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
Y 44                 PassingStationCollection.setSfcCode(SNCode);
45                 PassingStationCollection.setLocationCode(parts[1]);
46                 PassingStationCollection.setInboundTime(new Date());
47                 daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
e4c3b0 48                 log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
Y 49                 break;
50             case "2":   //请求记录工位数据
51                 List<DaCollectionParamConf> b;
52                 DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
01cb63 53                 daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
e4c3b0 54                 b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
4c41b4 55
Y 56                 List<NodeId> nodeId = b.stream().map(info -> {
01cb63 57                     NodeId nodeid = new NodeId(2,info.getGatherAddress());
4c41b4 58                     return nodeid;
Y 59                 }).collect(Collectors.toList());
60                 List<DataValue> s=readValues(nodeId);
01cb63 61                 //保存PLC采集数据
4c41b4 62                 for(int i=0;i<nodeId.size();i++)
Y 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());
01cb63 68                     Config.setSfcCode(SNCode);
Y 69                     Config.setParamName(b.get(i).getGatherAddress());
4c41b4 70                     daParamCollectionService.insertDaParamCollection(Config);
Y 71                 }
01cb63 72                 //更新出站时间,计算节拍。
Y 73                 DaPassingStationCollection PSC=new DaPassingStationCollection();
74                 PSC.setSfcCode(SNCode);
75                 List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
76                 if(LPSC != null && LPSC.size() > 0){
77                     LPSC.get(0).setOutboundTime(new Date());
78                     LPSC.get(0).setCollectionTime(new Date());
79                     LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
80                     daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
81                 }
82                 //更新PLC节点状态
e4c3b0 83                 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build();
Y 84                 Boolean out2=clientHandler.write(node2);
85                 log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2);
86                 break;
87             default:
88                 break;
89         }
90     }
f7a995 91
Y 92     public void SNRetrieval(String Node, String value) throws Exception {
93         String[] parts = Node.split("[.]");
94         if(value=="1") {
95             //SN号检索
96             ClientHandler clientHandler=new ClientHandler();
97             NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
98             String SNCode=clientHandler.read(SN_node);
99
100             String a=daPassingStationCollectionService.SelectSN(SNCode);
101
102             // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件)
103             NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".CodeCheckFeed").value(a).type("short").build();
104             Boolean out1=clientHandler.write(node1);
105             DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
106             PassingStationCollection.setSfcCode(SNCode);
107             PassingStationCollection.setLocationCode(parts[1]);
108             PassingStationCollection.setInboundTime(new Date());
109             daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
110         }
111     }
112     public void SaveData(String Node, String value) throws Exception {
113         String[] parts = Node.split("[.]");
114         if(value=="1") {
115             //采集数据最终保存
116             ClientHandler clientHandler=new ClientHandler();
117             NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
118             String SNCode=clientHandler.read(SN_node);
119             List<DaCollectionParamConf> b;
120             DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
121             daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
122             b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
123
124             List<NodeId> nodeId = b.stream().map(info -> {
125                 NodeId nodeid = new NodeId(2,info.getGatherAddress());
126                 return nodeid;
127             }).collect(Collectors.toList());
128             List<DataValue> s=readValues(nodeId);
129             //保存PLC采集数据
130             for(int i=0;i<nodeId.size();i++)
131             {
132                 DaParamCollection Config=new DaParamCollection();
133                 Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
134                 Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
135                 Config.setParamValue(s.get(i).getValue().getValue().toString());
136                 Config.setSfcCode(SNCode);
137                 Config.setParamName(b.get(i).getGatherAddress());
138                 daParamCollectionService.insertDaParamCollection(Config);
139             }
140             //更新出站时间,计算节拍。
141             DaPassingStationCollection PSC=new DaPassingStationCollection();
142             PSC.setSfcCode(SNCode);
143             List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
144             if(LPSC != null && LPSC.size() > 0){
145                 LPSC.get(0).setOutboundTime(new Date());
146                 LPSC.get(0).setCollectionTime(new Date());
147                 LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
148                 daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
149             }
150             //请求最终保存反馈:1 保存完成 2 保存失败 3 保存失败,数据位超长
151             NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SaveFeedLast").value("1").type("short").build();
152             Boolean out1=clientHandler.write(node1);
153         }
154     }
e4c3b0 155 }