liuxiaolong
2019-11-13 f26a0cab5bca17b7eab57f6330e576271e17a17f
controllers/task.go
@@ -2,9 +2,13 @@
import (
   "basic.com/dbapi.git"
   "basic.com/pubsub/esutil.git"
   "basic.com/pubsub/protomsg.git"
   "encoding/json"
   "strconv"
   "time"
   "webserver/cache"
   "webserver/extend/config"
   "github.com/gin-gonic/gin"
   "webserver/extend/code"
@@ -35,6 +39,7 @@
)
/*
// @Security ApiKeyAuth
// @Summary 查找所有任务,包含任务信息和对应的算法信息
// @Description 查找所有任务
// @Produce json
@@ -68,6 +73,66 @@
}
/*
// @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 taskApi dbapi.TaskApi
   taskInfos := taskApi.FindAll()
   m := make(map[string]string)
   var arr []protomsg.TaskSdkInfo
   for _,ti :=range taskInfos{
      if ti.Task.Taskid != FaceExtract_VirtualTaskId{
         arr = append(arr,ti)
         m[ti.Task.Taskid] = ti.Task.Taskid
      }
   }
   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 {
         //处理已被删除的任务
         localConf, _ := cache.GetServerInfo()
         if localConf.AlarmIp != "" && localConf.ServerId != "" && localConf.AlarmPort>0 {
            indexName := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.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)
                     m[taskId] = taskId
                     tasks = append(tasks, TaskSdkVo{
                        Task:TaskVo{
                           Taskid:   taskId,
                           Taskname: tM["taskName"].(string),
                           DelFlag: true,
                        },
                        Sdks:[]SdkVo{},
                     })
                  }
               }
            }
         }
         util.ResponseFormat(c,code.Success,tasks)
      }
   }
}
/*
// @Security ApiKeyAuth
// @Summary 添加任务
// @Description 查找所有任务
// @Accept json
@@ -106,8 +171,10 @@
}
/*
// @Security ApiKeyAuth
// @Summary 给任务添加算法
// @Description 任务添加算法
// @Accept json
// @Produce json
// @Tags task
// @Param taskSdkAdd body controllers.TaskSdkAdd true "任务id"
@@ -133,12 +200,13 @@
}
/*
// @Security ApiKeyAuth
// @Summary 任务删除算法
// @Description 根据taskid和sdkid删除
// @Produce json
// @Tags task
// @Param taskId path string true "任务id"
// @Param sdkId path string true "算法id"
// @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]
@@ -160,12 +228,14 @@
}
/*
// @Security ApiKeyAuth
// @Summary 更新任务名称
// @Description 更新任务名称
// @Accept x-www-form-urlencoded
// @Produce json
// @Tags task
// @Param taskId query string true "taskId"
// @Param taskName query string true "taskName"
// @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]
@@ -192,8 +262,10 @@
}
/*
// @Security ApiKeyAuth
// @Summary 更新任务状态
// @Description (算法不变,只更新任务状态)
// @Accept json
// @Produce json
// @Tags task
// @Param taskStatus body controllers.TaskStatusVo true "参数"
@@ -218,13 +290,13 @@
   }
}
/*
// @Security ApiKeyAuth
// @Summary 删除任务
// @Description 根据任务id删除任务
// @Produce json
// @Tags task
// @Param taskId path string true "任务id"
// @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]
@@ -259,6 +331,7 @@
}
/*
// @Security ApiKeyAuth
// @Summary 保存算法规则
// @Description 保存算法规则
// @Accept json
@@ -287,11 +360,14 @@
}
/*
// @Security ApiKeyAuth
// @Summary 删除算法规则
// @Description 删除算法规则
// @Accept x-www-form-urlencoded
// @Produce json
// @Tags 算法规则
// @Param id query string true "id"
// @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]
@@ -311,14 +387,14 @@
   }
}
/*
// @Security ApiKeyAuth
// @Summary 查询算法规则
// @Description 查询算法规则
// @Produce json
// @Tags 算法规则
// @Param taskId path string true "任务id"
// @Param sdkId path string true "算法id"
// @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]
@@ -338,3 +414,23 @@
      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, "")
   }
}