diff --git a/src/bean/vo/request/host_manage.go b/src/bean/vo/request/host_manage.go index dc9cda59b0a4b0a2025977352e21fdc9afe87837..2039dd9bf4428a2e5979f247097d9c5c181efc72 100644 --- a/src/bean/vo/request/host_manage.go +++ b/src/bean/vo/request/host_manage.go @@ -4,7 +4,6 @@ type AddHostManageReq struct { HostName string `json:"host_name" binding:"required"` // 主机分组名称 HostFileUrl string `json:"host_file_url"` // 主机文件url Uuid string `json:"uuid"` //临时缓存uuid - //HostManageList []HostManageList `json:"host_manage_list"` //主机列表 } type HostManageList struct { @@ -20,11 +19,10 @@ type EditHostManageReq struct { Id int `json:"id" binding:"required"` // 主键ID HostFileUrl string `json:"host_file_url"` // 主机文件url Uuid string `json:"uuid"` //临时缓存uuid - //HostManageList []HostManageList `json:"host_manage_list"` //主机列表 } type DelHostManageReq struct { - Id []int `json:"id" vd:"len($)>0;msg:'请输入id'"` // 主键ID + Id []int `json:"id" binding:"required"` // 主键ID } type ListHostManageReq struct { diff --git a/src/bean/vo/request/task_manage.go b/src/bean/vo/request/task_manage.go index 6c7294e3c9a2fb4916424dbd81533a2a1e4b24a3..8a5a9d8b1ef7aacfad172952217cee7976993f74 100644 --- a/src/bean/vo/request/task_manage.go +++ b/src/bean/vo/request/task_manage.go @@ -1,27 +1,23 @@ package request type AddTaskManageReq struct { - TaskName string `json:"task_name" vd:"len($)>0;msg:'请输入任务名称'"` // 任务名称 - TaskDesc string `json:"task_desc"` // 任务描述 - YamlDesc string `json:"yaml_desc"` // yaml内容 - YamlUrl string `json:"yaml_url"` // yaml文件url - HostGroupId int `json:"host_group_id" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID + TaskName string `json:"task_name" binding:"required"` // 任务名称 + TaskDesc string `json:"task_desc"` // 任务描述 + YamlDesc string `json:"yaml_desc"` // yaml内容 + YamlUrl string `json:"yaml_url"` // yaml文件url + HostGroupId int `json:"host_group_id" binding:"required"` // 主机分组ID } type EditTaskManageReq struct { - Id int `json:"id" vd:"$>0;msg:'请输入id'"` // 主键ID - TaskDesc string `json:"task_desc"` // 任务描述 - YamlDesc string `json:"yaml_desc"` // yaml内容 - YamlUrl string `json:"yaml_url"` // yaml文件url - HostGroupId int `json:"host_group_id" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID + Id int `json:"id" binding:"required"` // 主键ID + TaskDesc string `json:"task_desc"` // 任务描述 + YamlDesc string `json:"yaml_desc"` // yaml内容 + YamlUrl string `json:"yaml_url"` // yaml文件url + HostGroupId int `json:"host_group_id" binding:"required"` // 主机分组ID } type DelTaskManageReq struct { - Id []int `json:"id" vd:"len($)>0;msg:'请输入id'"` // 主键ID -} - -type DetailsTaskManageReq struct { - Id int `json:"id" vd:"$>0;msg:'请输入id'"` // 主键ID + Id []int `json:"id" binding:"required"` // 主键ID } type ListTaskManageReq struct { @@ -33,10 +29,7 @@ type ListTaskManageReq struct { } type ExecScriptReq struct { - TaskId int `form:"task_id" binding:"required"` //任务id - //HostGroupId int `form:"host_group_id" binding:"required"` //主机分组id - Type int `form:"type"` //脚本额外变量类型1yaml 2json - Value string `form:"value"` //脚本额外变量值 - //Script string `form:"script"` //执行脚本 - //YmlFileName string `form:"yml_file_name"` //执行脚本url + TaskId int `form:"task_id" binding:"required"` //任务id + Type int `form:"type"` //脚本额外变量类型1yaml 2json + Value string `form:"value"` //脚本额外变量值 } diff --git a/src/controller/host_manage.go b/src/controller/host_manage.go index 4ae2ceb1b596c9cc1c9ffd0687bf6a75fe395787..616980272ce0be3154a1848a46a635f3eab41eb7 100644 --- a/src/controller/host_manage.go +++ b/src/controller/host_manage.go @@ -10,53 +10,8 @@ import ( "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" - "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" ) -// ParsingHostFiles 解析主机文件 -func ParsingHostFiles(c *gin.Context) (hostManageList []request.HostManageList, err error) { - //获取文件流 - metaData, _, err := c.Request.FormFile("host_file") - if err != nil { - err = resp.GetFileStreamError.WithError(err) - return - } - xlsxData, err := excelize.OpenReader(metaData) - if err != nil { - err = resp.ReadFileError.WithError(err) - return - } - //读取工作簿 - rows := xlsxData.GetRows("Sheet1") - - if len(rows) > 1001 { - err = resp.FailedToParseFile.WithError(errors.New("ip数量不可超过1000")) - return - } - - for i := 0; i < len(rows); i++ { - //默认跳过第一行 - if i < 1 { - continue - } - - var voucherType int - if rows[i][2] == "密码验证" { - voucherType = 0 - } else { - voucherType = 1 - } - hostManageList = append(hostManageList, request.HostManageList{ - Ip: rows[i][0], - Port: rows[i][1], - VoucherType: voucherType, - UserName: rows[i][3], - Password: rows[i][4], - }) - } - return -} - // GetMinioFiles 解析minio中xlsx类型文件 func GetMinioFiles(fileName string) (hostManageList []request.HostManageList, err error) { @@ -110,7 +65,7 @@ func AddHostManage(c *gin.Context) { err error ) if err = c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -119,20 +74,6 @@ func AddHostManage(c *gin.Context) { SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组名称为空")), nil) return } - //if len(req.HostManageList) == 0 { - // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil) - // return - //} - //for _, v := range req.HostManageList { - // if v.Ip == "" || v.UserName == "" { - // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil) - // return - // } - // if v.VoucherType == 0 && v.Password == "" { - // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil) - // return - // } - //} hostManageSvc := service.HostManageSvc{User: header.GetUser(c)} err = hostManageSvc.AddHostManage(req) @@ -150,26 +91,10 @@ func EditHostManage(c *gin.Context) { err error ) if err = c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } - //参数校验 - //if len(req.HostManageList) == 0 { - // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil) - // return - //} - //for _, v := range req.HostManageList { - // if v.Ip == "" || v.UserName == "" { - // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil) - // return - // } - // if v.VoucherType == 0 && v.Password == "" { - // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil) - // return - // } - //} - hostManageSvc := service.HostManageSvc{User: header.GetUser(c)} err = hostManageSvc.EditHostManage(req) if err != nil { @@ -183,12 +108,7 @@ func EditHostManage(c *gin.Context) { func DelHostManage(c *gin.Context) { var req request.DelHostManageReq 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) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -229,7 +149,7 @@ func DetailsHostManage(c *gin.Context) { func PageListHostManage(c *gin.Context) { var req request.ListHostManageReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -249,7 +169,7 @@ func StateHostManage(c *gin.Context) { err error ) if err = c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -283,9 +203,7 @@ func StateHostManage(c *gin.Context) { } case 3: //解析主机文件 - //hostManageList, err = ParsingHostFiles(c) hostManageList, err = GetMinioFiles(req.FileName) - if err != nil { SendJsonResponse(c, resp.ReadFileError.WithError(errors.New("解析主机文件失败")), nil) return @@ -325,7 +243,7 @@ func StateHostManage(c *gin.Context) { func HostIpExceptionList(c *gin.Context) { var req request.HostIpExceptionListReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -361,7 +279,7 @@ func HostIpExceptionList(c *gin.Context) { } } -// 导出 +// ExportIp 导出 func ExportIp(c *gin.Context) { detectionType := c.Query("detection_type") id := c.Query("id") diff --git a/src/controller/task_history.go b/src/controller/task_history.go index 904794b4b075c83add901c29171020e69f35f44e..472417043f7045ee6af40999bd8e45007d72de26 100644 --- a/src/controller/task_history.go +++ b/src/controller/task_history.go @@ -13,7 +13,7 @@ import ( func TaskHistoryList(c *gin.Context) { var req request.TaskHistoryReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -30,7 +30,7 @@ func TaskHistoryList(c *gin.Context) { func TaskInfoList(c *gin.Context) { var req request.TaskInfoListReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } diff --git a/src/controller/task_manage.go b/src/controller/task_manage.go index 3e6b3d1d6a297287f63de6ad2d9fc15f11d079bd..73cc1a1f4f2b3c2a4632826611f4b6db79ca7580 100644 --- a/src/controller/task_manage.go +++ b/src/controller/task_manage.go @@ -14,7 +14,6 @@ import ( "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" - "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" "io" "strings" ) @@ -23,12 +22,7 @@ import ( func AddTaskManage(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) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -45,12 +39,7 @@ func AddTaskManage(c *gin.Context) { 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) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -67,12 +56,7 @@ func EditTaskManage(c *gin.Context) { 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) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -113,7 +97,7 @@ func DetailsTaskManage(c *gin.Context) { func ListTaskManage(c *gin.Context) { var req request.ListTaskManageReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -132,7 +116,7 @@ func ExecScript(c *gin.Context) { err error ) if err = c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } diff --git a/src/controller/work_order_manage.go b/src/controller/work_order_manage.go index 9e9f4136f7fefcab5ea1f681d13bc7f7360bd87e..7cae6367d21c31526d32134085eff643f023536c 100644 --- a/src/controller/work_order_manage.go +++ b/src/controller/work_order_manage.go @@ -15,7 +15,7 @@ import ( func AddWorkOrderManage(c *gin.Context) { var req request.AddWorkOrderReq if err := c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -32,7 +32,7 @@ func AddWorkOrderManage(c *gin.Context) { func EditWorkOrderManage(c *gin.Context) { var req request.EditWorkOrderReq if err := c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } //参数校验 @@ -54,7 +54,7 @@ func EditWorkOrderManage(c *gin.Context) { func StateWorkOrderManage(c *gin.Context) { var req request.StateWorkOrderReq if err := c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } //参数校验 @@ -76,7 +76,7 @@ func StateWorkOrderManage(c *gin.Context) { func DelWorkOrderManage(c *gin.Context) { var req request.DelWorkOrderReq if err := c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } //参数校验 @@ -122,7 +122,7 @@ func DetailsWorkOrderManage(c *gin.Context) { func ListWorkOrderManage(c *gin.Context) { var req request.ListWorkOrderManageReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -139,7 +139,7 @@ func ListWorkOrderManage(c *gin.Context) { func PushWorkOrderManage(c *gin.Context) { var req request.PushWorkOrderReq if err := c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -156,7 +156,7 @@ func PushWorkOrderManage(c *gin.Context) { func CloseWorkOrderIssuance(c *gin.Context) { var req request.CloseWorkOrderReq if err := c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -173,7 +173,7 @@ func CloseWorkOrderIssuance(c *gin.Context) { func ListWorkOrderIssuance(c *gin.Context) { var req request.ListWorkOrderReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -214,7 +214,7 @@ func DetailsWorkOrderIssuance(c *gin.Context) { func FeedbackWorkOrderMe(c *gin.Context) { var req request.FeedbackWorkOrderReq if err := c.ShouldBindJSON(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -231,7 +231,7 @@ func FeedbackWorkOrderMe(c *gin.Context) { func ListWorkOrderMe(c *gin.Context) { var req request.ListWorkOrderReq if err := c.ShouldBind(&req); err != nil { - SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } @@ -244,7 +244,7 @@ func ListWorkOrderMe(c *gin.Context) { SendJsonPageResponse(c, resp.OK, list, total) } -// WorkOrderPushNoteMsg 我的业务工单列表 +// WorkOrderPushNoteMsg 推送短信 func WorkOrderPushNoteMsg(c *gin.Context) { phone := c.Query("phone") diff --git a/src/router/workorderrouter.go b/src/router/workorderrouter.go index 3cbf2833f662f53edafa8ba97676db479954b222..60e6dbaa946bea83833791aad6a37d51795cb5a7 100644 --- a/src/router/workorderrouter.go +++ b/src/router/workorderrouter.go @@ -12,7 +12,7 @@ import ( func InitWorkOrderRouter(e *gin.Engine) { so := e.Group(fmt.Sprintf("%s/work_order", conf.Options.Prefix)) //预警工单管理 - alert := so.Group("/alert") + alert := so.Group("/alert", header.SetContext) { alert.GET("", controller.DetailAlertList) // 详情 alert.GET("/list", controller.ListAlertList) // 列表 diff --git a/src/service/host_manage.go b/src/service/host_manage.go index 1e7eb9ab3aef508da8c19feeea68d4f119550ea6..42115d6aa25d9ce9bb225f511bffa3c2e539de7a 100644 --- a/src/service/host_manage.go +++ b/src/service/host_manage.go @@ -381,7 +381,7 @@ func (h *HostManageSvc) PageListHostManage(req request.ListHostManageReq) (total "task_manage tm WHERE tm.is_delete = 0 AND tm.host_group_id = hm.ID) AS task_cnt,(SELECT COUNT(*) FROM "+ "host_manage_list hml WHERE hml.is_delete = 0 AND hml.conn_status = 1 AND hml.host_group_id = hm.ID) AS "+ "ip_cnt_err,(SELECT COUNT(*) FROM host_manage_list hml WHERE hml.is_delete = 0 AND hml.host_group_id = hm.ID) AS ip_cnt"). - Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&hostManageListRes) + OrderBy("hm.create_time desc").Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&hostManageListRes) if err != nil { err = resp.DbSelectError.WithError(err) return diff --git a/src/service/task_history.go b/src/service/task_history.go index 2870ca34dc92114fa34feee9ad55412ac0fd224a..82ac5e547ceff598caffb46c0ee9bd2cf13c9b28 100644 --- a/src/service/task_history.go +++ b/src/service/task_history.go @@ -38,7 +38,7 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.TaskHistoryReq) (total int6 } //查询任务历史 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) + OrderBy("t2.exec_start_time desc").Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&taskHistoryListRes) if err != nil { err = resp.DbSelectError.WithError(err) return diff --git a/src/service/task_manage.go b/src/service/task_manage.go index 95dc98716fff6ac3d83133928f9b3bac6bd0f243..74883dabec889a592a20ca92d20acb0045bbf8f4 100644 --- a/src/service/task_manage.go +++ b/src/service/task_manage.go @@ -133,11 +133,6 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa return } - //err = db.Table("host_manage_list").Where("is_delete = 0 AND host_group_id = ?", id).Find(&hostList) - //if err != nil { - // err = resp.DbSelectError.WithError(err) - // return - //} for _, v := range hostList { if v.HostFileUrl != "" { taskManageRes.HostFileUrl = v.HostFileUrl @@ -174,7 +169,7 @@ func (t *TaskManageSvc) ListTaskManage(req request.ListTaskManageReq) (total int finder.OrderBy("tm.id") //查询任务 total, err = finder.Select("tm.id,tm.task_name,tm.task_desc,(select count(*) from task_history th "+ - "where th.task_id = tm.id) as exec_cnt,tm.create_user,tm.create_time"). + "where th.task_id = tm.id) as exec_cnt,tm.create_user,tm.create_time").OrderBy("tm.create_time desc"). Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&taskManageListRes) if err != nil { err = resp.DbSelectError.WithError(err) @@ -245,7 +240,6 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id } defer hostsGroup.Close() - //_, err = hostsGroup.Write([]byte(hostsIp)) _, err = hostsGroup.Write([]byte(strings.Join(hosts, "\n"))) if err != nil { err = resp.FileExecError.WithError(err)