From d20d38e22b06559d758c568769017e2acf632583 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 23 四月 2025 14:06:48 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/Command.java | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 232 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/Command.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/Command.java
new file mode 100644
index 0000000..f7334b8
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/Command.java
@@ -0,0 +1,232 @@
+package com.dy.common.mw.protocol;
+
+import java.io.Serializable;
+
+import com.alibaba.fastjson2.JSON ;
+import com.alibaba.fastjson2.JSONObject;
+
+public class Command implements Serializable{
+
+ public static final long serialVersionUID;
+ static {
+ serialVersionUID = 201211292156L;
+ }
+
+ /**
+ * 褰撳懡浠ょ粨鏋滆繑鍥炵殑缃戝潃鏄鍊兼椂锛屽拷鐣ユ墽琛岋紝渚嬪涓棿浠朵富鍔ㄤ笅鍙戠殑鍛戒护锛屽氨涓嶇敤杩斿洖鍛戒护缁撴灉
+ */
+ public static final String ignoreRtuResultSendWebUrl = "http://0.0.0.0" ;
+
+
+ /**
+ * 榛樿鍛戒护ID
+ * 濡傛灉鍛戒护涓嶅湪鏁版嵁搴撲腑瀛樺偍锛屾垨鍏朵粬鍙互鐢╠efaultId
+ */
+ public static final String defaultId = "999999999" ;
+
+ /**
+ * 鏈潯鍛戒护鐨処D
+ * 涓�鑸槸鍛戒护鍦ㄦ暟鎹簱涓瓨鍌ㄨ褰旾D鐨勫瓧绗︿覆褰㈠紡
+ */
+ public String id;
+
+ /**
+ * RTU鍗忚鍚嶇О锛岃繖涓彲浠ヤ负绌猴紝鍥犱负RTU涓婅鏁版嵁瑙f瀽鍑哄崗璁悕绉帮紝鐒跺悗绯荤粺鎶婂崗璁悕绉颁繚瀛樺湪RTU鏁版嵁璁板綍涓紝浠庢鍗忚鍚嶇О灏变笉鍐嶇┖浜�
+ */
+ public String protocol;
+
+ /**
+ * RTU鍗忚鍚嶇О锛岃繖涓彲浠ヤ负绌�
+ */
+ public Short protocolVersion;
+
+ /**
+ * RTU 鍦板潃
+ */
+ public String rtuAddr ;
+
+ /**
+ * 鍛戒护绫诲瀷:Rtu鍛戒护銆侀拡瀵圭洃鎺т腑闂翠欢鐨勫懡浠�
+ * 鐢眂om.dy.common.mw.protocol.CommandType绫诲畾涔�
+ */
+ public String type ;
+
+ /**
+ * 鍔熻兘鐮�
+ */
+ public String code ;
+
+ /**
+ * rtu杩斿洖鍛戒护缁撴灉 鍙戝悜鐩殑鍦皐eb URL
+ */
+ public String rtuResultSendWebUrl ;
+
+ /**
+ * 鍏蜂綋鍙傛暟鏁版嵁
+ */
+ public Object param ;
+
+ /**
+ * 鍏朵粬鏁版嵁
+ */
+ public Object attachment ;
+
+ public String toString(){
+ String s = "鍛戒护id=" + id + "\n" ;
+ s += (protocol == null ? "" : ("鍗忚=" + protocol + "\n"));
+ s += (protocolVersion == null ? "" : ("鍗忚鐗堟湰鍙�=" + protocolVersion + "\n"));
+ s += (rtuAddr == null ? "" : ("Rtu鍦板潃=" + rtuAddr + "\n"));
+ s += "鍛戒护绫诲瀷=" + (type.equals(CommandType.innerCommand)?"鍐呴儴鍛戒护":"RTU鍛戒护") + "\n" ;
+ s += (code == null ? "" : ("鍔熻兘鐮�=" + code + "\n")) ;
+ s += (rtuResultSendWebUrl == null ? "" : ("鍥炶皟缃戝潃=" + rtuResultSendWebUrl + "\n"));
+ if(param != null){
+ s += "鍙傛暟:" + param ;
+ }
+ if(attachment != null){
+ s += "鍏朵粬鏁版嵁:" + attachment ;
+ }
+ return s ;
+ }
+ /**
+ * 瀵硅薄杞垚json
+ * @return json
+ * @throws Exception 寮傚父
+ */
+ @SuppressWarnings("unused")
+ public String toJson()throws Exception{
+ try{
+ String json = JSON.toJSONString(this) ;
+ return json ;
+ }catch(Exception e){
+ throw new Exception(e.getMessage() , e ) ;
+ }
+ }
+ /**
+ * json杞垚瀵硅薄
+ * @param json json
+ * @return Command
+ * @throws Exception 寮傚父
+ */
+ @SuppressWarnings("unused")
+ public static Command jsonToObject(String json)throws Exception{
+ try{
+ JSONObject jsonObject = JSON.parseObject(json);
+ Command command = jsonObject.to(Command.class) ;
+ //command.param = jsonObject.getObject("param", class);
+ return command ;
+ }catch(Exception e){
+ throw new Exception(e.getMessage() , e ) ;
+ }
+ }
+
+ /**
+ * 鍒涘缓杩斿洖鐨勫嚭閿欏懡浠�
+ * @param error 閿欒娑堟伅
+ * @param commandId 鍛戒护ID
+ * @return Command
+ */
+ @SuppressWarnings("unused")
+ public Command createReturnErrorCommand(String error , String commandId, String code){
+ if(commandId == null){
+ this.setId(defaultId) ;
+ }else{
+ this.setId(commandId) ;
+ }
+ this.code = code ;
+ this.type = CommandType.resultCommand ;
+
+ CommandBackParam p = new CommandBackParam() ;
+ p.setSuccess(false) ;
+ p.setMessage(error) ;
+
+ this.param = p ;
+
+ return this ;
+ }
+
+ /**
+ * 鍒涘缓杩斿洖鐨勭畝鍗曟垚鍔熷懡浠わ紝閽堝鐩戞帶涓棿浠剁殑鍛戒护
+ * @param message 娑堟伅
+ * @param commandId 鍛戒护ID
+ * @param code 鍔熻兘鐮�
+ * @return Command
+ */
+ @SuppressWarnings("unused")
+ public Command createReturnSuccessCommand(String message , String commandId, String code){
+ if(commandId == null){
+ this.setId(defaultId) ;
+ }else{
+ this.setId(commandId) ;
+ }
+ this.code = code ;
+ this.type = CommandType.resultCommand ;
+
+ CommandBackParam p = new CommandBackParam() ;
+ p.setSuccess(true) ;
+ p.setMessage(message) ;
+
+ this.param = p ;
+
+ return this ;
+ }
+
+ public String getId() {
+ return id;
+ }
+ public Command setId(String id) {
+ this.id = id;
+ return this ;
+ }
+ public String getRtuAddr() {
+ return rtuAddr;
+ }
+ public Command setRtuAddr(String rtuAddr) {
+ this.rtuAddr = rtuAddr;
+ return this ;
+ }
+
+ public String getRtuResultSendWebUrl() {
+ return rtuResultSendWebUrl;
+ }
+
+ public void setRtuResultSendWebUrl(String rtuResultSendWebUrl) {
+ this.rtuResultSendWebUrl = rtuResultSendWebUrl;
+ }
+
+ public String getProtocol() {
+ return protocol;
+ }
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+ public String getType() {
+ return type;
+ }
+ public Command setType(String type) {
+ this.type = type;
+ return this ;
+ }
+ public String getCode() {
+ return code;
+ }
+ public Command setCode(String code) {
+ this.code = code;
+ return this ;
+ }
+ public Object getParam() {
+ return param;
+ }
+ public Command setParam(Object param) {
+ this.param = param;
+ return this ;
+ }
+ public Object getAttachment() {
+ return attachment;
+ }
+ @SuppressWarnings("unused")
+ public Command setAttachment(Object attachment) {
+ this.attachment = attachment;
+ return this ;
+ }
+
+}
--
Gitblit v1.8.0