liuxiaolong
2019-07-03 fa4e06fc0aaa891560117a15149158988a9bf2be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package controllers
 
import (
    "basic.com/dbapi.git"
    "basic.com/pubsub/protomsg.git"
    "encoding/json"
    "time"
 
    "github.com/gin-gonic/gin"
    "webserver/extend/code"
    "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
)
 
// @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)
        }
    }
}
 
// @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/add [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)
}
 
// @Summary 给任务添加算法
// @Description 任务添加算法
// @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/addTaskSdk [GET]
func (tc TaskController) AddTaskSdk(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.AddTaskSdk(taskId,sdkId)
    if flag {
        util.ResponseFormat(c, code.ComError, data)
    } else {
        util.ResponseFormat(c,code.Success,data)
    }
}
 
// @Summary 任务删除算法
// @Description 根据taskid和sdkid删除
// @Produce json
// @Tags task
// @Param taskId path string true "任务id"
// @Param sdkId path 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.ComError, data)
    } else {
        util.ResponseFormat(c,code.Success,data)
    }
}
 
// @Summary 更新任务状态
// @Description (算法不变,只更新任务状态)
// @Produce json
// @Tags task
// @Param taskId path string true "任务id"
// @Param taskName path string true "任务名称"
// @Param isAlarm path bool true "是否报警"
// @Param isEnable path bool 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 taskApi dbapi.TaskApi
    paramBody :=make(map[string]string,0)
    paramBody["taskId"] = c.Query("taskId")
    paramBody["taskName"] = c.Query("taskName")
    paramBody["isAlarm"] = c.Query("isAlarm")
    paramBody["isEnable"] = c.Query("isEnable")
    flag, data := taskApi.UpdateTaskStatus(paramBody)
    if flag {
        util.ResponseFormat(c,code.Success,data)
    } else {
        util.ResponseFormat(c,code.ComError,data)
    }
}
 
// @Summary 删除任务
// @Description 根据任务id删除任务
// @Produce json
// @Tags task
// @Param taskId path 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)
    }
 
}