New file |
| | |
| | | package client |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | "gat1400Exchange/vo" |
| | | ) |
| | | |
| | | const ( |
| | | FacesUrI = "/VIID/Faces" |
| | | ) |
| | | |
| | | func FaceCapture(msg []byte) int { |
| | | if clientStatus != vo.StatusSuccess { |
| | | return clientStatus |
| | | } |
| | | |
| | | rsp, err := util.HttpPost(FacesUrI, headers, msg) |
| | | if err != nil { |
| | | logger.Warn("Post faces failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | | } |
| | | |
| | | var stat vo.ResponseStatus |
| | | err = json.Unmarshal(rsp, &stat) |
| | | if err != nil { |
| | | logger.Warn("Post faces response unmarshal failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | | } |
| | | |
| | | logger.Debug("Post faces success.") |
| | | return stat.StatusCode |
| | | } |
| | |
| | | Host string `mapstructure:"host"` |
| | | Port string `mapstructure:"port"` |
| | | Password string `mapstructure:"password"` |
| | | Role string `mapstructure:"role"` // agent 设备端, proxy 1400中转 不处理deivce, server 全功能 |
| | | } |
| | | |
| | | type client struct { |
| | |
| | | package controller |
| | | |
| | | import ( |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/service" |
| | | "net/http" |
| | | "time" |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | // 如果开启了下级, 身份应该是消息代理, 不再转发到服务器 |
| | | face := req.FaceListObject.FaceObject[0] |
| | | |
| | | if config.ClientConf.Enable && config.ServeConf.Role == "agent" { |
| | | a.Repository.MsgForward(&req) |
| | | } else { |
| | | logger.Debug("Receive new message, Id:%s Ip:%s faceId:%s, LeftTopX:%d, appearTime:%s", c.RemoteIP(), face.DeviceID, face.FaceID, face.LeftTopX, face.FaceAppearTime) |
| | | |
| | | a.Repository.FaceForward(req.FaceListObject.FaceObject) |
| | | } |
| | | |
| | | // 设备保活 |
| | | service.KeepDeviceAlive(face.DeviceID) |
| | | |
| | | rspMsg := vo.ResponseStatus{ |
| | | RequestURL: c.FullPath(), |
| | |
| | | package controller |
| | | |
| | | import ( |
| | | "gat1400Exchange/models" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/service" |
| | | "net/http" |
| | | "time" |
| | |
| | | return |
| | | } |
| | | |
| | | // 上报设备信息 |
| | | var d = models.Device{ |
| | | Id: req.KeepaliveObject.DeviceID, |
| | | } |
| | | |
| | | err := d.Upsert() |
| | | if err != nil { |
| | | logger.Warn("Device db update camera error:%s", err.Error()) |
| | | } |
| | | |
| | | service.KeepDeviceAlive(req.KeepaliveObject.DeviceID) |
| | | |
| | | rspMsg := vo.ResponseStatus{ |
| | |
| | | } |
| | | |
| | | // 删库 |
| | | |
| | | rspMsg := vo.ResponseStatus{ |
| | | RequestURL: c.FullPath(), |
| | | StatusCode: vo.StatusSuccess, |
| | |
| | | |
| | | type Cache struct { |
| | | Id uint `gorm:"column:id;primary_key;auto_increment;unique;not null;"` |
| | | Type string `gorm:"column:type;"` // 消息类型 1400, basic |
| | | Data string `gorm:"column:data;type:text"` |
| | | CreateTime int64 `gorm:"column:create_time;"` |
| | | Retry int `gorm:"column:retry;"` |
| | |
| | | func (d *Positions) FindDevicePosition(devId string, timestamp int64) error { |
| | | return db.Table(d.TableName()).Where("device_id = ? AND create_time <= ?", devId, timestamp).Order("create_time desc").First(&d).Error |
| | | } |
| | | |
| | | func (d *Positions) FindPositionByTime(timestamp int64) error { |
| | | return db.Table(d.TableName()).Where("create_time <= ?", timestamp).Order("create_time desc").First(&d).Error |
| | | } |
| | |
| | | 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 floor string |
| | | |
| | | faceAppearTime, err := time.ParseInLocation("20060102150405", appearTime, time.Local) |
| | | if err != nil { |
| | | logger.Warn("Parse face appear time error, %s", err.Error()) |
| | | faceAppearTime = time.Now() |
| | | } |
| | | |
| | | if config.ServeConf.Role == "server" { |
| | | var device models.Device |
| | | |
| | | if err := device.FindById(deviceId); err != nil { |
| | |
| | | } |
| | | |
| | | // 匹配楼层 |
| | | 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 |
| | | } |
| | | |
| | | 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 |
| | | } |
File was renamed from service/report.go |
| | |
| | | } |
| | | |
| | | func KeepDeviceAlive(id string) { |
| | | // 上报设备信息 |
| | | var d = models.Device{ |
| | | Id: id, |
| | | } |
| | | |
| | | err := d.Upsert() |
| | | if err != nil { |
| | | logger.Warn("Device db update camera error:%s", err.Error()) |
| | | } |
| | | |
| | | deviceAliveCache.Add(id, true) |
| | | } |
| | |
| | | } |
| | | |
| | | elevator := data.Elevator[0] |
| | | |
| | | // 程序部署在设备端, 字符叠加器上报的名称允许为空. 在云端, 名称必须与摄像机相同 |
| | | if !config.ClientConf.Enable { |
| | | elevator.Name = strings.Trim(elevator.Name, " ") |
| | | if elevator.Name == "" { |
| | | continue |
| | | } |
| | | } |
| | | |
| | | var d = models.Device{ |
| | | Id: elevator.Name, |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "gat1400Exchange/client" |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/models" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | "gat1400Exchange/vo" |
| | | ) |
| | | |
| | | func ResendImageData() { |
| | |
| | | } |
| | | |
| | | for _, c := range cacheItems { |
| | | if c.Type == "1400" { |
| | | if client.FaceCapture([]byte(c.Data)) != vo.StatusSuccess { |
| | | c.UpdateRetryCount() |
| | | logger.Warn("The data resend failed. retry count %d", c.Retry+1) |
| | | continue |
| | | } |
| | | } else { |
| | | if !util.SendData([]byte(c.Data), config.ForwardConf.SyncServer) { |
| | | c.UpdateRetryCount() |
| | | logger.Warn("The data resend failed. retry count %d", c.Retry+1) |
| | | } else { |
| | | continue |
| | | } |
| | | } |
| | | |
| | | c.Delete() |
| | | logger.Debug("The data resend successful.") |
| | | } |
| | | } |
| | | |
| | | } |