| | |
| | | package com.billion.main.plcServer.sub; |
| | | |
| | | import com.billion.common.utils.StringUtils; |
| | | import com.billion.main.bs.domain.BsBomChildInfo; |
| | | import com.billion.main.bs.service.IBsBomChildInfoService; |
| | | import com.billion.main.constant.Constants; |
| | | import com.billion.main.da.domain.DaCollectionParamConf; |
| | | import com.billion.main.da.domain.DaMaterialCollection; |
| | | import com.billion.main.da.domain.DaParamCollection; |
| | | import com.billion.main.da.domain.DaStationCollection; |
| | | import com.billion.main.da.service.IDaCollectionParamConfService; |
| | | import com.billion.main.da.service.IDaMaterialCollectionService; |
| | | import com.billion.main.da.service.IDaParamCollectionService; |
| | | import com.billion.main.da.service.IDaStationCollectionService; |
| | | import com.billion.main.om.domain.OmOrderScheduling; |
| | |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.CompletableFuture; |
| | | @Slf4j |
| | |
| | | public IDaStationCollectionService daStationCollectionService; |
| | | public IOmProductionOrderInfoService omProductionOrderInfoService; |
| | | public IOmOrderSchedulingService omOrderSchedulingService; |
| | | public IBsBomChildInfoService bomChildInfoService; |
| | | public IBsBomChildInfoService bsBomChildInfoService; |
| | | public IDaCollectionParamConfService daCollectionParamConfService; |
| | | public IDaMaterialCollectionService daMaterialCollectionService; |
| | | |
| | | |
| | | public OPCUaSubscription(MiloService miloService, |
| | | IDaParamCollectionService daParamCollectionService, |
| | | IDaStationCollectionService daStationCollectionService, |
| | | IOmProductionOrderInfoService omProductionOrderInfoService, |
| | | IOmOrderSchedulingService omOrderSchedulingService, |
| | | IBsBomChildInfoService bomChildInfoService |
| | | IBsBomChildInfoService bsBomChildInfoService, |
| | | IDaCollectionParamConfService daCollectionParamConfService, |
| | | IDaMaterialCollectionService daMaterialCollectionService |
| | | ) { |
| | | OPCUaSubscription.miloService = miloService; |
| | | this.daParamCollectionService = daParamCollectionService; |
| | | this.daStationCollectionService = daStationCollectionService; |
| | | this.omProductionOrderInfoService = omProductionOrderInfoService; |
| | | this.omOrderSchedulingService = omOrderSchedulingService; |
| | | this.bomChildInfoService = bomChildInfoService; |
| | | this.bsBomChildInfoService = bsBomChildInfoService; |
| | | this.daCollectionParamConfService = daCollectionParamConfService; |
| | | this.daMaterialCollectionService = daMaterialCollectionService; |
| | | } |
| | | @Override |
| | | public void onSubscribe(String identifier, Object value) { |
| | |
| | | omOrderScheduling.setSfcCode(SFCCode.toString()); |
| | | omOrderSchedulinglist.add(omOrderScheduling); |
| | | omOrderSchedulingService.saveBatch(omOrderSchedulinglist); |
| | | // 缺少保存数据的方法 |
| | | //查询descriptive字段等于1的采集项保存到扫码保存到da_material_collection表里 |
| | | DaCollectionParamConf daCollectionParamConf1 = new DaCollectionParamConf(); |
| | | daCollectionParamConf1.setProcessesCode(device); |
| | | daCollectionParamConf1.setDescriptive("1"); |
| | | List<DaCollectionParamConf> daCollectionParamConfList1 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf1); |
| | | for (DaCollectionParamConf conf : daCollectionParamConfList1) { |
| | | String gatherAddress = conf.getGatherAddress(); |
| | | Object valueObj = miloService.readFromOpcUa(gatherAddress).getValue(); // 获取原始值对象:ml-citation{ref="4" data="citationList"} |
| | | if (valueObj == null || StringUtils.isEmpty(valueObj.toString())) { |
| | | log.warn("采集地址{}返回空值,跳过存储", gatherAddress); |
| | | continue; // 终止当前循环迭代:ml-citation{ref="1,2" data="citationList"} |
| | | } |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | materialCollection.setSfcCode(SFCCode.toString()); |
| | | materialCollection.setLocationCode(device); |
| | | materialCollection.setParamName(conf.getParameterSetName()); |
| | | materialCollection.setParamValue((String) miloService.readFromOpcUa(gatherAddress).getValue()); |
| | | materialCollection.setCollectTime(new Date()); |
| | | daMaterialCollectionService.insertDaMaterialCollection(materialCollection); |
| | | } |
| | | //查询descriptive字段等于2的采集项保存到扫码保存到da_param_collection表里 |
| | | DaCollectionParamConf daCollectionParamConf2 = new DaCollectionParamConf(); |
| | | daCollectionParamConf2.setProcessesCode(device); |
| | | daCollectionParamConf2.setDescriptive("2"); |
| | | List<DaCollectionParamConf> daCollectionParamConfList2 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf2); |
| | | for (DaCollectionParamConf conf : daCollectionParamConfList2) { |
| | | String gatherAddress = conf.getGatherAddress(); |
| | | Object valueObj = miloService.readFromOpcUa(gatherAddress).getValue(); // 获取原始值对象:ml-citation{ref="4" data="citationList"} |
| | | if (valueObj == null || StringUtils.isEmpty(valueObj.toString())) { |
| | | log.warn("采集地址{}返回空值,跳过存储", gatherAddress); |
| | | continue; // 终止当前循环迭代:ml-citation{ref="1,2" data="citationList"} |
| | | } |
| | | DaParamCollection paramCollection = new DaParamCollection(); |
| | | paramCollection.setSfcCode(SFCCode.toString()); |
| | | paramCollection.setLocationCode(device); |
| | | paramCollection.setParamName(conf.getParameterSetName()); |
| | | paramCollection.setParamValue((String) miloService.readFromOpcUa(gatherAddress).getValue()); |
| | | paramCollection.setCollectionTime(new Date()); |
| | | daParamCollectionService.insertDaParamCollection(paramCollection); |
| | | } |
| | | DaStationCollection daStationCollection = new DaStationCollection(); |
| | | daStationCollection.setLocationCode(device); |
| | | daStationCollection.setSfcCode(SFCCode.toString()); |
| | | daStationCollection.setInboundTime((Date) miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime").getValue()); |
| | | daStationCollection.setOutboundTime((Date) miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime").getValue()); |
| | | daStationCollectionService.insertDaStationCollection(daStationCollection); |
| | | |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("21").build()); |
| | | }else if(Constants.PLC.contains(device) && Constants.OP310.contains(device)){ |
| | | |
| | | Object SFCCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".SFCCode").getValue(); |
| | | //查询descriptive字段等于1的采集项保存到扫码保存到da_material_collection表里 |
| | | DaCollectionParamConf daCollectionParamConf1 = new DaCollectionParamConf(); |
| | | daCollectionParamConf1.setProcessesCode(device); |
| | | daCollectionParamConf1.setDescriptive("1"); |
| | | List<DaCollectionParamConf> daCollectionParamConfList1 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf1); |
| | | for (DaCollectionParamConf conf : daCollectionParamConfList1) { |
| | | String gatherAddress = conf.getGatherAddress(); |
| | | Object valueObj = miloService.readFromOpcUa(gatherAddress).getValue(); // 获取原始值对象:ml-citation{ref="4" data="citationList"} |
| | | if (valueObj == null || StringUtils.isEmpty(valueObj.toString())) { |
| | | log.warn("采集地址{}返回空值,跳过存储", gatherAddress); |
| | | continue; // 终止当前循环迭代:ml-citation{ref="1,2" data="citationList"} |
| | | } |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | materialCollection.setSfcCode(SFCCode.toString()); |
| | | materialCollection.setLocationCode(device); |
| | | materialCollection.setParamName(conf.getParameterSetName()); |
| | | materialCollection.setParamValue((String) miloService.readFromOpcUa(gatherAddress).getValue()); |
| | | materialCollection.setCollectTime(new Date()); |
| | | daMaterialCollectionService.insertDaMaterialCollection(materialCollection); |
| | | } |
| | | //查询descriptive字段等于2的采集项保存到扫码保存到da_param_collection表里 |
| | | DaCollectionParamConf daCollectionParamConf2 = new DaCollectionParamConf(); |
| | | daCollectionParamConf2.setProcessesCode(device); |
| | | daCollectionParamConf2.setDescriptive("2"); |
| | | List<DaCollectionParamConf> daCollectionParamConfList2 = daCollectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf2); |
| | | for (DaCollectionParamConf conf : daCollectionParamConfList2) { |
| | | String gatherAddress = conf.getGatherAddress(); |
| | | Object valueObj = miloService.readFromOpcUa(gatherAddress).getValue(); // 获取原始值对象:ml-citation{ref="4" data="citationList"} |
| | | if (valueObj == null || StringUtils.isEmpty(valueObj.toString())) { |
| | | log.warn("采集地址{}返回空值,跳过存储", gatherAddress); |
| | | continue; // 终止当前循环迭代:ml-citation{ref="1,2" data="citationList"} |
| | | } |
| | | DaParamCollection paramCollection = new DaParamCollection(); |
| | | paramCollection.setSfcCode(SFCCode.toString()); |
| | | paramCollection.setLocationCode(device); |
| | | paramCollection.setParamName(conf.getParameterSetName()); |
| | | paramCollection.setParamValue((String) miloService.readFromOpcUa(gatherAddress).getValue()); |
| | | paramCollection.setCollectionTime(new Date()); |
| | | daParamCollectionService.insertDaParamCollection(paramCollection); |
| | | } |
| | | DaStationCollection daStationCollection = new DaStationCollection(); |
| | | daStationCollection.setLocationCode(device); |
| | | daStationCollection.setSfcCode(SFCCode.toString()); |
| | | daStationCollection.setInboundTime((Date) miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime").getValue()); |
| | | daStationCollection.setOutboundTime((Date) miloService.readFromOpcUa(thoroughfare + "." + device + ".StopTime").getValue()); |
| | | daStationCollectionService.insertDaStationCollection(daStationCollection); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("21").build()); |
| | | } |
| | | } |
| | | } |
| | |
| | | public void plackWorkOrder(String thoroughfare, String device, String tab, String valueString) { |
| | | try { |
| | | if (Constants.WorkOrderRequest.equals(tab)) { |
| | | if(Constants.OP010.equals(device)){ |
| | | if (Constants.ZERO.equals(valueString)) { |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("0").build()); |
| | | } else if (Constants.ONE.equals(valueString)) { |
| | |
| | | } |
| | | } |
| | | } |
| | | } else if (Constants.C005.equals(device)) { |
| | | |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | |
| | | |
| | | //发下工艺配方方法 |
| | | private void formula(String thoroughfare, String device, BsBomChildInfo bsbomChildInfo) throws Exception { |
| | | List<BsBomChildInfo> bomChildList = bomChildInfoService.selectBsBomChildInfoList(bsbomChildInfo); |
| | | List<BsBomChildInfo> bomChildList = bsBomChildInfoService.selectBsBomChildInfoList(bsbomChildInfo); |
| | | for (int i = 1; i <= bomChildList.size(); i++) { |
| | | // 生成 MaterialCode 节点 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".Material1Code"+ i).value(bomChildList.get(i-1).getMaterialCode()).build()); |