| | |
| | | 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.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
| | | import com.kangaroohy.milo.service.MiloService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Time; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | |
| | | @Component |
| | | public class OPCUaSubscription implements SubscriptionCallback { |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
| | | public static MiloService miloService; |
| | | |
| | | public IDaCollectionParamConfService collectionParamConfService; |
| | |
| | | public IRmRepairRecordService rmRepairRecordService; |
| | | |
| | | public IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService; |
| | | |
| | | public HashMap<String,List<DaCollectionParamConf>> allCollectParamList = new HashMap<>(); |
| | | |
| | | public OPCUaSubscription(MiloService miloService, |
| | | IDaCollectionParamConfService collectionParamConfService, |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onSubscribe(String identifier, Object value) { |
| | | String ecpStr = "";//异常记录标记 |
| | |
| | | List<String> collect2 = lists.stream().filter(x -> OPCElement.SAVE_DATA.equals(x.getrFunction())) |
| | | .map(DaOpcuaConfig::getNode).collect(Collectors.toList()); |
| | | if (collect1.contains(identifier)){ |
| | | logger.info("-------监听到,{}的CODE_CHECK的信号",identifier); |
| | | //logger.info("-------time--------------,{}",LocalDateTime.now()); |
| | | //sn |
| | | this.SNRetrieval(identifier,value.toString()); |
| | | if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){ |
| | | //总装上线扫码传输数据 |
| | | log.info("-------监听到,{}的扫码枪扫码的CODE_CHECK的信号",identifier); |
| | | logger.info("-------监听到,{}的扫码枪扫码的CODE_CHECK的信号",identifier); |
| | | 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); |
| | | if (identifier.equals(OPCElement.OP060_HX_CODE_CHECK) && "1".equals(value.toString())){ |
| | | Object SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP060.Code1").getValue(); |
| | | if (null == SNCodeObject){ |
| | | SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP060.Code").getValue(); |
| | | } |
| | | if (null != SNCodeObject){ |
| | | String XT=null; |
| | | String CZ=null; |
| | | String SNCode = SNCodeObject.toString(); |
| | | DaParamCollection ParamCollection = new DaParamCollection(); |
| | | ParamCollection.setSfcCode(SNCode); |
| | | List<DaParamCollection> DaParamCollectionlist=daParamCollectionService.selectDaParamCollectionList(ParamCollection); |
| | | List<DaParamCollection> XTParamCollection = DaParamCollectionlist.stream().filter(x -> "箱体".equals(x.getParamName())).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(XTParamCollection)){ |
| | | DaParamCollection lastOne = XTParamCollection.get(0); |
| | | XT = lastOne.getParamValue(); |
| | | } |
| | | List<DaParamCollection> CZParamCollection = DaParamCollectionlist.stream().filter(x -> "曲轴".equals(x.getParamName())).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(CZParamCollection)){ |
| | | DaParamCollection lastOne = CZParamCollection.get(0); |
| | | CZ = lastOne.getParamValue(); |
| | | } |
| | | if(null != XT&&null != CZ) { |
| | | passingStationCollectionServiceImpl.sendMessage(XT+"*"+CZ,"OP060"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (collect2.contains(identifier)){ |
| | | if ("1".equals(value.toString())){ |
| | | logger.info("-------监听到,{}的SAVE_REQUEST_LAST的信号",identifier); |
| | | //logger.info("-------time--------------,{}",LocalDateTime.now()); |
| | | this.SaveData(identifier); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } 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){ |
| | | SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue(); |
| | | } |
| | | if (null != SNCodeObject){ |
| | | String SNCode = SNCodeObject.toString(); |
| | | passingStationCollectionServiceImpl.sendMessage(SNCode); |
| | | passingStationCollectionServiceImpl.sendMessage(SNCode,"OP120"); |
| | | } |
| | | } |
| | | |
| | |
| | | Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue(); |
| | | if(null != SNCodeObject) { |
| | | String SNCode=SNCodeObject.toString(); |
| | | String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]); |
| | | // String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]); |
| | | String a; |
| | | BsOrderScheduling bsOrderSchedulingQuery = new BsOrderScheduling(); |
| | | bsOrderSchedulingQuery.setEngineNo(SNCode); |
| | | List<BsOrderScheduling> queryOrderList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderSchedulingQuery); |
| | | if (CollUtil.isNotEmpty(queryOrderList)){ |
| | | a = "1"; |
| | | }else { |
| | | a = "4"; |
| | | } |
| | | //如果是返修工位需要传输返修工位号 |
| | | List<DaPassingStationCollection> daPassingStationCollections = new ArrayList<>(); |
| | | List<RmRepairRecord> rmRepairRecords = new ArrayList<>(); |
| | | if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node) |
| | | || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){ |
| | | //过站记录 |
| | | DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
| | | PassingStationCollection.setSfcCode(SNCode); |
| | | daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection); |
| | | // if (CollUtil.isNotEmpty(daPassingStationCollections)){ |
| | | // DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1); |
| | | // String outRsSign = lastOne.getOutRsSign(); |
| | | // if ("合格".equals(outRsSign)){ |
| | | // a = "1"; |
| | | // }else { |
| | | // a = "2"; |
| | | // } |
| | | // } |
| | | RmRepairRecord rmRepairRecord = new RmRepairRecord(); |
| | | rmRepairRecord.setBoxCode(SNCode); |
| | | rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord); |
| | | if (CollUtil.isNotEmpty(rmRepairRecords)){ |
| | | a = "1"; |
| | | }else { |
| | | a = "2"; |
| | | } |
| | | } |
| | | logger.info("-----返回codeCheckFeed-----,{}",a); |
| | | // String a="1"; |
| | | // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件) |
| | | if (StrUtil.isNotBlank(a)){ |
| | | int input = Integer.parseInt(a); |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", input); |
| | | log.info("-------监听到,{}的CodeCheck的信号",Node); |
| | | logger.info("发动机号:{},监听到{}的CodeCheck的信号",SNCode,Node); |
| | | miloService.writeToOpcByte(entity); |
| | | logger.info("监听到返回codecheckfeed信号,{}",entity); |
| | | //首站传输订单号 |
| | | if (OPCElement.OP050_HX_CODE_CHECK.equals(Node)){ |
| | | //查询订单号 |
| | |
| | | BsOrderScheduling bsOrderScheduling1 = tempList.get(0); |
| | | orderNum = bsOrderScheduling1.getOrderNo(); |
| | | } |
| | | |
| | | ReadWriteEntity entity2 = new ReadWriteEntity(parts[0]+"."+parts[1]+".OrderNumber", orderNum); |
| | | // miloService.writeToOpcByte(entity2); |
| | | miloService.writeToOpcUa(entity2); |
| | | } |
| | | //如果是返修工位需要传输返修工位号 |
| | | if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)){ |
| | | rework(SNCode); |
| | | if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node) |
| | | || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){ |
| | | rework(SNCode,Node,daPassingStationCollections,rmRepairRecords); |
| | | } |
| | | // miloService.writeToOpcByte(entity); |
| | | if (OPCElement.OP020_HX_CODE_CHECK.equals(Node)) { |
| | | //激光打码 |
| | | String[] printcode=SNCode.split("\\s+"); |
| | | ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.HOP020.PrintCode1", printcode[0]); |
| | | OPCUaSubscription.miloService.writeToOpcUa(entity3);//写SN |
| | | ReadWriteEntity entity5 = new ReadWriteEntity("CFL4HX.HOP020.PrintCode2", printcode[1]); |
| | | OPCUaSubscription.miloService.writeToOpcUa(entity5);//写SN |
| | | ReadWriteEntity entity6 = new ReadWriteEntity("CFL4HX.HOP020.SNDoor", "1"); |
| | | logger.info("发动机号{},请求打码内容写入成功,返回SNDoor信号信号1",SNCode); |
| | | miloService.writeToOpcByte(entity6); |
| | | } |
| | | System.out.println(entity); |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void rework(String SNCode) { |
| | | private void rework(String SNCode,String Node,List<DaPassingStationCollection> daPassingStationCollections,List<RmRepairRecord> rmRepairRecords) throws Exception{ |
| | | BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
| | | bsOrderScheduling.setEngineNo(SNCode); |
| | | List<String> allProcessCoed = new ArrayList<>(); |
| | | List<BsTechnologyRouteChildInfo> bsTechnologyRouteChildInfos = 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); |
| | | bsTechnologyRouteChildInfos = bsTechnologyRouteChildInfoService.selectAllTechnologyRouteByProductCode(s); |
| | | if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){ |
| | | allProcessCoed = bsTechnologyRouteChildInfos.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | RmRepairRecord rmRepairRecord = new RmRepairRecord(); |
| | | rmRepairRecord.setBoxCode(SNCode); |
| | | // RmRepairRecord rmRepairRecord = new RmRepairRecord(); |
| | | // rmRepairRecord.setBoxCode(SNCode); |
| | | List<ReadWriteEntity> writeList = new ArrayList<>(); |
| | | List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord); |
| | | //所有反工工位 |
| | | // List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord); |
| | | //过站记录 |
| | | // DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
| | | // PassingStationCollection.setSfcCode(SNCode); |
| | | //过站记录 |
| | | // List<DaPassingStationCollection> daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection); |
| | | |
| | | //所有返工工位 |
| | | 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)){ |
| | | if (CollUtil.isNotEmpty(collect1)){ |
| | | //查询出所有需要返修工位的最小op块 |
| | | Integer minOP = 0; |
| | | if (CollUtil.isNotEmpty(collect1)){ |
| | | |
| | | List<Integer> sortList = new ArrayList<>(); |
| | | collect1.stream().forEach(x ->{ |
| | | String op = x.replace("OP", ""); |
| | | if (StrUtil.isNotBlank(op)){ |
| | | int i = Integer.parseInt(op); |
| | | sortList.add(i); |
| | | } |
| | | }); |
| | | if (CollUtil.isNotEmpty(sortList)){ |
| | | List<Integer> collect2 = sortList.stream().filter(Objects::nonNull).sorted().collect(Collectors.toList()); |
| | | minOP = collect2.get(0); |
| | | } |
| | | } |
| | | //获取过站记录的最大工位 |
| | | String maxCode = null; |
| | | if (CollUtil.isNotEmpty(daPassingStationCollections)){ |
| | | List<DaPassingStationCollection> collect2 = daPassingStationCollections.stream().filter(x -> "不合格".equals(x.getOutRsSign())).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(collect2)){ |
| | | DaPassingStationCollection lastOne = collect2.get(collect2.size() - 1); |
| | | maxCode = lastOne.getLocationCode(); |
| | | }else { |
| | | DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1); |
| | | maxCode = lastOne.getLocationCode(); |
| | | } |
| | | |
| | | } |
| | | //所有放行工位 |
| | | List<String> passStation = new ArrayList<>(); |
| | | //所有生产工位 |
| | | List<String> productStation = new ArrayList<>(); |
| | | //最大工位编号 |
| | | Integer maxCodeNum = 0; |
| | | if (StrUtil.isNotEmpty(maxCode)){ |
| | | String finalMaxCode = maxCode; |
| | | //获取当前工位对应工步号 |
| | | List<String> collect2 = bsTechnologyRouteChildInfos.stream() |
| | | .filter(x -> x.getProcessesCode().equals(finalMaxCode)) |
| | | .map(BsTechnologyRouteChildInfo::getStepNo).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(collect2)){ |
| | | String s = collect2.get(0); |
| | | if (StrUtil.isNotBlank(s)){ |
| | | maxCodeNum = Integer.parseInt(s); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){ |
| | | bsTechnologyRouteChildInfos.forEach(x -> { |
| | | x.setStepNoNum(Integer.parseInt(x.getStepNo())); |
| | | }); |
| | | Integer finalMaxCodeNum = maxCodeNum; |
| | | //勾选的返修工位中最大的工位之后的工位----1 |
| | | List<BsTechnologyRouteChildInfo> collect3 = bsTechnologyRouteChildInfos.stream() |
| | | .filter(x -> x.getStepNoNum() >= finalMaxCodeNum).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(collect3)){ |
| | | //需要生产 |
| | | productStation.addAll(collect3.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList())); |
| | | } |
| | | //从第一个工位到返修的最大工位之间, |
| | | //勾选了返修标记的需要生产---1,未勾选的不生产---2 |
| | | productStation.addAll(collect1); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(productStation)){ |
| | | List<String> collect2 = allProcessCoed.stream().filter(x -> !productStation.contains(x)).collect(Collectors.toList()); |
| | | passStation.addAll(collect2); |
| | | } |
| | | String[] parts = Node.split("[.]"); |
| | | String par = parts[0]+"."+parts[1]; |
| | | if (CollUtil.isNotEmpty(passStation)){ |
| | | passStation.forEach(x -> { |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier(par+"."+x); |
| | | readWriteEntity.setValue(2); |
| | | writeList.add(readWriteEntity); |
| | | }); |
| | | } |
| | | if (CollUtil.isNotEmpty(productStation)){ |
| | | productStation.forEach(x -> { |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier(par+"."+x); |
| | | readWriteEntity.setValue(1); |
| | | writeList.add(readWriteEntity); |
| | | }); |
| | | } |
| | | //对OP755做特殊处理 |
| | | List<ReadWriteEntity> OP755List = new ArrayList<>(); |
| | | if (OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){ |
| | | List<String> patchList = new ArrayList<>(); |
| | | patchList.add(par+".OP740"); |
| | | patchList.add(par+".OP760"); |
| | | patchList.add(par+".OP770"); |
| | | patchList.add(par+".OP780"); |
| | | for (String s : patchList) { |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier(s); |
| | | readWriteEntity.setValue(0); |
| | | OP755List.add(readWriteEntity); |
| | | } |
| | | } |
| | | ReadWriteEntity readWriteEntity = new ReadWriteEntity(); |
| | | readWriteEntity.setIdentifier("Repair_sign"); |
| | | readWriteEntity.setValue(1); |
| | | writeList.add(readWriteEntity); |
| | | // miloService.writeToOpcByte(writeList); |
| | | readWriteEntity.setIdentifier(parts[0]+"."+parts[1]+".Repair_sign"); |
| | | readWriteEntity.setValue(minOP); |
| | | miloService.writeToOpcShort(readWriteEntity); |
| | | miloService.writeToOpcByte(writeList); |
| | | logger.info("{}返修写入:,{}",SNCode,writeList); |
| | | if (CollUtil.isNotEmpty(OP755List)){ |
| | | miloService.writeToOpcByte(OP755List); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | public void SaveData(String Node) throws Exception { |
| | | |
| | | String[] parts = Node.split("[.]"); |
| | | Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); |
| | | |
| | | if (null == SNCodeObject){ |
| | | SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue(); |
| | | } |
| | | if(null != SNCodeObject) |
| | | { |
| | | String SNCode = SNCodeObject.toString(); |
| | | List<DaCollectionParamConf> list; |
| | | DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); |
| | | daCollectionParamConf.setGatherAddress(parts[0] + "." + parts[1]); |
| | | list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
| | | Object object = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Runtime").getValue(); |
| | | String gatherAddress = parts[0] + "." + parts[1]; |
| | | List<DaCollectionParamConf> list = new ArrayList<>(); |
| | | if (allCollectParamList.containsKey(gatherAddress)){ |
| | | list = allCollectParamList.get(gatherAddress); |
| | | }else { |
| | | DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); |
| | | daCollectionParamConf.setGatherAddress(gatherAddress); |
| | | daCollectionParamConf.setRemarks("1"); |
| | | list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
| | | if (CollUtil.isNotEmpty(list)){ |
| | | //加入hashmap |
| | | allCollectParamList.put(gatherAddress,list); |
| | | } |
| | | } |
| | | |
| | | List<String> nodeIdList = list.stream().map(info -> { |
| | | String nodeid = info.getGatherAddress(); |
| | | return nodeid; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | if(!nodeIdList.isEmpty()){ |
| | | List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList); |
| | | List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); |
| | | for(int i=0;i<nodeIdList.size();i++){ |
| | | DaParamCollection ParamCollection = new DaParamCollection(); |
| | | if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){ |
| | | ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]); |
| | | ParamCollection.setLocationCode(parts[1]); |
| | | ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString()); |
| | | ParamCollection.setSfcCode(SNCode); |
| | | ParamCollection.setParamName(list.get(i).getCollectParameterName()); |
| | | ParamCollection.setParamUpper(list.get(i).getParamUpper()); |
| | | ParamCollection.setParamLower(list.get(i).getParamLower()); |
| | | ParamCollection.setUnit(list.get(i).getCollectParameterUnit()); |
| | | ParamCollection.setState("合格"); |
| | | ParamCollection.setType(list.get(i).getCollectParameterType()); |
| | | ParamCollection.setCollectionTime(new Date()); |
| | | daParamCollectionlist.add(ParamCollection); |
| | | } |
| | | } |
| | | daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
| | | List<ReadWriteEntity> readWriteEntityList = new ArrayList<>(); |
| | | if(CollUtil.isNotEmpty(nodeIdList)){ |
| | | //long time1 = new Date().getTime(); |
| | | readWriteEntityList = miloService.readFromOpcUa(nodeIdList); |
| | | //long time2 = new Date().getTime(); |
| | | //logger.info("读取点位花费时间:{},",time2-time1); |
| | | } |
| | | //返回plc保存成功 |
| | | if (parts.length==3){ |
| | | if ("SaveRequest".equals(parts[2])){ |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1); |
| | | miloService.writeToOpcByte(entity); |
| | | }else if ("SaveRequestLast".equals(parts[2])){ |
| | | ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1); |
| | | miloService.writeToOpcByte(entity); |
| | | } |
| | | logger.info("{}保存请求信号返回,MES->PLC的SaveFeedLast信号",Node); |
| | | //logger.info("-------请求返回-----,{}",LocalDateTime.now()); |
| | | } |
| | | |
| | | Object object = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Runtime").getValue(); |
| | | BsOrderScheduling bsOrderScheduling=bsOrderSchedulingService.selectBsOrderSchedulingSNCode(SNCode); |
| | | |
| | | List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); |
| | | if (CollUtil.isNotEmpty(nodeIdList)){ |
| | | for(int i=0;i<nodeIdList.size();i++){ |
| | | if(ObjectUtil.isNotEmpty(readWriteEntityList.get(i).getValue()) && !readWriteEntityList.get(i).getValue().toString().equals("0.0")){ |
| | | DaParamCollection ParamCollection = new DaParamCollection(); |
| | | ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]); |
| | | ParamCollection.setLocationCode(parts[1]); |
| | | if (readWriteEntityList.get(i) == null){ |
| | | ParamCollection.setParamValue("0"); |
| | | }else { |
| | | ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString()); |
| | | } |
| | | ParamCollection.setSfcCode(SNCode); |
| | | ParamCollection.setParamName(list.get(i).getCollectParameterName()); |
| | | ParamCollection.setParamUpper(list.get(i).getParamUpper()); |
| | | ParamCollection.setParamLower(list.get(i).getParamLower()); |
| | | ParamCollection.setUnit(list.get(i).getCollectParameterUnit()); |
| | | ParamCollection.setState("合格"); |
| | | ParamCollection.setType(list.get(i).getCollectParameterType()); |
| | | ParamCollection.setCollectionTime(new Date()); |
| | | ParamCollection.setWorkOrderNo(bsOrderScheduling.getOrderNo()); |
| | | daParamCollectionlist.add(ParamCollection); |
| | | } |
| | | } |
| | | daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
| | | logger.info("{}发动机({})采集数据保存完成",SNCode,Node); |
| | | } |
| | | Long beatTime = 0L; |
| | | if (ObjectUtil.isNotEmpty(object)){ |
| | | beatTime = (Long) object; |
| | | String str = object.toString(); |
| | | beatTime = Float.valueOf(str).longValue(); |
| | | } |
| | | Object ProductStatus = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".ProductStatus").getValue(); |
| | | logger.info("ProductStatus,{}",ProductStatus.toString()); |
| | | String str1="合格" ; |
| | | if (ObjectUtil.isNotEmpty(ProductStatus)){ |
| | | String productStatusString = ProductStatus.toString(); |
| | | if (productStatusString.contains("2") || productStatusString.contains("3")){ |
| | | str1="不合格"; |
| | | }else { |
| | | str1="合格"; |
| | | } |
| | | } |
| | | DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection(); |
| | | PassingStationCollection.setSfcCode(SNCode); |
| | |
| | | PassingStationCollection.setCollectionTime(new Date()); |
| | | PassingStationCollection.setCreateTime(new Date()); |
| | | PassingStationCollection.setBeatTime(beatTime.toString()); |
| | | PassingStationCollection.setOutRsSign("合格"); |
| | | PassingStationCollection.setOutRsSign(str1); |
| | | PassingStationCollection.setWorkOrderNo(bsOrderScheduling.getOrderNo()); |
| | | passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection); |
| | | logger.info("{}发动机({})过站数据保存完成",SNCode,Node); |
| | | |
| | | |
| | | //更新工单状态 |
| | | if ("OP790".equals(parts[1])) { |
| | | //bsOrderScheduling.setReport20("0"); |
| | | bsOrderScheduling.setProductionStatus("3"); |
| | | bsOrderScheduling.setFinalAssemblyOfflineTime(new Date()); |
| | | }else if("OP050".equals(parts[1])){ |
| | | bsOrderScheduling.setReport10("0"); |
| | | bsOrderScheduling.setProductionStatus("2"); |
| | | bsOrderScheduling.setBoxClosingOnlineTime(new Date()); |
| | | }else if("OP120".equals(parts[1])){ |
| | | bsOrderScheduling.setReport20("0"); |
| | | bsOrderScheduling.setFinalAssemblyLaunchTime(new Date()); |
| | | bsOrderScheduling.setClosingBoxOfflineTime(new Date()); |
| | | } |
| | | bsOrderScheduling.setQualityStatus(str1); |
| | | bsOrderScheduling.setCurrentWorkstation(parts[1]); |
| | | bsOrderSchedulingService.updateBsOrderScheduling(bsOrderScheduling); |
| | | } |
| | | } |
| | | } |