From 8aa296b660354adf440a005dcbc3883515ed71e2 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期一, 15 四月 2024 11:45:48 +0800 Subject: [PATCH] 修改新的上报协议 --- repository/captureRepo.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-) diff --git a/repository/captureRepo.go b/repository/captureRepo.go index c4ea02f..a76fa4d 100644 --- a/repository/captureRepo.go +++ b/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 { -- Gitblit v1.8.0