cl
2024-02-28 26c51e363815011b09411ae74eb8c5f9d2ea8404
提交 | 用户 | 时间
e57a89 1 package com.jcdm.main.da.opcuaconfig.cert;
2
3 import com.jcdm.framework.websocket.WebSocketServer;
4 import com.jcdm.framework.websocket.WebSocketUsers;
5 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
6 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
7 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
8 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
9 import com.jcdm.main.da.opcuaconfig.client.ClientHandler;
10 import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
11 import com.jcdm.main.da.opcuaconfig.init.BeanUtils;
12 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
13 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
14 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
15 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
16 import lombok.extern.slf4j.Slf4j;
17 import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
18 import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
19
20 import javax.websocket.Session;
21 import java.util.Date;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.stream.Collectors;
25
26 import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues;
27
28 @Slf4j
29 public class MethodName {
30     Map<String, Session> map = WebSocketUsers.getUsers();
31     private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class);
32     private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class);
33     private IDaPassingStationCollectionService daPassingStationCollectionService = BeanUtils.getBean(IDaPassingStationCollectionService.class);
34     private IBsFormulaChildInfoService bsFormulaChildInfoService = BeanUtils.getBean(IBsFormulaChildInfoService.class);
35     private List<DataValue> s=null;
36     public void Transit(String Node, String value) throws Exception {
37         log.info(Node+":"+value);
38         String[] parts = Node.split("[.]");
39         ClientHandler clientHandler=new ClientHandler();
40         NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
41         String SNCode=clientHandler.read(SN_node);
42         log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode);
43         switch (value) {
44             case "0":   //初始
45                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build();
46                 Boolean out=clientHandler.write(node);
47                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
48                 break;
49             case "1":   //请求下发进站状态
50                 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build();
51                 Boolean out1=clientHandler.write(node1);
52                 DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
53                 PassingStationCollection.setSfcCode(SNCode);
54                 PassingStationCollection.setLocationCode(parts[1]);
55                 PassingStationCollection.setInboundTime(new Date());
56                 daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
57                 log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
58                 WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "IN");
59                 break;
60             case "2":   //请求记录工位数据
61                 List<DaCollectionParamConf> b;
62                 DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
63                 daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
64                 b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
65
66                 List<NodeId> nodeId = b.stream().map(info -> {
67                     NodeId nodeid = new NodeId(2,info.getGatherAddress());
68                     return nodeid;
69                 }).collect(Collectors.toList());
70                 List<DataValue> s=readValues(nodeId);
71                 //保存PLC采集数据
72                 for(int i=0;i<nodeId.size();i++)
73                 {
74                     DaParamCollection Config=new DaParamCollection();
75                     Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
76                     Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
77                     Config.setParamValue(s.get(i).getValue().getValue().toString());
78                     Config.setSfcCode(SNCode);
79                     Config.setParamName(b.get(i).getGatherAddress());
80                     daParamCollectionService.insertDaParamCollection(Config);
81                 }
82                 //更新出站时间,计算节拍。
83                 DaPassingStationCollection PSC=new DaPassingStationCollection();
84                 PSC.setSfcCode(SNCode);
85                 List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
86                 if(LPSC != null && LPSC.size() > 0){
87                     LPSC.get(0).setOutboundTime(new Date());
88                     LPSC.get(0).setCollectionTime(new Date());
89                     LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
90                     daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
91                 }
92                 //更新PLC节点状态
93                 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build();
94                 Boolean out2=clientHandler.write(node2);
95                 WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "OUT");
96                 log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2);
97                 break;
98             default:
99                 break;
100         }
101     }
102
103     public void tighten(String Node, String value) throws Exception {
104         String[] parts = Node.split("[.]");
105         ClientHandler clientHandler=new ClientHandler();
106         System.out.println("Node:"+Node+"value:"+value);
107         switch (value){
108             case "1":
109                 //读扭矩
110                 NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSN").value("").type("").build();
111                 String SNCode=clientHandler.read(SN_node);
112
113                 //读角度
114                 NodeEntity SNDone= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSNDone").value("").type("").build();
115                 String RecordSNDone = clientHandler.read(SNDone);
116
117                 //读结果
118                 NodeEntity SNDone1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".WorkID").value("").type("").build();
119                 String WorkID = clientHandler.read(SNDone1);
120
121                 //保存参数采集表
122                 DaParamCollection paramCollection = new DaParamCollection();
123                 paramCollection.setLocationCode(parts[1]);
124                 paramCollection.setParamCode("RecordSN");
125                 paramCollection.setParamValue(SNCode);
126                 paramCollection.setParamName(parts[0]+"."+parts[1]+".RecordSN");
127                 daParamCollectionService.insertDaParamCollection(paramCollection);
128
129
130                 DaParamCollection paramCollection1 = new DaParamCollection();
131                 paramCollection1.setLocationCode(parts[1]);
132                 paramCollection1.setParamCode("RecordSNDone");
133                 paramCollection1.setParamValue(RecordSNDone);
134                 paramCollection1.setParamName(parts[0]+"."+parts[1]+".RecordSNDone");
135                 daParamCollectionService.insertDaParamCollection(paramCollection1);
136
137
138
139                 DaParamCollection paramCollection2 = new DaParamCollection();
140                 paramCollection2.setLocationCode(parts[1]);
141                 paramCollection2.setParamCode("WorkID");
142                 paramCollection2.setParamValue(WorkID);
143                 paramCollection2.setParamName(parts[0]+"."+parts[1]+".WorkID");
144                 daParamCollectionService.insertDaParamCollection(paramCollection2);
145
146                 //保存状态更新前端表单
147                 BsFormulaChildInfo test = bsFormulaChildInfoService.selectBsFormulaChildInfoByTypeTopOne("1", "test", parts[1]);
148                 test.setResults(WorkID);
149                 bsFormulaChildInfoService.updateBsFormulaChildInfo(test);
150                 WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "TIGHTEN");
151
152
153
154                 System.out.println("SNCode:"+SNCode);
155                 System.out.println("Node:"+Node+"value:"+value);
156                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".StationStatus").value("0").type("short").build();
157                 Boolean out=clientHandler.write(node);
158                 NodeEntity RecordSN= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSN").value("0").type("short").build();
159                 Boolean out1=clientHandler.write(RecordSN);
160                 NodeEntity riteRecordSNDone= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSNDone").value("0").type("short").build();
161                 Boolean out2=clientHandler.write(riteRecordSNDone);
162                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
163             default:
164                 break;
165         }
166     }
167
168
169 }