From 64358eae8ae53923f408963538e0f5a7c8bdb198 Mon Sep 17 00:00:00 2001 From: Administrator <zhubaomin> Date: 星期五, 22 十二月 2023 15:53:53 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/web/com/CommandCtrl.java | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 106 insertions(+), 2 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/web/com/CommandCtrl.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/web/com/CommandCtrl.java index 454c899..ddfb760 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/web/com/CommandCtrl.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/web/com/CommandCtrl.java @@ -1,6 +1,12 @@ package com.dy.aceMw.web.com; +import com.dy.aceMw.server.forTcp.TcpSessionCache; +import com.dy.aceMw.server.local.CommandInnerDeaLer; +import com.dy.aceMw.server.local.ReturnCommand; +import com.dy.aceMw.server.tasks.RtuDownTask; +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 lombok.extern.slf4j.Slf4j; @@ -15,7 +21,7 @@ * @Author liurunyu * @Date 2023/12/21 13:58 * @LastEditTime 2023/12/21 13:58 - * @Description + * @Description 鍛戒护鎺ユ敹 */ @Slf4j @RestController @@ -25,6 +31,104 @@ @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) public BaseResponse<Command> send(@RequestBody Command com) { - return BaseResponseUtils.buildSuccess(com); + log.info("鏀跺埌web绯荤粺鍙戞潵鐨勫懡浠わ細\n" + com.toString()) ; + + String commandType = com.getType() ; + if(commandType == null){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛屾敹鍒板懡浠ょ殑鍛戒护绫诲瀷涓虹┖锛�", com.getId(), com.getCode())); + } + String commandId = com.getId() ; + if(commandId == null){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛屾敹鍒板懡浠ょ殑鍛戒护ID涓虹┖锛�",null, com.getCode())); + } + + String code = com.getCode() ; + if(code == null){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛屾敹鍒板懡浠ょ殑鍛戒护鍔熻兘鐮佷负绌猴紒", com.getId(), null)); + } + + if(commandType.equals(CommandType.innerCommand)){ + //閫氫俊涓棿浠跺唴閮ㄥ懡浠わ紝渚嬪鏌ヨ鐩戞帶涓棿浠舵椂閽燂紝鏌ヨ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鎴愬憳鍚屾寰楀埌鍛戒护澶勭悊缁撴灉锛屼絾鏋勯�犲懡浠ゅ強涓嬪彂鍛戒护鍜屽懡浠ょ粨鏋滄帴鏀惰寮傛寰楀埌 + 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.resultCommand)){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛岄�氫俊涓棿浠朵笉鎺ョ粨鏋滅被鍨嬬殑鍛戒护锛�", com.getId(), com.getCode())); + }else{ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛屾敹鍒板懡浠ょ殑鍛戒护鍔熻兘鐮佷负绌猴紒", com.getId(), com.getCode())); + } } + + /** + * 澶勭悊鍙戝悜RTU鐨勫閮ㄥ懡浠� + * @return 缁撴灉 + */ + private BaseResponse<Command> dealOuterCommand(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()){ + return BaseResponseUtils.buildError(ReturnCommand.errored("鍑洪敊锛孯TU锛堝湴鍧�=" + rtuAddr + "锛夌绾匡紒", command.getId(), command.getCode())) ; + } + + //鐢熸垚寮傛浠诲姟 + RtuDownTask task = new RtuDownTask() ; + task.data = command ; + try{ + log.info("鏋勯�犱笅鍙戣繙绋嬪懡浠�" + command.getCode() + "鐨勬牳蹇冧换鍔★紝骞舵斁鍏ヤ换鍔¢槦鍒椾腑"); + CoreUnit.getInstance().pushCoreTask(task); + }catch(Exception e){ + log.error(e.getMessage(), e); + return BaseResponseUtils.buildError(ReturnCommand.successed("鍛戒护澶勭悊澶辫触" + e.getMessage(), command.getId(), command.getCode())) ; + } + + return BaseResponseUtils.buildSuccess(ReturnCommand.successed("鍛戒护宸叉帴鍙楋紝鍗冲皢鏋勯�犲苟涓嬪彂鍛戒护銆�", command.getId(), command.getCode())); + } + + /** + * 鏀跺埌鍛戒护缁撴灉 + * @param command + private void dealCommandResult(String jgSenderName, Command command){ + Object obj = command.getParam() ; + if(obj != null){ + CommandBackParam p = (CommandBackParam)obj ; + if(p.getSuccess()){ + log.info("鍛戒护" + (command.getId().equals(Command.defaultId)?"":("(id=" + command.getId() + ")")) + "鎵ц鎴愬姛" + + (p.getMessage() == null?"":(p.getMessage().equals("")?"":("锛�" + p.getMessage())))); + }else{ + log.error("鍛戒护" + (command.getId().equals(Command.defaultId)?"":("(id=" + command.getId() + ")")) + "鎵ц澶辫触" + + (p.getMessage() == null?"":(p.getMessage().equals("")?"":("锛�" + p.getMessage())))); + } + } + } + */ } -- Gitblit v1.8.0