From 70f61b0638e32274d0e5f9b972ce2a18f139f1b4 Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期四, 12 六月 2025 09:51:30 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java | 193 +++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 164 insertions(+), 29 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java index 46ad9d1..a53defb 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java @@ -1,17 +1,22 @@ package com.dy.rtuMw.web.com; import com.dy.common.softUpgrade.state.UpgradeTaskVo; +import com.dy.common.webUtil.ResultCodeMsg; import com.dy.rtuMw.resource.ResourceUnit; import com.dy.rtuMw.server.ServerProperties; import com.dy.rtuMw.server.forTcp.TcpSessionCache; import com.dy.rtuMw.server.local.CommandInnerDeaLer; import com.dy.rtuMw.server.local.ReturnCommand; +import com.dy.rtuMw.server.mqtt.MqttManager; +import com.dy.rtuMw.server.msCenter.MsCenterUnit; +import com.dy.rtuMw.server.tasks.WebDownCom4MqttTask; import com.dy.rtuMw.server.tasks.WebDownComTask; import com.dy.common.mw.core.CoreUnit; import com.dy.common.mw.protocol.Command; import com.dy.common.mw.protocol.CommandType; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.rtuMw.server.tasks.WebDownTransparentComTask; import com.dy.rtuMw.server.upgrade.UpgradeUnit; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServletRequest; @@ -53,7 +58,21 @@ */ @GetMapping("/rtuLogFile") public void rtuLogFile(String rtuAddr, HttpServletRequest req, HttpServletResponse rep){ - File logFile = ResourceUnit.getInstance().getLogFile(rtuAddr + ".log") ; + logFile(rtuAddr, req, rep) ; + } + + /** + * 涓嬭浇鎺у埗鍣紙RTU锛変笂涓嬭鏁版嵁鐨刲og鏃ュ織鏂囦欢 + * @param devId + * @param req + * @param rep + */ + @GetMapping("/mqttDevLogFile") + public void mqttDevLogFile(String devId, HttpServletRequest req, HttpServletResponse rep){ + logFile(devId, req, rep) ; + } + private void logFile(String fileName, HttpServletRequest req, HttpServletResponse rep){ + File logFile = ResourceUnit.getInstance().getLogFile(fileName + ".log") ; if(logFile != null && logFile.exists()){ //鍦⊿pring Boot涓紝application/octet-stream;charset=UTF-8閫氬父琛ㄧず鍝嶅簲鐨勫唴瀹规槸瀛楄妭娴侊紝 //骞朵笖瀛楃闆嗘槸UTF-8銆傚浜庤繖绉嶇被鍨嬬殑鍝嶅簲锛孲pring Boot榛樿浣跨敤ByteArrayHttpMessageConverter鏉ュ鐞嗭紝 @@ -62,7 +81,7 @@ //瀛楃闆嗛�氬父鐢ㄤ簬鏂囨湰鍐呭锛岃�宎pplication/octet-stream閫氬父鐢ㄤ簬浜岃繘鍒跺唴瀹癸紝鍥犳鍦ㄨ繖绉嶆儏鍐典笅鎸囧畾瀛楃闆嗗彲鑳芥槸涓嶅悎閫傜殑銆� //涓嶈繃锛屽鏋滀綘纭疄闇�瑕佸鐞嗗甫鏈夌壒瀹氬瓧绗﹂泦鐨刟pplication/octet-stream鍝嶅簲锛屼綘鍙兘闇�瑕佽嚜瀹氫箟HttpMessageConverter銆� rep.addHeader("content-type", "application/octet-stream;charset=UTF-8"); - rep.addHeader("Content-Disposition", "attachment;fileName=" + (rtuAddr + ".log")) ; + rep.addHeader("Content-Disposition", "attachment;fileName=" + (fileName + ".log")) ; ServletOutputStream out = null; FileInputStream in = null ; try { @@ -107,27 +126,38 @@ */ @GetMapping("/rtuLogText") public BaseResponse<List<String>> rtuLogText(String rtuAddr){ + return logText(rtuAddr, true) ; + } + /** + * 涓嬭浇鎺у埗鍣紙RTU锛変笂涓嬭鏁版嵁鐨刲og鏃ュ織鏂囦欢 + * @param devId + */ + @GetMapping("/mqttDevLogText") + public BaseResponse<List<String>> mqttDevLogText(String devId){ + return logText(devId, false) ; + } + /** + * 涓嬭浇鎺у埗鍣紙RTU锛変笂涓嬭鏁版嵁鐨刲og鏃ュ織鏂囦欢 + * @param fileName + * @param reverseOrder + */ + private BaseResponse<List<String>> logText(String fileName, boolean reverseOrder){ List<String> list ; - File logFile = ResourceUnit.getInstance().getLogFile(rtuAddr + ".log") ; + File logFile = ResourceUnit.getInstance().getLogFile(fileName + ".log") ; if(logFile != null && logFile.exists()){ BufferedReader reader = null ; try { reader = new BufferedReader(new FileReader(logFile)) ; - //鏂扮殑瀹炵幇鏂规硶 Stream<String> linesStream = reader.lines() ; - //list = linesStream.toList() ; //鎸夊師鏉ラ『搴� - list = linesStream.sorted(Comparator.reverseOrder()).collect(Collectors.toList()) ;//鍊掑簭 - /* 鍘熸潵鐨勫疄鐜版柟娉� - list = new ArrayList() ; - String line ; - while((line = reader.readLine()) != null){ - list.add(line) ; + if(reverseOrder){ + list = linesStream.sorted(Comparator.reverseOrder()).collect(Collectors.toList()) ;//鍊掑簭 + }else{ + list = linesStream.toList() ; //鎸夊師鏉ラ『搴� } - */ return BaseResponseUtils.buildSuccess(list); } catch (Exception e) { list = new ArrayList() ; - list.add("璇诲彇鎺у埗鍣紙" + rtuAddr + "锛夌殑鏃ュ織鏂囦欢寮傚父锛�" + (e.getMessage() == null?"":("锛�" + e.getMessage()))) ; + list.add("璇诲彇鎺у埗鍣紙" + fileName + "锛夌殑鏃ュ織鏂囦欢寮傚父锛�" + (e.getMessage() == null?"":("锛�" + e.getMessage()))) ; return BaseResponseUtils.buildSuccess(list); }finally{ if(reader != null){ @@ -139,10 +169,28 @@ } }else{ list = new ArrayList() ; - list.add("鏈緱鍒版帶鍒跺櫒锛�" + rtuAddr + "锛夌殑鏃ュ織鏂囦欢") ; + list.add("鏈緱鍒版帶鍒跺櫒锛�" + fileName + "锛夌殑鏃ュ織鏂囦欢") ; return BaseResponseUtils.buildSuccess(list); } } + + + /** + * 娉ㄥ唽娑堟伅鎺ユ敹鑰� + * @param msReceiverWebUrl 娑堟伅鎺ユ敹鑰厀eb http post url + * @return + */ + @GetMapping("/registerMsReceiverWebUrl") + public BaseResponse<Boolean> registerMsReceiverWebUrl(String msReceiverWebUrl){ + try{ + MsCenterUnit.getInstance().registerMsReceiver(msReceiverWebUrl); + }catch (Exception e){ + log.error("娉ㄥ唽娑堟伅鎺ユ敹鑰呮椂鍙戠敓寮傚父", e); + return BaseResponseUtils.buildError("娉ㄥ唽娑堟伅鎺ユ敹鑰呮椂鍙戠敓寮傚父" + (e.getMessage() == null?"":("锛�" + e.getMessage()))); + } + return BaseResponseUtils.buildSuccess(true); + } + /** * 鎺ユ敹web绯荤粺鍙戞潵鍗囩骇浠诲姟 * @param vo @@ -158,6 +206,27 @@ return BaseResponseUtils.buildError("璁剧疆RTU鍗囩骇浠诲姟鏃跺彂鐢熷紓甯�" + (e.getMessage() == null?"":("锛�" + e.getMessage()))); } return BaseResponseUtils.buildSuccess(true); + } + + /** + * 鎺ユ敹web绯荤粺鍙戞潵寮哄埗缁撴潫鍗囩骇浠诲姟 + * @return + */ + @GetMapping(path = "ugForceOver") + public BaseResponse<String> ugForceOver() { + log.info("鏀跺埌鍋滄RTU鍗囩骇浠诲姟鍛戒护") ; + try{ + String mes = UpgradeUnit.getInstance().forceOverUpgradeTask(); + if(mes == null){ + mes = "鍋滄鍗囩骇浠诲姟鎴愬姛" ; + return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.SUCCESS_CODE, mes, mes); + }else{ + return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.FAIL_CODE, mes, mes); + } + }catch (Exception e){ + log.error("鍋滄RTU鍗囩骇浠诲姟鏃跺彂鐢熷紓甯�", e); + return BaseResponseUtils.buildError("鍋滄RTU鍗囩骇浠诲姟鏃跺彂鐢熷紓甯�" + (e.getMessage() == null?"":("锛�" + e.getMessage()))); + } } /** @@ -187,28 +256,28 @@ //閫氫俊涓棿浠跺唴閮ㄥ懡浠わ紝渚嬪鏌ヨ鐩戞帶涓棿浠舵椂閽燂紝鏌ヨRTU鍦ㄧ嚎鎯呭喌绛� try{ Command reCom = new CommandInnerDeaLer().deal(com) ; - /* - boolean error = false ; - if(reCom.param != null && reCom.param != null){ - CommandBackParam cbp = (CommandBackParam)reCom.param ; - if(cbp.getSuccess() != null && !cbp.getSuccess().booleanValue()){ - error = true ; - return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null)); - } - } - if(!error){ - return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null)); - } - */ return BaseResponseUtils.buildSuccess(reCom); }catch(Exception e){ return BaseResponseUtils.buildError(ReturnCommand.errored("澶勭悊鍐呴儴鍛戒护鍑洪敊" + (e.getMessage() == null?"":("锛�" + e.getMessage())), com.getId(), com.getCode()) ); } - }else if(commandType.equals(CommandType.outerCommand)){ - //鍙戝悜RTU鐨勫閮ㄥ懡浠わ紝寮傛澶勭悊锛寃eb绔痡roups鎴愬憳鍚屾寰楀埌鍛戒护澶勭悊缁撴灉锛屼絾鏋勯�犲懡浠ゅ強涓嬪彂鍛戒护鍜屽懡浠ょ粨鏋滄帴鏀惰寮傛寰楀埌 + //鍙戝悜RTU鐨勫閮ㄥ懡浠� try{ return this.dealOuterCommand(com) ; + }catch(Exception e){ + return BaseResponseUtils.buildError(ReturnCommand.errored("澶勭悊鍙戝悜RTU鐨勫閮ㄥ懡浠ゅ嚭閿�" + (e.getMessage() == null?"":("锛�" + e.getMessage())), com.getId(), com.getCode()) ); + } + }else if(commandType.equals(CommandType.outerTransCommand)){ + //鍙戝悜RTU鐨勫閮ㄩ�忎紶鍛戒护 + try{ + return this.dealOutTransparentCommand(com) ; + }catch(Exception e){ + return BaseResponseUtils.buildError(ReturnCommand.errored("澶勭悊鍙戝悜RTU鐨勫閮ㄩ�忎紶鍛戒护鍑洪敊" + (e.getMessage() == null?"":("锛�" + e.getMessage())), com.getId(), com.getCode()) ); + } + }else if(commandType.equals(CommandType.mqttCommand)){ + //鍙戝悜MQTT鐨勫閮ㄥ懡浠� + try{ + return this.dealMqttCommand(com) ; }catch(Exception e){ return BaseResponseUtils.buildError(ReturnCommand.errored("澶勭悊鍙戝悜RTU鐨勫閮ㄥ懡浠ゅ嚭閿�" + (e.getMessage() == null?"":("锛�" + e.getMessage())), com.getId(), com.getCode()) ); } @@ -266,4 +335,70 @@ return BaseResponseUtils.buildSuccess(ReturnCommand.successed("鍛戒护宸叉帴鍙楋紝鍗冲皢鏋勯�犲苟涓嬪彂鍛戒护銆�", command.getId(), command.getCode())); } + + + /** + * 澶勭悊鍙戝悜RTU鐨勫閮ㄥ懡浠� + * @return 缁撴灉 + */ + private BaseResponse<Command> dealOutTransparentCommand(Command command){ + String rtuAddr = command.getRtuAddr() ; + if(rtuAddr == null || rtuAddr.trim().equals("")){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孯TU鍦板潃涓虹┖锛�", command.getId(), command.getCode())) ; + } + rtuAddr = rtuAddr.trim() ; + Boolean onLine = TcpSessionCache.isConnect(rtuAddr); + if(onLine == null){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孯TU锛堝湴鍧�=" + rtuAddr + "锛夋湭涓婄嚎锛�", command.getId(), command.getCode())) ; + }else if(!onLine.booleanValue()){ + if(!ServerProperties.isLowPower){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孯TU锛堝湴鍧�=" + rtuAddr + "锛夌绾匡紒", command.getId(), command.getCode())) ; + } + } + + //鐢熸垚寮傛浠诲姟 + WebDownTransparentComTask task = new WebDownTransparentComTask() ; + task.data = command ; + try{ + log.info("鏋勯�犱笅鍙戣繙绋嬮�忎紶鍛戒护" + command.getCode() + "鐨勬牳蹇冧换鍔★紝骞舵斁鍏ヤ换鍔¢槦鍒椾腑"); + CoreUnit.getInstance().pushCoreTask(task); + }catch(Exception e){ + log.error(e.getMessage(), e); + return BaseResponseUtils.buildError(ReturnCommand.errored("閫忎紶鍛戒护澶勭悊澶辫触" + e.getMessage(), command.getId(), command.getCode())) ; + } + + return BaseResponseUtils.buildSuccess(ReturnCommand.successed("閫忎紶鍛戒护宸叉帴鍙楋紝鍗冲皢鏋勯�犲苟涓嬪彂鍛戒护銆�", command.getId(), command.getCode())); + } + + /** + * 澶勭悊鍙戝悜RTU鐨勫閮ㄥ懡浠� + * @return 缁撴灉 + */ + private BaseResponse<Command> dealMqttCommand(Command command){ + String rtuAddr = command.getRtuAddr() ; + if(rtuAddr == null || rtuAddr.trim().equals("")){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛岃澶嘔D涓虹┖锛�", command.getId(), command.getCode())) ; + } + if(!ServerProperties.mqttUnitEnable.booleanValue()){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孧QTT杩炴帴妯″潡閰嶇疆鏈惎鍔紒", command.getId(), command.getCode())) ; + } + if(MqttManager.getInstance().poolIsClose()){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孧QTT杩炴帴姹犳按鍒涘缓鎴愬姛锛�", command.getId(), command.getCode())) ; + } + + //鐢熸垚寮傛浠诲姟 + WebDownCom4MqttTask task = new WebDownCom4MqttTask() ; + task.data = command ; + try{ + log.info("鏋勯�犱笅鍙慚QTT鍛戒护" + command.getCode() + "鐨勬牳蹇冧换鍔★紝骞舵斁鍏ヤ换鍔¢槦鍒椾腑"); + CoreUnit.getInstance().pushCoreTask(task); + }catch(Exception e){ + log.error(e.getMessage(), e); + return BaseResponseUtils.buildError(ReturnCommand.successed("MQTT鍛戒护澶勭悊澶辫触" + e.getMessage(), command.getId(), command.getCode())) ; + } + return BaseResponseUtils.buildSuccess(ReturnCommand.successed("MQTT鍛戒护宸叉帴鍙楋紝鍗冲皢鏋勯�犲苟涓嬪彂鍛戒护銆�", command.getId(), command.getCode())); + } + + + } -- Gitblit v1.8.0