春风项目四线(合箱线、总装线)
yyt
2024-01-26 ae94cec8409d048bff4e33f48831f68beab557b5
提交 | 用户 | 时间
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     }
91 }