From 0d753084de2b9c50955fc387b1776a0d37a914c5 Mon Sep 17 00:00:00 2001 From: admin <15939171744@163.com> Date: 星期五, 25 四月 2025 09:37:47 +0800 Subject: [PATCH] 优化 --- jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java | 178 +++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 118 insertions(+), 60 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 5a34de4..0a7f109 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 @@ -109,66 +109,108 @@ if (Constants.RECORD_DATA.equals(tab)) { //鍑哄叆绔� if (Constants.ONE.equals(valueString)) {//鍏ョ珯 if(Constants.OP040_OP160.contains(device)){//浜哄伐宸ヤ綅 - Object snCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); - if (ObjectUtil.isNull(snCodeObjcet)){ + Object snCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); + if (ObjectUtil.isNull(snCodeObject)){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build()); }else{ - String productNum = snCodeObjcet.toString(); - //灏嗕骇鍝丼N鍙戦�佸埌鍓嶅彴 - productNum = "productNum,"+ productNum; - WebSocketUsers.sendMessageToUserByText(map.get(device), productNum); - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build()); + String productNum = snCodeObject.toString().trim(); + if(productNum.length()<10){ + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build()); + }else{ + //灏嗕骇鍝丼N鍙戦�佸埌鍓嶅彴 + productNum = "productNum,"+ productNum; + WebSocketUsers.sendMessageToUserByText(map.get(device), productNum); + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build()); + String str = thoroughfare + "." + device + ".MESScrew"; + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(1).build());//鎷х揣姝ラ + } + } }else {//鑷姩宸ヤ綅 - //鎵�鏈夎繘绔欏皢杩涚珯鏃堕棿鍐欑粰PLC - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String currentDate = dateFormat.format(new Date()); - miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(currentDate).build()); + Object snCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); + if (ObjectUtil.isNull(snCodeObject)){ + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build()); + }else{ + //鎵�鏈夎繘绔欏皢杩涚珯鏃堕棿鍐欑粰PLC + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String currentDate = dateFormat.format(new Date()); + miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(currentDate).build()); - Integer recordDataDone = 11; - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build()); + Integer recordDataDone = 11; + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build()); + } + } } else if(Constants.TWO.equals(valueString)){//鍑虹珯 if(Constants.OP040_OP160.contains(device)){//浜哄伐宸ヤ綅 - WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); - } else if (Constants.OP165.equals(device)) { - WebSocketUsers.sendMessageToUserByText(map.get(device), "print");//鎵撳嵃 - } else if (Constants.OP0170_OP230.contains(device)) { + if(Constants.OP165.equals(device)){ + WebSocketUsers.sendMessageToUserByText(map.get(device), "print");//鎵撳嵃 + }else { + WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); + } + } else if (Constants.OP0170_OP220.contains(device)) { WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); } else{//鑷姩宸ヤ綅 //鍏堝垽鏂槸鍚︽湁浜у搧SN - Object snCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); + Object snCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); Object orderObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue(); - if (ObjectUtil.isNull(snCodeObjcet)){ + if (ObjectUtil.isNull(snCodeObject)){ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(25).build()); }else { - //鎵�鏈夊嚭绔欏皢鍑虹珯鏃堕棿鍐欑粰PLC - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String currentDate = dateFormat.format(new Date()); - miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StopTime").value(currentDate).build()); Integer result = 21; - 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(); - if (Constants.OP010.equals(device)) { - CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { - updateOrderStatus(snCode, "3");//OP010宸ヤ綅鏇存柊宸ュ崟鐘舵�佷负鎵ц涓� - reportFactoryMes(snCode, device, format.format(new Date()));//宸ュ巶MES鎶ュ伐 - }); + String snCode = snCodeObject.toString().trim();//浜у搧SN + String orderNumber = orderObjcet.toString().trim();//宸ュ崟鍙� + if(snCode.length()<10){ + result = 22; + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build()); + }else { + //鎵�鏈夊嚭绔欏皢鍑虹珯鏃堕棿鍐欑粰PLC + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String currentDate = dateFormat.format(new Date()); + miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StopTime").value(currentDate).build()); + + Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//绔欑姸鎬佸湴鍧� + if (ObjectUtil.isNotNull(stationStatusObjcet)) { + String stationStatus = stationStatusObjcet.toString(); + if (Constants.OP010.equals(device)) { + Object housingCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".HousingCode").getValue();//澹充綋鏉$爜锛屽瓨鍒板伐鍗曪紝杩斾慨鐢� + if (ObjectUtil.isNull(housingCodeObject)){ + result = 25; + }else{ + String housingCode = housingCodeObject.toString();//澹充綋鏉$爜锛屽瓨鍒板伐鍗曪紝杩斾慨鐢� + if(housingCode.length()<10){ + result = 25; + }else{ + CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { + updateOrderStatus(snCode, "3",housingCode);//OP010宸ヤ綅鏇存柊宸ュ崟鐘舵�佷负鎵ц涓�,骞舵洿鏂颁富鐗╂枡澹充綋鏉$爜 + reportFactoryMes(snCode, device, format.format(new Date()));//宸ュ巶MES鎶ュ伐 + }); + } + } + } + if(Constants.OP230.equals(device)){ + WebSocketUsers.sendMessageToUserByText(map.get(device), "twoHundredAndThirtyEND"); + CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { + updateOrderStatus(snCode, "5","");//OP230宸ヤ綅鏇存柊宸ュ崟鐘舵�佷负宸插畬鎴� + reportFactoryMes(snCode, "OP240", format.format(new Date()));//宸ュ巶MES鎶ュ伐 //鏆傛椂 OP240宸ヤ綅杩樻病鏈夊ソ锛屽湪230鎶�240鐨勫伐 + }); + miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SNCode").value("").build()); + } + if(result == 21){ + 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); } - 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()); } - miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build()); + } } } @@ -312,6 +354,8 @@ parentVO.setRecordId(UUID.randomUUID().toString()); if("2".equals(stationStatus)){//宸ョ珯鐘舵�� parentVO.setTotalResult("0"); + }else{ + parentVO.setTotalResult("1"); } parentVO.setProductNum(snCode); parentVO.setCheckList(mesList); @@ -344,7 +388,8 @@ List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>() .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE) .eq(OmProductionOrdeInfo::getStationCode,device)//宸ヤ綅 - .eq(OmProductionOrdeInfo::getProductCode,materialCode));//浜у搧绫诲瀷 + //.eq(OmProductionOrdeInfo::getProductCode,materialCode) + );//浜у搧绫诲瀷 if (CollUtil.isNotEmpty(orderList)){ Long id = orderList.get(0).getId(); productNum = orderList.get(0).getProductNum();//浜у搧鐮� @@ -352,9 +397,9 @@ }else{ // 鏌ヨ鏈�鏂扮殑宸ュ崟淇℃伅 OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder(); - - log.info("璇锋眰宸ュ巶MES宸ュ崟锛氬叆鍙俤evice{},materialCode锛歿}", device, materialCode); - String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "OP010",materialCode); + String facMaterialCode = Constants.facMaterialMap.get(materialCode); + log.info("璇锋眰宸ュ巶MES宸ュ崟锛氬叆鍙俤evice{},璇锋眰宸ュ巶鐗╂枡缂栫爜,浜у搧鐗╂枡缂栫爜MaterialCode{}", device,materialCode); + String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), device,facMaterialCode); log.info("璇锋眰宸ュ巶MES宸ュ崟锛氬嚭鍙俻ack锛歿}", orderJsonString); JSONObject jsonObject = new JSONObject(orderJsonString); @@ -362,12 +407,13 @@ JSONObject dataObject = jsonObject.getJSONObject("data"); String code = jsonObject.getStr("code"); // 鍒ゆ柇鎺ュ崟鏄惁鎴愬姛 - if(code.equals("success")) { + if("success".equals(code)) { OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum")); omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum")); omProductionOrdeInfo.setStationCode(device); - omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode")); + omProductionOrdeInfo.setProductCode(materialCode); + omProductionOrdeInfo.setMaterialCode(dataObject.getStr("materialCode")); omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity"))); omProductionOrdeInfo.setOnlineCompletionMark("0"); omProductionOrdeInfo.setSfResult("0"); @@ -385,6 +431,8 @@ miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SNCode").value(productNum).build()); miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build()); miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build()); + }else{ + miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build()); } } catch (Exception e) { @@ -396,13 +444,20 @@ * 鏇存柊宸ュ崟 * @param snCode 浜у搧sn * @param orderStatus 宸ュ崟鐘舵�� + * @param materialCode 澹充綋鏉$爜 * @throws Exception e */ - private static void updateOrderStatus(String snCode,String orderStatus){ + private static void updateOrderStatus(String snCode,String orderStatus,String materialCode){ try { //鏇存柊宸ュ崟鐘舵�佷负宸叉墽琛� LambdaUpdateWrapper<OmProductionOrdeInfo> updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.set(OmProductionOrdeInfo::getOrderStatus,orderStatus); + if(!materialCode.isEmpty()){//涓婄嚎 + updateWrapper.set(OmProductionOrdeInfo::getTrolleyYard,materialCode);//澹充綋鏉$爜 + updateWrapper.set(OmProductionOrdeInfo::getActualStartTime,new Date());//寮�濮嬫椂闂� + }else{//涓嬬嚎 + updateWrapper.set(OmProductionOrdeInfo::getActualEndTime,new Date());//缁撴潫鏃堕棿 + } updateWrapper.eq(OmProductionOrdeInfo::getProductNum,snCode); omProductionOrdeInfoService.update(new OmProductionOrdeInfo(),updateWrapper); } catch (Exception e) { @@ -415,27 +470,30 @@ * 宸ュ巶MES鎶ュ伐 * @param productNum 閫氶亾 * @param stationCode 宸ヤ綅 - * @param confirmTime 鐗╂枡鍙� + * @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) + public static void reportFactoryMes(String productNum,String stationCode,String confirmTime) { + String result = ""; + String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime; try { - CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { - log.info("璇锋眰宸ュ巶MES鎶ュ伐锛氬叆鍙俤evice{},productNum锛歿}", stationCode, productNum); - 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);*/ - String result = response.body(); - log.info("璇锋眰宸ュ巶MES鎶ュ伐锛氬嚭鍙傦細{}", result); - }); - + log.info("鎵ц宸ュ巶MES鎶ュ伐鏂规硶start锛屽簭鍒楀彿{}宸ヤ綅鍙穥}url{}",productNum,stationCode ,url); + HttpResponse response = HttpRequest.get(url).execute(); + //HttpRequest httpRequest = HttpRequest.get(url); + result = response.body(); + log.info("鎵ц宸ュ巶MES鎶ュ伐鏂规硶绗竴娆nd锛屽簭鍒楀彿{}宸ヤ綅鍙穥}杩斿洖鏁版嵁{}",productNum,stationCode ,result); }catch (Exception e){ throw new RuntimeException(e); + }finally { + if(result.isEmpty()){ + HttpResponse response = HttpRequest.get(url).execute(); + result = response.body(); + log.info("鎵ц宸ュ巶MES鎶ュ伐鏂规硶绗簩娆nd锛屽簭鍒楀彿{}宸ヤ綅鍙穥}杩斿洖鏁版嵁{}",productNum,stationCode ,result); + } } } - public static String TightenTheConversionOkNg(String param){ // 鍘婚櫎棣栧熬鐨勬柟鎷彿锛岀劧鍚庢寜鐓ч�楀彿鍒嗗壊瀛楃涓� String[] parts = param.substring(1, param.length() - 1).split(","); -- Gitblit v1.9.3