From cd44522023ba6fece1d93670bfef5f73b5d09f57 Mon Sep 17 00:00:00 2001 From: wujian <14790700720@163.com> Date: 星期三, 26 六月 2024 09:43:42 +0800 Subject: [PATCH] add mainCode --- jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java | 136 +++++++++++++++++++++++++++++---------------- 1 files changed, 87 insertions(+), 49 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java index f1e40ab..503c6ea 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java +++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java @@ -4,6 +4,9 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jcdm.framework.websocket.WebSocketUsers; import com.jcdm.main.constant.Constants; @@ -17,20 +20,24 @@ import com.jcdm.main.da.passingStationCollection.query.ProductOrderVO; import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; +import com.jcdm.main.restful.qingYan.doman.ChildVO; +import com.jcdm.main.restful.qingYan.doman.ParentVO; import com.jcdm.main.work.domain.KeyCodeRelation; +import com.jcdm.main.work.domain.QingYanTestInfo; +import com.jcdm.main.work.domain.SendFactoryMes; import com.jcdm.main.work.domain.WorkOrder; -import com.jcdm.main.work.service.KeyCodeCheckService; -import com.jcdm.main.work.service.KeyCodeRelationService; -import com.jcdm.main.work.service.WorkOrderService; +import com.jcdm.main.work.service.*; 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.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.websocket.Session; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -40,33 +47,10 @@ public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - //鏂拌嚜鍔ㄥ伐绔� - public List<String> automaticList = Arrays.asList("OP280","OP310A","OP310B", "OP300A","OP300B", "OP320A","OP320B", "OP340A","OP340B", "OP350A","OP350B", "OP360","OP365","OP370", "OP390", "OP470"); - - //閲囬泦妯$粍宸ヤ綅 ModuleCode - public List<String> moduleCodeList = Arrays.asList("OP300A","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330"); - - //鍖哄垎妯$粍鍨嬪彿宸ヤ綅 - public List<String> distinguishingModules = Arrays.asList("OP300","OP310", "OP340", "OP350", "OP330"); - - //鍖哄垎灏忚溅鐮� - public List<String> agvId = Arrays.asList("OP360", "OP390", "OP470","OP280"); - - - //鍖哄垎pack鍨嬪彿鐨勫伐浣� - public List<String> packIdList = Arrays.asList("OP280","OP360","OP390","OP470"); - - //娴嬭瘯璁惧鎵嬪姩宸ヤ綅 - public List<String> testList = Arrays.asList("OP430-1","OP430-2","OP430-3","OP430-4","OP480-1","OP480-2","OP480-3","OP440"); - - - //绌虹殑 - public List<String> nullList = Arrays.asList("OP250","OP260"); public static MiloService miloService; - Map<String, Session> map = WebSocketUsers.getUsers(); public IDaPassingStationCollectionService daPassingStationCollectionService; @@ -78,6 +62,12 @@ public static WorkOrderService workOrderService; public static KeyCodeCheckService keyCodeCheckService; public static KeyCodeRelationService keyCodeRelationService; + public static QingYanTestInfoService qingYanTestInfoService; + public static SendFactoryMesService sendFactoryMesService; + public static List<SendFactoryMes> sendFactoryMesList; + + @Value("${orderLineUrl}") + private static String orderLineUrl; public OPCUaSubscription(MiloService miloService, IDaPassingStationCollectionService daPassingStationCollectionService, @@ -86,7 +76,9 @@ IOmProductionOrdeInfoService omProductionOrdeInfoService, WorkOrderService workOrderService, KeyCodeCheckService keyCodeCheckService, - KeyCodeRelationService keyCodeRelationService) { + KeyCodeRelationService keyCodeRelationService, + QingYanTestInfoService qingYanTestInfoService, + List<SendFactoryMes> sendFactoryMesList) { OPCUaSubscription.miloService = miloService; this.daPassingStationCollectionService = daPassingStationCollectionService; OPCUaSubscription.collectionParamConfService = collectionParamConfService; @@ -95,6 +87,8 @@ OPCUaSubscription.workOrderService = workOrderService; OPCUaSubscription.keyCodeCheckService = keyCodeCheckService; OPCUaSubscription.keyCodeRelationService = keyCodeRelationService; + OPCUaSubscription.qingYanTestInfoService = qingYanTestInfoService; + OPCUaSubscription.sendFactoryMesList = sendFactoryMesList; } @@ -156,6 +150,15 @@ PART1.add(Constants.OP065); if (Constants.OP010.equals(device)){ //010宸ヤ綅鏃犺繃绔欒褰曪紝鍙粰鏀捐淇″彿 + List<SendFactoryMes> collect = sendFactoryMesList.stream().filter(x -> device.equals(x.getLocationCode())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)){ + for (SendFactoryMes sendFactoryMes : collect) { + ChildVO childVO = new ChildVO(); + childVO.setItemCode(sendFactoryMes.getItemCode()); + childVO.setItemText(sendFactoryMes.getItemText()); + childVO.setItemType(sendFactoryMes.getItemType()); + } + } miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(21).build()); log.info("鍐欏叆鍒板伐浣峽}鐨凴ecordDataDone鏁版嵁锛歿}",device,21); }else if (PART1.contains(device)){ @@ -354,22 +357,29 @@ .eq(DaCollectionParamConf::getRemarks, Constants.ONE)); if (CollUtil.isNotEmpty(list)){ List<DaParamCollection> saveParamList = new ArrayList<>(); - List<String> collect1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())) - .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); + List<DaCollectionParamConf> confColl1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())).collect(Collectors.toList()); + List<DaCollectionParamConf> confColl2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())).collect(Collectors.toList()); + List<DaCollectionParamConf> confColl3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())).collect(Collectors.toList()); + List<DaCollectionParamConf> confColl4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())).collect(Collectors.toList()); + List<DaCollectionParamConf> confColl0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())).collect(Collectors.toList()); + List<String> collect1 = confColl1.stream().map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); List<ReadWriteEntity> paramCollectionList1 = miloService.readFromOpcUa(collect1); - List<String> collect2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())) + List<String> collect2 = confColl2.stream() .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); List<ReadWriteEntity> paramCollectionList2 = miloService.readFromOpcUa(collect2); - List<String> collect3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())) + List<String> collect3 = confColl3.stream() .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); List<ReadWriteEntity> paramCollectionList3 = miloService.readFromOpcUa(collect3); - List<String> collect4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())) + List<String> collect4 = confColl4.stream() .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); List<ReadWriteEntity> paramCollectionList4 = miloService.readFromOpcUa(collect4); - List<String> collect0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())) + List<String> collect0 = confColl0.stream() .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); List<ReadWriteEntity> paramCollectionList0 = miloService.readFromOpcUa(collect0); + + if (CollUtil.isNotEmpty(paramCollectionList1)){ + List<ChildVO> checkList = new ArrayList<>(); for (int i = 0; i < paramCollectionList1.size(); i++) { DaParamCollection daParamCollection = new DaParamCollection(); if (CollUtil.isNotEmpty(keyCodeList) && keyCodeList.size() == 4){ @@ -385,6 +395,34 @@ daParamCollection.setLocationCode(device); daParamCollection.setCollectionTime(new Date()); saveParamList.add(daParamCollection); + ChildVO childVO = new ChildVO(); + childVO.setItemCode(confColl1.get(i).getCollectParameterName()); + childVO.setItemType(confColl1.get(i).getItemType()); + childVO.setItemValue(paramValue); + childVO.setItemText(confColl1.get(i).getParameterSetName()); + childVO.setCheckResult("1"); + childVO.setCheckTime(new Date().toString()); + checkList.add(childVO); + } + //涓婁紶鍒板伐鍘俶es + ParentVO vo = new ParentVO(); + vo.setStationCode(device); + vo.setCheckList(checkList); + vo.setSiteCode("3983"); + vo.setRecordId(UUID.randomUUID().toString()); + vo.setTotalResult("1"); + if (CollUtil.isNotEmpty(keyCodeList) && keyCodeList.size() == 4){ + vo.setProductNum(keyCodeList.get(0)); + } + try{ + CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { + log.info("寮�濮嬫墽琛屽紓姝ユ柟娉�"); + HttpResponse execute = HttpRequest.post(orderLineUrl).body(JSONUtil.toJsonStr(vo)).execute(); + System.out.println(execute.body()); + log.info("寮傛鏂规硶鎵ц缁撴潫"); + }); + }catch (Exception e){ + System.out.println(e.getMessage()); } } if (CollUtil.isNotEmpty(paramCollectionList2)){ @@ -476,11 +514,11 @@ Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_1").getValue(); if (ObjectUtil.isNotNull(value1)){ String string = value1.toString(); - List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>() - .eq(DaParamCollection::getKeyCode, string)); + List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>() + .eq(QingYanTestInfo::getKeyCode, string)); if (CollUtil.isNotEmpty(list)){ - DaParamCollection daParamCollection = list.get(0); - if (Constants.ONE.equals(daParamCollection.getState())){ + QingYanTestInfo qingYanTestInfo = list.get(0); + if (Constants.ONE.equals(qingYanTestInfo.getStatus())){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(1).build()); }else { flag = false; @@ -491,11 +529,11 @@ Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_2").getValue(); if (ObjectUtil.isNotNull(value2)){ String string = value2.toString(); - List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>() - .eq(DaParamCollection::getKeyCode, string)); + List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>() + .eq(QingYanTestInfo::getKeyCode, string)); if (CollUtil.isNotEmpty(list)){ - DaParamCollection paramCollection = list.get(0); - if (Constants.ONE.equals(paramCollection.getState())){ + QingYanTestInfo qingYanTestInfo = list.get(0); + if (Constants.ONE.equals(qingYanTestInfo.getStatus())){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(1).build()); }else { flag = false; @@ -506,11 +544,11 @@ Object value3 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_3").getValue(); if (ObjectUtil.isNotNull(value3)){ String string = value3.toString(); - List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>() - .eq(DaParamCollection::getKeyCode, string)); + List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>() + .eq(QingYanTestInfo::getKeyCode, string)); if (CollUtil.isNotEmpty(list)){ - DaParamCollection paramCollection = list.get(0); - if (Constants.ONE.equals(paramCollection.getState())){ + QingYanTestInfo qingYanTestInfo = list.get(0); + if (Constants.ONE.equals(qingYanTestInfo.getStatus())){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(1).build()); }else { flag = false; @@ -521,11 +559,11 @@ Object value4 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_4").getValue(); if (ObjectUtil.isNotNull(value4)){ String string = value4.toString(); - List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>() - .eq(DaParamCollection::getKeyCode, string)); + List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>() + .eq(QingYanTestInfo::getKeyCode, string)); if (CollUtil.isNotEmpty(list)){ - DaParamCollection paramCollection = list.get(0); - if (Constants.ONE.equals(paramCollection.getState())){ + QingYanTestInfo qingYanTestInfo = list.get(0); + if (Constants.ONE.equals(qingYanTestInfo.getStatus())){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(1).build()); }else { flag = false; -- Gitblit v1.9.3