From d93d2bc56ed06b3c060ff48f49591e8c5d779230 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 14 九月 2023 22:33:45 +0800
Subject: [PATCH] 通讯方式字段转换

---
 constvar/const.go  |   19 +++++++++++++++----
 nsq/msg_handler.go |    2 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/constvar/const.go b/constvar/const.go
index d92f9f9..eb2f630 100644
--- a/constvar/const.go
+++ b/constvar/const.go
@@ -34,12 +34,23 @@
 type PlcMethod string
 
 const (
-	PlcMethodModbusTCP PlcMethod = "modbusTCP"
-	PlcMethodSerial    PlcMethod = "serial"
+	PlcMethodModbusTCP        PlcMethod = "modbusTCP"
+	PlcMethodSerial           PlcMethod = "serial"
+	PlcMethodModbusTCPChinese PlcMethod = "缃戠粶"
+	PlcMethodSerialChinese    PlcMethod = "涓插彛"
 )
 
-func (slf PlcMethod) Valid() bool {
-	return slf == PlcMethodModbusTCP || slf == PlcMethodSerial
+func (slf *PlcMethod) ConvertToEnglish() {
+	if *slf == PlcMethodModbusTCPChinese {
+		*slf = PlcMethodModbusTCP
+	}
+	if *slf == PlcMethodSerialChinese {
+		*slf = PlcMethodSerial
+	}
+}
+
+func (slf *PlcMethod) Valid() bool {
+	return *slf == PlcMethodModbusTCP || *slf == PlcMethodSerial
 }
 
 const (
diff --git a/nsq/msg_handler.go b/nsq/msg_handler.go
index 9d1b5bf..b13dd4b 100644
--- a/nsq/msg_handler.go
+++ b/nsq/msg_handler.go
@@ -156,6 +156,8 @@
 		return nil
 	}
 
+	resp.PlcConfig.Method.ConvertToEnglish()
+
 	var record model.DevicePlc
 	err = mapstructure.Decode(resp.PlcConfig, &record)
 	if err != nil {

--
Gitblit v1.8.0