zhangzengfei
2024-08-23 d3ea6799865812baaa1439922d6123e70a0cccdc
修复otherFeature字段传送楼层信息
5个文件已修改
112 ■■■■■ 已修改文件
models/positions.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/floor.go 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
repository/captureRepo.go 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/nvcs.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
vo/forward.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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"`
pkg/floor.go
@@ -6,30 +6,31 @@
    "strings"
)
// 已弃用
// 生成一个包含楼层的人脸id,解析楼层
// 使用48位源id, 其中前41位是imageid, 不可以修改 41-43位填 06 代表图像, +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
}
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)
            }
            // 尝试从faceId提取楼层
            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
            }
            // 尝试从faceId提取楼层
            if pd.CameraFloor == "" && config.ClientConf.AddFloorToFaceId {
                pd.CameraFloor, _ = pkg.ParseFloorFromId(v.PersonID)
            }
            //// 尝试从faceId提取楼层
            //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)
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上 固 枪"
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"`