From d819b10d18dc61a53c6f375d82f29d9f953cce4e Mon Sep 17 00:00:00 2001 From: cl <418351270@qq.com> Date: 星期二, 30 七月 2024 10:11:03 +0800 Subject: [PATCH] 修改采集参数 --- jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java | 262 ++++++++++++++++++++++++++++++++++++++++++++++++++-- jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java | 8 2 files changed, 256 insertions(+), 14 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java b/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java index 718629f..0cd9456 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java +++ b/jcdm-main/src/main/java/com/jcdm/main/constant/Constants.java @@ -59,10 +59,10 @@ public static final Integer INT_THREE= 3; public static final Integer INT_FOUR= 4; public static final Integer INT_ZERO= 0; - /* public static final String FACTORY_EMS_UAT_GET_RUL = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/"; - public static final String FACTORY_EMS_UAT_POST_RUL = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/interface/";*/ - public static final String FACTORY_EMS_UAT_GET_RUL = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/"; - public static final String FACTORY_EMS_UAT_POST_RUL = "https://imes-group.geelycv.com/api/mom-open/restful/interface/"; + public static final String FACTORY_EMS_UAT_GET_RUL = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/"; + public static final String FACTORY_EMS_UAT_POST_RUL = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/interface/"; +/* public static final String FACTORY_EMS_UAT_GET_RUL = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/"; + public static final String FACTORY_EMS_UAT_POST_RUL = "https://imes-group.geelycv.com/api/mom-open/restful/interface/";*/ public static final String FACTORY_EMS_SITE_CODE = "3983"; 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 a9e850b..cb79010 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 @@ -3,16 +3,13 @@ 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.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.jcdm.common.core.domain.AjaxResult; import com.jcdm.framework.websocket.WebSocketUsers; import com.jcdm.main.constant.Constants; -import com.jcdm.main.da.cellData.domain.DaCellData; import com.jcdm.main.da.cellData.service.IDaCellDataService; import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; @@ -20,7 +17,6 @@ import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; -import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp; import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService; import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; @@ -32,9 +28,7 @@ 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 org.springframework.web.bind.annotation.GetMapping; import javax.websocket.Session; import java.text.SimpleDateFormat; @@ -106,18 +100,266 @@ public void subHandle(String thoroughfare,String device,String tab,String valueString){ try{ - //鍑哄叆绔� - if (Constants.RECORD_DATA.equals(tab)) { + if (Constants.RECORD_DATA.equals(tab)) { //鍑哄叆绔� if (Constants.ONE.equals(valueString)) {//鍏ョ珯 Integer recordDataDone = 11; miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build()); } else if(Constants.TWO.equals(valueString)){//鍑虹珯 - Integer recordDataDone = 21; - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build()); + Integer result = 21; + //鍏堝垽鏂槸鍚︽湁浜у搧SN + Object snCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); + Object orderObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue(); + if (ObjectUtil.isNull(snCodeObjcet)){ + result = 25;//鏈幏鍙栬鐢熶骇鐨勫伐鍗曪紝璇疯仈绯荤鐞嗗憳 + }else{ + String snCode = snCodeObjcet.toString();//浜у搧SN + String orderNumber = orderObjcet.toString();//宸ュ崟鍙� + Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//绔欑姸鎬佸湴鍧� + if (ObjectUtil.isNotNull(stationStatusObjcet)){ + String stationStatus = stationStatusObjcet.toString(); + result = savePassingStation(thoroughfare, device,snCode,orderNumber,stationStatus);//淇濆瓨杩囩珯 + if(result == 21) { + result = saveParamCollection(device,snCode,orderNumber,stationStatus);//淇濆瓨鍙傛暟锛屽彂閫佸伐鍘侻ES + } + }else{ + result = 23; + log.info("璇诲彇鍒板伐浣峽}StationStatus鏁版嵁锛歿},杩斿洖RecordDataDone鐨勫�间负{}",device,"IS NULL锛�",result); + } + } + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build()); + } + }else if (Constants.RECORD_SN.equals(tab)){//璇锋眰浜у搧搴忓垪鍙� + if (Constants.ONE.equals(valueString)){ + Integer recordSNDone = 11; + //杩涚珯PLC缁欎骇鍝佺被鍨嬶紝MES璇诲彇浜у搧绫诲瀷 + Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//浜у搧绫诲瀷 + if (ObjectUtil.isNotNull(productTypeObjcet)){ + String productType = productTypeObjcet.toString();//浜у搧绫诲瀷 + String materialCode = Constants.materialMap.get(productType); + //鎺ユ敹宸ュ崟锛屼繚瀛樺埌鏁版嵁搴�,骞朵笖灏嗗伐鍗曚紶缁橮LC + CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { + receivingWorkOrders(thoroughfare, device,materialCode); + }); + }else{ + recordSNDone = 12; + } + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(recordSNDone).build()); } } }catch (Exception e) { log.error(e.getMessage()); } } + + /** + * 淇濆瓨杩囩珯鏁版嵁 + * @param thoroughfare 閫氶亾 + * @param device 宸ヤ綅 + * @param snCode 浜у搧搴忓垪鍙� + * @param stationStatus 绔欑姸鎬� + * @return Integer + * @throws Exception e + */ + private static Integer savePassingStation(String thoroughfare, String device,String snCode,String orderNumber,String stationStatus){ + Integer result = 21; + try { + //璇昏繘绔欐椂闂� + Date startTime = new Date(); + ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//杩涚珯鏃堕棿 + if (ObjectUtil.isNotNull(startTimeRead.getValue())){ + startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString()))); + }else{ + result = 23; + log.info("璇诲彇鍒板伐浣峽}鐨凷tartTime鏁版嵁锛歿},杩斿洖RecordDataDone鐨勫�间负{}",device,"IS NULL锛�",result); + return result; + } + + DaPassingStationCollection passingStationCollection = new DaPassingStationCollection(); + passingStationCollection.setSfcCode(snCode);//浜у搧搴忓垪鍙� + passingStationCollection.setWorkOrderNo(orderNumber);//宸ュ崟鍙� + passingStationCollection.setLocationCode(device);//宸ヤ綅 + passingStationCollection.setInboundTime(startTime);//杩涚珯鏃堕棿 + passingStationCollection.setOutboundTime(new Date());//鍑虹珯鏃堕棿 + passingStationCollection.setOutRsSign(stationStatus);//绔欑姸鎬佸�� + passingStationCollection.setCollectionTime(new Date());//閲囬泦鏃堕棿 + daPassingStationCollectionService.save(passingStationCollection); + + } catch (Exception e) { + throw new RuntimeException(e); + } + + return result; + } + + /** + * 淇濆瓨鍙傛暟鏁版嵁鍜屽彂閫佸伐鍘侻ES + * @param device 宸ヤ綅 + * @param snCode 浜у搧SN + * @param orderNumber 宸ュ崟鍙� + * @param stationStatus 绔欑姸鎬� + * @return result + * @throws Exception e + */ + private static Integer saveParamCollection(String device,String snCode,String orderNumber,String stationStatus){ + Integer result = 21;//杩斿洖缁撴灉 + try { + //鏌ヨ鍙傛暟閰嶇疆琛� + List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>() + .eq(DaCollectionParamConf::getProcessesCode, device)//宸ヤ綅 + .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//鏄惁閲囬泦 + ); + if (CollUtil.isNotEmpty(list)){ + + List<String> collect = list.stream() + .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); + List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect); + + List<DaParamCollection> collectionList = new ArrayList<>(); + List<ChildVO> mesList = new ArrayList<>(); + for (int i = 0; i < readWriteEntityList.size(); i++) { + DaParamCollection daParamCollection = new DaParamCollection(); + daParamCollection.setSfcCode(snCode);//浜у搧SN + daParamCollection.setWorkOrderNo(orderNumber);//宸ュ崟鍙� + daParamCollection.setParamCode(list.get(i).getCollectParameterId());//鍙傛暟缂栫爜 + daParamCollection.setParamName(list.get(i).getCollectParameterName());//鍙傛暟鍚嶇О + String paramValue = ""; + if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){ + paramValue = readWriteEntityList.get(i).getValue().toString();//鍙傛暟鍊� + if("DATE".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){ + paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString(); + }else if("MODEL".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){ + paramValue = Constants.materialMap.get(paramValue); + } + } + daParamCollection.setParamValue(paramValue);//鍙傛暟鍊� + daParamCollection.setLocationCode(device);//宸ヤ綅 + daParamCollection.setCollectionTime(new Date());//閲囬泦鏃堕棿 + collectionList.add(daParamCollection);//灏佽鍙傛暟閲囬泦list + + //鍙戦�佺粰宸ュ巶mes鍙傛暟灏佽 + ChildVO childVO = new ChildVO(); + childVO.setItemCode(list.get(i).getCollectParameterId());//鍙傛暟缂栫爜 + childVO.setItemType(list.get(i).getItemType()); + childVO.setItemValue(paramValue);//鍙傛暟鍊� + childVO.setItemText(list.get(i).getCollectParameterName()); + childVO.setCheckResult("1"); + childVO.setCheckTime(format.format(new Date())); + mesList.add(childVO); + } + + /* CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { + //鎻掑叆鍙傛暟閲囬泦琛� + daParamCollectionService.insertBatch(collectionList); + //鐢熶骇鎶ュ伐锛堥宸ヤ綅鍜屾湯宸ヤ綅锛� + if(Constants.OP010.equals(device)) { + reportFactoryMes(snCode, device, format.format(new Date())); + } + //涓婁紶鍒板伐鍘俶es + ParentVO parentVO = new ParentVO(); + parentVO.setStationCode(device);//宸ヤ綅 + parentVO.setSiteCode("3983"); + parentVO.setRecordId(UUID.randomUUID().toString()); + if("2".equals(stationStatus)){//宸ョ珯鐘舵�� + parentVO.setTotalResult("0"); + }else { + parentVO.setTotalResult("1"); + } + parentVO.setProductNum(snCode); + parentVO.setCheckList(mesList); + log.info("鎵ц宸ュ巶MES鏂规硶start锛屽伐浣嶅彿{} 浼犲叆鏁版嵁锛歿}",device ,parentVO); + HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute(); + log.info("鎵ц宸ュ巶MES鏂规硶end锛屽伐浣嶅彿{} 杩斿洖鏁版嵁锛歿}",device,execute.body()); + + });*/ + } + }catch (Exception e) { + throw new RuntimeException(e); + } + return result; + } + + /** + * 鎺ユ敹宸ュ崟淇℃伅 + * @param thoroughfare 閫氶亾 + * @param device 宸ヤ綅 + * @param materialCode 鐗╂枡鍙� + * @throws Exception e + */ + public synchronized void receivingWorkOrders(String thoroughfare ,String device ,String materialCode) + { + try { + String productNum = "";//妯$粍鐮� + String orderNum = "";//宸ュ崟鍙� + + //鍏堟煡璇㈣〃涓槸鍚︽湁鍓╀綑宸ュ崟 + List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>() + .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE) + .eq(OmProductionOrdeInfo::getStationCode,device)//宸ヤ綅 + .eq(OmProductionOrdeInfo::getProductCode,materialCode));//浜у搧绫诲瀷 + if (CollUtil.isNotEmpty(orderList)){ + Long id = orderList.get(0).getId(); + productNum = orderList.get(0).getProductNum();//妯$粍鐮� + orderNum = orderList.get(0).getWorkOrderNo(); + }else{ + // 鏌ヨ鏈�鏂扮殑宸ュ崟淇℃伅 + OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder(); + + log.info("璇锋眰宸ュ巶MES宸ュ崟锛氬叆鍙俤evice{},materialCode锛歿}", device, materialCode); + String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode); + log.info("璇锋眰宸ュ巶MES宸ュ崟锛氬嚭鍙俻ack锛歿}", orderJsonString); + + JSONObject jsonObject = new JSONObject(orderJsonString); + // 浠嶫SONObject涓幏鍙杁ata瀵硅薄 + JSONObject dataObject = jsonObject.getJSONObject("data"); + String code = jsonObject.getStr("code"); + // 鍒ゆ柇鎺ュ崟鏄惁鎴愬姛 + if(code.equals("success")) { + OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); + omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum")); + omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum")); + omProductionOrdeInfo.setStationCode(device); + omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode")); + omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity"))); + omProductionOrdeInfo.setOnlineCompletionMark("0"); + omProductionOrdeInfo.setSfResult("0"); + omProductionOrdeInfo.setProductModel(dataObject.getStr("model")); + omProductionOrdeInfo.setCreateTime(new Date()); + omProductionOrdeInfo.setCreateUser("宸ュ巶MES"); + omProductionOrdeInfoService.save(omProductionOrdeInfo); + + productNum = dataObject.getStr("productNum"); + orderNum = dataObject.getStr("productionOrderNum"); + } + } + //涓嬪彂浜у搧SN鍜屽伐鍗曞彿 + if(!productNum.isEmpty() && !orderNum.isEmpty()){ + miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build()); + miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build()); + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * 宸ュ巶MES鎶ュ伐 + * @param productNum 閫氶亾 + * @param stationCode 宸ヤ綅 + * @param confirmTime 鐗╂枡鍙� + * @throws Exception e + */ + //{"code":"success","data":{"productNum":"LCV123456P0600036","stationCode":"1HZ01","resultCode":"S","resultText":"鎶ュ伐鎴愬姛"},"message":"API璋冪敤鎴愬姛"} + public static void reportFactoryMes(String productNum, String stationCode, String confirmTime) + { + String result = ""; + try { + String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime; + HttpResponse response = HttpRequest.get(url).execute(); + /*HttpRequest httpRequest = HttpRequest.get(url);*/ + result = response.body(); + }catch (Exception e){ + throw new RuntimeException(e); + } + } } -- Gitblit v1.9.3