From d3ea6799865812baaa1439922d6123e70a0cccdc Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期五, 23 八月 2024 17:39:04 +0800
Subject: [PATCH] 修复otherFeature字段传送楼层信息
---
pkg/floor.go | 42 ++++++++++++--------
repository/captureRepo.go | 51 ++++++++++++++++---------
models/positions.go | 2
vo/forward.go | 2
service/nvcs.go | 15 +++----
5 files changed, 66 insertions(+), 46 deletions(-)
diff --git a/models/positions.go b/models/positions.go
index 237cba5..0978bca 100644
--- a/models/positions.go
+++ b/models/positions.go
@@ -3,7 +3,7 @@
import "time"
type Positions struct {
- Id uint `gorm:"column:id;primary_key;auto_increment;unique;not null;"`
+ Id uint `gorm:"column:id;primary_key;auto_increment;" json:"id"`
DeviceId string `gorm:"column:device_id;index" json:"device_id"`
Pos string `gorm:"column:pos" json:"pos"`
RunDir int `gorm:"column:run_dir" json:"run_dir"`
diff --git a/pkg/floor.go b/pkg/floor.go
index 379d22b..c4c52a7 100644
--- a/pkg/floor.go
+++ b/pkg/floor.go
@@ -6,30 +6,31 @@
"strings"
)
+// 宸插純鐢�
// 鐢熸垚涓�涓寘鍚ゼ灞傜殑浜鸿劯id,瑙f瀽妤煎眰
// 浣跨敤48浣嶆簮id, 鍏朵腑鍓�41浣嶆槸imageid, 涓嶅彲浠ヤ慨鏀� 41-43浣嶅~ 06 浠h〃鍥惧儚, +99 + 3浣嶆ゼ灞�(绗竴浣�0琛ㄧず姝�,1琛ㄧず璐�)
func GenerateFaceIdContainFloor(srcId, floorStr string) string {
- floorNum, _ := ParseFloor(floorStr)
+ floorNum, _ := ParseFloor("0", floorStr)
newId := srcId[0:43] + "99" + floorNum
//newId := srcId[0:43] + "99" + floorNum + snowflake.CreateRandomNumber(1)
return newId
}
-func ParseFloorFromId(srcId string) (string, error) {
+func ParseFloorFromId(srcId string) (string, string, error) {
if len(srcId) != 48 {
- return "", fmt.Errorf("invalid id %s", srcId)
+ return "", "", fmt.Errorf("invalid id %s", srcId)
}
if srcId[43:45] != "99" {
- return "", fmt.Errorf("invalid flag %s", srcId[43:45])
+ return "", "", fmt.Errorf("invalid flag %s", srcId[43:45])
}
return RestoreFloor(srcId[45:48])
}
// ParseFloor parses the floor string and returns a three-character string
-func ParseFloor(floor string) (string, error) {
+func ParseFloor(direction, floor string) (string, error) {
var sign string
var number string
@@ -50,32 +51,39 @@
// Format the number to be two digits
formattedNumber := fmt.Sprintf("%02s", number)
- return sign + formattedNumber, nil
+ return direction + sign + formattedNumber, nil
}
// RestoreFloor restores the three-character string back to the original floor string
-func RestoreFloor(encoded string) (string, error) {
- if len(encoded) != 3 {
- return "", fmt.Errorf("encoded string must be 3 characters long")
+func RestoreFloor(encoded string) (string, string, error) {
+ if len(encoded) != 4 {
+ return "", "", fmt.Errorf("encoded string must be 3 characters long")
}
- sign := encoded[0]
- number := encoded[1:]
+ direction := encoded[0]
+ sign := encoded[1]
+ number := encoded[2:]
// Convert the number back to integer to remove any leading zeros
parsedNumber, err := strconv.Atoi(number)
if err != nil {
- return "", err
+ return "", "", err
}
- var restoredFloor string
+ var floorStr, directionStr string
if sign == '1' {
- restoredFloor = fmt.Sprintf("-%dF", parsedNumber)
+ floorStr = fmt.Sprintf("-%dF", parsedNumber)
} else if sign == '0' {
- restoredFloor = fmt.Sprintf("%dF", parsedNumber)
+ floorStr = fmt.Sprintf("%dF", parsedNumber)
} else {
- return "", fmt.Errorf("invalid sign character in encoded string")
+ return "", "", fmt.Errorf("invalid sign character in encoded string")
}
- return restoredFloor, nil
+ if direction == '1' {
+ directionStr = "in"
+ } else if direction == '2' {
+ directionStr = "out"
+ }
+
+ return directionStr, floorStr, nil
}
diff --git a/repository/captureRepo.go b/repository/captureRepo.go
index 9e6af55..f2d9f9b 100644
--- a/repository/captureRepo.go
+++ b/repository/captureRepo.go
@@ -94,14 +94,8 @@
// 澶勭悊姊帶濉啓鐨勬ゼ灞備俊鎭� 鏆傛椂浣跨敤otherFeature瀛楁
if face.OtherFeature != "" && pd.CameraFloor == "" {
- pd.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
+ pd.Direction, pd.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
}
-
- // 灏濊瘯浠巉aceId鎻愬彇妤煎眰
- if pd.CameraFloor == "" && config.ClientConf.AddFloorToFaceId {
- pd.CameraFloor, _ = pkg.ParseFloorFromId(face.FaceID)
- }
- //logger.Debug("device %s, CameraFloor:%s", deviceId, pd.CameraFloor)
payload, err := json.Marshal(pd)
if err != nil {
@@ -182,10 +176,10 @@
pd.CameraFloor = v.BehaviorDescription
}
- // 灏濊瘯浠巉aceId鎻愬彇妤煎眰
- if pd.CameraFloor == "" && config.ClientConf.AddFloorToFaceId {
- pd.CameraFloor, _ = pkg.ParseFloorFromId(v.PersonID)
- }
+ //// 灏濊瘯浠巉aceId鎻愬彇妤煎眰
+ //if pd.CameraFloor == "" && config.ClientConf.AddFloorToFaceId {
+ // pd.CameraFloor, _ = pkg.ParseFloorFromId(v.PersonID)
+ //}
//logger.Debug("device %s, CameraFloor:%s", deviceId, pd.CameraFloor)
payload, err := json.Marshal(pd)
@@ -284,17 +278,38 @@
faceAppearTime = time.Now()
}
+ var floor, runDir string
var devPos models.Positions
_ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 鍔�5绉掔數姊叧闂ㄧ殑鏃堕棿
if devPos.Pos == "" {
devPos.Pos = "1F"
}
- for idx, face := range msg.FaceListObject.FaceObject {
- msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(devPos.Pos)
- if config.ClientConf.AddFloorToFaceId {
- msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
+ floor = devPos.Pos
+
+ for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
+ var dbPos models.Positions
+ if err := dbPos.FindMovePosition(faceAppearTime.Unix()+5, floor); err == nil {
+ switch dbPos.RunDir {
+ case service.RunUp:
+ runDir = "1"
+ case service.RunDown:
+ runDir = "2"
+ case service.RunStop:
+ runDir = "0"
+ }
+
+ break
}
+
+ time.Sleep(1 * time.Second)
+ }
+
+ for idx, _ := range msg.FaceListObject.FaceObject {
+ msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(runDir, floor)
+ //if config.ClientConf.AddFloorToFaceId {
+ // msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
+ //}
}
}
@@ -326,9 +341,9 @@
for idx, v := range msg.PersonListObject.PersonObject {
msg.PersonListObject.PersonObject[idx].BehaviorDescription = devPos.Pos
- if config.ClientConf.AddFloorToFaceId {
- msg.PersonListObject.PersonObject[idx].PersonID = pkg.GenerateFaceIdContainFloor(v.PersonID, devPos.Pos)
- }
+ //if config.ClientConf.AddFloorToFaceId {
+ // msg.PersonListObject.PersonObject[idx].PersonID = pkg.GenerateFaceIdContainFloor(v.PersonID, devPos.Pos)
+ //}
}
b, _ := json.Marshal(msg)
diff --git a/service/nvcs.go b/service/nvcs.go
index 787716a..d5b1f41 100644
--- a/service/nvcs.go
+++ b/service/nvcs.go
@@ -67,8 +67,6 @@
logger.Info("UDP server listening on port %s...", port)
- var runState string
- var iRunSate int
// 鏃犻檺寰幆绛夊緟鎺ユ敹鏁版嵁
for {
// 鍒涘缓涓�涓紦鍐插尯鏉ュ瓨鍌ㄦ帴鏀剁殑鏁版嵁
@@ -98,6 +96,9 @@
continue
}
+ var runState string
+ var iRunSate int
+
// 璁板綍鐢垫杩愯鐘舵��
iRunSate = data.Elevator[0].Status.RunDir
if config.NVCSConf.RunState {
@@ -106,14 +107,10 @@
} else if data.Elevator[0].Status.RunDir == RunDown {
runState = "涓�"
}
+ }
- // 宸插埌鏈�涓嬪眰
- if data.Elevator[0].Status.Floor == 0 {
- runState = "涓�"
- }
- if data.Elevator[0].Status.Floor == data.Elevator[0].Status.TotalFloors {
- runState = "涓�"
- }
+ if !config.NVCSConf.RunState {
+ runState = ""
}
// 璁剧疆osd 鏍煎紡 "1F涓� 鍥� 鏋�"
diff --git a/vo/forward.go b/vo/forward.go
index a016cc6..3240b46 100644
--- a/vo/forward.go
+++ b/vo/forward.go
@@ -32,7 +32,7 @@
type PushDataInfoV2 struct {
CameraId string `json:"cameraId"`
- CameraFloor string `json:"cameraFloor"` //鎽勫儚鏈烘ゼ灞�
+ CameraFloor string `json:"cameraFloor"` // 鎽勫儚鏈烘ゼ灞�
Direction string `json:"direction"` // 鎽勫儚鏈鸿繍琛屾柟鍚� up or down
PicDate string `json:"picDate"`
PicId string `json:"picId"`
--
Gitblit v1.8.0