Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CnChunfeng
/
crm_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
aaed198b
authored
Jun 04, 2020
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加钉钉告警转发
parent
11c8777c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
11 deletions
cmd/queue/bom_order/main.go
internal/service/dingding.go
cmd/queue/bom_order/main.go
View file @
aaed198b
...
@@ -3,7 +3,7 @@ package main
...
@@ -3,7 +3,7 @@ package main
import
(
import
(
"crm-server/configs"
"crm-server/configs"
"crm-server/internal/dao"
"crm-server/internal/dao"
_
"crm-server/internal/service"
"crm-server/internal/service"
"encoding/json"
"encoding/json"
"flag"
"flag"
"fmt"
"fmt"
...
@@ -58,14 +58,14 @@ func main() {
...
@@ -58,14 +58,14 @@ func main() {
conn
,
err
:=
amqp
.
Dial
(
"amqp://"
+
configs
.
RABBITMQBOM
+
"/"
)
conn
,
err
:=
amqp
.
Dial
(
"amqp://"
+
configs
.
RABBITMQBOM
+
"/"
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"Failed to connect to RabbitMQ "
,
err
.
Error
())
logger
.
Info
(
"Failed to connect to RabbitMQ "
,
err
.
Error
())
//sendMsg("bom_crm队列任务,连接MQ失败,原因:"+err.Error()
)
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,连接MQ失败,原因:"
+
err
.
Error
(),
""
)
}
}
defer
conn
.
Close
()
defer
conn
.
Close
()
ch
,
err
:=
conn
.
Channel
()
ch
,
err
:=
conn
.
Channel
()
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"Failed to open a channel "
,
err
.
Error
())
logger
.
Info
(
"Failed to open a channel "
,
err
.
Error
())
//sendMsg("bom_crm队列任务,打开channel失败,原因:"+err.Error()
)
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,打开channel失败,原因:"
+
err
.
Error
(),
""
)
}
}
defer
ch
.
Close
()
defer
ch
.
Close
()
...
@@ -86,13 +86,13 @@ func main() {
...
@@ -86,13 +86,13 @@ func main() {
)
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"Failed to declare a queue "
,
err
.
Error
())
logger
.
Info
(
"Failed to declare a queue "
,
err
.
Error
())
//sendMsg("bom_crm队列任务,声明queue失败,原因:"+err.Error()
)
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,声明queue失败,原因:"
+
err
.
Error
(),
""
)
}
}
err
=
ch
.
QueueBind
(
q
.
Name
,
"bom_crm"
,
"bom"
,
false
,
nil
)
err
=
ch
.
QueueBind
(
q
.
Name
,
"bom_crm"
,
"bom"
,
false
,
nil
)
if
nil
!=
err
{
if
nil
!=
err
{
logger
.
Info
(
"Failed to bind a queue and exchange "
,
err
.
Error
())
logger
.
Info
(
"Failed to bind a queue and exchange "
,
err
.
Error
())
//sendMsg("bom_crm队列任务,队列绑定失败,原因:"+err.Error()
)
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,队列绑定失败,原因:"
+
err
.
Error
(),
""
)
}
}
msgs
,
err
:=
ch
.
Consume
(
msgs
,
err
:=
ch
.
Consume
(
...
@@ -106,7 +106,7 @@ func main() {
...
@@ -106,7 +106,7 @@ func main() {
)
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"Failed to register a consumer "
,
err
.
Error
())
logger
.
Info
(
"Failed to register a consumer "
,
err
.
Error
())
//sendMsg("bom_crm队列任务,注册消费者失败,原因:"+err.Error()
)
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,注册消费者失败,原因:"
+
err
.
Error
(),
""
)
}
}
forever
:=
make
(
chan
bool
)
forever
:=
make
(
chan
bool
)
...
@@ -115,7 +115,6 @@ func main() {
...
@@ -115,7 +115,6 @@ func main() {
go
func
()
{
go
func
()
{
for
d
:=
range
msgs
{
for
d
:=
range
msgs
{
fmt
.
Println
(
string
(
d
.
Body
))
fmt
.
Println
(
string
(
d
.
Body
))
//sendMsg("获取bom_crm队列:"+string(d.Body))
json
.
Unmarshal
(
d
.
Body
,
&
bom_order
)
json
.
Unmarshal
(
d
.
Body
,
&
bom_order
)
consume
(
bom_order
)
consume
(
bom_order
)
}
}
...
@@ -132,13 +131,13 @@ func consume(bom BomOrder) {
...
@@ -132,13 +131,13 @@ func consume(bom BomOrder) {
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"Failed to connect crm db "
,
err
.
Error
())
logger
.
Info
(
"Failed to connect crm db "
,
err
.
Error
())
//sendMsg("bom_crm队列任务,连接CRM数据库失败,原因:"+err.Error()
)
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,连接CRM数据库失败,原因:"
+
err
.
Error
(),
""
)
return
return
}
}
if
crmUserId
==
0
{
// 不存在推送告警
if
crmUserId
==
0
{
// 不存在推送告警
logger
.
Info
(
"没有找到crm用户,用户ID:"
+
strconv
.
Itoa
(
bom
.
UserId
))
logger
.
Info
(
"没有找到crm用户,用户ID:"
+
strconv
.
Itoa
(
bom
.
UserId
))
//sendMsg("bom_crm队列任务,用户ID("+strconv.Itoa(bom.UserId)+")CRM不存在
")
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,用户ID("
+
strconv
.
Itoa
(
bom
.
UserId
)
+
")CRM不存在"
,
"
"
)
return
return
}
}
...
@@ -169,10 +168,10 @@ func consume(bom BomOrder) {
...
@@ -169,10 +168,10 @@ func consume(bom BomOrder) {
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"Failed to insert into lie_bom_extend db "
,
err
.
Error
())
logger
.
Info
(
"Failed to insert into lie_bom_extend db "
,
err
.
Error
())
//sendMsg("bom_crm队列任务,添加到lie_bom_extend表失败,原因:"+err.Error()
)
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,添加到lie_bom_extend表失败,原因:"
+
err
.
Error
(),
""
)
return
return
}
}
logger
.
Info
(
"已添加到lie_bom_extend,用户ID:"
+
strconv
.
Itoa
(
bom
.
UserId
)
+
",BOM-ID:"
+
strconv
.
Itoa
(
bom
.
BomId
))
logger
.
Info
(
"已添加到lie_bom_extend,用户ID:"
+
strconv
.
Itoa
(
bom
.
UserId
)
+
",BOM-ID:"
+
strconv
.
Itoa
(
bom
.
BomId
))
//sendMsg("bom_crm队列任务,添加到lie_bom_extend表成功
")
service
.
DingAlert
(
configs
.
Ding_crm_token
,
"bom_crm队列任务,已添加到lie_bom_extend表,用户ID:"
+
strconv
.
Itoa
(
bom
.
UserId
)
+
",BOM-ID:"
+
strconv
.
Itoa
(
bom
.
BomId
),
"
"
)
}
}
internal/service/dingding.go
View file @
aaed198b
...
@@ -5,6 +5,8 @@ import (
...
@@ -5,6 +5,8 @@ import (
"crm-server/internal/common"
"crm-server/internal/common"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/ichunt2019/logger"
"io/ioutil"
"net/http"
"net/http"
"net/url"
"net/url"
"strconv"
"strconv"
...
@@ -14,6 +16,7 @@ import (
...
@@ -14,6 +16,7 @@ import (
const
APIMD5STR
string
=
"fh6y5t4rr351d2c3bryi"
const
APIMD5STR
string
=
"fh6y5t4rr351d2c3bryi"
const
APIDOMAIN
string
=
configs
.
Api_url
+
"/msg/sendMessageByAuto"
const
APIDOMAIN
string
=
configs
.
Api_url
+
"/msg/sendMessageByAuto"
const
ADMINTEL
int64
=
17600091664
const
ADMINTEL
int64
=
17600091664
const
DINGALERTURL
string
=
configs
.
Api_url
+
"/msg/dingalert"
func
AdminErr
(
err
error
)
{
func
AdminErr
(
err
error
)
{
...
@@ -74,3 +77,23 @@ func SendBomMsg(user_id int64 , client_account string){
...
@@ -74,3 +77,23 @@ func SendBomMsg(user_id int64 , client_account string){
}
}
}
}
func
DingAlert
(
token
string
,
text
string
,
at
string
)
[]
byte
{
curr_time
:=
time
.
Now
()
.
Unix
()
resp
,
err
:=
http
.
PostForm
(
DINGALERTURL
,
url
.
Values
{
"token"
:
{
token
},
"text"
:
{
text
},
"at"
:
{
at
},
"k1"
:
{
strconv
.
FormatInt
(
int64
(
curr_time
),
10
)},
"k2"
:
{
common
.
Md5
(
common
.
Md5
(
strconv
.
FormatInt
(
int64
(
curr_time
),
10
))
+
APIMD5STR
)},
})
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
logger
.
Info
(
err
.
Error
())
}
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
// 获取接口返回数据
return
body
}
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