Commit 83170a80 authored by 陈子龙's avatar 陈子龙

任务历史列表 fix

parent 12b7d656
package entity
import "time"
type WorkOrder struct {
Id int `json:"id" xorm:"pk autoincr" ` // id
OrderName string `json:"order_name" xorm:"order_name"` // 工单名称
OrderLevel int `json:"order_level" xorm:"order_level"` // 工单等级(1紧急任务 2重要任务 3一般任务)
OrderDesc string `json:"order_desc" xorm:"order_desc"` // 工单描述
OrderCnt int `json:"order_cnt" xorm:"order_cnt"` // 实例工单数
PushObj string `json:"push_obj" xorm:"push_obj"` // 推送对象
TimingType int `json:"timing_type" xorm:"timing_type"` // 定时类型(1手动下发 2按周 3自定义时间)
TimingRule string `json:"timing_rule" xorm:"timing_rule"` // 定时规则
TimingState int `json:"timing_state" xorm:"timing_state"` // 定时状态(0禁用 1启用)
CreateUser string `json:"create_user" xorm:"create_user" ` // 创建人
CreateTime time.Time `json:"create_time" xorm:"create_time" ` // 创建时间
UpdateUser string `json:"update_user" xorm:"update_user"` // 修改人
UpdateTime time.Time `json:"update_time" xorm:"update_time" ` // 修改时间
}
package request package request
type TaskHistoryReq struct { type TaskHistoryReq struct {
TaskId int `json:"task_id" form:"task_id" binding:"required"` // 主键ID Search string `json:"search" form:"search"` // 关键词
Pagination
}
type TaskInfoListReq struct {
TaskId int `json:"task_id" form:"task_id" binding:"required"` // 主键ID
Search string `json:"search" form:"search"` // 关键词
Pagination Pagination
} }
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
// TaskHistoryList 任务历史列表 // TaskHistoryList 任务历史列表
func TaskHistoryList(c *gin.Context) { func TaskHistoryList(c *gin.Context) {
var req request.Pagination var req request.TaskHistoryReq
if err := c.ShouldBind(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return return
...@@ -28,7 +28,7 @@ func TaskHistoryList(c *gin.Context) { ...@@ -28,7 +28,7 @@ func TaskHistoryList(c *gin.Context) {
// TaskInfoList 任务历史详情列表 // TaskInfoList 任务历史详情列表
func TaskInfoList(c *gin.Context) { func TaskInfoList(c *gin.Context) {
var req request.TaskHistoryReq var req request.TaskInfoListReq
if err := c.ShouldBind(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return return
......
package controller
import (
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
)
// AddWorkOrderManage 新增业务工单管理
func AddWorkOrderManage(c *gin.Context) {
//var req request.AddTaskManageReq
//if err := c.ShouldBindJSON(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
//}
////参数校验
//if err := util.ValidateSimple(req, "TaskName,HostGroupId"); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
//}
//
//taskManageSvc := service.TaskManageSvc{}
//err := taskManageSvc.AddTaskManage(req)
//if err != nil {
// SendJsonResponse(c, err, nil)
// return
//}
SendJsonResponse(c, resp.OK, nil)
}
//
//// EditTaskManage 编辑任务
//func EditTaskManage(c *gin.Context) {
// var req request.EditTaskManageReq
// if err := c.ShouldBindJSON(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
// //参数校验
// if err := util.ValidateSimple(req, "Id,HostGroupId"); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// err := taskManageSvc.EditTaskManage(req)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.OK, nil)
//}
//
//// DelTaskManage 删除任务
//func DelTaskManage(c *gin.Context) {
// var req request.DelTaskManageReq
// if err := c.ShouldBindJSON(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
// //参数校验
// if err := util.ValidateSimple(req, "Id"); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// err := taskManageSvc.DelTaskManage(req)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.OK, nil)
//}
//
//// DetailsTaskManage 任务详情
//func DetailsTaskManage(c *gin.Context) {
// var (
// err error
// id string
// )
//
// if id = c.Query("id"); id == "" {
// id = c.Param("id")
// }
// if id == "" {
// SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("id为空")), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// data, err := taskManageSvc.DetailsTaskManage(cast.ToInt(id))
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.OK, data)
//}
//
//// ListTaskManage 任务列表
//func ListTaskManage(c *gin.Context) {
// var req request.ListTaskManageReq
// if err := c.ShouldBind(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// total, list, err := taskManageSvc.ListTaskManage(req)
// if err != nil {
// SendJsonPageResponse(c, err, nil, 0)
// return
// }
// SendJsonPageResponse(c, resp.OK, list, total)
//}
...@@ -48,5 +48,5 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) { ...@@ -48,5 +48,5 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
// 初始化prometheus路由 // 初始化prometheus路由
InitPrometheusRouter(r) InitPrometheusRouter(r)
// 初始化工单管理路由 // 初始化工单管理路由
//InitAutomatedMaintenRouter(r) InitWorkOrderRouter(r)
} }
package router
import (
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
)
// InitWorkOrderRouter 初始化工单路由
func InitWorkOrderRouter(e *gin.Engine) {
so := e.Group(fmt.Sprintf("%s/work_order", conf.Options.Prefix))
//业务工单管理
manage := so.Group("/work_order_manage")
{
manage.POST("/add", controller.AddWorkOrderManage) // 新增
//manage.PUT("/edit", controller.EditTaskManage) // 编辑
//manage.DELETE("/del", controller.DelTaskManage) // 删除
//manage.GET("/details", controller.DetailsTaskManage) // 详情
//manage.GET("/list", controller.ListTaskManage) // 列表
//manage.POST("/exec/script", controller.ExecScript) // 立即执行
}
////任务历史
//taskHistory := so.Group("/task_history")
//{
// taskHistory.GET("/list", controller.TaskHistoryList) // 任务历史列表
// taskHistory.GET("/task_info_list", controller.TaskInfoList) // 任务历史详情列表
// taskHistory.GET("/task_exec_log", controller.TaskExecLog) // 任务执行日志
//}
//
////主机管理
//host := so.Group("/host_manage")
//{
// host.POST("/add", controller.AddHostManage) // 新增
// host.PUT("/edit", controller.EditHostManage) // 编辑
// host.DELETE("/del", controller.DelHostManage) // 删除
// host.GET("/details", controller.DetailsHostManage) // 详情
// host.GET("/page_list", controller.PageListHostManage) // 列表
// host.POST("/state", controller.StateHostManage) // 状态检测
// host.GET("/ip_exception_list", controller.HostIpExceptionList) // 主机ip异常列表
// host.GET("/export", controller.ExportIp) // 导出ip列表
// host.GET("/list", controller.ListHostManage) // 主机分组列表-不分页
//}
}
...@@ -15,7 +15,7 @@ type TaskHistorySvc struct { ...@@ -15,7 +15,7 @@ type TaskHistorySvc struct {
} }
// TaskHistoryList 任务历史列表 // TaskHistoryList 任务历史列表
func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, taskHistoryListRes []response.TaskHistoryListRes, err error) { func (t *TaskHistorySvc) TaskHistoryList(req request.TaskHistoryReq) (total int64, taskHistoryListRes []response.TaskHistoryListRes, err error) {
var ( var (
//dueDate int //dueDate int
start time.Time start time.Time
...@@ -32,6 +32,9 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t ...@@ -32,6 +32,9 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t
" WHERE ID IN (SELECT MAX(ID) FROM task_history GROUP BY task_id) ORDER BY ID DESC) t2", "t1.id = t2.task_id"). " WHERE ID IN (SELECT MAX(ID) FROM task_history GROUP BY task_id) ORDER BY ID DESC) t2", "t1.id = t2.task_id").
Where("t1.is_delete = 0") Where("t1.is_delete = 0")
if req.Search != "" {
finder.Where("t1.task_name LIKE ?", "%"+req.Search+"%")
}
//查询任务历史 //查询任务历史
total, err = finder.Select("t2.state,t2.task_id,t1.task_name,t2.exec_start_time,t2.exec_end_time,t2.create_user"). total, err = finder.Select("t2.state,t2.task_id,t1.task_name,t2.exec_start_time,t2.exec_end_time,t2.create_user").
Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&taskHistoryListRes) Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&taskHistoryListRes)
...@@ -61,7 +64,7 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t ...@@ -61,7 +64,7 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t
} }
// TaskInfoList 任务历史详情列表 // TaskInfoList 任务历史详情列表
func (t *TaskHistorySvc) TaskInfoList(req request.TaskHistoryReq) (total int64, taskInfoListRes []response.TaskInfoListRes, err error) { func (t *TaskHistorySvc) TaskInfoList(req request.TaskInfoListReq) (total int64, taskInfoListRes []response.TaskInfoListRes, err error) {
var ( var (
//dueDate int //dueDate int
start time.Time start time.Time
...@@ -74,7 +77,9 @@ func (t *TaskHistorySvc) TaskInfoList(req request.TaskHistoryReq) (total int64, ...@@ -74,7 +77,9 @@ func (t *TaskHistorySvc) TaskInfoList(req request.TaskHistoryReq) (total int64,
} }
finder := db.Table("task_history").Where("task_id = ?", req.TaskId) finder := db.Table("task_history").Where("task_id = ?", req.TaskId)
if req.Search != "" {
finder.Where("exec_desc LIKE ?", "%"+req.Search+"%")
}
//查询任务历史 //查询任务历史
total, err = finder.OrderBy("id desc").Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&taskInfoListRes) total, err = finder.OrderBy("id desc").Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&taskInfoListRes)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment