From d5dab07dc674de7edbbc1bd6ade0486f54fbdb26 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 06 五月 2025 19:19:35 +0800
Subject: [PATCH] 1、实现万用token(0000-0000-1234-9876-5); 2、web端单独实现命令结果等待器,并修改相关部分; 3、web端实现透传命令; 4、修改一些不当注释; 5、优化一些代码。

---
 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