From 019f1c8bac7e8986d299aff70c123dedc1747d72 Mon Sep 17 00:00:00 2001 From: admin <15939171744@163.com> Date: 星期四, 06 六月 2024 11:15:10 +0800 Subject: [PATCH] - --- jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java | 135 +++++++++++++++++++++++++++++++++----------- 1 files changed, 100 insertions(+), 35 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java index 104b1b7..4c55ea1 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java +++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java @@ -3,6 +3,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -16,6 +17,8 @@ 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.da.testDeviceInterface.domain.DaTestDeviceInterface; +import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService; import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; import com.jcdm.main.plcserver.conf.OPCElement; @@ -24,6 +27,9 @@ import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; import com.kangaroohy.milo.service.MiloService; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -32,9 +38,11 @@ import java.util.*; import java.util.stream.Collectors; - +@Slf4j @Component public class OPCUaSubscription implements SubscriptionCallback { + + private static final Logger logger = LoggerFactory.getLogger("sys-user"); public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -42,7 +50,7 @@ public List<String> automaticList = Arrays.asList("OP280","OP310A","OP310B", "OP300A","OP300B", "OP320A","OP320B", "OP340A","OP340B", "OP350A","OP350B", "OP360","OP365","OP370", "OP390", "OP470"); //閲囬泦妯$粍宸ヤ綅 ModuleCode - public List<String> moduleCodeList = Arrays.asList("OP300A","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330"); + public List<String> moduleCodeList = Arrays.asList("OP300A","OP310A","OP310B","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330"); //鍖哄垎妯$粍鍨嬪彿宸ヤ綅 public List<String> distinguishingModules = Arrays.asList("OP300","OP310", "OP340", "OP350", "OP330"); @@ -74,22 +82,28 @@ public static IOmProductionOrdeInfoService omProductionOrdeInfoService; + private static IDaTestDeviceInterfaceService daTestDeviceInterfaceService; + + public OPCUaSubscription(MiloService miloService, IDaPassingStationCollectionService daPassingStationCollectionService, IDaCollectionParamConfService collectionParamConfService, IDaParamCollectionService daParamCollectionService, - IOmProductionOrdeInfoService omProductionOrdeInfoService) { + IOmProductionOrdeInfoService omProductionOrdeInfoService, + IDaTestDeviceInterfaceService daTestDeviceInterfaceService) { OPCUaSubscription.miloService = miloService; this.daPassingStationCollectionService = daPassingStationCollectionService; OPCUaSubscription.collectionParamConfService = collectionParamConfService; OPCUaSubscription.daParamCollectionService = daParamCollectionService; OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService; + OPCUaSubscription.daTestDeviceInterfaceService = daTestDeviceInterfaceService; } @Override public void onSubscribe(String identifier, Object value) { + logger.info("鍦板潃锛�"+identifier+"鍊硷細"+value); try { if(null != value && Integer.valueOf(value.toString())!= 0) { String[] nodes = identifier.split("[.]"); @@ -164,10 +178,11 @@ } }else { //鎵嬪姩宸ヤ綅澶勭悊閫昏緫 - WebSocketUsers.sendMessageToUserByText(map.get(device), "IN"); - String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; - - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); +// if (map.containsKey(device)){ + WebSocketUsers.sendMessageToUserByText(map.get(device), "IN"); + String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); +// } } @@ -181,16 +196,34 @@ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(recordDataDoneValue)).build()); }else { //鎵嬪姩宸ヤ綅 - if(device.contains("OP330")){ - String str = device.substring(0,5); - WebSocketUsers.sendMessageToUserByText(map.get(str), "END"); - }else { +// if(device.contains("OP330")){ +// String str = device.substring(0,5); +// WebSocketUsers.sendMessageToUserByText(map.get(str), "END"); +// }else { WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); - } +// } if(testList.stream().anyMatch(s -> s.equals(device))){ String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); +// Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue(); +// DaTestDeviceInterface deviceInterfaceOne = null; +// +// if (ObjectUtil.isNotNull(packCodeObject)) { +// String modelCode = packCodeObject.toString(); +// deviceInterfaceOne = daTestDeviceInterfaceService.getOne(new LambdaQueryWrapper<DaTestDeviceInterface>() +// .eq(DaTestDeviceInterface::getProductNum, modelCode) +// .eq(DaTestDeviceInterface::getStationCode, device)); +// } +// +// if (deviceInterfaceOne != null && "1".equals(deviceInterfaceOne.getTotalResult())) { +// writeToOpc(RecordDataDoneAddress, (short) 21); +// } else { +// writeToOpc(RecordDataDoneAddress, (short) 22); +// } +// writeToOpc(RecordDataDoneAddress, (short) 21); } + + } }else { System.out.println("^"); @@ -210,11 +243,15 @@ List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList()); String joinedString = String.join(",", collect.toString()); WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString)); + if(device.contains("270") || device.contains("260")){ + logger.info("璇诲彇鍒板伐浣峽}鐨凷caner鏁版嵁锛歿}",device,TightenTheConversionOkNg(joinedString)); + } } } } } catch (Exception e) { - + logger.info("璁㈤槄鏂规硶鎶ラ敊:{}"+e.getMessage()); + logger.error("璁㈤槄鏂规硶鎶ラ敊",e); } } @@ -242,7 +279,10 @@ read = read + "ModuleCode"; if(device.equals("OP365")){ try { +// result = saveStationInfo365(thoroughfare,device); +// return result; saveStationInfo365(thoroughfare,device); +// return result; }catch (Exception e){ e.printStackTrace(); } @@ -287,6 +327,7 @@ result = "21"; } + }catch (Exception e) { System.out.println(e.getMessage()); @@ -515,32 +556,56 @@ * 淇濆瓨杩囩珯閲囬泦 */ public void saveStationInfo365(String thoroughfare,String device) throws Exception { + String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; String prefix = thoroughfare+"."+device+"."; List<DaPassingStationCollection> passingStationCollections = new ArrayList<>(); - String ModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue().toString(); - String ModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue().toString(); - String StationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue().toString(); - String StationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue().toString(); - String[] modeles = {ModuleCodeA,ModuleCodeB}; - String[] StationStatus = {StationStatusA,StationStatusB}; + String ModuleCodeA = ""; + String ModuleCodeB = ""; + String StationStatusA = ""; + String StationStatusB = ""; - String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString(); - String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString(); - for (int i = 0; i < 2; i++) { - DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); - String strt = TimeUtil.stringProcessing(startTime); - String end = TimeUtil.stringProcessing(stopTime); - daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//鍏ョ珯鏃堕棿 - daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//鍑虹珯鏃堕棿 - daPassingStationCollection.setSfcCode(modeles[i]); - daPassingStationCollection.setLocationCode(device); - daPassingStationCollection.setOutRsSign(StationStatus[i]);//鍑虹珯鏄惁鍚堟牸 - passingStationCollections.add(daPassingStationCollection); + Object objectModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue(); + Object objectModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue(); + Object objectStationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue(); + Object objectStationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue(); + + if(ObjectUtil.isNotNull(objectModuleCodeA) && ObjectUtil.isNotNull(objectStationStatusA) && ObjectUtil.isNotNull(objectModuleCodeB) && ObjectUtil.isNotNull(objectStationStatusB)){ + ModuleCodeA = objectModuleCodeA.toString(); + ModuleCodeB = objectModuleCodeB.toString(); + StationStatusA = objectStationStatusA.toString(); + StationStatusB = objectStationStatusB.toString(); + + String[] modeles = {ModuleCodeA,ModuleCodeB}; + String[] StationStatus = {StationStatusA,StationStatusB}; + + String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString(); + String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString(); + for (int i = 0; i < 2; i++) { + DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); + String strt = TimeUtil.stringProcessing(startTime); + String end = TimeUtil.stringProcessing(stopTime); + daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//鍏ョ珯鏃堕棿 + daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//鍑虹珯鏃堕棿 + daPassingStationCollection.setSfcCode(modeles[i]); + daPassingStationCollection.setLocationCode(device); + daPassingStationCollection.setOutRsSign(StationStatus[i]);//鍑虹珯鏄惁鍚堟牸 + passingStationCollections.add(daPassingStationCollection); + } + daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections); + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); +// return "21"; + }else { + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build()); +// return "22"; } - daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections); - String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); - return; + } + + private static void writeToOpc(String identifier, short value) { + try { + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(identifier).value(value).build()); + } catch (Exception e) { + throw new RuntimeException(e); + } } } -- Gitblit v1.9.3