| | |
| | | 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)){ |
| | | |
| | | }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.ZERO.equals(valueString)) { |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("0").build()); |
| | | } else if (Constants.ONE.equals(valueString)) { |
| | | // 查询数据库获取符合条件的订单信息 |
| | | OmProductionOrderInfo getEarliestOrder = omProductionOrderInfoService.getEarliestOrder(); |
| | | if (getEarliestOrder != null) { |
| | | //判断当前下发数量 |
| | | if(getEarliestOrder.getRemarks() >= getEarliestOrder.getPlanQty()){ |
| | | //更新工单状态 |
| | | omProductionOrderInfoService.updateOrderStatus5(); |
| | | //查询新满足的工单 |
| | | OmProductionOrderInfo getEarliestOrder2 = omProductionOrderInfoService.getEarliestOrder(); |
| | | if (getEarliestOrder2 != null) { |
| | | // 将数据写入到地址块中 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getEarliestOrder2.getWorkOrderNo()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getEarliestOrder2.getPlanQty())).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getEarliestOrder2.getEngineType()).build()); |
| | | 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)) { |
| | | // 查询数据库获取符合条件的订单信息 |
| | | OmProductionOrderInfo getEarliestOrder = omProductionOrderInfoService.getEarliestOrder(); |
| | | if (getEarliestOrder != null) { |
| | | //判断当前下发数量 |
| | | if(getEarliestOrder.getRemarks() >= getEarliestOrder.getPlanQty()){ |
| | | //更新工单状态 |
| | | omProductionOrderInfoService.updateOrderStatus5(); |
| | | //查询新满足的工单 |
| | | OmProductionOrderInfo getEarliestOrder2 = omProductionOrderInfoService.getEarliestOrder(); |
| | | if (getEarliestOrder2 != null) { |
| | | // 将数据写入到地址块中 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getEarliestOrder2.getWorkOrderNo()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getEarliestOrder2.getPlanQty())).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getEarliestOrder2.getEngineType()).build()); |
| | | //生成sn码 |
| | | OmProductionOrderInfo serialNumber = omProductionOrderInfoService.getSerialNumber(); |
| | | String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | if(A3.equals(String.valueOf(serialNumber.getRemarks()))){ |
| | | String A1 = getEarliestOrder2.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", serialNumber.getPlanQty()); |
| | | String SFCCode = A1 + A2 + A3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | omProductionOrderInfoService.updateSerialNumber(); |
| | | }else{ |
| | | OmProductionOrderInfo newNumber = omProductionOrderInfoService.updateYear(); |
| | | String A1 = getEarliestOrder2.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", newNumber.getPlanQty()); |
| | | String SFCCode = A1 + A2 + A3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | omProductionOrderInfoService.updateSerialNumber(); |
| | | } |
| | | // 更新 WorkOrderRequestDone 地址块 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(device); |
| | | bsbomChildInfo.setBomCode(getEarliestOrder2.getWorkOrderNo()); |
| | | //发下工艺配方 |
| | | formula(thoroughfare, device, bsbomChildInfo); |
| | | omProductionOrderInfoService.updateOrderStatus2(); |
| | | |
| | | } |
| | | } else if (getEarliestOrder.getRemarks() < getEarliestOrder.getPlanQty()) { |
| | | //更新工单状态 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getEarliestOrder.getWorkOrderNo()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getEarliestOrder.getPlanQty())).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getEarliestOrder.getEngineType()).build()); |
| | | //生成sn码 |
| | | OmProductionOrderInfo serialNumber = omProductionOrderInfoService.getSerialNumber(); |
| | | String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | if(A3.equals(String.valueOf(serialNumber.getRemarks()))){ |
| | | String A1 = getEarliestOrder2.getEngineType();//获取产品型号 |
| | | String A1 = getEarliestOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", serialNumber.getPlanQty()); |
| | |
| | | omProductionOrderInfoService.updateSerialNumber(); |
| | | }else{ |
| | | OmProductionOrderInfo newNumber = omProductionOrderInfoService.updateYear(); |
| | | String A1 = getEarliestOrder2.getEngineType();//获取产品型号 |
| | | String A1 = getEarliestOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", newNumber.getPlanQty()); |
| | |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(device); |
| | | bsbomChildInfo.setBomCode(getEarliestOrder2.getWorkOrderNo()); |
| | | bsbomChildInfo.setBomCode(getEarliestOrder.getWorkOrderNo()); |
| | | //发下工艺配方 |
| | | formula(thoroughfare, device, bsbomChildInfo); |
| | | omProductionOrderInfoService.updateOrderStatus2(); |
| | | |
| | | } |
| | | } else if (getEarliestOrder.getRemarks() < getEarliestOrder.getPlanQty()) { |
| | | //更新工单状态 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getEarliestOrder.getWorkOrderNo()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getEarliestOrder.getPlanQty())).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getEarliestOrder.getEngineType()).build()); |
| | | //生成sn码 |
| | | OmProductionOrderInfo serialNumber = omProductionOrderInfoService.getSerialNumber(); |
| | | String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | if(A3.equals(String.valueOf(serialNumber.getRemarks()))){ |
| | | String A1 = getEarliestOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", serialNumber.getPlanQty()); |
| | | String SFCCode = A1 + A2 + A3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | omProductionOrderInfoService.updateSerialNumber(); |
| | | }else{ |
| | | OmProductionOrderInfo newNumber = omProductionOrderInfoService.updateYear(); |
| | | String A1 = getEarliestOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", newNumber.getPlanQty()); |
| | | String SFCCode = A1 + A2 + A3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | omProductionOrderInfoService.updateSerialNumber(); |
| | | } |
| | | // 更新 WorkOrderRequestDone 地址块 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(device); |
| | | bsbomChildInfo.setBomCode(getEarliestOrder.getWorkOrderNo()); |
| | | //发下工艺配方 |
| | | formula(thoroughfare, device, bsbomChildInfo); |
| | | omProductionOrderInfoService.updateOrderStatus2(); |
| | | } |
| | | } |
| | | } 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()); |