| | |
| | | import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.milo.opcua.sdk.client.nodes.UaNode; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | |
| | | public IDaCollectionParamConfService daCollectionParamConfService; |
| | | public IDaMaterialCollectionService daMaterialCollectionService; |
| | | public ISysCountService sysCountService; |
| | | |
| | | public IBsLineInfoService bsLineInfoService; |
| | | |
| | | |
| | |
| | | if (Constants.ZERO.equals(valueString)){ |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(0).build()); |
| | | //请求进站 |
| | | } else if (Constants.ONE.equals(valueString)){ |
| | | } if (Constants.ONE.equals(valueString)){ |
| | | //1.1//首工站 |
| | | if(Constants.ONLINE.contains(device)){ |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build()); |
| | | } |
| | | //1.2//除首工站所有工站 |
| | | else if( |
| | | Constants.TEST.contains(device) || |
| | | // Constants.TEST.contains(device) || |
| | | Constants.PLC1.contains(device) || |
| | | Constants.PLC2.contains(device) || |
| | | Constants.PLC3.contains(device) || |
| | |
| | | } |
| | | } |
| | | //出站保存数据 |
| | | } else if (Constants.TWO.equals(valueString)) { |
| | | } if (Constants.TWO.equals(valueString)) { |
| | | OmProductionOrderInfo omProductionOrderInfo = new OmProductionOrderInfo(); |
| | | OmOrderScheduling omOrderScheduling = new OmOrderScheduling(); |
| | | Object SFCCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".SFCCode").getValue(); |
| | |
| | | if (Objects.equals(nowQty, getPreOrder2.getPlanQty().toString())){ |
| | | omProductionOrderInfoService.updatePreStatus2(); |
| | | } |
| | | }else if (Constants.OP020.equals(device)){ |
| | | final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 遍历 MaterialCode35 到 MaterialCode40 共6组数据 |
| | | for (int i = 35; i <= 40; i++) { // 修改循环范围 |
| | | // 构建OPC UA节点地址(例如:PLC1.OP020.MaterialCode35) |
| | | String nodeId = "PLC1." + device + ".MaterialCode" + i; |
| | | // 创建采集对象 |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | materialCollection.setSfcCode(SFCCode.toString()); |
| | | materialCollection.setLocationCode(device); |
| | | // 设置参数名称(活塞1到活塞6) |
| | | int pistonNumber = i - 34; // 35→1, 36→2...40→6 |
| | | materialCollection.setParamName("活塞" + pistonNumber); |
| | | // 通过OPC UA读取参数值 |
| | | ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); |
| | | if (dataRead != null && dataRead.getValue() != null) { |
| | | materialCollection.setParamValue(dataRead.getValue().toString()); |
| | | } else { |
| | | materialCollection.setParamValue("N/A"); // 处理空值情况 |
| | | } |
| | | Date collectTime = new Date(); |
| | | ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//进站时间 |
| | | collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); |
| | | materialCollection.setCollectTime( collectTime); |
| | | // 插入数据库 |
| | | daMaterialCollectionService.insertDaMaterialCollection(materialCollection); |
| | | } |
| | | }else if (Constants.OP130.equals(device)){ |
| | | final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 遍历 MaterialCode35 到 MaterialCode40 共6组数据 |
| | | String nodeId = "PLC1." + device + ".MaterialCode35" ; |
| | | // 创建采集对象 |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | materialCollection.setSfcCode(SFCCode.toString()); |
| | | materialCollection.setLocationCode(device); |
| | | materialCollection.setParamName("缸盖码"); |
| | | // 通过OPC UA读取参数值 |
| | | ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); |
| | | if (dataRead != null && dataRead.getValue() != null) { |
| | | materialCollection.setParamValue(dataRead.getValue().toString()); |
| | | } else { |
| | | materialCollection.setParamValue("N/A"); // 处理空值情况 |
| | | } |
| | | Date collectTime = new Date(); |
| | | ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//进站时间 |
| | | collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); |
| | | materialCollection.setCollectTime( collectTime); |
| | | // 插入数据库 |
| | | daMaterialCollectionService.insertDaMaterialCollection(materialCollection); |
| | | // }else if (Constants.OP020.equals(device)){ |
| | | // final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // // 遍历 MaterialCode35 到 MaterialCode40 共6组数据 |
| | | // for (int i = 35; i <= 40; i++) { // 修改循环范围 |
| | | // // 构建OPC UA节点地址(例如:PLC1.OP020.MaterialCode35) |
| | | // String nodeId = "PLC2." + device + ".MaterialCode" + i; |
| | | // // 创建采集对象 |
| | | // DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | // materialCollection.setSfcCode(SFCCode.toString()); |
| | | // materialCollection.setLocationCode(device); |
| | | // // 设置参数名称(活塞1到活塞6) |
| | | // int pistonNumber = i - 34; // 35→1, 36→2...40→6 |
| | | // materialCollection.setParamName("活塞" + pistonNumber); |
| | | // // 通过OPC UA读取参数值 |
| | | // ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); |
| | | // if (dataRead != null && dataRead.getValue() != null && !Objects.equals(dataRead.getValue(), " ")) { |
| | | // materialCollection.setParamValue(dataRead.getValue().toString()); |
| | | // Date collectTime = new Date(); |
| | | // ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//进站时间 |
| | | // collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); |
| | | // materialCollection.setCollectTime( collectTime); |
| | | // // 插入数据库 |
| | | // daMaterialCollectionService.insertDaMaterialCollection(materialCollection); |
| | | // } else { |
| | | // log.info("活塞号为空: {}",materialCollection.getParamName() ); |
| | | // } |
| | | // } |
| | | // }else if (Constants.OP130.equals(device)){ |
| | | // final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // // 遍历 MaterialCode35 到 MaterialCode40 共6组数据 |
| | | // String nodeId = "PLC3." + device + ".MaterialCode35" ; |
| | | // // 创建采集对象 |
| | | // DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | // materialCollection.setSfcCode(SFCCode.toString()); |
| | | // materialCollection.setLocationCode(device); |
| | | // materialCollection.setParamName("缸盖码"); |
| | | // // 通过OPC UA读取参数值 |
| | | // ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); |
| | | // if (dataRead != null && dataRead.getValue() != null && !Objects.equals(dataRead.getValue(), " ")) { |
| | | // materialCollection.setParamValue(dataRead.getValue().toString()); |
| | | // Date collectTime = new Date(); |
| | | // ReadWriteEntity collectTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime");//进站时间 |
| | | // collectTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(collectTimeRead.getValue().toString()))); |
| | | // materialCollection.setCollectTime( collectTime); |
| | | // // 插入数据库 |
| | | // daMaterialCollectionService.insertDaMaterialCollection(materialCollection); |
| | | // } else { |
| | | // log.info("缸盖码为空: {}",materialCollection.getParamName() ); |
| | | // } |
| | | |
| | | } |
| | | //出站保存 |
| | | DaStationCollection daStationCollection = new DaStationCollection(); |
| | |
| | | daCollectionParamConf1.setDescriptive("1"); |
| | | List<DaCollectionParamConf> daCollectionParamConfList1 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf1); |
| | | for (DaCollectionParamConf conf : daCollectionParamConfList1) { |
| | | String index = String.valueOf(daCollectionParamConfList1.indexOf(conf)); |
| | | String gatherAddress = conf.getGatherAddress(); |
| | | String valueObj = null; |
| | | ReadWriteEntity entity = miloService.readFromOpcUa(gatherAddress); |
| | |
| | | valueObj = value.toString(); // 最终赋值 |
| | | if (!Objects.equals(valueObj, " ")) { |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | materialCollection.setRemark(index); |
| | | materialCollection.setSfcCode(SFCCode.toString()); |
| | | materialCollection.setLocationCode(device); |
| | | materialCollection.setParamName(conf.getParameterSetName()); |
| | |
| | | List<DaCollectionParamConf> daCollectionParamConfList2 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf2); |
| | | for (DaCollectionParamConf conf : daCollectionParamConfList2) { |
| | | String gatherAddress = conf.getGatherAddress(); |
| | | String valueObj = miloService.readFromOpcUa(gatherAddress).getValue().toString(); // 获取原始值对象:ml-citation{ref="4" data="citationList"} |
| | | if (!Objects.equals(valueObj, "0.0") && !Objects.equals(valueObj, "0")) { |
| | | DaParamCollection paramCollection = new DaParamCollection(); |
| | | paramCollection.setSfcCode(SFCCode.toString()); |
| | | paramCollection.setLocationCode(device); |
| | | paramCollection.setParamName(conf.getParameterSetName()); |
| | | paramCollection.setParamValue(miloService.readFromOpcUa(gatherAddress).getValue().toString()); |
| | | Date Time = new Date(); |
| | | ReadWriteEntity TimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime"); |
| | | Time = format.parse(TimeUtil.test(TimeUtil.stringProcessing(TimeRead.getValue().toString()))); |
| | | paramCollection.setCollectTime(Time); |
| | | daParamCollectionService.insertDaParamCollection(paramCollection); |
| | | try{ |
| | | Object valueObj = miloService.readFromOpcUa(gatherAddress).getValue(); // 获取原始值对象:ml-citation{ref="4" data="citationList"} |
| | | if (!Objects.equals(valueObj, "0.0") && !Objects.equals(valueObj, "0") && valueObj != null ) { |
| | | DaParamCollection paramCollection = new DaParamCollection(); |
| | | paramCollection.setSfcCode(SFCCode.toString()); |
| | | paramCollection.setLocationCode(device); |
| | | paramCollection.setParamName(conf.getParameterSetName()); |
| | | paramCollection.setParamValue(miloService.readFromOpcUa(gatherAddress).getValue().toString()); |
| | | Date Time = new Date(); |
| | | ReadWriteEntity TimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime"); |
| | | Time = format.parse(TimeUtil.test(TimeUtil.stringProcessing(TimeRead.getValue().toString()))); |
| | | paramCollection.setCollectTime(Time); |
| | | daParamCollectionService.insertDaParamCollection(paramCollection); |
| | | } |
| | | else { |
| | | log.info("采集项为空: {}", gatherAddress); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage()); |
| | | } |
| | | else { |
| | | log.info("采集项为空: {}", gatherAddress); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |