| | |
| | | package com.jcdm.main.plcserver.sub; |
| | | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.jcdm.main.bs.domain.BsTechnologyRouteChildInfo; |
| | | import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling; |
| | | import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService; |
| | | import com.jcdm.main.bs.technologyRouteChild.service.IBsTechnologyRouteChildInfoService; |
| | | import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
| | | import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
| | | import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig; |
| | |
| | | import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
| | | import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl; |
| | | import com.jcdm.main.plcserver.conf.OPCElement; |
| | | import com.jcdm.main.rm.repairRecord.domain.RmRepairRecord; |
| | | import com.jcdm.main.rm.repairRecord.service.IRmRepairRecordService; |
| | | 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.text.Format; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | |
| | | |
| | | public static final HashMap<String,Integer> map = new HashMap<>(); |
| | | |
| | | public IBsOrderSchedulingService bsOrderSchedulingService; |
| | | |
| | | public IRmRepairRecordService rmRepairRecordService; |
| | | |
| | | public IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService; |
| | | |
| | | public OPCUaSubscription(MiloService miloService, |
| | | IDaCollectionParamConfService collectionParamConfService, |
| | | IDaParamCollectionService daParamCollectionService, |
| | | DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl, |
| | | List<DaOpcuaConfig> lists) { |
| | | IBsOrderSchedulingService bsOrderSchedulingService, |
| | | List<DaOpcuaConfig> lists, |
| | | IRmRepairRecordService rmRepairRecordService, |
| | | IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService) { |
| | | OPCUaSubscription.miloService = miloService; |
| | | this.collectionParamConfService = collectionParamConfService; |
| | | this.daParamCollectionService = daParamCollectionService; |
| | | this.passingStationCollectionServiceImpl = passingStationCollectionServiceImpl; |
| | | this.bsOrderSchedulingService = bsOrderSchedulingService; |
| | | this.lists = lists; |
| | | this.rmRepairRecordService = rmRepairRecordService; |
| | | this.bsTechnologyRouteChildInfoService = bsTechnologyRouteChildInfoService; |
| | | |
| | | |
| | | } |
| | |
| | | public void onSubscribe(String identifier, Object value) { |
| | | String ecpStr = "";//异常记录标记 |
| | | try { |
| | | if(null != value) { |
| | | if(null != value && "1".equals(value.toString())) { |
| | | //1、检索SN号 |
| | | //2、过站参数采集 |
| | | //3、扫码枪数据回传 |
| | |
| | | if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){ |
| | | //总装上线扫码传输数据 |
| | | log.info("-------监听到,{}的扫码枪扫码的CODE_CHECK的信号",identifier); |
| | | Integer i = map.getOrDefault(identifier + "的扫码枪扫码的CODE_CHECK的信号",0); |
| | | if (0==i){ |
| | | map.put(identifier + "的扫码枪扫码的CODE_CHECK的信号",i+1); |
| | | } |
| | | String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]"); |
| | | Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); |
| | | if (null != SNCodeObject){ |
| | | String SNCode = SNCodeObject.toString(); |
| | | passingStationCollectionServiceImpl.sendMessage(SNCode); |
| | | scannerGunMessage(); |
| | | } |
| | | } |
| | | if (collect2.contains(identifier)){ |
| | | if ("1".equals(value.toString())){ |
| | | //save |
| | | this.SaveData(identifier); |
| | | //返回plc保存成功 |
| | | String[] parts = identifier.split("[.]"); |
| | | if (parts.length==3){ |
| | | if ("SaveRequest".equals(parts[2])){ |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1); |
| | | log.info("-------监听到,{}的saveRequest的信号",identifier); |
| | | Integer i = map.getOrDefault(identifier + "的saveRequest的信号",0); |
| | | if (0==i){ |
| | | map.put(identifier + "的saveRequest的信号",i+1); |
| | | } |
| | | // miloService.writeToOpcByte(entity); |
| | | }else if ("SaveRequestLast".equals(parts[2])){ |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1); |
| | | log.info("-------监听到,{}的SaveRequestLast的信号",identifier); |
| | | Integer i = map.getOrDefault(identifier + "的SaveRequestLast的信号",0); |
| | | if (0==i){ |
| | | map.put(identifier + "的SaveRequestLast的信号",i+1); |
| | | } |
| | | // miloService.writeToOpcByte(entity); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else if (collect2.contains(identifier)){ |
| | | //save |
| | | this.SaveData(identifier); |
| | | //返回plc保存成功 |
| | | String[] parts = identifier.split("[.]"); |
| | | if (parts.length==3){ |
| | | if ("SaveRequest".equals(parts[2])){ |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1); |
| | | log.info("-------监听到,{}的saveRequest的信号",identifier); |
| | | Integer i = map.getOrDefault(identifier + "的saveRequest的信号",0); |
| | | if (0==i){ |
| | | map.put(identifier + "的saveRequest的信号",i+1); |
| | | } |
| | | // miloService.writeToOpcByte(entity); |
| | | }else if ("SaveRequestLast".equals(parts[2])){ |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1); |
| | | log.info("-------监听到,{}的SaveRequestLast的信号",identifier); |
| | | Integer i = map.getOrDefault(identifier + "的SaveRequestLast的信号",0); |
| | | if (0==i){ |
| | | map.put(identifier + "的SaveRequestLast的信号",i+1); |
| | | } |
| | | // miloService.writeToOpcByte(entity); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | //OP010保存请求 |
| | | // if (identifier.equals(OPCElement.OP120_SaveRequestLast) && "1".equals(value.toString())) { |
| | | // this.SaveData(OPCElement.OP120_SaveRequestLast); |
| | | // //1、更新工单数据 |
| | | // //2、保存过站采集数据 |
| | | // //3、保存参数采集数据 |
| | | // ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesSaveFeed, 1); |
| | | // miloService.writeToOpcByte(entity); |
| | | // } |
| | | // else if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){ |
| | | // //总装上线扫码传输数据 |
| | | // String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]"); |
| | | // Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); |
| | | // if (null != SNCodeObject){ |
| | | // String SNCode = SNCodeObject.toString(); |
| | | // passingStationCollectionServiceImpl.sendMessage(SNCode); |
| | | // } |
| | | // } |
| | | // //OP010请求检索条码 |
| | | // else if (identifier.equals(OPCElement.OP010_CodeCheck) && "1".equals(value.toString())) { |
| | | // ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesCodeCheckFeed, 1); |
| | | // miloService.writeToOpcByte(entity); |
| | | // } |
| | | } |
| | | |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | |
| | | System.out.println(e.getMessage()); |
| | | } finally { |
| | | if (!"".equals(ecpStr)) { |
| | | System.out.println(ecpStr + "\r\n"); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void scannerGunMessage() throws Exception { |
| | | String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]"); |
| | | Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); |
| | | if (null != SNCodeObject){ |
| | | String SNCode = SNCodeObject.toString(); |
| | | passingStationCollectionServiceImpl.sendMessage(SNCode); |
| | | } |
| | | } |
| | | |
| | |
| | | if(null != SNCodeObject) { |
| | | String SNCode=SNCodeObject.toString(); |
| | | String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]); |
| | | // String a="1"; |
| | | // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件) |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", a); |
| | | log.info("-------监听到,{}的CodeCheck的信号",Node); |
| | | Integer i = map.getOrDefault(Node + "的CodeCheck的信号",0); |
| | | if (0==i){ |
| | | map.put(Node + "的CodeCheck的信号",i+1); |
| | | } |
| | | if (StrUtil.isNotBlank(a)){ |
| | | int input = Integer.parseInt(a); |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", input); |
| | | log.info("-------监听到,{}的CodeCheck的信号",Node); |
| | | //首站传输订单号 |
| | | if (OPCElement.OP050_HX_CODE_CHECK.equals(Node)){ |
| | | //查询订单号 |
| | | BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
| | | bsOrderScheduling.setEngineNo(SNCode); |
| | | List<BsOrderScheduling> tempList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling); |
| | | String orderNum = ""; |
| | | if (CollUtil.isNotEmpty(tempList)){ |
| | | BsOrderScheduling bsOrderScheduling1 = tempList.get(0); |
| | | orderNum = bsOrderScheduling1.getOrderNo(); |
| | | } |
| | | |
| | | ReadWriteEntity entity2 = new ReadWriteEntity(parts[0]+"."+parts[1]+".OrderNumber", orderNum); |
| | | // miloService.writeToOpcByte(entity2); |
| | | } |
| | | //如果是返修工位需要传输返修工位号 |
| | | if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)){ |
| | | rework(SNCode); |
| | | } |
| | | // miloService.writeToOpcByte(entity); |
| | | DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
| | | PassingStationCollection.setSfcCode(SNCode); |
| | | PassingStationCollection.setLocationCode(parts[1]); |
| | | PassingStationCollection.setInboundTime(new Date()); |
| | | passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void rework(String SNCode) { |
| | | BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
| | | bsOrderScheduling.setEngineNo(SNCode); |
| | | List<String> allProcessCoed = new ArrayList<>(); |
| | | List<String> collect = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling).stream().map(BsOrderScheduling::getModel).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(collect)){ |
| | | String s = collect.get(0); |
| | | //查找次机型的完整工序 |
| | | List<BsTechnologyRouteChildInfo> bsTechnologyRouteChildInfos = bsTechnologyRouteChildInfoService.selectAllTechnologyRouteByProductCode(SNCode); |
| | | if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){ |
| | | allProcessCoed = bsTechnologyRouteChildInfos.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | RmRepairRecord rmRepairRecord = new RmRepairRecord(); |
| | | rmRepairRecord.setBoxCode(SNCode); |
| | | List<ReadWriteEntity> writeList = new ArrayList<>(); |
| | | List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord); |
| | | //所有反工工位 |
| | | List<String> collect1 = rmRepairRecords.stream().map(RmRepairRecord::getProcessesCode).collect(Collectors.toList()); |
| | | //所有放行工位 |
| | | List<String> collect2 = allProcessCoed; |
| | | if (CollUtil.isNotEmpty(rmRepairRecords)){ |
| | | //数据库查询出的工位 |
| | | rmRepairRecords.forEach(x -> { |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier(x.getProcessesCode()); |
| | | readWriteEntity.setValue(1); |
| | | writeList.add(readWriteEntity); |
| | | }); |
| | | collect2 = allProcessCoed.stream().filter(x -> !collect1.contains(x)).collect(Collectors.toList()); |
| | | } |
| | | if (CollUtil.isNotEmpty(collect2)){ |
| | | collect2.forEach(x -> { |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier(x); |
| | | readWriteEntity.setValue(2); |
| | | writeList.add(readWriteEntity); |
| | | }); |
| | | } |
| | | if (CollUtil.isNotEmpty(writeList)){ |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier("Repair_sign"); |
| | | readWriteEntity.setValue(1); |
| | | writeList.add(readWriteEntity); |
| | | // miloService.writeToOpcByte(writeList); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
| | | } |
| | | |
| | | Object object = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Runtime").getValue(); |
| | | Long beatTime = 0L; |
| | | if (ObjectUtil.isNotEmpty(object)){ |
| | | beatTime = (Long) object; |
| | | } |
| | | DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
| | | PassingStationCollection.setSfcCode(SNCode); |
| | | PassingStationCollection.setLocationCode(parts[1]); |
| | | PassingStationCollection.setOutboundTime(new Date()); |
| | | PassingStationCollection.setInboundTime(new Date(new Date().getTime()-beatTime*1000)); |
| | | PassingStationCollection.setCollectionTime(new Date()); |
| | | PassingStationCollection.setCreateTime(new Date()); |
| | | PassingStationCollection.setBeatTime(beatTime.toString()); |
| | | PassingStationCollection.setOutRsSign("合格"); |
| | | passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection); |
| | | |
| | | |
| | | } |
| | | } |
| | | } |