| | |
| | | import ( |
| | | "encoding/base64" |
| | | "encoding/json" |
| | | "gat1400Exchange/client" |
| | | "time" |
| | | |
| | | "gat1400Exchange/config" |
| | |
| | | return |
| | | } |
| | | |
| | | // 部署在服务端的1400代理, 仅接收1400信息, 楼层信息暂存在oherFeature字段 |
| | | if config.ServeConf.Role == "proxy" { |
| | | if face.OtherFeature != "" { |
| | | pd.CameraFloor = face.OtherFeature |
| | | } |
| | | } |
| | | |
| | | payload, err := json.Marshal(pd) |
| | | if err != nil { |
| | | logger.Warn("Marshal error, %s", err.Error()) |
| | |
| | | |
| | | if !util.SendData(payload, config.ForwardConf.SyncServer) { |
| | | cacheItem, _ := json.Marshal(pd) |
| | | c.CacheData(cacheItem) |
| | | c.CacheData(cacheItem, "basic") |
| | | logger.Warn("The data forwarding failed, adding to local cache.") |
| | | } else { |
| | | logger.Debug("The data forwarding successful. deviceId:%s", deviceId) |
| | |
| | | |
| | | func (c CaptureRepository) PackPushDataV2(deviceId, faceId, appearTime string, bgImgBytes, faceImgBytes []byte) *vo.PushDataInfoV2 { |
| | | var pd = new(vo.PushDataInfoV2) |
| | | var device models.Device |
| | | var floor string |
| | | |
| | | 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秒电梯关门的时间 |
| | | if devPos.Pos == "" { |
| | | devPos.Pos = device.Floor |
| | | if config.ServeConf.Role == "server" { |
| | | 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 |
| | | } |
| | | |
| | | // 匹配楼层 |
| | | var devPos models.Positions |
| | | _ = devPos.FindDevicePosition(deviceId, faceAppearTime.Unix()+5) // 加5秒电梯关门的时间 |
| | | if devPos.Pos == "" { |
| | | devPos.Pos = device.Floor |
| | | } |
| | | |
| | | floor = devPos.Pos |
| | | } |
| | | |
| | | pd.PicMaxImages = append(pd.PicMaxImages, bgImgBytes) |
| | |
| | | pd.PicId = faceId |
| | | pd.PicDate = faceAppearTime.Format("2006-01-02 15:04:05") |
| | | pd.DataSource = "camera" |
| | | pd.CameraFloor = devPos.Pos |
| | | pd.CameraFloor = floor |
| | | pd.CameraId = deviceId |
| | | |
| | | return pd |
| | | } |
| | | |
| | | func (c CaptureRepository) CacheData(payload []byte) { |
| | | func (c CaptureRepository) CacheData(payload []byte, msgType string) { |
| | | var cacheItem = models.Cache{ |
| | | Type: msgType, |
| | | Data: string(payload), |
| | | CreateTime: time.Now().Unix(), |
| | | Retry: 0, |
| | |
| | | |
| | | cacheItem.Save() |
| | | } |
| | | |
| | | func (c CaptureRepository) MsgForward(msg *vo.RequestFaceList) { |
| | | faceInfo := msg.FaceListObject.FaceObject[0] |
| | | // 匹配楼层 |
| | | faceAppearTime, err := time.ParseInLocation("20060102150405", faceInfo.FaceAppearTime, time.Local) |
| | | if err != nil { |
| | | logger.Warn("Parse face appear time error, %s", err.Error()) |
| | | faceAppearTime = time.Now() |
| | | } |
| | | |
| | | var devPos models.Positions |
| | | _ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 加5秒电梯关门的时间 |
| | | if devPos.Pos == "" { |
| | | devPos.Pos = "1F" |
| | | } |
| | | |
| | | for idx, _ := range msg.FaceListObject.FaceObject { |
| | | msg.FaceListObject.FaceObject[idx].OtherFeature = devPos.Pos |
| | | } |
| | | |
| | | b, _ := json.Marshal(msg) |
| | | if client.FaceCapture(b) != vo.StatusSuccess { |
| | | cacheItem, _ := json.Marshal(msg) |
| | | c.CacheData(cacheItem, "1400") |
| | | logger.Warn("The data forwarding failed, adding to local cache.") |
| | | } |
| | | |
| | | return |
| | | } |