package controllers
|
|
import (
|
"basic.com/pubsub/esutil.git"
|
"basic.com/valib/bhomeclient.git"
|
"basic.com/valib/bhomedbapi.git"
|
"basic.com/valib/logger.git"
|
"strconv"
|
"time"
|
commonModel "vamicro/camera-common/models"
|
"vamicro/config"
|
"vamicro/scene-service/service"
|
"vamicro/scene-service/vo"
|
)
|
|
type CameraTaskController struct {
|
|
}
|
//
|
//用于接收多个摄像机的id,以逗号隔开
|
type MultiCamera struct {
|
CameraIds []string `json:"cameraIds"`
|
}
|
|
type Task struct {
|
Taskid string `gorm:"primary_key" json:"taskid"`
|
Taskname string `gorm:"type:varchar(100);" json:"taskname" example:"任务一"`
|
CreateAt time.Time
|
Createby string
|
UpdateAt time.Time
|
Enable bool `gorm:"default:0"`
|
IsAlarm bool `gorm:"default:0"`
|
DelFlag bool `gorm:"default:0"`
|
Isfull bool `gorm:"default:0"`
|
}
|
|
type CameraTaskInfoVo struct {
|
Camera commonModel.Camera `json:"camera"`
|
Tasks []Task `json:"tasks"`
|
Polygon vo.CameraPolygonVo `json:"polygon"`
|
}
|
//
|
// @Security ApiKeyAuth
|
// @Summary 查询所有任务
|
// @Description "查询所有任务"
|
// @Accept json
|
// @Produce json
|
// @Tags 摄像机规则
|
// @Param cameraIds body controllers.MultiCamera false "摄像机id数组"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/camera/alltask [post]
|
func (ctc CameraTaskController) FindTasksByCameraIds(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
|
var mulCamera MultiCamera
|
c.BindJSON(&mulCamera)
|
|
sv := service.CameraRuleService{
|
Broker: h.Bk,
|
}
|
|
var camRuleArr []vo.CameraAndRules
|
for _,camId :=range mulCamera.CameraIds {
|
d,_ := sv.GetAllByCid(camId, "", nil, nil, nil, nil)
|
if len(d.AllGroupRules) > 0 {
|
camRuleArr = append(camRuleArr, d)
|
}
|
}
|
logger.Debug("alltask camRuleArr:", camRuleArr)
|
var result []SceneIfDelResult
|
m := make(map[string]string)
|
for _,cg :=range camRuleArr {
|
for _,g := range cg.AllGroupRules {
|
m[g.Id] = g.SceneName
|
result = append(result, SceneIfDelResult{
|
Id: g.Id,
|
Name: g.SceneName,
|
IsDelete: false,
|
})
|
}
|
}
|
var sysApi bhomedbapi.SysSetApi
|
sb,localConf := sysApi.GetServerInfo()
|
if sb && localConf.AlarmIp != "" && localConf.ServerId != "" && localConf.AlarmPort>0 {
|
indexName := config.EsInfo.EsIndex.AiOcean.IndexName
|
esTaskM, e := esutil.AggregateTaskList(localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)), indexName, localConf.ServerId, mulCamera.CameraIds)
|
if e==nil && esTaskM !=nil {
|
for _,tM :=range esTaskM {
|
if _,ok := m[tM["taskId"].(string)];!ok {//表示此任务已被删除
|
taskId := tM["taskId"].(string)
|
taskName := tM["taskName"].(string)
|
if taskId != "" {
|
result = append(result, SceneIfDelResult{
|
Id: taskId,
|
Name: taskName,
|
IsDelete: true,
|
})
|
}
|
}
|
}
|
}
|
}
|
|
return &bhomeclient.Reply{ Success:true, Data: result }
|
}
|
|
type SceneIfDelResult struct {
|
Id string `json:"id"`
|
Name string `json:"name"`
|
IsDelete bool `json:"isDelete"`
|
}
|