Commit 0efa5942 authored by 陈子龙's avatar 陈子龙

Merge branch 'dev-czl' into dev

parents 0301cb6e bb51ed47
......@@ -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 {
......
package request
type AddTaskManageReq struct {
TaskName string `json:"task_name" vd:"len($)>0;msg:'请输入任务名称'"` // 任务名称
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" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID
HostGroupId int `json:"host_group_id" binding:"required"` // 主机分组ID
}
type EditTaskManageReq struct {
Id int `json:"id" vd:"$>0;msg:'请输入id'"` // 主键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" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID
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 {
......@@ -34,9 +30,6 @@ 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
}
......@@ -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")
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -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")
......
......@@ -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) // 列表
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
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