| | |
| | | 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.billion.main.om.domain.OmProductionOrderInfo; |
| | | import com.billion.main.om.service.IOmOrderSchedulingService; |
| | | import com.billion.main.om.service.IOmProductionOrderInfoService; |
| | | import com.billion.main.sys.domain.SysCount; |
| | | import com.billion.main.sys.service.ISysCountService; |
| | | 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.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.CompletableFuture; |
| | | @Slf4j |
| | | @Component |
| | | public class OPCUaSubscription implements SubscriptionCallback { |
| | | public static MiloService miloService; |
| | | |
| | | |
| | | public IDaParamCollectionService daParamCollectionService; |
| | | |
| | | public IDaStationCollectionService daStationCollectionService; |
| | | public IOmProductionOrderInfoService omProductionOrderInfoService; |
| | | public IOmOrderSchedulingService omOrderSchedulingService; |
| | | public IBsBomChildInfoService bsBomChildInfoService; |
| | | public IDaCollectionParamConfService daCollectionParamConfService; |
| | | public IDaMaterialCollectionService daMaterialCollectionService; |
| | | public ISysCountService sysCountService; |
| | | |
| | | |
| | | public OPCUaSubscription(MiloService miloService, |
| | | IDaParamCollectionService daParamCollectionService) { |
| | | IDaParamCollectionService daParamCollectionService, |
| | | IDaStationCollectionService daStationCollectionService, |
| | | IOmProductionOrderInfoService omProductionOrderInfoService, |
| | | IOmOrderSchedulingService omOrderSchedulingService, |
| | | IBsBomChildInfoService bsBomChildInfoService, |
| | | IDaCollectionParamConfService daCollectionParamConfService, |
| | | IDaMaterialCollectionService daMaterialCollectionService, |
| | | ISysCountService sysCountService |
| | | ) { |
| | | OPCUaSubscription.miloService = miloService; |
| | | this.daParamCollectionService = daParamCollectionService; |
| | | |
| | | |
| | | this.daStationCollectionService = daStationCollectionService; |
| | | this.omProductionOrderInfoService = omProductionOrderInfoService; |
| | | this.omOrderSchedulingService = omOrderSchedulingService; |
| | | this.bsBomChildInfoService = bsBomChildInfoService; |
| | | this.daCollectionParamConfService = daCollectionParamConfService; |
| | | this.daMaterialCollectionService = daMaterialCollectionService; |
| | | this.sysCountService = sysCountService; |
| | | } |
| | | |
| | | @Override |
| | | public void onSubscribe(String identifier, Object value) { |
| | | log.info("地址:"+identifier+"值:"+value); |
| | | try { |
| | | if(null != value ) { |
| | | String[] nodes = identifier.split("[.]"); |
| | | String thoroughfare = nodes[0];//通道 |
| | | String device = nodes[1];//设备 |
| | | String tab = nodes[2];//标记 |
| | | String valueString = value.toString();//地址值 |
| | | CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
| | | onSubscribe(thoroughfare,device,tab,valueString); |
| | | plackWorkOrder(thoroughfare,device,tab,valueString); |
| | | }); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | public void onSubscribe(String thoroughfare,String device,String tab,String valueString) { |
| | | try { |
| | | if (Constants.RecordData.equals(tab)){ |
| | | //工站交互初始化 |
| | | if (Constants.ZERO.equals(valueString)){ |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("0").build()); |
| | | //请求进站 |
| | | } else if (Constants.ONE.equals(valueString)){ |
| | | //1.1//首工站 |
| | | if(Constants.C005.equals(device) || Constants.OP005.equals(device) || Constants.P010.equals(device)){ |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("11").build()); |
| | | } |
| | | ///////除首工站所有工站 |
| | | else if(Constants.PLC1.contains(device) && Constants.OP310.contains(device)){ |
| | | //校验SFCCode是否存在 |
| | | Object SFCCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".SFCCode").getValue(); |
| | | Object PalletID = miloService.readFromOpcUa(thoroughfare + "." + device + ".PalletID").getValue(); |
| | | if (SFCCode == null ) { |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("23").build()); |
| | | } else { |
| | | OmOrderScheduling omOrderScheduling = new OmOrderScheduling(); |
| | | omOrderScheduling.setRemarks(PalletID.toString()); |
| | | List<OmOrderScheduling> resultList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling); |
| | | log.info("查询结果数量: {}", resultList); |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(device); |
| | | bsbomChildInfo.setBomCode(resultList.get(0).getWorkOrderNo()); |
| | | //下发配方 |
| | | formula(thoroughfare, device, bsbomChildInfo); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("11").build()); |
| | | |
| | | } |
| | | } |
| | | //出站保存数据 |
| | | } else if (Constants.TWO.equals(valueString)) { |
| | | OmProductionOrderInfo omProductionOrderInfo = new OmProductionOrderInfo(); |
| | | OmOrderScheduling omOrderScheduling = new OmOrderScheduling(); |
| | | Object SFCCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".SFCCode").getValue(); |
| | | //上线工位 |
| | | if(Constants.ONLINE.contains(device)){ |
| | | Object workOrderNumber = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue(); |
| | | Object nowQty = miloService.readFromOpcUa(thoroughfare + "." + device + ".PalletID").getValue(); |
| | | omOrderScheduling.setWorkOrderNo(workOrderNumber.toString()); |
| | | omOrderScheduling.setNowQty((Long) nowQty); |
| | | omOrderScheduling.setSfcCode(SFCCode.toString()); |
| | | //托盘绑定SFCCode和工单和产线 |
| | | if(Constants.OP005.equals(device)){ |
| | | omOrderScheduling.setRemarks("Body"); |
| | | } |
| | | if(Constants.C005.equals(device)){ |
| | | omOrderScheduling.setRemarks("Head"); |
| | | } |
| | | omOrderSchedulingService.insertOmOrderScheduling(omOrderScheduling); |
| | | }else if(Constants.OFFLINE.contains(device)){ |
| | | if(Constants.C070.equals(device)){ |
| | | omOrderScheduling.setRemarks("Head"); |
| | | omOrderScheduling.setSfcCode(SFCCode.toString()); |
| | | List<OmOrderScheduling> omOrderSchedulingList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling); |
| | | Object nowQty = omOrderSchedulingList.get(0).getNowQty(); |
| | | Object WorkOrderNumber = omOrderSchedulingList.get(0).getWorkOrderNo(); |
| | | omProductionOrderInfo.setWorkOrderNo(WorkOrderNumber.toString()); |
| | | List<OmProductionOrderInfo> omProductionOrderInfoList = omProductionOrderInfoService.selectOmProductionOrderInfoList(omProductionOrderInfo); |
| | | Object headQty = omProductionOrderInfoList.get(0).getHeadQty(); |
| | | if (nowQty == headQty){ |
| | | omProductionOrderInfoList.get(0).setHeadStatus("3"); |
| | | |
| | | |
| | | omProductionOrderInfoService.updateOmProductionOrderInfo(omProductionOrderInfoList.get(0)); |
| | | } |
| | | } else if (Constants.OP310.equals(device)) { |
| | | omOrderScheduling.setRemarks("Body"); |
| | | omOrderScheduling.setSfcCode(SFCCode.toString()); |
| | | List<OmOrderScheduling> omOrderSchedulingList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling); |
| | | Object nowQty = omOrderSchedulingList.get(0).getNowQty(); |
| | | Object WorkOrderNumber = omOrderSchedulingList.get(0).getWorkOrderNo(); |
| | | omProductionOrderInfo.setWorkOrderNo(WorkOrderNumber.toString()); |
| | | List<OmProductionOrderInfo> omProductionOrderInfoList = omProductionOrderInfoService.selectOmProductionOrderInfoList(omProductionOrderInfo); |
| | | Object bodyQty = omProductionOrderInfoList.get(0).getBodyQty(); |
| | | if (nowQty == bodyQty){ |
| | | omProductionOrderInfoList.get(0).setBodyStatus("3"); |
| | | |
| | | |
| | | omProductionOrderInfoService.updateOmProductionOrderInfo(omProductionOrderInfoList.get(0)); |
| | | } |
| | | } |
| | | } else if (Constants.P010.equals(device)) { |
| | | Object workOrderNumber = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue(); |
| | | Object nowQty = miloService.readFromOpcUa(thoroughfare + "." + device + ".PalletID").getValue(); |
| | | omOrderScheduling.setWorkOrderNo(workOrderNumber.toString()); |
| | | omOrderScheduling.setNowQty((Long) nowQty); |
| | | omOrderScheduling.setSfcCode(SFCCode.toString()); |
| | | omOrderScheduling.setRemarks("Pre"); |
| | | omOrderSchedulingService.insertOmOrderScheduling(omOrderScheduling); |
| | | List<OmOrderScheduling> omOrderSchedulingList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling); |
| | | Object WorkOrderNumber = omOrderSchedulingList.get(0).getWorkOrderNo(); |
| | | omProductionOrderInfo.setWorkOrderNo(WorkOrderNumber.toString()); |
| | | List<OmProductionOrderInfo> omProductionOrderInfoList = omProductionOrderInfoService.selectOmProductionOrderInfoList(omProductionOrderInfo); |
| | | Object preQty = omProductionOrderInfoList.get(0).getPreQty(); |
| | | if (nowQty == preQty){ |
| | | omProductionOrderInfoList.get(0).setPreStatus("3"); |
| | | |
| | | |
| | | omProductionOrderInfoService.updateOmProductionOrderInfo(omProductionOrderInfoList.get(0)); |
| | | |
| | | } |
| | | } |
| | | //查询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()); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | } |
| | | //首工站下发工单,并生成SN码 |
| | | private static final String[] MONTH = {"A","B","C","D","E","F","G","H","I","J","K","L"}; |
| | | 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)){ |
| | | if (Constants.OP005.equals(device)){ |
| | | // 查询数据库获取符合条件的订单信息 |
| | | OmProductionOrderInfo getBodyOrder = omProductionOrderInfoService.getBodyOrder(); |
| | | if (getBodyOrder != null) { |
| | | //判断当前下发数量是否满足计划数量 |
| | | //更新工单状态 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getBodyOrder.getWorkOrderNo()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getBodyOrder.getPlanQty())).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getBodyOrder.getEngineType()).build()); |
| | | //生成sn码 |
| | | SysCount serialNumber = sysCountService.getSerialNumber(); |
| | | String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | //判断是否跨年 |
| | | if(A3.equals(String.valueOf(serialNumber.getYear()))){ |
| | | String A1 = getBodyOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3";//固定产线 |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", serialNumber.getSerialNumber()); |
| | | String SFCCode = A1 + A2 + A3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MESSFCCode").value(SFCCode).build()); |
| | | sysCountService.updateSerialNumber(); |
| | | }else{ |
| | | sysCountService.clean(); |
| | | sysCountService.updateYear(); |
| | | String A1 = getBodyOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String newA3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", sysCountService.getSerialNumber().getSerialNumber()); |
| | | String SFCCode = A1 + A2 + newA3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MESSFCCode").value(SFCCode).build()); |
| | | sysCountService.updateSerialNumber(); |
| | | } |
| | | // 更新 WorkOrderRequestDone 地址块 |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(device); |
| | | bsbomChildInfo.setBomCode(getBodyOrder.getWorkOrderNo()); |
| | | //发下工艺配方 |
| | | formula(thoroughfare, device, bsbomChildInfo); |
| | | omProductionOrderInfoService.updateBodyStatus1(); |
| | | //判断缸体工单完成 |
| | | OmProductionOrderInfo getBodyOrder2 = omProductionOrderInfoService.getBodyOrder(); |
| | | if (Objects.equals(getBodyOrder2.getBodyQty(), getBodyOrder2.getPlanQty())){ |
| | | omProductionOrderInfoService.updateBodyStatus2(); |
| | | } |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".PalletID").value(getBodyOrder2.getBodyQty()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
| | | } |
| | | } else if (Constants.C005.equals(device)) { |
| | | // 查询数据库获取符合条件的订单信息 |
| | | OmProductionOrderInfo getHeadOrder = omProductionOrderInfoService.getHeadOrder(); |
| | | if (getHeadOrder != null) { |
| | | //判断当前下发数量是否满足计划数量 |
| | | //更新工单状态 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getHeadOrder.getWorkOrderNo()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getHeadOrder.getPlanQty())).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getHeadOrder.getEngineType()).build()); |
| | | //生成sn码 |
| | | SysCount headNumber = sysCountService.getHeadNumber(); |
| | | String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | //判断是否跨年 |
| | | if(A3.equals(String.valueOf(headNumber.getYear()))){ |
| | | String A1 = getHeadOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3";//固定产线 |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", headNumber.getHeadNumber()); |
| | | String SFCCode = A1 + A2 + A3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MESSFCCode").value(SFCCode).build()); |
| | | sysCountService.updateHeadNumber(); |
| | | }else{ |
| | | sysCountService.clean(); |
| | | sysCountService.updateYear(); |
| | | String A1 = getHeadOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String newA3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", sysCountService.getHeadNumber().getHeadNumber()); |
| | | String SFCCode = A1 + A2 + newA3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MESSFCCode").value(SFCCode).build()); |
| | | sysCountService.updateHeadNumber(); |
| | | } |
| | | // 更新 WorkOrderRequestDone 地址块 |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(device); |
| | | bsbomChildInfo.setBomCode(getHeadOrder.getWorkOrderNo()); |
| | | //发下工艺配方 |
| | | formula(thoroughfare, device, bsbomChildInfo); |
| | | omProductionOrderInfoService.updateHeadStatus1(); |
| | | //判断缸体工单完成 |
| | | OmProductionOrderInfo getHeadOrder2 = omProductionOrderInfoService.getHeadOrder(); |
| | | if (Objects.equals(getHeadOrder2.getHeadQty(), getHeadOrder2.getPlanQty())){ |
| | | omProductionOrderInfoService.updateHeadStatus2(); |
| | | } |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".PalletID").value(getHeadOrder2.getHeadQty()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
| | | } |
| | | } else if (Constants.P010.equals(device)) { |
| | | // 查询数据库获取符合条件的订单信息 |
| | | OmProductionOrderInfo getPreOrder = omProductionOrderInfoService.getPreOrder(); |
| | | if (getPreOrder != null) { |
| | | //判断当前下发数量是否满足计划数量 |
| | | //更新工单状态 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getPreOrder.getWorkOrderNo()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getPreOrder.getPlanQty())).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getPreOrder.getEngineType()).build()); |
| | | //生成sn码 |
| | | SysCount preNumber = sysCountService.getPreNumber(); |
| | | String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | if(A3.equals(String.valueOf(preNumber.getYear()))){ |
| | | String A1 = getPreOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", preNumber.getPreNumber()); |
| | | String SFCCode = A1 + A2 + A3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MESSFCCode").value(SFCCode).build()); |
| | | sysCountService.updatePreNumber(); |
| | | }else{ |
| | | sysCountService.clean(); |
| | | sysCountService.updateYear(); |
| | | String A1 = getPreOrder.getEngineType();//获取产品型号 |
| | | String A2 = "3"; |
| | | String newA3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
| | | String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
| | | String A5 = String.format("%05d", sysCountService.getPreNumber().getPreNumber()); |
| | | String SFCCode = A1 + A2 + newA3+ A4 + A5; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MESSFCCode").value(SFCCode).build()); |
| | | sysCountService.updateHeadNumber(); |
| | | } |
| | | |
| | | // 更新 WorkOrderRequestDone 地址块 |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(device); |
| | | bsbomChildInfo.setBomCode(getPreOrder.getWorkOrderNo()); |
| | | //发下工艺配方 |
| | | formula(thoroughfare, device, bsbomChildInfo); |
| | | omProductionOrderInfoService.updatePreStatus1(); |
| | | //判断缸体工单完成 |
| | | OmProductionOrderInfo getPreOrder2 = omProductionOrderInfoService.getPreOrder(); |
| | | if (Objects.equals(getPreOrder2.getPreQty(), getPreOrder2.getPlanQty())){ |
| | | omProductionOrderInfoService.updatePreStatus2(); |
| | | } |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".PalletID").value(getPreOrder2.getPreQty()).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | //发下工艺配方方法 |
| | | private void formula(String thoroughfare, String device, BsBomChildInfo bsbomChildInfo) throws Exception { |
| | | 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()); |
| | | // 生成 MaterialNumber 节点 |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".Material1Number"+ i).value(bomChildList.get(i-1).getCostQty()).build()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | // |
| | | |