package com.jcdm.main.da.opcuaconfig.cert; import com.jcdm.framework.websocket.WebSocketServer; import com.jcdm.framework.websocket.WebSocketUsers; import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo; import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService; import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; import com.jcdm.main.da.opcuaconfig.client.ClientHandler; import com.jcdm.main.da.opcuaconfig.domain.NodeEntity; import com.jcdm.main.da.opcuaconfig.init.BeanUtils; import com.jcdm.main.da.paramCollection.domain.DaParamCollection; import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; import lombok.extern.slf4j.Slf4j; import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; import javax.websocket.Session; import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues; @Slf4j public class MethodName { Map map = WebSocketUsers.getUsers(); private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class); private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class); private IDaPassingStationCollectionService daPassingStationCollectionService = BeanUtils.getBean(IDaPassingStationCollectionService.class); private IBsFormulaChildInfoService bsFormulaChildInfoService = BeanUtils.getBean(IBsFormulaChildInfoService.class); private List s=null; public void Transit(String Node, String value) throws Exception { log.info(Node+":"+value); String[] parts = Node.split("[.]"); ClientHandler clientHandler=new ClientHandler(); NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build(); String SNCode=clientHandler.read(SN_node); log.info("读取节点:{},结果:{}", SN_node.getIdentifier(),SNCode); switch (value) { case "0": //初始 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build(); Boolean out=clientHandler.write(node); log.info("节点:{},响应结果:{}", node.getIdentifier(),out); break; case "1": //请求下发进站状态 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build(); Boolean out1=clientHandler.write(node1); DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); PassingStationCollection.setSfcCode(SNCode); PassingStationCollection.setLocationCode(parts[1]); PassingStationCollection.setInboundTime(new Date()); daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection); log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1); WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "IN"); break; case "2": //请求记录工位数据 List b; DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]); b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); List nodeId = b.stream().map(info -> { NodeId nodeid = new NodeId(2,info.getGatherAddress()); return nodeid; }).collect(Collectors.toList()); List s=readValues(nodeId); //保存PLC采集数据 for(int i=0;i LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC); if(LPSC != null && LPSC.size() > 0){ LPSC.get(0).setOutboundTime(new Date()); LPSC.get(0).setCollectionTime(new Date()); LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime()))); daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0)); } //更新PLC节点状态 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build(); Boolean out2=clientHandler.write(node2); WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "OUT"); log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2); break; default: break; } } public void tighten(String Node, String value) throws Exception { String[] parts = Node.split("[.]"); ClientHandler clientHandler=new ClientHandler(); System.out.println("Node:"+Node+"value:"+value); switch (value){ case "1": //读扭矩 NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSN").value("").type("").build(); String SNCode=clientHandler.read(SN_node); //读角度 NodeEntity SNDone= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSNDone").value("").type("").build(); String RecordSNDone = clientHandler.read(SNDone); //读结果 NodeEntity SNDone1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".WorkID").value("").type("").build(); String WorkID = clientHandler.read(SNDone1); //保存参数采集表 DaParamCollection paramCollection = new DaParamCollection(); paramCollection.setLocationCode(parts[1]); paramCollection.setParamCode("RecordSN"); paramCollection.setParamValue(SNCode); paramCollection.setParamName(parts[0]+"."+parts[1]+".RecordSN"); daParamCollectionService.insertDaParamCollection(paramCollection); DaParamCollection paramCollection1 = new DaParamCollection(); paramCollection1.setLocationCode(parts[1]); paramCollection1.setParamCode("RecordSNDone"); paramCollection1.setParamValue(RecordSNDone); paramCollection1.setParamName(parts[0]+"."+parts[1]+".RecordSNDone"); daParamCollectionService.insertDaParamCollection(paramCollection1); DaParamCollection paramCollection2 = new DaParamCollection(); paramCollection2.setLocationCode(parts[1]); paramCollection2.setParamCode("WorkID"); paramCollection2.setParamValue(WorkID); paramCollection2.setParamName(parts[0]+"."+parts[1]+".WorkID"); daParamCollectionService.insertDaParamCollection(paramCollection2); //保存状态更新前端表单 BsFormulaChildInfo test = bsFormulaChildInfoService.selectBsFormulaChildInfoByTypeTopOne("1", "test", parts[1]); test.setResults(WorkID); bsFormulaChildInfoService.updateBsFormulaChildInfo(test); WebSocketUsers.sendMessageToUserByText(map.get(parts[1]), "TIGHTEN"); System.out.println("SNCode:"+SNCode); System.out.println("Node:"+Node+"value:"+value); NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".StationStatus").value("0").type("short").build(); Boolean out=clientHandler.write(node); NodeEntity RecordSN= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSN").value("0").type("short").build(); Boolean out1=clientHandler.write(RecordSN); NodeEntity riteRecordSNDone= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordSNDone").value("0").type("short").build(); Boolean out2=clientHandler.write(riteRecordSNDone); log.info("节点:{},响应结果:{}", node.getIdentifier(),out); default: break; } } }