Commit 4ce32e64 authored by 陈子龙's avatar 陈子龙

绑定用户信息

parent cb700e91
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/spf13/cast" "github.com/spf13/cast"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "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/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
) )
...@@ -133,7 +134,7 @@ func AddHostManage(c *gin.Context) { ...@@ -133,7 +134,7 @@ func AddHostManage(c *gin.Context) {
// } // }
//} //}
hostManageSvc := service.HostManageSvc{} hostManageSvc := service.HostManageSvc{User: header.GetUser(c)}
err = hostManageSvc.AddHostManage(req) err = hostManageSvc.AddHostManage(req)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
...@@ -169,7 +170,7 @@ func EditHostManage(c *gin.Context) { ...@@ -169,7 +170,7 @@ func EditHostManage(c *gin.Context) {
// } // }
//} //}
hostManageSvc := service.HostManageSvc{} hostManageSvc := service.HostManageSvc{User: header.GetUser(c)}
err = hostManageSvc.EditHostManage(req) err = hostManageSvc.EditHostManage(req)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "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/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"io" "io"
...@@ -31,7 +32,7 @@ func AddTaskManage(c *gin.Context) { ...@@ -31,7 +32,7 @@ func AddTaskManage(c *gin.Context) {
return return
} }
taskManageSvc := service.TaskManageSvc{} taskManageSvc := service.TaskManageSvc{User: header.GetUser(c)}
id, err := taskManageSvc.AddTaskManage(req) id, err := taskManageSvc.AddTaskManage(req)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
...@@ -53,7 +54,7 @@ func EditTaskManage(c *gin.Context) { ...@@ -53,7 +54,7 @@ func EditTaskManage(c *gin.Context) {
return return
} }
taskManageSvc := service.TaskManageSvc{} taskManageSvc := service.TaskManageSvc{User: header.GetUser(c)}
id, err := taskManageSvc.EditTaskManage(req) id, err := taskManageSvc.EditTaskManage(req)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
...@@ -135,7 +136,7 @@ func ExecScript(c *gin.Context) { ...@@ -135,7 +136,7 @@ func ExecScript(c *gin.Context) {
return return
} }
taskManageSvc := service.TaskManageSvc{} taskManageSvc := service.TaskManageSvc{User: header.GetUser(c)}
taskManage, err := taskManageSvc.GetTaskManage(req.TaskId) taskManage, err := taskManageSvc.GetTaskManage(req.TaskId)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/spf13/cast" "github.com/spf13/cast"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "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/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
) )
...@@ -18,7 +19,7 @@ func AddWorkOrderManage(c *gin.Context) { ...@@ -18,7 +19,7 @@ func AddWorkOrderManage(c *gin.Context) {
return return
} }
workOrderManageSvc := service.WorkOrderManageSvc{} workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)}
err := workOrderManageSvc.AddWorkOrderManage(req) err := workOrderManageSvc.AddWorkOrderManage(req)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
...@@ -40,7 +41,7 @@ func EditWorkOrderManage(c *gin.Context) { ...@@ -40,7 +41,7 @@ func EditWorkOrderManage(c *gin.Context) {
return return
} }
workOrderManageSvc := service.WorkOrderManageSvc{} workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)}
err := workOrderManageSvc.EditWorkOrderManage(req) err := workOrderManageSvc.EditWorkOrderManage(req)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
...@@ -142,7 +143,7 @@ func PushWorkOrderManage(c *gin.Context) { ...@@ -142,7 +143,7 @@ func PushWorkOrderManage(c *gin.Context) {
return return
} }
workOrderManageSvc := service.WorkOrderManageSvc{} workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)}
err := workOrderManageSvc.PushWorkOrderManage(req) err := workOrderManageSvc.PushWorkOrderManage(req)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
...@@ -234,7 +235,7 @@ func ListWorkOrderMe(c *gin.Context) { ...@@ -234,7 +235,7 @@ func ListWorkOrderMe(c *gin.Context) {
return return
} }
workOrderManageSvc := service.WorkOrderManageSvc{} workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)}
total, list, err := workOrderManageSvc.ListWorkOrderMe(req) total, list, err := workOrderManageSvc.ListWorkOrderMe(req)
if err != nil { if err != nil {
SendJsonPageResponse(c, err, nil, 0) SendJsonPageResponse(c, err, nil, 0)
......
...@@ -5,13 +5,14 @@ import ( ...@@ -5,13 +5,14 @@ import (
"github.com/gin-gonic/gin" "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/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
) )
// InitAutomatedMaintenRouter 初始化自动化运维路由 // InitAutomatedMaintenRouter 初始化自动化运维路由
func InitAutomatedMaintenRouter(e *gin.Engine) { func InitAutomatedMaintenRouter(e *gin.Engine) {
so := e.Group(fmt.Sprintf("%s/automated_mainten", conf.Options.Prefix)) so := e.Group(fmt.Sprintf("%s/automated_mainten", conf.Options.Prefix))
//任务管理 //任务管理
task := so.Group("/task_manage") task := so.Group("/task_manage", header.SetContext)
{ {
task.POST("/add", controller.AddTaskManage) // 新增 task.POST("/add", controller.AddTaskManage) // 新增
task.PUT("/edit", controller.EditTaskManage) // 编辑 task.PUT("/edit", controller.EditTaskManage) // 编辑
...@@ -22,7 +23,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) { ...@@ -22,7 +23,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) {
} }
//任务历史 //任务历史
taskHistory := so.Group("/task_history") taskHistory := so.Group("/task_history", header.SetContext)
{ {
taskHistory.GET("/list", controller.TaskHistoryList) // 任务历史列表 taskHistory.GET("/list", controller.TaskHistoryList) // 任务历史列表
taskHistory.GET("/task_info_list", controller.TaskInfoList) // 任务历史详情列表 taskHistory.GET("/task_info_list", controller.TaskInfoList) // 任务历史详情列表
...@@ -30,7 +31,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) { ...@@ -30,7 +31,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) {
} }
//主机管理 //主机管理
host := so.Group("/host_manage") host := so.Group("/host_manage", header.SetContext)
{ {
host.POST("/add", controller.AddHostManage) // 新增 host.POST("/add", controller.AddHostManage) // 新增
host.PUT("/edit", controller.EditHostManage) // 编辑 host.PUT("/edit", controller.EditHostManage) // 编辑
......
...@@ -5,20 +5,21 @@ import ( ...@@ -5,20 +5,21 @@ import (
"github.com/gin-gonic/gin" "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/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
) )
// InitWorkOrderRouter 初始化工单路由 // InitWorkOrderRouter 初始化工单路由
func InitWorkOrderRouter(e *gin.Engine) { func InitWorkOrderRouter(e *gin.Engine) {
so := e.Group(fmt.Sprintf("%s/work_order", conf.Options.Prefix)) 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("", controller.DetailAlertList) // 详情
alert.GET("/list", controller.ListAlertList) // 列表 alert.GET("/list", controller.ListAlertList) // 列表
} }
//业务工单管理 //业务工单管理
manage := so.Group("/work_order_manage") manage := so.Group("/work_order_manage", header.SetContext)
{ {
manage.POST("/add", controller.AddWorkOrderManage) // 新增 manage.POST("/add", controller.AddWorkOrderManage) // 新增
manage.PUT("/edit", controller.EditWorkOrderManage) // 编辑 manage.PUT("/edit", controller.EditWorkOrderManage) // 编辑
...@@ -30,7 +31,7 @@ func InitWorkOrderRouter(e *gin.Engine) { ...@@ -30,7 +31,7 @@ func InitWorkOrderRouter(e *gin.Engine) {
} }
//业务工单列表 //业务工单列表
list := so.Group("/work_order_issuance") list := so.Group("/work_order_issuance", header.SetContext)
{ {
list.PUT("/close", controller.CloseWorkOrderIssuance) // 关闭工单 list.PUT("/close", controller.CloseWorkOrderIssuance) // 关闭工单
list.GET("/list", controller.ListWorkOrderIssuance) // 业务工单下发列表 list.GET("/list", controller.ListWorkOrderIssuance) // 业务工单下发列表
...@@ -38,7 +39,7 @@ func InitWorkOrderRouter(e *gin.Engine) { ...@@ -38,7 +39,7 @@ func InitWorkOrderRouter(e *gin.Engine) {
} }
//我的业务工单 //我的业务工单
me := so.Group("/work_order_me") me := so.Group("/work_order_me", header.SetContext)
{ {
me.PUT("/feedback", controller.FeedbackWorkOrderMe) // 处置反馈 me.PUT("/feedback", controller.FeedbackWorkOrderMe) // 处置反馈
me.GET("/list", controller.ListWorkOrderMe) // 我的业务工单列表 me.GET("/list", controller.ListWorkOrderMe) // 我的业务工单列表
......
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
) )
type HostManageSvc struct { type HostManageSvc struct {
User *entity.SystemUser User entity.SystemUserInfo
} }
const AnsibleGroup string = "HostGroup" const AnsibleGroup string = "HostGroup"
...@@ -53,9 +53,9 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error) ...@@ -53,9 +53,9 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
//新增主机分组 //新增主机分组
hostManage := entity.HostManage{ hostManage := entity.HostManage{
HostName: req.HostName, HostName: req.HostName,
CreateUser: "", CreateUser: h.User.SystemAccount,
CreateTime: time.Now(), CreateTime: time.Now(),
UpdateUser: "", UpdateUser: h.User.SystemAccount,
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
_, err = session.Table("host_manage").Insert(&hostManage) _, err = session.Table("host_manage").Insert(&hostManage)
...@@ -156,7 +156,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error ...@@ -156,7 +156,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
//修改主机分组信息 //修改主机分组信息
hostManage := entity.HostManage{ hostManage := entity.HostManage{
UpdateUser: "", UpdateUser: h.User.SystemAccount,
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
_, err = session.Table("host_manage").Where("is_delete = 0 AND id = ?", req.Id). _, err = session.Table("host_manage").Where("is_delete = 0 AND id = ?", req.Id).
......
...@@ -17,7 +17,7 @@ import ( ...@@ -17,7 +17,7 @@ import (
) )
type TaskManageSvc struct { type TaskManageSvc struct {
User *entity.SystemUser User entity.SystemUserInfo
} }
// AddTaskManage 新增任务 // AddTaskManage 新增任务
...@@ -45,9 +45,9 @@ func (t *TaskManageSvc) AddTaskManage(req request.AddTaskManageReq) (id int, err ...@@ -45,9 +45,9 @@ func (t *TaskManageSvc) AddTaskManage(req request.AddTaskManageReq) (id int, err
YamlDesc: req.YamlDesc, YamlDesc: req.YamlDesc,
YamlUrl: req.YamlUrl, YamlUrl: req.YamlUrl,
HostGroupId: req.HostGroupId, HostGroupId: req.HostGroupId,
CreateUser: "", CreateUser: t.User.SystemAccount,
CreateTime: time.Now(), CreateTime: time.Now(),
UpdateUser: "", UpdateUser: t.User.SystemAccount,
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
_, err = db.Table("task_manage").Insert(&taskManage) _, err = db.Table("task_manage").Insert(&taskManage)
...@@ -71,7 +71,7 @@ func (t *TaskManageSvc) EditTaskManage(req request.EditTaskManageReq) (id int, e ...@@ -71,7 +71,7 @@ func (t *TaskManageSvc) EditTaskManage(req request.EditTaskManageReq) (id int, e
YamlDesc: req.YamlDesc, YamlDesc: req.YamlDesc,
YamlUrl: req.YamlUrl, YamlUrl: req.YamlUrl,
HostGroupId: req.HostGroupId, HostGroupId: req.HostGroupId,
UpdateUser: "", UpdateUser: t.User.SystemAccount,
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
//编辑任务 //编辑任务
...@@ -244,6 +244,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id ...@@ -244,6 +244,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id
err = resp.FileExecError.WithError(err) err = resp.FileExecError.WithError(err)
return return
} }
defer hostsGroup.Close() defer hostsGroup.Close()
//_, err = hostsGroup.Write([]byte(hostsIp)) //_, err = hostsGroup.Write([]byte(hostsIp))
_, err = hostsGroup.Write([]byte(strings.Join(hosts, "\n"))) _, err = hostsGroup.Write([]byte(strings.Join(hosts, "\n")))
...@@ -258,6 +259,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id ...@@ -258,6 +259,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id
err = resp.FileExecError.WithError(err) err = resp.FileExecError.WithError(err)
return return
} }
defer f2.Close() defer f2.Close()
_, err = f2.Write([]byte(script)) _, err = f2.Write([]byte(script))
if err != nil { if err != nil {
...@@ -268,7 +270,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id ...@@ -268,7 +270,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id
//新增任务历史 //新增任务历史
id, err = AddExecHistory(request.AddExecHistory{ id, err = AddExecHistory(request.AddExecHistory{
TaskId: req.TaskId, TaskId: req.TaskId,
CreateUser: "", CreateUser: t.User.SystemAccount,
}) })
if err != nil { if err != nil {
return return
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
) )
type WorkOrderManageSvc struct { type WorkOrderManageSvc struct {
User *entity.SystemUser User entity.SystemUserInfo
} }
// AddWorkOrderManage 新增业务工单 // AddWorkOrderManage 新增业务工单
...@@ -48,9 +48,9 @@ func (w *WorkOrderManageSvc) AddWorkOrderManage(req request.AddWorkOrderReq) (er ...@@ -48,9 +48,9 @@ func (w *WorkOrderManageSvc) AddWorkOrderManage(req request.AddWorkOrderReq) (er
OrderDesc: req.OrderDesc, OrderDesc: req.OrderDesc,
PushObj: fmt.Sprintf("%s", pushObj), PushObj: fmt.Sprintf("%s", pushObj),
TimingType: req.TimingType, TimingType: req.TimingType,
CreateUser: "", CreateUser: w.User.SystemAccount,
CreateTime: time.Now(), CreateTime: time.Now(),
UpdateUser: "", UpdateUser: w.User.SystemAccount,
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
...@@ -108,7 +108,7 @@ func (w *WorkOrderManageSvc) EditWorkOrderManage(req request.EditWorkOrderReq) ( ...@@ -108,7 +108,7 @@ func (w *WorkOrderManageSvc) EditWorkOrderManage(req request.EditWorkOrderReq) (
OrderDesc: req.OrderDesc, OrderDesc: req.OrderDesc,
PushObj: fmt.Sprintf("%s", pushObj), PushObj: fmt.Sprintf("%s", pushObj),
TimingType: req.TimingType, TimingType: req.TimingType,
UpdateUser: "", UpdateUser: w.User.SystemAccount,
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
if req.TimingType == 2 { if req.TimingType == 2 {
...@@ -312,7 +312,7 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) ( ...@@ -312,7 +312,7 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) (
OrderId: req.Id, OrderId: req.Id,
PushObj: fmt.Sprintf("%s", pushObj), PushObj: fmt.Sprintf("%s", pushObj),
OrderState: 1, OrderState: 1,
CreateUser: "admin", CreateUser: w.User.SystemAccount,
CreateTime: time.Now(), CreateTime: time.Now(),
} }
_, err = session.Table("work_order_issuance").Insert(&workOrderIssuance) _, err = session.Table("work_order_issuance").Insert(&workOrderIssuance)
...@@ -559,6 +559,8 @@ func (w *WorkOrderManageSvc) ListWorkOrderMe(req request.ListWorkOrderReq) (tota ...@@ -559,6 +559,8 @@ func (w *WorkOrderManageSvc) ListWorkOrderMe(req request.ListWorkOrderReq) (tota
Join("INNER", "work_order_issuance woi", "wome.order_issuance_id = woi.id"). Join("INNER", "work_order_issuance woi", "wome.order_issuance_id = woi.id").
Join("INNER", "work_order_manage wom", "woi.order_id = wom.id") Join("INNER", "work_order_manage wom", "woi.order_id = wom.id")
finder.Where("wome.system_account = ?", w.User.SystemAccount)
if req.Search != "" { if req.Search != "" {
finder.Where(fmt.Sprintf("wom.order_name LIKE '%s'", "%"+req.Search+"%")) finder.Where(fmt.Sprintf("wom.order_name LIKE '%s'", "%"+req.Search+"%"))
} }
......
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