package controllers
|
|
import (
|
"basic.com/dbapi.git"
|
"basic.com/pubsub/esutil.git"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
"time"
|
"webserver/cache"
|
"webserver/extend/code"
|
"webserver/extend/config"
|
"webserver/extend/util"
|
)
|
|
type TaskController struct{}
|
|
type TaskVo struct {
|
Taskid string `json:"taskid"`
|
Taskname string `json:"taskname" example:"任务一"`
|
CreateAt time.Time `json:"create_at"`
|
Createby string `json:"create_by"`
|
UpdateAt time.Time `json:"update_at"`
|
Enable bool `json:"enable"`
|
IsAlarm bool `json:"is_alarm"`
|
DelFlag bool `json:"del_flag"`
|
}
|
|
type TaskSdkVo struct {
|
Task TaskVo `json:"task"`
|
Sdks []SdkVo `json:"sdks"`
|
}
|
|
var (
|
FaceExtract_VirtualTaskId = "92496BDF-2BFA-98F2-62E8-96DD9866ABD2"//虚拟任务id
|
FaceExtract_VirtualSdkId = "virtual-faceextract-sdk-pull"//结果输出的算法id
|
)
|
|
//// @Security ApiKeyAuth
|
//// @Summary 查找所有任务,包含任务信息和对应的算法信息
|
//// @Description 查找所有任务
|
//// @Produce json
|
//// @Tags task
|
//// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
|
//// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
|
//// @Router /data/api-v/task/findAll [GET]
|
//func (tc TaskController) FindAll(c *gin.Context) {
|
// // 显示所有任务: 获取信息
|
// var taskApi dbapi.TaskApi
|
//
|
// taskInfos := taskApi.FindAll()
|
// var arr []protomsg.TaskSdkInfo
|
// for _,ti :=range taskInfos{
|
// if ti.Task.Taskid != FaceExtract_VirtualTaskId{
|
// arr = append(arr,ti)
|
// }
|
// }
|
// var tasks []TaskSdkVo
|
// dataBytes, err := json.Marshal(arr)
|
// if err !=nil {
|
// util.ResponseFormat(c,code.ComError,[]TaskSdkVo{})
|
// } else {
|
// if err := json.Unmarshal(dataBytes, &tasks);err !=nil {
|
// util.ResponseFormat(c,code.ComError,[]TaskSdkVo{})
|
// } else {
|
// util.ResponseFormat(c,code.Success,tasks)
|
// }
|
// }
|
//}
|
|
// @Security ApiKeyAuth
|
// @Summary 检索页面获取所有任务列表(包含已删除的任务)
|
// @Description 检索页面获取所有任务列表(包含已删除的任务)
|
// @Produce json
|
// @Tags task
|
// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
|
// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
|
// @Router /data/api-v/task/aggregateTaskList [GET]
|
func (tc TaskController) AggregateTaskList(c *gin.Context) {
|
// 显示所有任务: 获取信息
|
var api dbapi.CameraRuleApi
|
|
var result []SceneIfDelResult
|
m := make(map[string]string)
|
if b, allRules := api.FindAll(); b {
|
for _,cg :=range allRules {
|
for _,g := range cg.Rules {
|
m[g.Id] = g.SceneName
|
result = append(result, SceneIfDelResult{
|
Id: g.Id,
|
Name: g.SceneName,
|
IsDelete: false,
|
})
|
}
|
}
|
}
|
|
localConf, _ := cache.GetServerInfo()
|
if 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)
|
if e==nil && esTaskM !=nil {
|
for _,tM :=range esTaskM {
|
if _,ok := m[tM["taskId"].(string)];!ok {//表示此任务已被删除
|
taskId := tM["taskId"].(string)
|
taskName := tM["taskName"].(string)
|
m[taskId] = taskName
|
if taskId != "" {
|
result = append(result, SceneIfDelResult{
|
Id: taskId,
|
Name: taskName,
|
IsDelete: true,
|
})
|
}
|
}
|
}
|
}
|
}
|
util.ResponseFormat(c, code.Success, result)
|
}
|
|
//// @Security ApiKeyAuth
|
//// @Summary 添加任务
|
//// @Description 查找所有任务
|
//// @Accept json
|
//// @Produce json
|
//// @Tags task
|
//// @Param reqMap body controllers.TaskVo false "任务AAA"
|
//// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
|
//// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
|
//// @Router /data/api-v/task/addTask [POST]
|
//func (tc TaskController) AddTask(c *gin.Context) {
|
// var task TaskVo
|
// var taskApi dbapi.TaskApi
|
// err := c.BindJSON(&task)
|
// if err !=nil {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// paramBody := util.Struct2Map(task)
|
// flag, data := taskApi.Add(paramBody)
|
// if !flag {
|
// util.ResponseFormat(c, code.ComError, data)
|
// return
|
// }
|
//
|
// util.ResponseFormat(c, code.Success, data)
|
//}
|
//
|
//type TaskSdkAdd struct {
|
// TaskId string `json:"taskId"`
|
// Sdks []SdkSort `json:"sdks"`
|
//}
|
//type SdkSort struct {
|
// SdkId string `json:"sdkId"`
|
// Sort int `json:"sort"`
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 给任务添加算法
|
//// @Description 任务添加算法
|
//// @Accept json
|
//// @Produce json
|
//// @Tags task
|
//// @Param taskSdkAdd body controllers.TaskSdkAdd true "任务id"
|
//// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
|
//// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
|
//// @Router /data/api-v/task/addTaskSdk [post]
|
//func (tc TaskController) AddTaskSdk(c *gin.Context) {
|
// var addVo TaskSdkAdd
|
// err := c.BindJSON(&addVo)
|
// if err !=nil || addVo.TaskId == "" || len(addVo.Sdks)==0 {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// paramBody := util.Struct2Map(addVo)
|
// var taskApi dbapi.TaskApi
|
// flag,data := taskApi.AddTaskSdk(paramBody)
|
// if flag {
|
// util.ResponseFormat(c, code.Success, data)
|
// } else {
|
// util.ResponseFormat(c,code.ComError,data)
|
// }
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 任务删除算法
|
//// @Description 根据taskid和sdkid删除
|
//// @Produce json
|
//// @Tags task
|
//// @Param taskId query string true "任务id"
|
//// @Param sdkId query string true "算法id"
|
//// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
|
//// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
|
//// @Router /data/api-v/task/delTaskSdk [GET]
|
//func (tc TaskController) DeleteTaskSdk(c *gin.Context) {
|
// var taskApi dbapi.TaskApi
|
// taskId := c.Query("taskId")
|
// sdkId := c.Query("sdkId")
|
// if taskId == "" || sdkId == "" {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// flag,data := taskApi.DeleteTaskSdk(taskId,sdkId)
|
// if flag {
|
// util.ResponseFormat(c, code.Success, data)
|
// } else {
|
// util.ResponseFormat(c,code.ComError, data)
|
// }
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 更新任务名称
|
//// @Description 更新任务名称
|
//// @Accept x-www-form-urlencoded
|
//// @Produce json
|
//// @Tags task
|
//// @Param taskId formData string true "taskId"
|
//// @Param taskName formData string true "taskName"
|
//// @Success 200 {string} json "{"code":200, msg:"",data:"",success:true}"
|
//// @Failure 500 {string} json "{"code":500, msg:"",data:"",success:false}"
|
//// @Router /data/api-v/task/updateTaskName [POST]
|
//func (tc TaskController) UpdateTaskName(c *gin.Context) {
|
// taskId := c.PostForm("taskId")
|
// taskName := c.PostForm("taskName")
|
// if taskId == "" || taskName == "" {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// var api dbapi.TaskApi
|
// if api.UpdateTaskName(taskId, taskName) {
|
// util.ResponseFormat(c,code.UpdateSuccess,"更新成功")
|
// } else {
|
// util.ResponseFormat(c,code.ComError,"更新失败")
|
// }
|
//
|
//}
|
//
|
//type TaskStatusVo struct {
|
// TaskId string `json:"taskId"`
|
// Enable bool `json:"enable"`
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 更新任务状态
|
//// @Description (算法不变,只更新任务状态)
|
//// @Accept json
|
//// @Produce json
|
//// @Tags task
|
//// @Param taskStatus body controllers.TaskStatusVo true "参数"
|
//// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
|
//// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
|
//// @Router /data/api-v/task/updateTaskStatus [POST]
|
//func (tc TaskController) UpdateTaskStatus(c *gin.Context) {
|
// var tsvo TaskStatusVo
|
// err := c.BindJSON(&tsvo)
|
// if err !=nil {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// var taskApi dbapi.TaskApi
|
// paramBody := util.Struct2Map(tsvo)
|
// flag, data := taskApi.UpdateTaskStatus(paramBody)
|
// if flag {
|
// util.ResponseFormat(c,code.Success,data)
|
// } else {
|
// util.ResponseFormat(c,code.ComError,data)
|
// }
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 删除任务
|
//// @Description 根据任务id删除任务
|
//// @Produce json
|
//// @Tags task
|
//// @Param taskId query string true "任务id"
|
//// @Success 200 {string} json "{"code":200, msg:"请求处理成功",data:"",success:true}"
|
//// @Failure 500 {string} json "{"code":500, msg:"请求失败",data:"",success:false}"
|
//// @Router /data/api-v/task/delete [GET]
|
//func (tc TaskController) DeleteTask(c *gin.Context) {
|
// var taskApi dbapi.TaskApi
|
// taskId := c.Query("taskId")
|
// if taskId == "" {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// flag, data := taskApi.Delete(taskId)
|
// if flag {
|
// util.ResponseFormat(c,code.Success,data)
|
// } else {
|
// util.ResponseFormat(c,code.ComError,data)
|
// }
|
//
|
//}
|
//
|
//type TaskSdkRules struct {
|
// TaskId string `json:"taskId"`
|
// SdkId string `json:"sdkId"`
|
// Rules []TaskSdkRuleVo `json:"rules"`
|
//}
|
//
|
//type TaskSdkRuleVo struct {
|
// Id string `json:"id"`
|
// SdkArgAlias string `json:"sdk_arg_alias"`
|
// Operator string `json:"operator"`
|
// SdkArgValue string `json:"sdk_arg_value"`
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 保存算法规则
|
//// @Description 保存算法规则
|
//// @Accept json
|
//// @Produce json
|
//// @Tags 算法规则
|
//// @Param sdkrules body controllers.TaskSdkRules true "算法参数规则"
|
//// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
//// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
//// @Router /data/api-v/task/saveTaskSdkRule [post]
|
//func (tc TaskController) SaveTaskSdkRule(c *gin.Context) {
|
// var rules TaskSdkRules
|
// err := c.BindJSON(&rules)
|
// if err !=nil || rules.TaskId == "" || rules.SdkId == "" || len(rules.Rules) == 0 {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// paramBody := util.Struct2Map(rules)
|
// var api dbapi.TaskSdkRuleApi
|
// b,d := api.SaveTaskSdkRule(paramBody)
|
// if b {
|
// util.ResponseFormat(c,code.Success,d)
|
// } else {
|
// util.ResponseFormat(c,code.ComError,"保存失败")
|
// }
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 删除算法规则
|
//// @Description 删除算法规则
|
//// @Accept x-www-form-urlencoded
|
//// @Produce json
|
//// @Tags 算法规则
|
//// @Param taskId formData string true "taskId"
|
//// @Param sdkId formData string true "sdkId"
|
//// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
//// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
//// @Router /data/api-v/task/deleteTaskSdkRule [post]
|
//func (tc TaskController) DeleteTaskSdkRule(c *gin.Context) {
|
// taskId := c.PostForm("taskId")
|
// sdkId := c.PostForm("sdkId")
|
// if taskId == "" || sdkId == "" {
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// var api dbapi.TaskSdkRuleApi
|
// if api.DeleteTaskSdkRule(taskId, sdkId) {
|
// util.ResponseFormat(c,code.Success,"删除成功")
|
// } else {
|
// util.ResponseFormat(c,code.ComError, "删除失败")
|
// }
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 查询算法规则
|
//// @Description 查询算法规则
|
//// @Produce json
|
//// @Tags 算法规则
|
//// @Param taskId query string true "任务id"
|
//// @Param sdkId query string true "算法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/task/getRulesByTaskSdk [get]
|
//func (tc TaskController) GetRulesByTaskSdk(c *gin.Context) {
|
// taskId := c.Query("taskId")
|
// sdkId := c.Query("sdkId")
|
// if taskId == "" || sdkId == ""{
|
// util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
// return
|
// }
|
// var taskSdkApi dbapi.TaskSdkRuleApi
|
// b, d := taskSdkApi.GetRulesByTaskSdk(taskId, sdkId)
|
// if b {
|
// util.ResponseFormat(c,code.Success,d)
|
// } else {
|
// util.ResponseFormat(c,code.ComError,"查询失败")
|
// }
|
//}
|
//
|
//// @Security ApiKeyAuth
|
//// @Summary 统计每个任务的摄像机数量
|
//// @Description 统计每个任务的摄像机数量
|
//// @Produce json
|
//// @Tags task
|
//// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
//// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
//// @Router /data/api-v/task/statisticTaskCamera [get]
|
//func (tc TaskController) StatisticTaskCamera(c *gin.Context) {
|
// var taskApi dbapi.TaskApi
|
// b,d := taskApi.StatisticTaskCamera()
|
// if b {
|
// util.ResponseFormat(c,code.Success, d)
|
// } else {
|
// util.ResponseFormat(c,code.ComError, "")
|
// }
|
//}
|