懒羊羊
2024-01-26 49138a936668c30fbb4063e5d0bb518a400e6c39
提交 | 用户 | 时间
d3409e 1 package com.jcdm.main.da.opcuaconfig.cert;
2
49138a 3 import com.jcdm.framework.websocket.WebSocketServer;
4 import com.jcdm.framework.websocket.WebSocketUsers;
d3409e 5 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
6 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
7 import com.jcdm.main.da.opcuaconfig.client.ClientHandler;
8 import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
9 import com.jcdm.main.da.opcuaconfig.init.BeanUtils;
10 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
11 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
12 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
13 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
14 import lombok.extern.slf4j.Slf4j;
15 import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
16 import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
17
49138a 18 import javax.websocket.Session;
d3409e 19 import java.util.Date;
20 import java.util.List;
49138a 21 import java.util.Map;
d3409e 22 import java.util.stream.Collectors;
23
24 import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues;
25
26 @Slf4j
27 public class MethodName {
49138a 28     Map<String, Session> map = WebSocketUsers.getUsers();
d3409e 29     private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class);
30     private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class);
31     private IDaPassingStationCollectionService daPassingStationCollectionService = BeanUtils.getBean(IDaPassingStationCollectionService.class);
32     private List<DataValue> s=null;
9e8be0 33     public void Transit(String Node, String value) throws Exception {
d3409e 34         log.info(Node+":"+value);
35         String[] parts = Node.split("[.]");
36         ClientHandler clientHandler=new ClientHandler();
37         NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
38         String SNCode=clientHandler.read(SN_node);
39         log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode);
40         switch (value) {
41             case "0":   //初始
42                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build();
43                 Boolean out=clientHandler.write(node);
44                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
45                 break;
46             case "1":   //请求下发进站状态
47                 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build();
48                 Boolean out1=clientHandler.write(node1);
49                 DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
50                 PassingStationCollection.setSfcCode(SNCode);
51                 PassingStationCollection.setLocationCode(parts[1]);
52                 PassingStationCollection.setInboundTime(new Date());
53                 daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
54                 log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
49138a 55                 WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "IN");
d3409e 56                 break;
57             case "2":   //请求记录工位数据
58                 List<DaCollectionParamConf> b;
59                 DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
60                 daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
61                 b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
62
63                 List<NodeId> nodeId = b.stream().map(info -> {
64                     NodeId nodeid = new NodeId(2,info.getGatherAddress());
65                     return nodeid;
66                 }).collect(Collectors.toList());
67                 List<DataValue> s=readValues(nodeId);
68                 //保存PLC采集数据
69                 for(int i=0;i<nodeId.size();i++)
70                 {
71                     DaParamCollection Config=new DaParamCollection();
72                     Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
73                     Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
74                     Config.setParamValue(s.get(i).getValue().getValue().toString());
75                     Config.setSfcCode(SNCode);
76                     Config.setParamName(b.get(i).getGatherAddress());
77                     daParamCollectionService.insertDaParamCollection(Config);
78                 }
79                 //更新出站时间,计算节拍。
80                 DaPassingStationCollection PSC=new DaPassingStationCollection();
81                 PSC.setSfcCode(SNCode);
82                 List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
83                 if(LPSC != null && LPSC.size() > 0){
84                     LPSC.get(0).setOutboundTime(new Date());
85                     LPSC.get(0).setCollectionTime(new Date());
86                     LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
87                     daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
88                 }
89                 //更新PLC节点状态
90                 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build();
91                 Boolean out2=clientHandler.write(node2);
49138a 92                 WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "OUT");
d3409e 93                 log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2);
94                 break;
95             default:
96                 break;
97         }
98     }
99 }