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
f169407e
Commit
f169407e
authored
Jul 12, 2023
by
黄智
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
b73fef70
5a6f72db
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
258 additions
and
103 deletions
+258
-103
.beagle.yml
.beagle.yml
+9
-9
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
src/bean/entity/alert_list.go
src/bean/entity/alert_list.go
+1
-0
src/bean/vo/request/alert_list.go
src/bean/vo/request/alert_list.go
+9
-1
src/common/conf/options.go
src/common/conf/options.go
+7
-5
src/controller/alert_list.go
src/controller/alert_list.go
+21
-0
src/controller/host_manage.go
src/controller/host_manage.go
+3
-2
src/controller/task_manage.go
src/controller/task_manage.go
+4
-3
src/controller/work_order_manage.go
src/controller/work_order_manage.go
+17
-4
src/main.go
src/main.go
+35
-34
src/router/automatedmaintenrouter.go
src/router/automatedmaintenrouter.go
+4
-3
src/router/workorderrouter.go
src/router/workorderrouter.go
+8
-5
src/service/alert_list.go
src/service/alert_list.go
+27
-8
src/service/host_manage.go
src/service/host_manage.go
+41
-18
src/service/task_manage.go
src/service/task_manage.go
+7
-6
src/service/work_order.go
src/service/work_order.go
+62
-5
No files found.
.beagle.yml
View file @
f169407e
...
...
@@ -50,7 +50,7 @@ steps:
base
:
registry.cn-hangzhou.aliyuncs.com/xmod/alpine:3
dockerfile
:
.beagle/dockerfile
repo
:
smart-operation/so-operation-api
Version
:
"
v
1
.0.0"
Version
:
"
v
3
.0.0"
channel
:
amd64
args
:
"
TARGETOS=linux,TARGETARCH=amd64"
registry
:
hub.wodcloud.com
...
...
@@ -65,7 +65,7 @@ steps:
namespace
:
smart-manage
deployment
:
so-operation-api
container
:
so-operation-api
image
:
hub.wodcloud.com/smart-operation/so-operation-api:v
1
.0.0-amd64
image
:
hub.wodcloud.com/smart-operation/so-operation-api:v
3
.0.0-amd64
environment
:
KUBERNETES_SERVER
:
from_secret
:
KUBERNETES_SERVER
...
...
@@ -80,7 +80,7 @@ steps:
base
:
registry.cn-hangzhou.aliyuncs.com/xmod/alpine:3-arm64
dockerfile
:
.beagle/dockerfile
repo
:
smart-operation/so-operation-api
Version
:
"
v
1
.0.0"
Version
:
"
v
3
.0.0"
channel
:
arm64
args
:
"
TARGETOS=linux,TARGETARCH=arm64"
registry
:
hub.wodcloud.com
...
...
@@ -97,8 +97,8 @@ steps:
settings
:
insecure
:
true
platforms
:
linux/amd64,linux/arm64
template
:
hub.wodcloud.com/smart-operation/so-operation-api:v
1
.0.0-ARCH
target
:
hub.wodcloud.com/smart-operation/so-operation-api:v
1
.0.0
template
:
hub.wodcloud.com/smart-operation/so-operation-api:v
3
.0.0-ARCH
target
:
hub.wodcloud.com/smart-operation/so-operation-api:v
3
.0.0
username
:
from_secret
:
REGISTRY_USER
password
:
...
...
@@ -131,8 +131,8 @@ steps:
REGISTRY_PASSWORD
:
from_secret
:
REGISTRY_PASSWORD
settings
:
source
:
hub.wodcloud.com/smart-operation/so-operation-api:v
1
.0.0-amd64
target
:
hub.wodcloud.com/smart-operation/so-operation-api:v
1
.0-amd64
source
:
hub.wodcloud.com/smart-operation/so-operation-api:v
3
.0.0-amd64
target
:
hub.wodcloud.com/smart-operation/so-operation-api:v
3
.0-amd64
registry
:
hub.wodcloud.com
-
name
:
harbor-arm64
...
...
@@ -147,8 +147,8 @@ steps:
REGISTRY_PASSWORD
:
from_secret
:
REGISTRY_PASSWORD
settings
:
source
:
hub.wodcloud.com/smart-operation/so-operation-api:v
1
.0.0-arm64
target
:
hub.wodcloud.com/smart-operation/so-operation-api:v
1
.0-arm64
source
:
hub.wodcloud.com/smart-operation/so-operation-api:v
3
.0.0-arm64
target
:
hub.wodcloud.com/smart-operation/so-operation-api:v
3
.0-arm64
registry
:
hub.wodcloud.com
---
...
...
go.mod
View file @
f169407e
...
...
@@ -28,6 +28,7 @@ require (
github.com/tealeg/xlsx v1.0.5
github.com/thoas/go-funk v0.9.3
github.com/valyala/fasthttp v1.47.0
github.com/wanghuiyt/ding v0.0.2
go.uber.org/zap v1.24.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
k8s.io/apimachinery v0.27.3
...
...
go.sum
View file @
f169407e
...
...
@@ -465,6 +465,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK9c=
github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
github.com/wanghuiyt/ding v0.0.2 h1:6ZISlgCSy6MVeaFR8kAdniALMRqd56GyO9LlmYdTw/s=
github.com/wanghuiyt/ding v0.0.2/go.mod h1:T1vPz74YMmGCBVKZzVsen/YAYRZ2bvBYXldUyD7Y4vc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
...
...
src/bean/entity/alert_list.go
View file @
f169407e
...
...
@@ -24,6 +24,7 @@ type AlertList struct {
LastPushTime
jsontime
.
Time
`json:"last_push_time"`
// 最近推送时间
Status
int
`json:"status"`
// 状态,1:已恢复 2:未恢复 3:已关闭
DisposedList
[]
DisposedList
`json:"disposed_list"`
// 处置列表
IsDisposed
int
`json:"is_disposed"`
// 是否处置(工单管理),1:已处置,2:未处置 通过DisposedList逻辑处理回显
CloseRemark
string
`json:"close_remark"`
// 关闭备注(预警关闭提醒)
CloseUser
string
`json:"close_user"`
// 关闭用户,预警关闭提醒
CloseTime
jsontime
.
Time
`json:"close_time"`
// 关闭关闭时间,预警关闭提醒
...
...
src/bean/vo/request/alert_list.go
View file @
f169407e
package
request
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
import
(
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
)
type
DetailAlertList
struct
{
Id
int
`json:"id" form:"id" binding:"required"`
...
...
@@ -34,3 +36,9 @@ type ListAlertList struct {
StartTime
string
`json:"start_time" form:"start_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
EndTime
string
`json:"end_time" form:"end_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
}
type
DisposeAlertList
struct
{
Id
int
`json:"id" form:"id" binding:"required"`
Status
int
`json:"status" form:"status" binding:"oneof=1 2"`
// 状态,1:已恢复 2:未恢复 3:已关闭
DisposalContent
string
`json:"disposal_content" binding:"required"`
// 处置内容(工单管理,结果反馈)
}
src/common/conf/options.go
View file @
f169407e
...
...
@@ -36,11 +36,13 @@ type Config struct {
LocationUrl
string
LocationKey
string
PrivateKeySSH
string
PublicKeySSH
string
SmsAccessKeyId
string
SmsAccessSecret
string
SmsTemplateLogin
string
SmsSignName
string
//PublicKeySSH string
OrderDingTalkAccessToken
string
OrderDingTalkSecret
string
SmsAccessKeyId
string
SmsAccessSecret
string
SmsTemplateLogin
string
SmsSignName
string
}
const
(
...
...
src/controller/alert_list.go
View file @
f169407e
...
...
@@ -102,3 +102,24 @@ func ListAlertList(c *gin.Context) {
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
func
DisposeAlertList
(
c
*
gin
.
Context
)
{
var
req
request
.
DisposeAlertList
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertListSvc
{
User
:
header
.
GetUser
(
c
)}
err
=
svc
.
DisposeAlertList
(
db
.
NewSession
(),
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
src/controller/host_manage.go
View file @
f169407e
...
...
@@ -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
)
...
...
src/controller/task_manage.go
View file @
f169407e
...
...
@@ -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
)
...
...
src/controller/work_order_manage.go
View file @
f169407e
...
...
@@ -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
)
...
...
@@ -242,3 +243,15 @@ func ListWorkOrderMe(c *gin.Context) {
}
SendJsonPageResponse
(
c
,
resp
.
OK
,
list
,
total
)
}
// WorkOrderPushNoteMsg 我的业务工单列表
func
WorkOrderPushNoteMsg
(
c
*
gin
.
Context
)
{
phone
:=
c
.
Query
(
"phone"
)
err
:=
service
.
WorkOrderPushNoteMsg
(
phone
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
err
,
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
src/main.go
View file @
f169407e
...
...
@@ -56,33 +56,34 @@ func initConfig() {
conf
.
LoggerLevel
=
util
.
SetEnvStr
(
"LOG_LEVEL"
,
"info"
)
conf
.
RunMode
=
util
.
SetEnvStr
(
"GIN_MODE"
,
"debug"
)
// project run mode, available parameters: debug、release
conf
.
Options
=
&
conf
.
Config
{
Prefix
:
*
prefix
,
DbURL
:
util
.
SetEnvStr
(
"DB_URL"
,
"host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"
),
DbDriver
:
util
.
SetEnvStr
(
"DB_DRIVER"
,
"postgres"
),
RedisURL
:
util
.
SetEnvStr
(
"REDIS_URL"
,
"localhost:7001"
),
RedisDB
:
0
,
RedisTag
:
"bg"
,
LogDirPrefix
:
util
.
SetEnvStr
(
"LOG_DIR_PREFIX"
,
"/app/log"
),
// 日志目录
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"https://cache.wodcloud.com"
),
// Minio 服务地址
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
//TempDirPrefix: util.SetEnvStr("TEMP_DIR_PREFIX", "/app/xlsx/"), //模板目录前缀
Prefix
:
*
prefix
,
DbURL
:
util
.
SetEnvStr
(
"DB_URL"
,
"host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"
),
DbDriver
:
util
.
SetEnvStr
(
"DB_DRIVER"
,
"postgres"
),
RedisURL
:
util
.
SetEnvStr
(
"REDIS_URL"
,
"localhost:7001"
),
RedisDB
:
0
,
RedisTag
:
"bg"
,
LogDirPrefix
:
util
.
SetEnvStr
(
"LOG_DIR_PREFIX"
,
"/app/log"
),
// 日志目录
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"https://cache.wodcloud.com"
),
// Minio 服务地址
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
PrometheusHost
:
util
.
SetEnvStr
(
"PROMETHEUS_HOST"
,
"https://prometheus.wodcloud.com"
),
// Prometheus Host
AccessRuleModeKey
:
"accessRuleMode"
,
LocationUrl
:
util
.
SetEnvStr
(
"LOCATION_URL"
,
"https://apis.map.qq.com/ws/location/v1/ip"
),
LocationKey
:
util
.
SetEnvStr
(
"LOCATION_KEY"
,
"QKFBZ-PGGWJ-VZQFF-FHPA7-QWT5H-YHF4T"
),
PrivateKeySSH
:
util
.
SetEnvStr
(
"PRIVATE_KEY_SSH"
,
"-----BEGIN OPENSSH PRIVATE KEY-----
\n
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAlwAAAAdzc2gtcn
\n
NhAAAAAwEAAQAAAIEAsOFk9OUB8wg9fd+PDHyX8nEtTSPSZY+tjxq2da1Pf5FkIn+U1da6
\n
h2eqowF9lnyvlt7uEledTIWQZDGWToGYCZnRommSZEpo/vII+l1P28bJVHfgWFCqmxNfIB
\n
ZFQ4KrOp9rXKidmrd8flhK/NTLJNqryrhhIiDs3CTyAliscIsAAAIQTuM2gU7jNoEAAAAH
\n
c3NoLXJzYQAAAIEAsOFk9OUB8wg9fd+PDHyX8nEtTSPSZY+tjxq2da1Pf5FkIn+U1da6h2
\n
eqowF9lnyvlt7uEledTIWQZDGWToGYCZnRommSZEpo/vII+l1P28bJVHfgWFCqmxNfIBZF
\n
Q4KrOp9rXKidmrd8flhK/NTLJNqryrhhIiDs3CTyAliscIsAAAADAQABAAAAgDjcfGPtqq
\n
7CG2J3l7jf5MjfcTy3I0/a3GSApd82k7PivVoJwYLswJH+1XAJbqIN+zR4/fePitWqqjxL
\n
ZJJgPstuXpBZuJDvGwMqfl7wHRL2Qx34sRG02hG5e3uIfMxe5lHcPba0qsVQt+vOhu9MUb
\n
sYF/mfuQJKt/Oi8nA1BbrBAAAAQFQPrap7AtYWEoCIY7gtpFMW51iDTAv5GN99DsKNuBby
\n
wQX2S0Wg/da75m/emJn/2IbmaKApvrx8LbenpyywfBkAAABBAN6xiYQ2j7eRjLV4h4Hbie
\n
VwlPYP4otKHdF5meObr+2ifYiMktdv/44V1XWKhgavjGFNWx2sHgj7byb51e/bi3MAAABB
\n
AMtVxa55G0wS9Yw1WK2F4JdYZ65ZAnUuo2rbA2dMDQxsOQxgel5Ox2XmC7e0GKrO9BJKPo
\n
R2fHEOdm9KOmoB8IkAAAAWY2hlbnppbG9uZ0BleGFtcGxlLmNvbQECAwQF
\n
-----END OPENSSH PRIVATE KEY-----
\n
"
),
PublicKeySSH
:
util
.
SetEnvStr
(
"PUBLIC_KEY_SSH"
,
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCw4WT05QHzCD19348MfJfycS1NI9Jlj62PGrZ1rU9/kWQif5TV1rqHZ6qjAX2WfK+W3u4SV51MhZBkMZZOgZgJmdGiaZJkSmj+8gj6XU/bxslUd+BYUKqbE18gFkVDgqs6n2tcqJ2at3x+WEr81Msk2qvKuGEiIOzcJPICWKxwiw== chenzilong@example.com
\n
"
),
SmsAccessKeyId
:
util
.
SetEnvStr
(
"SMS_ACCESS_KEY"
,
"LTAI4GBcVubRjzX7ABPcHnhB"
),
// 短信key
SmsAccessSecret
:
util
.
SetEnvStr
(
"SMS_ACCESS_SECRET"
,
"dYE2dtABFOqYtK1ijcrits0yedHkw7"
),
// 短信secret
SmsTemplateLogin
:
util
.
SetEnvStr
(
"SMS_TEMPLATE_LOGIN"
,
"SMS_212925130"
),
// 短信验证码模板
SmsSignName
:
util
.
SetEnvStr
(
"SMS_SIGN_NAME"
,
"比格数据"
),
// 签名
PrivateKeySSH
:
util
.
SetEnvStr
(
"PRIVATE_KEY_SSH"
,
""
),
//PublicKeySSH: util.SetEnvStr("PUBLIC_KEY_SSH", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCw4WT05QHzCD19348MfJfycS1NI9Jlj62PGrZ1rU9/kWQif5TV1rqHZ6qjAX2WfK+W3u4SV51MhZBkMZZOgZgJmdGiaZJkSmj+8gj6XU/bxslUd+BYUKqbE18gFkVDgqs6n2tcqJ2at3x+WEr81Msk2qvKuGEiIOzcJPICWKxwiw== chenzilong@example.com\n"),
OrderDingTalkAccessToken
:
util
.
SetEnvStr
(
"ORDER_DING_TALK_ACCESS_TOKEN"
,
"203fe1644b446bba0a34e6e622c523d39ee9916fdad94b9c64224449f659e20b"
),
OrderDingTalkSecret
:
util
.
SetEnvStr
(
"ORDER_DING_TALK_SECRET"
,
"SECa73d8372e336451c9daf29a99f750ee1bdd170c1dab910eab9cd06d729a831b7"
),
SmsAccessKeyId
:
util
.
SetEnvStr
(
"SMS_ACCESS_KEY"
,
"LTAI4GBcVubRjzX7ABPcHnhB"
),
// 短信key
SmsAccessSecret
:
util
.
SetEnvStr
(
"SMS_ACCESS_SECRET"
,
"dYE2dtABFOqYtK1ijcrits0yedHkw7"
),
// 短信secret
SmsTemplateLogin
:
util
.
SetEnvStr
(
"SMS_TEMPLATE_LOGIN"
,
"SMS_212925130"
),
// 短信验证码模板
SmsSignName
:
util
.
SetEnvStr
(
"SMS_SIGN_NAME"
,
"比格数据"
),
// 签名
}
}
...
...
@@ -160,19 +161,19 @@ func initAnsibleSSH() {
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
else
{
_
,
err
:=
f
.
Write
([]
byte
(
conf
.
Options
.
PrivateKeySSH
))
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
}
f2
,
err
:=
os
.
Create
(
"/root/.ssh/id_rsa.pub"
)
defer
f2
.
Close
()
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
else
{
_
,
err
:=
f
.
Write
([]
byte
(
conf
.
Options
.
PublicKeySSH
))
_
,
err
=
f
.
Write
([]
byte
(
conf
.
Options
.
PrivateKeySSH
))
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
}
//f2, err := os.Create("/root/.ssh/id_rsa.pub")
//defer f2.Close()
//if err != nil {
// fmt.Println(err.Error())
//} else {
// _, err := f.Write([]byte(conf.Options.PublicKeySSH))
// if err != nil {
// fmt.Println(err.Error())
// }
//}
}
src/router/automatedmaintenrouter.go
View file @
f169407e
...
...
@@ -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
)
// 编辑
...
...
src/router/workorderrouter.go
View file @
f169407e
...
...
@@ -5,6 +5,7 @@ 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 初始化工单路由
...
...
@@ -13,12 +14,13 @@ func InitWorkOrderRouter(e *gin.Engine) {
//预警工单管理
alert
:=
so
.
Group
(
"/alert"
)
{
alert
.
GET
(
""
,
controller
.
DetailAlertList
)
// 详情
alert
.
GET
(
"/list"
,
controller
.
ListAlertList
)
// 列表
alert
.
GET
(
""
,
controller
.
DetailAlertList
)
// 详情
alert
.
GET
(
"/list"
,
controller
.
ListAlertList
)
// 列表
alert
.
PUT
(
"/dispose"
,
controller
.
DisposeAlertList
)
// 处置反馈
}
//业务工单管理
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 +32,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,9 +40,10 @@ 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
)
// 我的业务工单列表
}
//so.POST("/note_sg", controller.WorkOrderPushNoteMsg)
}
src/service/alert_list.go
View file @
f169407e
...
...
@@ -75,6 +75,7 @@ func (a *AlertListSvc) GetDataById(req request.DetailAlertList) (resp response.A
DisposalTime
:
now
,
},
},
IsDisposed
:
2
,
CloseRemark
:
""
,
CloseUser
:
""
,
DeferPush
:
0
,
...
...
@@ -165,6 +166,7 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL
DisposalTime
:
now
,
},
},
IsDisposed
:
2
,
CloseRemark
:
""
,
CloseUser
:
""
,
DeferPush
:
0
,
...
...
@@ -235,14 +237,23 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL
PushCount
:
1
,
LastPushTime
:
now
,
Status
:
3
,
CloseRemark
:
"关闭备注"
,
CloseUser
:
"xiaowang"
,
CloseTime
:
now
,
DeferPush
:
1
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
DisposedList
:
[]
entity
.
DisposedList
{
{
IsDisposed
:
1
,
DisposalContent
:
"已做处置"
,
DisposalUser
:
"xiaowang"
,
DisposalTime
:
now
,
},
},
IsDisposed
:
1
,
CloseRemark
:
"关闭备注"
,
CloseUser
:
"xiaowang"
,
CloseTime
:
now
,
DeferPush
:
1
,
CreatedBy
:
"admin"
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
},
AlertCondition
:
entity
.
AlertCondition
{
ThresholdsMax
:
80
,
...
...
@@ -290,3 +301,11 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL
resp
.
TotalCount
=
int64
(
len
(
resp
.
List
))
return
}
func
(
a
*
AlertListSvc
)
DisposeAlertList
(
session
*
xorm
.
Session
,
req
request
.
DisposeAlertList
)
error
{
now
:=
jsontime
.
Now
()
_
=
now
// TODO 我的预警工单处置
conf
.
Logger
.
Info
(
"dispose alert"
,
zap
.
Any
(
"payload"
,
req
))
return
nil
}
src/service/host_manage.go
View file @
f169407e
...
...
@@ -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
)
.
...
...
@@ -326,7 +326,8 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
return
}
//查询任务列表
err
=
db
.
Table
(
"task_manage"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
id
)
.
Find
(
&
taskList
)
err
=
db
.
Table
(
"task_manage"
)
.
Alias
(
"tm"
)
.
Where
(
"tm.is_delete = 0 AND tm.host_group_id = ?"
,
id
)
.
Select
(
"tm.id,tm.task_name,tm.task_desc,(select count(1) from task_history th where th.task_id = tm.id) as exec_cnt"
)
.
Find
(
&
taskList
)
if
err
!=
nil
{
err
=
resp
.
DbSelectError
.
WithError
(
err
)
return
...
...
@@ -454,10 +455,17 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
for
_
,
v
:=
range
hostManageList
{
//修改状态
connStatus
,
err1
:=
StatusDetection
(
v
.
Ip
)
if
err1
!=
nil
{
session
.
Rollback
()
return
err1
}
hostManageListConn
:=
entity
.
HostManageList
{
ConnStatus
:
connStatus
,
}
_
,
err
=
session
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND id = ?"
,
v
.
Id
)
.
Cols
(
"conn_status"
)
.
Update
(
&
entity
.
HostManageList
{
ConnStatus
:
StatusDetection
(
v
.
Ip
),
})
Cols
(
"conn_status"
)
.
Update
(
&
hostManageListConn
)
if
err
!=
nil
{
err
=
resp
.
DbUpdateError
.
WithError
(
err
)
session
.
Rollback
()
...
...
@@ -541,7 +549,10 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
id
=
uuid
.
New
()
.
String
()
for
k
,
v
:=
range
hostManageListCaches
{
//调用状态检测函数
hostManageListCaches
[
k
]
.
ConnStatus
=
StatusDetection
(
v
.
Ip
)
hostManageListCaches
[
k
]
.
ConnStatus
,
err
=
StatusDetection
(
v
.
Ip
)
if
err
!=
nil
{
return
}
hostManageListCaches
[
k
]
.
Id
=
id
}
...
...
@@ -610,16 +621,25 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq)
}
// StatusDetection 状态检测
func
StatusDetection
(
ip
string
)
(
ipConn
int
)
{
func
StatusDetection
(
ip
string
)
(
ipConn
int
,
err
error
)
{
var
cmd
*
exec
.
Cmd
cmd
=
exec
.
Command
(
"ansible"
,
fmt
.
Sprintf
(
"%s"
,
AnsibleIp
+
ip
),
"-m"
,
"ping"
)
output
,
err
:=
cmd
.
Output
()
if
err
!=
nil
{
fmt
.
Println
(
"ping:"
,
string
(
output
))
return
1
//执行cmd命令
if
err
=
cmd
.
Start
();
err
!=
nil
{
err
=
resp
.
CmdExecError
.
WithError
(
err
)
return
}
if
cmd
.
ProcessState
.
Success
()
{
return
0
,
nil
}
fmt
.
Println
(
"ping:"
,
string
(
output
))
return
0
return
1
,
nil
//output, err := cmd.Output()
//if err != nil {
// fmt.Println("ping:", string(output))
// return 1
//}
//fmt.Println("ping:", string(output))
//return 0
}
// ExportIpStr 结果导出
...
...
@@ -776,14 +796,17 @@ func CronStatusDetection() {
// }
//}
for
_
,
v
:=
range
hostManageList
{
connStatus
,
err1
:=
StatusDetection
(
v
.
Ip
)
if
err1
!=
nil
{
fmt
.
Println
(
"CronStatusDetection err:"
,
err1
.
Error
())
}
//修改状态
_
,
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND id = ?"
,
v
.
Id
)
.
Cols
(
"conn_status"
)
.
Update
(
&
entity
.
HostManageList
{
ConnStatus
:
StatusDetection
(
v
.
Ip
)
,
ConnStatus
:
connStatus
,
})
if
err
!=
nil
{
fmt
.
Println
(
"CronStatusDetection err:"
,
err
.
Error
())
return
}
}
fmt
.
Println
(
"CronPersonalCardDate success!"
)
...
...
src/service/task_manage.go
View file @
f169407e
...
...
@@ -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
(),
}
//编辑任务
...
...
@@ -237,13 +237,13 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id
}
//写入主机信息
//hostsIp := strings.Replace(strings.Trim(fmt.Sprint(hosts), "[]"), " ", " ", -1)
hostsGroup
,
err
:=
os
.
Create
(
"/etc/ansible/hosts_"
+
fmt
.
Sprintf
(
"%d"
,
req
.
TaskId
))
if
err
!=
nil
{
err
=
resp
.
FileExecError
.
WithError
(
err
)
return
}
defer
hostsGroup
.
Close
()
//_, err = hostsGroup.Write([]byte(hostsIp))
_
,
err
=
hostsGroup
.
Write
([]
byte
(
strings
.
Join
(
hosts
,
"
\n
"
)))
...
...
@@ -258,6 +258,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 +269,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
...
...
src/service/work_order.go
View file @
f169407e
...
...
@@ -3,17 +3,22 @@ package service
import
(
"errors"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
json
"github.com/json-iterator/go"
"github.com/wanghuiyt/ding"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"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/util"
"go.uber.org/zap"
"time"
)
type
WorkOrderManageSvc
struct
{
User
*
entity
.
SystemUser
User
entity
.
SystemUserInfo
}
// AddWorkOrderManage 新增业务工单
...
...
@@ -48,9 +53,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 +113,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 +317,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 +564,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
+
"%"
))
}
...
...
@@ -604,3 +611,53 @@ func (w *WorkOrderManageSvc) ListWorkOrderMe(req request.ListWorkOrderReq) (tota
}
return
}
// WorkOrderPushDingTalkMsg 推送钉钉消息
func
WorkOrderPushDingTalkMsg
(
orderName
,
phone
string
,
orderLevel
int
)
(
err
error
)
{
d
:=
ding
.
Webhook
{
AccessToken
:
conf
.
Options
.
OrderDingTalkAccessToken
,
//"203fe1644b446bba0a34e6e622c523d39ee9916fdad94b9c64224449f659e20b",
Secret
:
conf
.
Options
.
OrderDingTalkSecret
,
//"SECa73d8372e336451c9daf29a99f750ee1bdd170c1dab910eab9cd06d729a831b7",
}
var
orderLevels
string
switch
orderLevel
{
case
1
:
orderLevels
=
"紧急任务"
case
2
:
orderLevels
=
"重要任务"
case
3
:
orderLevels
=
"一般任务"
}
//有一条工单需要您处理:工单类型:【业务工单】 工单名称:【$工单名称】 工单等级:【$工单等级】
err
=
d
.
SendMessageText
(
"有一条工单需要您处理:
\n
工单类型:【业务工单】
\n
工单名称:【"
+
orderName
+
"】
\n
工单等级:【"
+
orderLevels
+
"】"
,
phone
)
return
}
// WorkOrderPushNoteMsg 推送短信消息
func
WorkOrderPushNoteMsg
(
phone
string
)
(
err
error
)
{
smsClient
,
err
:=
dysmsapi
.
NewClientWithAccessKey
(
"cn-hangzhou"
,
conf
.
Options
.
SmsAccessKeyId
,
conf
.
Options
.
SmsAccessSecret
)
if
err
!=
nil
{
conf
.
Logger
.
Error
(
"dysmsapi client error"
,
zap
.
Error
(
err
))
return
resp
.
FAIL
.
ErrorDetail
(
err
)
}
code
:=
util
.
Rand6
()
params
:=
map
[
string
]
interface
{}{
"code"
:
code
}
templateParam
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
conf
.
Logger
.
Error
(
"序列化模板失败!"
,
zap
.
Error
(
err
))
return
resp
.
FAIL
.
ErrorDetail
(
err
)
}
request
:=
dysmsapi
.
CreateSendSmsRequest
()
request
.
Scheme
=
"https"
request
.
PhoneNumbers
=
phone
request
.
TemplateCode
=
conf
.
Options
.
SmsTemplateLogin
request
.
SignName
=
conf
.
Options
.
SmsSignName
request
.
TemplateParam
=
string
(
templateParam
)
req
,
err
:=
smsClient
.
SendSms
(
request
)
if
err
!=
nil
{
return
resp
.
FAIL
.
ErrorDetail
(
err
)
}
fmt
.
Printf
(
"response is %#v
\n
"
,
req
)
return
nil
}
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