170 lines
5.9 KiB
Go
170 lines
5.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"hpds-iot-web/internal/proto"
|
|
"hpds-iot-web/internal/service"
|
|
"hpds-iot-web/model"
|
|
e "hpds-iot-web/pkg/err"
|
|
)
|
|
|
|
func (s HandlerService) TaskList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("TaskList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
if req.Size < 1 {
|
|
req.Size = 20
|
|
}
|
|
if req.Size > 1000 {
|
|
req.Size = 1000
|
|
}
|
|
if req.Page < 1 {
|
|
req.Page = 1
|
|
}
|
|
data, err = repo.TaskList(c, req)
|
|
go s.SaveLog("任务列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) AddTask(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("AddTask", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.AddTask(c, req)
|
|
go s.SaveLog("新增任务", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
func (s HandlerService) ReRunTask(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("ReRunTask", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.ReRunTask(c, req)
|
|
go s.SaveLog("重新执行任务", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) TaskInfo(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("TaskInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.TaskInfo(c, req)
|
|
go s.SaveLog("获取任务信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) TaskResult(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.ReportRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("TaskResult", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
if req.Size < 1 {
|
|
req.Size = 20
|
|
}
|
|
if req.Size > 1000 {
|
|
req.Size = 1000
|
|
}
|
|
if req.Page < 1 {
|
|
req.Page = 1
|
|
}
|
|
data, err = repo.TaskResult(c, req)
|
|
go s.SaveLog("获取任务结果信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) TaskLog(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskLogItem
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("TaskLog", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.TaskLog(c, req)
|
|
go s.SaveLog("获取任务日志信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) TrainingTaskList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("TrainingTaskList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
if req.Size < 1 {
|
|
req.Size = 20
|
|
}
|
|
if req.Size > 1000 {
|
|
req.Size = 1000
|
|
}
|
|
if req.Page < 1 {
|
|
req.Page = 1
|
|
}
|
|
data, err = repo.TrainingTaskList(c, req)
|
|
go s.SaveLog("获取训练任务列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
func (s HandlerService) TrainingTaskInfo(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("TrainingTaskInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.TrainingTaskInfo(c, req)
|
|
go s.SaveLog("获取训练任务详情", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
func (s HandlerService) TrainingTaskLog(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewTaskService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.TaskItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("TrainingTaskLog", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.TrainingTaskLog(c, req)
|
|
go s.SaveLog("获取训练任务日志详情", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|