| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | |
| | |
| | | |
| | | 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; |
| | | |
| | |
| | | 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, |
| | |
| | | IOmProductionOrdeInfoService omProductionOrdeInfoService, |
| | | WorkOrderService workOrderService, |
| | | KeyCodeCheckService keyCodeCheckService, |
| | | KeyCodeRelationService keyCodeRelationService) { |
| | | KeyCodeRelationService keyCodeRelationService, |
| | | QingYanTestInfoService qingYanTestInfoService, |
| | | List<SendFactoryMes> sendFactoryMesList) { |
| | | OPCUaSubscription.miloService = miloService; |
| | | this.daPassingStationCollectionService = daPassingStationCollectionService; |
| | | OPCUaSubscription.collectionParamConfService = collectionParamConfService; |
| | |
| | | OPCUaSubscription.workOrderService = workOrderService; |
| | | OPCUaSubscription.keyCodeCheckService = keyCodeCheckService; |
| | | OPCUaSubscription.keyCodeRelationService = keyCodeRelationService; |
| | | OPCUaSubscription.qingYanTestInfoService = qingYanTestInfoService; |
| | | OPCUaSubscription.sendFactoryMesList = sendFactoryMesList; |
| | | |
| | | } |
| | | |
| | |
| | | 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("写入到工位{}的RecordDataDone数据:{}",device,21); |
| | | }else if (PART1.contains(device)){ |
| | |
| | | .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){ |
| | |
| | | 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); |
| | | } |
| | | //上传到工厂mes |
| | | 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)){ |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |