zhangzengfei
2024-10-22 2c77f012601b7788dc58b0c9fd99aad587983b0d
完善楼层相关操作
2 文件已重命名
9个文件已修改
132 ■■■■ 已修改文件
client/faces.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
client/notify.go 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
client/system.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controller/captureCtl.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nvcs/a2.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/file.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/floor.go 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/http.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
repository/captureRepo.go 52 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/device.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/resend.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
client/faces.go
@@ -2,11 +2,11 @@
import (
    "fmt"
    "gat1400Exchange/pkg"
    "encoding/json"
    "gat1400Exchange/config"
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/util"
    "gat1400Exchange/vo"
)
@@ -21,7 +21,7 @@
    }
    url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, FacesUrI)
    rsp, err := util.HttpPost(url, headers, msg)
    rsp, err := pkg.HttpPost(url, headers, msg)
    if err != nil {
        logger.Warn("Post faces failed, %s", err.Error())
        return vo.StatusOtherError
@@ -44,7 +44,7 @@
    }
    url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, PersonsUrI)
    rsp, err := util.HttpPost(url, headers, msg)
    rsp, err := pkg.HttpPost(url, headers, msg)
    if err != nil {
        logger.Warn("Post person failed, %s", err.Error())
        return vo.StatusOtherError
client/notify.go
@@ -2,8 +2,8 @@
import (
    "encoding/json"
    "gat1400Exchange/pkg"
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/util"
    "gat1400Exchange/vo"
)
@@ -12,7 +12,7 @@
        return clientStatus
    }
    rsp, err := util.HttpPost(url, headers, msg)
    rsp, err := pkg.HttpPost(url, headers, msg)
    if err != nil {
        logger.Warn("Post notification failed, %s", err.Error())
        return vo.StatusOtherError
@@ -35,7 +35,7 @@
    //    return clientStatus
    //}
    rsp, err := util.HttpPost(url, headers, msg)
    rsp, err := pkg.HttpPost(url, headers, msg)
    if err != nil {
        logger.Warn("Post subscribe failed, %s", err.Error())
        return vo.StatusOtherError
@@ -55,7 +55,7 @@
}
func UpdateSubscribe(url string, msg []byte) int {
    rsp, err := util.HttpPut(url, headers, msg)
    rsp, err := pkg.HttpPut(url, headers, msg)
    if err != nil {
        logger.Warn("Put subscribe failed, %s", err.Error())
        return vo.StatusOtherError
@@ -75,7 +75,7 @@
}
func GetSubscribes(url string) ([]byte, error) {
    rsp, err := util.HttpGet(url, headers)
    rsp, err := pkg.HttpGet(url, headers)
    if err != nil {
        logger.Warn("Get subscribe failed, %s", err.Error())
    }
client/system.go
@@ -3,11 +3,11 @@
import (
    "encoding/json"
    "fmt"
    "gat1400Exchange/pkg"
    "io/ioutil"
    "gat1400Exchange/config"
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/util"
    "gat1400Exchange/vo"
    dac "github.com/xinsnake/go-http-digest-auth-client"
@@ -91,7 +91,7 @@
    url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, KeepaliveUrI)
    b, _ := json.Marshal(body)
    rsp, err := util.HttpPost(url, headers, b)
    rsp, err := pkg.HttpPost(url, headers, b)
    if err != nil {
        logger.Warn("Keepalive request failed, %s", err.Error())
        return vo.StatusOtherError
controller/captureCtl.go
@@ -14,7 +14,6 @@
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/repository"
    "gat1400Exchange/service"
    "gat1400Exchange/util"
    "gat1400Exchange/vo"
    "github.com/gin-gonic/gin"
@@ -63,7 +62,7 @@
            today := time.Now().Format("2006-01-02")
            imagePath := path.Join(config.LogConf.Path, "gat1400_face_images", today, img.ImageID+".jpeg")
            err = util.WriteToFile(imagePath, imageBytes)
            err = pkg.WriteToFile(imagePath, imageBytes)
            if err == nil {
                face.SubImageList.SubImageInfoObject[idx].Data = ""
                face.SubImageList.SubImageInfoObject[idx].StoragePath = config.ImageConf.ImageUriPrefix + "/" + today + "/" + img.ImageID + ".jpeg"
nvcs/a2.go
@@ -3,14 +3,13 @@
import (
    "encoding/json"
    "fmt"
    "gat1400Exchange/pkg"
    "net/http"
    "strings"
    "time"
    "gat1400Exchange/config"
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/util"
    "github.com/gin-gonic/gin"
)
@@ -58,7 +57,7 @@
        "Cookie": "eyJuYW1lIjoiYWRtaW4iLCAicGFzZCI6ImFkbWluMTIzIn0=",
    }
    rsp, err := util.HttpPost(url, header, payload)
    rsp, err := pkg.HttpPost(url, header, payload)
    if err != nil {
        logger.Warn("Get A2 floor data failure,%s", err.Error())
        return
pkg/file.go
File was renamed from util/file.go
@@ -1,4 +1,4 @@
package util
package pkg
import (
    "fmt"
pkg/floor.go
@@ -10,7 +10,7 @@
// 生成一个包含楼层的人脸id,解析楼层
// 使用48位源id, 其中前41位是imageid, 不可以修改 41-43位填 06 代表图像, +99 + 3位楼层(第一位0表示正,1表示负)
func GenerateFaceIdContainFloor(srcId, floorStr string) string {
    floorNum, _ := ParseFloor("0", floorStr)
    floorNum, _ := BuildFloorString("0", floorStr)
    newId := srcId[0:43] + "99" + floorNum
    //newId := srcId[0:43] + "99" + floorNum + snowflake.CreateRandomNumber(1)
@@ -29,10 +29,20 @@
    return RestoreFloor(srcId[45:48])
}
// ParseFloor parses the floor string and returns a three-character string
func ParseFloor(direction, floor string) (string, error) {
// BuildFloorString parses the floor string and returns a string
func BuildFloorString(direction, floor string) (string, error) {
    var dire string
    var sign string
    var number string
    switch direction {
    case "in":
        dire = "1"
    case "out":
        dire = "2"
    default:
        dire = "0"
    }
    // Check if the floor is negative
    if strings.HasPrefix(floor, "-") {
@@ -51,7 +61,7 @@
    // Format the number to be two digits
    formattedNumber := fmt.Sprintf("%02s", number)
    return direction + sign + formattedNumber, nil
    return dire + sign + formattedNumber, nil
}
// RestoreFloor restores the three-character string back to the original floor string
@@ -93,3 +103,25 @@
    return directionStr, floorStr, nil
}
func CheckDirection(str1, str2 string) string {
    // 去掉字符串最后一个字符 'F'
    numStr1 := strings.TrimSuffix(str1, "F")
    numStr2 := strings.TrimSuffix(str2, "F")
    // 转换为 int 类型
    num1, err1 := strconv.Atoi(numStr1)
    num2, err2 := strconv.Atoi(numStr2)
    // 检查转换是否成功
    if err1 != nil || err2 != nil {
        return ""
    }
    // 比较两个整数的大小
    if num1 > num2 {
        return "out"
    } else {
        return "in"
    }
}
pkg/http.go
File was renamed from util/http.go
@@ -1,4 +1,4 @@
package util
package pkg
import (
    "bytes"
repository/captureRepo.go
@@ -3,8 +3,6 @@
import (
    "encoding/base64"
    "encoding/json"
    "strconv"
    "strings"
    "time"
    "gat1400Exchange/client"
@@ -53,7 +51,7 @@
                    bgImageStr = image.Data
                }
            } else if image.StoragePath != "" {
                imgData, err := util.ImageDownload(image.StoragePath, nil)
                imgData, err := pkg.ImageDownload(image.StoragePath, nil)
                if err != nil {
                    logger.Warn("Image download failure, %s", err.Error())
                } else {
@@ -89,24 +87,24 @@
        // 转发图像
        logger.Debug("Prepare forward image, deviceId:%s, bgImage len:%d, smImage len:%d server:%s", deviceId, len(bgImageBytes), len(faceImageBytes), config.ForwardConf.SyncServer)
        if deviceId != "" && bgImageStr != "" && config.ForwardConf.SyncServer != "" {
            pd := c.PackPushDataV2(deviceId, faceId, face.FaceAppearTime, bgImageBytes, faceImageBytes)
            if pd == nil {
            pushData := c.PackPushDataV2(deviceId, faceId, face.FaceAppearTime, bgImageBytes, faceImageBytes)
            if pushData == nil {
                return
            }
            // 处理梯控填写的楼层信息 暂时使用otherFeature字段
            if face.OtherFeature != "" && pd.CameraFloor == "" {
                pd.Direction, pd.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
            if face.OtherFeature != "" && pushData.CameraFloor == "" {
                pushData.Direction, pushData.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
            }
            payload, err := json.Marshal(pd)
            payload, err := json.Marshal(pushData)
            if err != nil {
                logger.Warn("Marshal error, %s", err.Error())
                return
            }
            if !util.SendData(payload, config.ForwardConf.SyncServer) {
                cacheItem, _ := json.Marshal(pd)
            if !pkg.SendData(payload, config.ForwardConf.SyncServer) {
                cacheItem, _ := json.Marshal(pushData)
                c.CacheData(cacheItem, "basic")
                logger.Warn("The data forwarding failed, adding to local cache.")
            } else {
@@ -147,7 +145,7 @@
                    bgImageStr = image.Data
                }
            } else if image.StoragePath != "" {
                imgData, err := util.ImageDownload(image.StoragePath, nil)
                imgData, err := pkg.ImageDownload(image.StoragePath, nil)
                if err != nil {
                    logger.Warn("Image download failure, %s", err.Error())
                } else {
@@ -190,7 +188,7 @@
                return
            }
            if !util.SendData(payload, config.ForwardConf.SyncServer) {
            if !pkg.SendData(payload, config.ForwardConf.SyncServer) {
                cacheItem, _ := json.Marshal(pd)
                c.CacheData(cacheItem, "basic")
                logger.Warn("The data forwarding failed, adding to local cache.")
@@ -221,7 +219,7 @@
        for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
            if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
                runDir = compareFloor(floor, runState.Floor)
                runDir = pkg.CheckDirection(floor, runState.Floor)
                break
            }
@@ -274,7 +272,7 @@
        for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
            if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
                runDir = compareFloor(floor, runState.Floor)
                runDir = pkg.CheckDirection(floor, runState.Floor)
                break
            }
@@ -282,7 +280,7 @@
        }
        for idx, _ := range msg.FaceListObject.FaceObject {
            msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(runDir, floor)
            msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.BuildFloorString(runDir, floor)
            //if config.ClientConf.AddFloorToFaceId {
            //    msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
            //}
@@ -336,30 +334,8 @@
    logger.Debug("Pub record message %s, %s", deviceId, msgId)
    body, _ := json.Marshal(&msg)
    _, err := util.HttpPost(config.ForwardConf.RecordServer, nil, body)
    _, err := pkg.HttpPost(config.ForwardConf.RecordServer, nil, body)
    if err != nil {
        logger.Warn(err.Error())
    }
}
func compareFloor(str1, str2 string) string {
    // 去掉字符串最后一个字符 'F'
    numStr1 := strings.TrimSuffix(str1, "F")
    numStr2 := strings.TrimSuffix(str2, "F")
    // 转换为 int 类型
    num1, err1 := strconv.Atoi(numStr1)
    num2, err2 := strconv.Atoi(numStr2)
    // 检查转换是否成功
    if err1 != nil || err2 != nil {
        return ""
    }
    // 比较两个整数的大小
    if num1 > num2 {
        return "2"
    } else {
        return "1"
    }
}
service/device.go
@@ -3,11 +3,11 @@
import (
    "encoding/json"
    "fmt"
    "gat1400Exchange/pkg"
    "time"
    "gat1400Exchange/config"
    "gat1400Exchange/models"
    "gat1400Exchange/util"
)
type DevReportData struct {
@@ -85,7 +85,7 @@
        }
        headers := map[string]string{"Content-Type": "application/json; charset=UTF-8"}
        _, err = util.HttpPost(config.ForwardConf.ReportServer, headers, data)
        _, err = pkg.HttpPost(config.ForwardConf.ReportServer, headers, data)
        if err != nil {
            return err
        }
service/resend.go
@@ -4,8 +4,8 @@
    "gat1400Exchange/client"
    "gat1400Exchange/config"
    "gat1400Exchange/models"
    "gat1400Exchange/pkg"
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/util"
    "gat1400Exchange/vo"
)
@@ -46,7 +46,7 @@
                return
            }
        } else {
            if !util.SendData([]byte(c.Data), config.ForwardConf.SyncServer) {
            if !pkg.SendData([]byte(c.Data), config.ForwardConf.SyncServer) {
                c.UpdateRetryCount()
                logger.Warn("The data resend failed. retry count %d", c.Retry+1)
                return