| | |
| | | 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; |
| | |
| | | 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) || |
| | |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | if(Constants.OP080.equals(device) ){ |
| | | if(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(); |
| | |
| | | } |
| | | } |
| | | //出站保存数据 |
| | | } 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)){ |
| | | } |
| | | 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; |
| | | String nodeId = "PLC2." + device + ".MaterialCode" + i; |
| | | // 创建采集对象 |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | materialCollection.setSfcCode(SFCCode.toString()); |
| | |
| | | materialCollection.setParamName("活塞" + pistonNumber); |
| | | // 通过OPC UA读取参数值 |
| | | ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); |
| | | if (dataRead != null && dataRead.getValue() != null) { |
| | | 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.plusSave(materialCollection); |
| | | } else { |
| | | materialCollection.setParamValue("N/A"); // 处理空值情况 |
| | | log.info("活塞号为空: {}",materialCollection.getParamName() ); |
| | | } |
| | | 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" ; |
| | | String nodeId = "PLC3." + device + ".MaterialCode35" ; |
| | | // 创建采集对象 |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | materialCollection.setSfcCode(SFCCode.toString()); |
| | |
| | | materialCollection.setParamName("缸盖码"); |
| | | // 通过OPC UA读取参数值 |
| | | ReadWriteEntity dataRead = miloService.readFromOpcUa(nodeId); |
| | | if (dataRead != null && dataRead.getValue() != null) { |
| | | 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.plusSave(materialCollection); |
| | | } else { |
| | | materialCollection.setParamValue("N/A"); // 处理空值情况 |
| | | log.info("缸盖码为空: {}",materialCollection.getParamName() ); |
| | | } |
| | | 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); |
| | | } |
| | | //出站保存 |
| | | DaStationCollection daStationCollection = new DaStationCollection(); |
| | |
| | | valueObj = value.toString(); // 最终赋值 |
| | | if (!Objects.equals(valueObj, " ")) { |
| | | DaMaterialCollection materialCollection = new DaMaterialCollection(); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |