From 823cbaa8e120a6fc2e72a4e62c06d375cc821562 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期一, 15 一月 2024 17:24:02 +0800
Subject: [PATCH] 1、增加流浪控制器实体(和数据库表); 2、修改部分通信协议实现; 3、增加部分通信协议实现; 4、增加通信中间件RTU上行数据处理任务树部分节点。
---
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/web/com/CommandCtrl.java | 94 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 92 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..aa5f651 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,13 @@
package com.dy.aceMw.web.com;
+import com.dy.aceMw.server.ServerProperties;
+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 +22,7 @@
* @Author liurunyu
* @Date 2023/12/21 13:58
* @LastEditTime 2023/12/21 13:58
- * @Description
+ * @Description 鍛戒护鎺ユ敹
*/
@Slf4j
@RestController
@@ -25,6 +32,89 @@
@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()){
+ if(!ServerProperties.isLowPower){
+ 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()));
+ }
+
}
--
Gitblit v1.8.0