Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
37ae654f
"src/pages/technical-support/doc-manage/index.vue" did not exist on "8a26a769a75c18374a68bb9264359da600b8a00d"
Commit
37ae654f
authored
Jul 03, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-czl' into dev
parents
9cc03d88
13632684
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
104 additions
and
14 deletions
+104
-14
src/bean/vo/request/doc_lib.go
src/bean/vo/request/doc_lib.go
+6
-0
src/bean/vo/response/host_manage.go
src/bean/vo/response/host_manage.go
+2
-1
src/bean/vo/response/task_manage.go
src/bean/vo/response/task_manage.go
+1
-0
src/controller/doc_lib.go
src/controller/doc_lib.go
+33
-0
src/controller/host_manage.go
src/controller/host_manage.go
+4
-4
src/router/router.go
src/router/router.go
+4
-1
src/service/doc_lib.go
src/service/doc_lib.go
+33
-0
src/service/host_manage.go
src/service/host_manage.go
+8
-4
src/service/task_manage.go
src/service/task_manage.go
+13
-4
No files found.
src/bean/vo/request/doc_lib.go
View file @
37ae654f
package
request
package
request
type
DocLibGetReq
struct
{
FileName
string
`uri:"file_name" binding:"required"`
//文档名称
Ext
string
`uri:"ext" binding:"required"`
//后缀格式
Opt
string
`uri:"opt" binding:"required,oneof=preview download"`
//操作
}
src/bean/vo/response/host_manage.go
View file @
37ae654f
...
@@ -26,13 +26,14 @@ type HostManage struct {
...
@@ -26,13 +26,14 @@ type HostManage struct {
}
}
type
HostList
struct
{
type
HostList
struct
{
Id
int
`json:"id"`
// id
//
Id int `json:"id"` // id
Ip
string
`json:"ip"`
// ip
Ip
string
`json:"ip"`
// ip
Port
string
`json:"port"`
// 端口
Port
string
`json:"port"`
// 端口
VoucherType
int
`json:"voucher_type"`
// 凭证类型(0密码验证 密钥验证)
VoucherType
int
`json:"voucher_type"`
// 凭证类型(0密码验证 密钥验证)
UserName
string
`json:"user_name"`
// 用户名
UserName
string
`json:"user_name"`
// 用户名
Password
string
`json:"password"`
// 密码
Password
string
`json:"password"`
// 密码
HostFileUrl
string
`json:"-"`
// 主机文件url
HostFileUrl
string
`json:"-"`
// 主机文件url
Cnt
int
`json:"cnt""`
//主机ip数量
}
}
type
TaskList
struct
{
type
TaskList
struct
{
...
...
src/bean/vo/response/task_manage.go
View file @
37ae654f
...
@@ -13,6 +13,7 @@ type TaskManageListRes struct {
...
@@ -13,6 +13,7 @@ type TaskManageListRes struct {
type
TaskManageRes
struct
{
type
TaskManageRes
struct
{
Id
int
`json:"id"`
// id
Id
int
`json:"id"`
// id
HostGroupId
int
`json:"host_group_id"`
// 主机分组id
TaskName
string
`json:"task_name"`
// 任务名称
TaskName
string
`json:"task_name"`
// 任务名称
TaskDesc
string
`json:"task_desc"`
// 任务描述
TaskDesc
string
`json:"task_desc"`
// 任务描述
YamlDesc
string
`json:"yaml_desc"`
// yaml文件
YamlDesc
string
`json:"yaml_desc"`
// yaml文件
...
...
src/controller/doc_lib.go
View file @
37ae654f
...
@@ -2,8 +2,12 @@ package controller
...
@@ -2,8 +2,12 @@ package controller
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"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/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
"net/http"
"net/http/httputil"
"net/url"
)
)
func
AddFile
(
c
*
gin
.
Context
)
{
func
AddFile
(
c
*
gin
.
Context
)
{
...
@@ -16,3 +20,32 @@ func AddFile(c *gin.Context) {
...
@@ -16,3 +20,32 @@ func AddFile(c *gin.Context) {
}
}
SendJsonResponse
(
c
,
resp
.
OK
,
doc
)
SendJsonResponse
(
c
,
resp
.
OK
,
doc
)
}
}
func
DownloadFile
(
c
*
gin
.
Context
)
{
var
req
request
.
DocLibGetReq
if
err
:=
c
.
ShouldBindUri
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
return
}
docLibSvc
:=
service
.
DocLibSvc
{}
docUrl
,
err
:=
docLibSvc
.
DownloadFile
(
c
,
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
switch
req
.
Opt
{
case
"download"
:
//c.Redirect(http.StatusMovedPermanently, docUrl.String())
docUrlParse
,
_
:=
url
.
Parse
(
docUrl
.
String
())
proxy
:=
httputil
.
ReverseProxy
{
Director
:
func
(
req
*
http
.
Request
)
{
req
.
Header
=
c
.
Request
.
Header
req
.
Host
=
docUrlParse
.
Host
req
.
URL
=
docUrlParse
},
}
proxy
.
ServeHTTP
(
c
.
Writer
,
c
.
Request
)
case
"preview"
:
c
.
Redirect
(
http
.
StatusMovedPermanently
,
docUrl
.
String
())
}
}
src/controller/host_manage.go
View file @
37ae654f
...
@@ -80,8 +80,8 @@ func GetMinioFiles(fileName string) (hostManageList []request.HostManageList, er
...
@@ -80,8 +80,8 @@ func GetMinioFiles(fileName string) (hostManageList []request.HostManageList, er
}
}
for
i
:=
0
;
i
<
len
(
rows
);
i
++
{
for
i
:=
0
;
i
<
len
(
rows
);
i
++
{
//默认跳过
第一
行
//默认跳过
前两
行
if
i
<
1
{
if
i
<
2
{
continue
continue
}
}
...
@@ -371,11 +371,11 @@ func ExportIp(c *gin.Context) {
...
@@ -371,11 +371,11 @@ func ExportIp(c *gin.Context) {
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"导出类型解析错误"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"导出类型解析错误"
)),
nil
)
return
return
}
}
if
id
==
""
{
if
cast
.
ToInt
(
detectionType
)
==
1
&&
id
==
""
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"id为空"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"id为空"
)),
nil
)
return
return
}
}
if
uuid
==
""
{
if
cast
.
ToInt
(
detectionType
)
==
0
&&
uuid
==
""
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"uuid为空"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"uuid为空"
)),
nil
)
return
return
}
}
...
...
src/router/router.go
View file @
37ae654f
...
@@ -29,6 +29,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -29,6 +29,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
}
}
base
.
POST
(
"/add_file"
,
controller
.
AddFile
)
//文件上传
base
.
POST
(
"/add_file"
,
controller
.
AddFile
)
//文件上传
base
.
GET
(
"/download_file/:file_name/:ext/:opt"
,
controller
.
DownloadFile
)
//文件下载
// 初始化自动化运维路由
// 初始化自动化运维路由
InitAutomatedMaintenRouter
(
r
)
InitAutomatedMaintenRouter
(
r
)
...
@@ -46,4 +47,6 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -46,4 +47,6 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitMetricConfigRouter
(
r
)
InitMetricConfigRouter
(
r
)
// 初始化prometheus路由
// 初始化prometheus路由
InitPrometheusRouter
(
r
)
InitPrometheusRouter
(
r
)
// 初始化工单管理路由
//InitAutomatedMaintenRouter(r)
}
}
src/service/doc_lib.go
View file @
37ae654f
...
@@ -7,12 +7,15 @@ import (
...
@@ -7,12 +7,15 @@ import (
"github.com/google/uuid"
"github.com/google/uuid"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7"
"github.com/pkg/errors"
"github.com/pkg/errors"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"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"
"io"
"io"
"mime/multipart"
"mime/multipart"
"net/http"
"net/http"
"net/url"
"path"
"path"
"time"
)
)
var
maxFileByte
int64
=
20971520
//20M
var
maxFileByte
int64
=
20971520
//20M
...
@@ -111,3 +114,33 @@ func (d DocLibSvc) GetFile(fileName string) (obj io.Reader, err error) {
...
@@ -111,3 +114,33 @@ func (d DocLibSvc) GetFile(fileName string) (obj io.Reader, err error) {
// return
// return
//}
//}
}
}
func
(
d
DocLibSvc
)
DownloadFile
(
ctx
*
gin
.
Context
,
req
request
.
DocLibGetReq
)
(
docUrl
*
url
.
URL
,
err
error
)
{
var
(
minioClient
*
minio
.
Client
)
minioClient
,
err
=
client
.
GetMinioConnect
()
if
err
!=
nil
{
err
=
errors
.
Wrap
(
err
,
"getMinio"
)
return
}
remotePath
:=
fmt
.
Sprintf
(
"%s%s"
,
req
.
FileName
,
req
.
Ext
)
reqParams
:=
make
(
url
.
Values
)
switch
req
.
Opt
{
case
"info"
:
return
case
"preview"
:
reqParams
.
Set
(
"response-Content-Type"
,
req
.
Ext
)
case
"download"
:
reqParams
.
Set
(
"response-Content-Disposition"
,
fmt
.
Sprintf
(
"attachment; filename=%s%s"
,
req
.
FileName
,
req
.
Ext
))
reqParams
.
Set
(
"response-Content-Type"
,
"application/octet-stream"
)
reqParams
.
Set
(
"response-Content-Transfer-Encoding"
,
"binary"
)
}
docUrl
,
err
=
minioClient
.
PresignedGetObject
(
ctx
,
conf
.
Options
.
MinioBucket
,
remotePath
,
time
.
Second
*
60
*
60
,
reqParams
)
if
err
!=
nil
{
err
=
errors
.
Wrap
(
err
,
"get file url from minio fail"
)
return
}
return
}
src/service/host_manage.go
View file @
37ae654f
...
@@ -305,7 +305,9 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
...
@@ -305,7 +305,9 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
return
return
}
}
//查询主机列表
//查询主机列表
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
id
)
.
Find
(
&
hostList
)
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
id
)
.
Select
(
"string_agg(ip,',') as ip,port,voucher_type,user_name,password,host_file_url,count(1) as cnt"
)
.
GroupBy
(
"ip_group,port,voucher_type,user_name,PASSWORD,host_file_url"
)
.
Find
(
&
hostList
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbSelectError
.
WithError
(
err
)
err
=
resp
.
DbSelectError
.
WithError
(
err
)
return
return
...
@@ -321,18 +323,20 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
...
@@ -321,18 +323,20 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
if
v
.
HostFileUrl
!=
""
{
if
v
.
HostFileUrl
!=
""
{
hostManageRes
.
HostFileUrl
=
v
.
HostFileUrl
hostManageRes
.
HostFileUrl
=
v
.
HostFileUrl
}
}
hostManageRes
.
IpCnt
=
hostManageRes
.
IpCnt
+
v
.
Cnt
}
}
hostManageRes
.
Id
=
hostManage
.
Id
hostManageRes
.
Id
=
hostManage
.
Id
hostManageRes
.
HostName
=
hostManage
.
HostName
hostManageRes
.
HostName
=
hostManage
.
HostName
hostManageRes
.
TaskCnt
=
len
(
taskList
)
hostManageRes
.
TaskCnt
=
len
(
taskList
)
hostManageRes
.
IpCnt
=
len
(
hostList
)
//
hostManageRes.IpCnt = len(hostList)
hostManageRes
.
CreateUser
=
hostManage
.
CreateUser
hostManageRes
.
CreateUser
=
hostManage
.
CreateUser
hostManageRes
.
CreateTime
=
hostManage
.
CreateTime
hostManageRes
.
CreateTime
=
hostManage
.
CreateTime
hostManageRes
.
UpdateUser
=
hostManage
.
UpdateUser
hostManageRes
.
UpdateUser
=
hostManage
.
UpdateUser
hostManageRes
.
UpdateTime
=
hostManage
.
UpdateTime
hostManageRes
.
UpdateTime
=
hostManage
.
UpdateTime
if
hostManageRes
.
HostFileUrl
==
""
{
hostManageRes
.
HostList
=
hostList
hostManageRes
.
HostList
=
hostList
}
hostManageRes
.
TaskList
=
taskList
hostManageRes
.
TaskList
=
taskList
return
return
...
...
src/service/task_manage.go
View file @
37ae654f
...
@@ -117,7 +117,7 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
...
@@ -117,7 +117,7 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
//查询任务详情
//查询任务详情
finder
:=
db
.
Table
(
"task_manage"
)
.
Alias
(
"tm"
)
.
finder
:=
db
.
Table
(
"task_manage"
)
.
Alias
(
"tm"
)
.
Where
(
"is_delete = 0 AND id = ?"
,
id
)
Where
(
"is_delete = 0 AND id = ?"
,
id
)
_
,
err
=
finder
.
Select
(
"tm.id,tm.task_name,tm.task_desc,tm.yaml_desc,tm.yaml_url,tm.create_user,tm.create_time,"
+
_
,
err
=
finder
.
Select
(
"tm.id,tm.task_name,tm.task_desc,tm.yaml_desc,tm.yaml_url,tm.create_user,tm.create_time,
tm.host_group_id,
"
+
"(select count(1) from task_history th where th.task_id = tm.id) as exec_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id) as exec_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 1) as success_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 1) as success_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 2) as fail_cnt"
)
.
Get
(
&
taskManageRes
)
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 2) as fail_cnt"
)
.
Get
(
&
taskManageRes
)
...
@@ -128,18 +128,27 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
...
@@ -128,18 +128,27 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
//查询主机列表
//查询主机列表
hostList
:=
make
([]
response
.
HostList
,
0
)
hostList
:=
make
([]
response
.
HostList
,
0
)
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
id
)
.
Find
(
&
hostList
)
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
taskManageRes
.
HostGroupId
)
.
Select
(
"string_agg(ip,',') as ip,port,voucher_type,user_name,password,host_file_url"
)
.
GroupBy
(
"ip_group,port,voucher_type,user_name,PASSWORD,host_file_url"
)
.
Find
(
&
hostList
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbSelectError
.
WithError
(
err
)
err
=
resp
.
DbSelectError
.
WithError
(
err
)
return
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
{
for
_
,
v
:=
range
hostList
{
if
v
.
HostFileUrl
!=
""
{
if
v
.
HostFileUrl
!=
""
{
taskManageRes
.
HostFileUrl
=
v
.
HostFileUrl
taskManageRes
.
HostFileUrl
=
v
.
HostFileUrl
}
}
}
}
if
taskManageRes
.
HostFileUrl
==
""
{
taskManageRes
.
HostList
=
hostList
taskManageRes
.
HostList
=
hostList
}
return
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment