zhangzengfei
2024-04-15 8aa296b660354adf440a005dcbc3883515ed71e2
修改新的上报协议
2个文件已修改
49 ■■■■■ 已修改文件
repository/captureRepo.go 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
vo/forward.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
repository/captureRepo.go
@@ -48,7 +48,7 @@
        // 转发图像
        logger.Debug("准备转发,deviceId:%s, image len:%d, server:%s", deviceId, len(faceImageStr), config.ForwardConf.SyncServer)
        if deviceId != "" && faceImageStr != "" && config.ForwardConf.SyncServer != "" {
            pd := c.PackPushData(deviceId, faceId, faceImageStr, face.FaceAppearTime)
            pd := c.PackPushDataV2(deviceId, faceId, faceImageStr, face.FaceAppearTime)
            if pd == nil {
                return
            }
@@ -63,6 +63,41 @@
    }
    return
}
func (c CaptureRepository) PackPushDataV2(deviceId, faceId, faceImage, appearTime string) *vo.PushDataInfoV2 {
    var pd = new(vo.PushDataInfoV2)
    var device models.Device
    if err := device.FindById(deviceId); err != nil {
        logger.Warn("Can't find device in database, device:%s, %s", deviceId, err.Error())
        return pd
    }
    // 匹配楼层
    faceAppearTime, err := time.ParseInLocation("20060102150405", appearTime, time.Local)
    if err != nil {
        logger.Warn("Parse face appear time error,%s", err.Error())
        faceAppearTime = time.Now()
    }
    var devPos models.Positions
    _ = devPos.FindDevicePosition(deviceId, faceAppearTime.Unix()+5) // 加5秒电梯关门的时间
    imageBytes, err := base64.StdEncoding.DecodeString(faceImage)
    if err != nil {
        logger.Warn("Decode Image Base64 String failure,%s", err.Error())
        return pd
    }
    pd.PicMaxImages = append(pd.PicMaxImages, imageBytes)
    pd.PicId = faceId
    pd.PicDate = faceAppearTime.Format("2006-01-02 15:04:05")
    pd.DataSource = "camera"
    pd.CameraFloor = devPos.Pos
    pd.CameraId = deviceId
    return pd
}
func (c CaptureRepository) PackPushData(deviceId, faceId, faceImage, appearTime string) *vo.PushDataInfo {
@@ -119,7 +154,7 @@
    return pd
}
func (c CaptureRepository) SendData(pushDataInfo *vo.PushDataInfo, url string) (id string, err error) {
func (c CaptureRepository) SendData(pushDataInfo interface{}, url string) (id string, err error) {
    id = ""
    payload, err := json.Marshal(pushDataInfo)
    if err != nil {
vo/forward.go
@@ -29,3 +29,13 @@
    PicMaxImages [][]byte `json:"picMaxImages"`
    PicSmImages  [][]byte `json:"picSmImages"`
}
type PushDataInfoV2 struct {
    CameraId     string   `json:"cameraId"`
    CameraFloor  string   `json:"cameraFloor"` //摄像机楼层
    PicDate      string   `json:"picDate"`
    PicId        string   `json:"picId"`
    DataSource   string   `json:"dataSource"`
    PicMaxImages [][]byte `json:"picMaxImages"`
    PicSmImages  [][]byte `json:"picSmImages"`
}