| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.billion.main.bs.domain.BsBomChildInfo; |
| | | import com.billion.main.bs.domain.BsLineInfo; |
| | | import com.billion.main.bs.service.IBsBomChildInfoService; |
| | | import com.billion.main.bs.service.IBsLineInfoService; |
| | | import com.billion.main.constant.Constants; |
| | | import com.billion.main.da.domain.DaCollectionParamConf; |
| | | import com.billion.main.da.domain.DaMaterialCollection; |
| | |
| | | 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; |
| | | |
| | | |
| | | public OPCUaSubscription(MiloService miloService, |
| | |
| | | IBsBomChildInfoService bsBomChildInfoService, |
| | | IDaCollectionParamConfService daCollectionParamConfService, |
| | | IDaMaterialCollectionService daMaterialCollectionService, |
| | | ISysCountService sysCountService |
| | | ISysCountService sysCountService, |
| | | IBsLineInfoService bsLineInfoService |
| | | ) { |
| | | OPCUaSubscription.miloService = miloService; |
| | | this.daParamCollectionService = daParamCollectionService; |
| | |
| | | this.daCollectionParamConfService = daCollectionParamConfService; |
| | | this.daMaterialCollectionService = daMaterialCollectionService; |
| | | this.sysCountService = sysCountService; |
| | | this.bsLineInfoService = bsLineInfoService; |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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.PLC1.contains(device) || |
| | | Constants.PLC2.contains(device) || |
| | | Constants.PLC3.contains(device) || |
| | |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(EngineType).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SerialNumber").value(SerialNumber).build()); |
| | | } |
| | | //9L发动机涂胶轨迹下发 |
| | | else if(Constants.OP080.equals(device) && Constants.PLC_4.equals(thoroughfare)){ |
| | | // 1. 初始化工单对象并查询工单信息 |
| | | String workOrderNo = resultList.get(0).getWorkOrderNo(); |
| | | OmProductionOrderInfo queryOrder = new OmProductionOrderInfo(); |
| | | queryOrder.setWorkOrderNo(workOrderNo); |
| | | List<OmProductionOrderInfo> orderList = omProductionOrderInfoService.selectOmProductionOrderInfoList(queryOrder); |
| | | // 2. 判断类型分支逻辑 |
| | | String engineName = orderList.get(0).getEngineName(); |
| | | if (!"9L".equals(engineName)) { |
| | | // 非9L直接写0 |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".GlueType").value(0).build()); |
| | | } else { |
| | | // 3. 查询产线配置的两条预置数据 |
| | | BsLineInfo lineQuery = new BsLineInfo(); |
| | | lineQuery.setLineCode(engineName); // 假设通过lineCode=9L获取两条数据 |
| | | List<BsLineInfo> configuredLines = bsLineInfoService.selectBsLineInfoList(lineQuery); |
| | | // 第一条配置数据的校验 |
| | | BsLineInfo firstLine = configuredLines.get(0); |
| | | BsBomChildInfo checkFirst = new BsBomChildInfo(); |
| | | checkFirst.setMaterialCode(firstLine.getLineName()); |
| | | checkFirst.setBomCode(workOrderNo); |
| | | List<BsBomChildInfo> firstCheckList = bsBomChildInfoService.selectBsBomChildInfoList(checkFirst); |
| | | if (firstCheckList.size() == 1) { |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".GlueType").value(1).build()); |
| | | } else { |
| | | // 第二条配置数据的校验 |
| | | BsLineInfo secondLine = configuredLines.get(1); |
| | | BsBomChildInfo checkSecond = new BsBomChildInfo(); |
| | | checkSecond.setMaterialCode(secondLine.getLineName()); |
| | | checkSecond.setBomCode(workOrderNo); |
| | | List<BsBomChildInfo> secondCheckList = bsBomChildInfoService.selectBsBomChildInfoList(checkSecond); |
| | | if (secondCheckList.size() == 1) { |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".GlueType").value(2).build()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | String getWorkOrderNo = resultList.get(0).getWorkOrderNo(); |
| | | BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
| | | bsbomChildInfo.setLocationCode(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 = "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); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |