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

绑定用户信息

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