¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.jcdm.main.plcserver.sub; |
| | | |
| | | |
| | | import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
| | | import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
| | | 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 com.jcdm.main.plcserver.conf.OPCElement; |
| | | import com.kangaroohy.milo.model.ReadWriteEntity; |
| | | import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Component |
| | | public class OPCUaSubscription implements SubscriptionCallback { |
| | | |
| | | public static MiloService miloService; |
| | | |
| | | public IDaPassingStationCollectionService daPassingStationCollectionService; |
| | | |
| | | public IDaCollectionParamConfService collectionParamConfService; |
| | | |
| | | public IDaParamCollectionService daParamCollectionService; |
| | | |
| | | public OPCUaSubscription(MiloService miloService, |
| | | IDaPassingStationCollectionService daPassingStationCollectionService, |
| | | IDaCollectionParamConfService collectionParamConfService, |
| | | IDaParamCollectionService daParamCollectionService) { |
| | | OPCUaSubscription.miloService = miloService; |
| | | this.daPassingStationCollectionService = daPassingStationCollectionService; |
| | | this.collectionParamConfService = collectionParamConfService; |
| | | this.daParamCollectionService = daParamCollectionService; |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onSubscribe(String identifier, Object value) { |
| | | |
| | | try { |
| | | if(null != value) { |
| | | String[] nodes = identifier.split("[.]"); |
| | | String thoroughfare = nodes[0];//éé |
| | | String device = nodes[1];//è®¾å¤ |
| | | String tab = nodes[2];//æ è®° |
| | | String tabVlaue = value.toString();//å°åå¼ |
| | | |
| | | //请æ±ä¸åSNå· |
| | | if (("RecordSN").equals(tab) && "1".equals(tabVlaue)) { |
| | | //è·åSNå·æ¹æ³ |
| | | String SNCode = getSNCode(); |
| | | |
| | | //ä¸åSN |
| | | String SNCodeAddress = thoroughfare + "." + device + ".SNCode"; |
| | | miloService.writeToOpcChar(ReadWriteEntity.builder().identifier(SNCodeAddress).value(SNCode).build()); |
| | | //ä¸åSNå®æ |
| | | String recordSNDoneAddress = thoroughfare + "." + device + ".RecordSNDone"; |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(recordSNDoneAddress).value(1).build()); |
| | | } |
| | | //请æ±è®°å½æ°æ® |
| | | else if (("RecordData").equals(tab)) { |
| | | String recordDataDoneValue = ""; |
| | | |
| | | if("1".equals(tabVlaue)){ |
| | | recordDataDoneValue = "11"; |
| | | |
| | | //è¿ç«ä¿åæ°æ® |
| | | //inSaveDate(thoroughfare,device) |
| | | //è®°å½æ°æ®å®æ |
| | | String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build()); |
| | | }else if("2".equals(tabVlaue)){ |
| | | |
| | | //åºç«ä¿åæ°æ® |
| | | recordDataDoneValue = outSaveDate(thoroughfare,device); |
| | | //è®°å½æ°æ®å®æ |
| | | String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build()); |
| | | }else{ |
| | | System.out.println("^"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * è·åSNCode |
| | | */ |
| | | public String getSNCode(){ |
| | | String SNCode = ""; |
| | | return SNCode; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åºç«ä¿åæ°æ® |
| | | */ |
| | | public String outSaveDate(String thoroughfare,String device) { |
| | | String result = ""; |
| | | try { |
| | | //读åSNCode |
| | | String SNCodeAddress = thoroughfare + "." + device + ".SNCode"; |
| | | Object SNCodeObject = miloService.readFromOpcUa(SNCodeAddress).getValue(); |
| | | if(null == SNCodeObject || "".equals(SNCodeObject)){ |
| | | result = "22"; |
| | | }else{ |
| | | String SNCode = SNCodeObject.toString(); |
| | | //1ãæ´æ°å·¥åä¿¡æ¯ |
| | | //updateOrderInfo(); |
| | | //2ãä¿åè¿ç«ééæ°æ® |
| | | saveStationInfo(SNCode,thoroughfare,device); |
| | | //3ãä¿ååæ°ééæ°æ® |
| | | SaveParamData(SNCode,thoroughfare,device); |
| | | |
| | | result = "21"; |
| | | |
| | | } |
| | | |
| | | }catch (Exception e) { |
| | | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * ä¿åè¿ç«éé |
| | | */ |
| | | public void saveStationInfo(String SNCode,String thoroughfare,String device){ |
| | | DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); |
| | | daPassingStationCollection.setSfcCode(SNCode); |
| | | //daPassingStationCollection.setInboundTime();//å
¥ç«æ¶é´ |
| | | daPassingStationCollection.setOutboundTime(new Date());//åºç«æ¶é´ |
| | | //daPassingStationCollection.setOutRsSign();//åºç«æ¯å¦åæ ¼ |
| | | daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection); |
| | | } |
| | | |
| | | public void SaveParamData(String SNCode,String thoroughfare,String device) throws Exception { |
| | | List<DaCollectionParamConf> list; |
| | | DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); |
| | | daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device); |
| | | list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
| | | |
| | | List<String> nodeIdList = list.stream().map(info -> { |
| | | String nodeid = info.getGatherAddress(); |
| | | return nodeid; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | if(!nodeIdList.isEmpty()){ |
| | | List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList); |
| | | List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); |
| | | for(int i=0;i<nodeIdList.size();i++){ |
| | | DaParamCollection ParamCollection = new DaParamCollection(); |
| | | if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){ |
| | | ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]); |
| | | ParamCollection.setLocationCode(device); |
| | | ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString()); |
| | | ParamCollection.setSfcCode(SNCode); |
| | | ParamCollection.setParamName(list.get(i).getCollectParameterName()); |
| | | ParamCollection.setParamUpper(list.get(i).getParamUpper()); |
| | | ParamCollection.setParamLower(list.get(i).getParamLower()); |
| | | ParamCollection.setUnit(list.get(i).getCollectParameterUnit()); |
| | | //ParamCollection.setState("åæ ¼"); |
| | | ParamCollection.setType(list.get(i).getCollectParameterType()); |
| | | ParamCollection.setCollectionTime(new Date()); |
| | | daParamCollectionlist.add(ParamCollection); |
| | | } |
| | | } |
| | | //daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
| | | } |
| | | |
| | | } |
| | | } |