From 9be303b5cca06c62ed4ba783f9b1e0a4145e7009 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期六, 18 五月 2024 12:36:02 +0800
Subject: [PATCH] 修改ape添加接口

---
 service/nvcs.go |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/service/nvcs.go b/service/nvcs.go
index 7882db5..7af51b1 100644
--- a/service/nvcs.go
+++ b/service/nvcs.go
@@ -6,6 +6,8 @@
 	"fmt"
 	"io/ioutil"
 	"net"
+	"strings"
+	"time"
 
 	"gat1400Exchange/config"
 	"gat1400Exchange/models"
@@ -35,7 +37,7 @@
 }
 
 // 瀵规帴缃戠粶瑙嗛瀛楃鍙犲姞鍣�,鎺ユ敹udp鍙戦�佺殑妤煎眰淇℃伅, 鏇存柊device鍦板潃
-func NVCSServer() {
+func NVCSA1UDPServer() {
 	// 鎸囧畾鐩戝惉鐨勭鍙�
 	port := config.ServeConf.Port
 
@@ -74,12 +76,12 @@
 		decodedBytes, err := ioutil.ReadAll(reader)
 
 		var data ElevatorData
-		// Unmarshal JSON into the struct
 		err = json.Unmarshal(decodedBytes, &data)
 		if err != nil {
 			logger.Warn("ElevatorData unmarshal error:%s", err.Error())
 			continue
 		}
+		logger.Debug("Received %d bytes from %s, %+v", numBytes, clientAddr, data)
 
 		if len(data.Elevator) == 0 {
 			continue
@@ -90,19 +92,31 @@
 		}
 
 		elevator := data.Elevator[0]
-		var d = models.Device{
-			Id:  elevator.Name,
-			Pos: elevator.Status.FloorName,
-			Ip:  elevator.IP,
+
+		// 绋嬪簭閮ㄧ讲鍦ㄨ澶囩, 瀛楃鍙犲姞鍣ㄤ笂鎶ョ殑鍚嶇О鍏佽涓虹┖. 鍦ㄤ簯绔�, 鍚嶇О蹇呴』涓庢憚鍍忔満鐩稿悓
+		if config.ServeConf.Role != "agent" {
+			elevator.Name = strings.Trim(elevator.Name, " ")
+			if elevator.Name == "" {
+				continue
+			}
 		}
 
-		err = d.Upsert()
+		var d = models.Positions{
+			DeviceId:   elevator.Name,
+			Pos:        elevator.Status.FloorName,
+			CreateTime: time.Now().Unix(),
+			TimeString: time.Now().Format("2006-01-02 15:04:05"),
+		}
+
+		err = d.Save()
 		if err != nil {
-			logger.Warn("Device db update error:%s", err.Error())
+			logger.Warn("Device position update error:%s", err.Error())
 		}
+	}
+}
 
-		deviceAliveCache.Add(elevator.Name, true)
-
-		logger.Debug("Received %d bytes from %s, %+v", numBytes, clientAddr, data)
+func StartNVCSServer() {
+	if config.NVCSConf.Model == "A1" {
+		go NVCSA1UDPServer()
 	}
 }

--
Gitblit v1.8.0