| | |
| | | import ( |
| | | "context" |
| | | "encoding/json" |
| | | "gat1400Exchange/config" |
| | | "strings" |
| | | "sync" |
| | | "time" |
| | |
| | | } |
| | | } |
| | | |
| | | func InitSubscribeTask() error { |
| | | func InitSubscribeTask() { |
| | | var s models.Subscribe |
| | | subList, err := s.FindAll() |
| | | subList, err := s.FindByFromId(config.ClientConf.ServerId) |
| | | if err != nil { |
| | | logger.Error("Find account by channel error:%v", err) |
| | | return err |
| | | logger.Error("Find subscribe error, server id %s, %v", config.ClientConf.ServerId, err) |
| | | return |
| | | } |
| | | |
| | | for idx, _ := range subList { |
| | |
| | | CreateTask(&subList[idx]) |
| | | } |
| | | |
| | | return nil |
| | | return |
| | | } |
| | | |
| | | func AddFaceCapture(face *vo.FaceObject) { |
| | | func AddFaceNotification(face *vo.FaceObject) { |
| | | TaskProcMap.Range(func(key, value interface{}) bool { |
| | | value.(TaskProcInfo).task.AddFace(face) |
| | | return true |
| | | }) |
| | | |
| | | logger.Debug("添加人脸.") |
| | | //TaskWaitGroup.Wait() |
| | | logger.Debug("Add Face Notification.") |
| | | } |
| | | |
| | | func StopSubscribeTask() { |
| | |
| | | } |
| | | |
| | | type SubscribeTask struct { |
| | | ctx context.Context |
| | | conf *models.Subscribe |
| | | faceList []*vo.FaceObject |
| | | mutex sync.Mutex |
| | | ctx context.Context |
| | | conf *models.Subscribe |
| | | faceList []*vo.FaceObject |
| | | mutex sync.Mutex |
| | | lastExecTime int64 |
| | | } |
| | | |
| | | func (task *SubscribeTask) Start() { |
| | |
| | | for _, subType := range subDetails { |
| | | triggerTime := time.Now().Format("20060102150405") |
| | | |
| | | // 上报设备 |
| | | if subType == vo.SubscribeApe { |
| | | // 上报设备 控制设备通知控制频率, 避免频繁, 上级一般会下发秒级的任务, 但设备不会频繁更新, |
| | | if subType == vo.SubscribeApe && time.Now().Unix()-task.lastExecTime > 60*10 { |
| | | var notification = vo.DeviceNotification{ |
| | | NotificationID: triggerTime + snowflake.GenerateIdStr(), |
| | | SubscribeID: task.conf.Id, |
| | |
| | | } |
| | | var ids []string |
| | | for idx, _ := range task.faceList { |
| | | // 按海康示例填充修改字段 |
| | | task.faceList[idx].ShotTime = task.faceList[idx].FaceAppearTime |
| | | task.faceList[idx].EntryTime = triggerTime |
| | | for i, _ := range task.faceList[idx].SubImageList.SubImageInfoObject { |
| | | task.faceList[idx].SubImageList.SubImageInfoObject[i].EventSort = 2 |
| | | } |
| | | |
| | | ids = append(ids, task.faceList[idx].FaceID) |
| | | notification.FaceObjectList.FaceObject = append(notification.FaceObjectList.FaceObject, *task.faceList[idx]) |
| | | } |
| | |
| | | client.Notify(task.conf.Ext.ReceiveAddr, b) |
| | | } |
| | | } |
| | | |
| | | task.lastExecTime = time.Now().Unix() |
| | | } |