Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
golang-queue-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
763e05fc
authored
Jan 07, 2020
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加邮件发送
parent
1129ba91
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
178 additions
and
48 deletions
dal/order/OrderActionLog/OrderActionLog.go
go.mod
order/sendPurchaseEmail/main.go
order/sendPurchaseEmail/sendEmail/sendEmail.go
util/config.go
util/ding/ding.go
dal/order/OrderActionLog/OrderActionLog.go
View file @
763e05fc
...
...
@@ -2,9 +2,10 @@ package OrderActionLog
import
(
"database/sql"
"fmt"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/util"
"fmt"
"log"
"time"
)
...
...
@@ -76,23 +77,24 @@ func Query() {
func
Insert
(
order_id
int
,
operator_id
int
,
operator_type
int
,
event
string
)
(
err
error
)
{
create_time
:=
time
.
Now
()
.
Unix
()
result
,
err
:=
db
.
DB
.
Exec
(
"insert into lie_order_action_log (order_id, operator_id, operator_type, event, create_time) values (?, ?, ?, ?, ?)"
,
order_id
,
operator_id
,
operator_type
,
event
,
create_time
)
if
err
!=
nil
{
panic
(
err
)
}
_
,
err1
:=
db
.
DB
.
Exec
(
"insert into lie_order_action_log (order_id, operator_id, operator_type, event, create_time) values (?, ?, ?, ?, ?)"
,
order_id
,
operator_id
,
operator_type
,
event
,
create_time
)
id
,
err
:=
result
.
LastInsertId
()
if
err
!=
nil
{
panic
(
err
)
}
affected
,
err
:=
result
.
RowsAffected
()
if
err
!=
nil
{
panic
(
err
)
if
err1
!=
nil
{
logger
.
Fatal
(
"数据库操作失败"
)
return
err1
}
fmt
.
Printf
(
"last insert id:%d affect rows:%d
\n
"
,
id
,
affected
)
//id, err := result.LastInsertId()
//if err != nil {
// panic(err)
//}
//
//affected, err := result.RowsAffected()
//if err != nil {
// panic(err)
//}
//
//fmt.Printf("last insert id:%d affect rows:%d\n", id, affected)
return
err
}
\ No newline at end of file
go.mod
View file @
763e05fc
...
...
@@ -7,7 +7,7 @@ require (
github.com/gin-gonic/gin v1.5.0
github.com/go-sql-driver/mysql v1.4.1
github.com/ichunt2019/go-msgserver v1.0.4
github.com/ichunt2019/logger v1.0.5
// indirect
github.com/ichunt2019/logger v1.0.5
github.com/jmoiron/sqlx v1.2.0
github.com/prometheus/common v0.7.0 // indirect
github.com/tealeg/xlsx v1.0.5
...
...
order/sendPurchaseEmail/main.go
View file @
763e05fc
...
...
@@ -3,10 +3,10 @@ package main
import
(
"fmt"
"github.com/ichunt2019/go-msgserver/utils/rabbitmq"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/order/sendPurchaseEmail/sendEmail"
"go-queue-server/util"
"github.com/ichunt2019/logger"
"sync"
"time"
)
...
...
order/sendPurchaseEmail/sendEmail/sendEmail.go
View file @
763e05fc
package
sendEmail
import
(
"fmt"
"encoding/json"
_
"fmt"
"github.com/ichunt2019/logger"
"go-queue-server/dal/order/OrderActionLog"
"go-queue-server/util"
"go-queue-server/util/ding"
"io/ioutil"
"net/http"
"
encoding/json
"
"
strconv
"
"strings"
"io/ioutil"
"go-queue-server/dal/order/OrderActionLog"
)
// json 返回值
type
JosnResp
struct
{
Errcode
int
`json:"err_code"`
Errmsg
string
`json:"msg"`
Errmsg
string
`json:"err_msg"`
}
// 队列参数
type
DataParams
struct
{
OrderId
int
`json:"order_id"`
OperatorId
int
`json:"operator_id"`
OperatorEvent
string
`json:"operator_event"`
}
func
SendPurchaseEmail
(
data
string
)
(
err
error
)
{
// 发送采购邮件
func
SendPurchaseEmail
(
data
string
)
(
err
error
)
{
crm_url
:=
util
.
Configs
.
Crm_domain
.
SendMailUrl
// CRM发送邮件接口
header_map
:=
map
[
string
]
string
{
"api-key"
:
"crm a1b2c3d4e5f6g7h8i9jk"
,
"Content-Type"
:
"application/json"
,
}
client
:=
&
http
.
Client
{}
err
=
http_post
(
crm_url
,
data
,
header_map
)
// 钉钉通知 默认参数
var
mobile
[]
string
=
make
([]
string
,
0
)
var
isAtAll
bool
=
false
if
err
!=
nil
{
ding
.
Send
(
"邮件接口请求失败,原因:"
+
err
.
Error
(),
mobile
,
isAtAll
)
logger
.
Info
(
err
.
Error
())
return
err
}
req
,
_
:=
http
.
NewRequest
(
"POST"
,
crm_url
,
strings
.
NewReader
(
string
(
data
)))
// 添加操作日志
var
data_params
*
DataParams
json
.
Unmarshal
([]
byte
(
data
),
&
data_params
)
req
.
Header
.
Set
(
"api-key"
,
"crm a1b2c3d4e5f6g7h8i9jk"
)
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
resp
,
err
:=
client
.
Do
(
req
)
order_id
:=
data_params
.
OrderId
operator_id
:=
data_params
.
OperatorId
operator_event
:=
data_params
.
OperatorEvent
defer
resp
.
Body
.
Close
(
)
err
=
OrderActionLog
.
Insert
(
order_id
,
operator_id
,
2
,
operator_event
)
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
ding
.
Send
(
"添加操作日志失败"
,
mobile
,
isAtAll
)
return
err
}
res
:=
JosnResp
{}
ding
.
Send
(
"订单ID:"
+
strconv
.
Itoa
(
order_id
)
+
","
+
operator_event
,
mobile
,
isAtAll
)
err1
:=
json
.
Unmarshal
([]
byte
(
body
),
&
res
)
// 推送ERP
api_url
:=
util
.
Configs
.
Api_domain
.
ApiUrl
+
"order/sysiteminfo"
params
:=
"order_id="
+
strconv
.
Itoa
(
order_id
)
api_header_map
:=
make
(
map
[
string
]
string
,
0
)
if
err1
!=
nil
{
fmt
.
Println
(
err1
)
}
err
=
http_post
(
api_url
,
params
,
api_header_map
)
var
data_map
map
[
string
]
interface
{}
json
.
Unmarshal
([]
byte
(
data
),
&
data_map
)
if
err
!=
nil
{
ding
.
Send
(
"ERP同步接口请求失败,原因:"
+
err
.
Error
(),
mobile
,
isAtAll
)
logger
.
Info
(
err
.
Error
())
return
err
}
order_id
:=
data_map
[
"order_id"
];
operator_id
:=
data_map
[
"operator_id"
];
operator_event
:=
data_map
[
"operator_event"
];
return
}
// 添加操作日志
OrderActionLog
.
Insert
(
order_id
,
operator_id
,
2
,
operator_event
)
func
http_post
(
url
string
,
data
string
,
header
map
[
string
]
string
)
(
err
error
)
{
client
:=
&
http
.
Client
{}
// 推送ERP
req
,
_
:=
http
.
NewRequest
(
"POST"
,
url
,
strings
.
NewReader
(
string
(
data
)))
if
len
(
header
)
>
0
{
for
k
,
v
:=
range
header
{
req
.
Header
.
Set
(
k
,
v
)
}
}
resp
,
err
:=
client
.
Do
(
req
)
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
logger
.
Info
(
err
.
Error
())
}
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
res
:=
JosnResp
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
body
),
&
res
);
err
!=
nil
{
json_res
,
_
:=
json
.
Marshal
(
res
)
logger
.
Info
(
string
(
json_res
))
// 记录body错误信息
return
err
}
return
}
...
...
util/config.go
View file @
763e05fc
...
...
@@ -11,6 +11,7 @@ type Config struct{
Rabbitmq_ichunt
*
RabbitmqIchunt
Crm_domain
*
SendMail
Ding_msg
*
Ding
Api_domain
*
ApiDomain
}
...
...
@@ -35,6 +36,10 @@ type Ding struct {
JingDiao
string
`toml:"jingDiao"`
}
type
ApiDomain
struct
{
ApiUrl
string
`toml:"api_url"`
}
var
Configs
*
Config
=
new
(
Config
)
func
Init
(){
...
...
util/ding/ding.go
View file @
763e05fc
package
ding
import
(
_
"fmt"
"go-queue-server/util"
"net/http"
"strings"
"encoding/json"
"io/ioutil"
"github.com/ichunt2019/logger"
)
func
send
()
{
type
Msg
struct
{
Msgtype
string
`json:"msgtype"`
Text
Contents
`json:"text"`
At
Ats
`json:"at"`
}
type
Contents
struct
{
Content
string
`json:"content"`
}
type
Ats
struct
{
AtMobiles
[]
string
`json:"atMobiles"`
IsAtAll
bool
`json:"isAtAll"`
}
// json 返回值
type
JosnResp
struct
{
Errcode
int
`json:"errcode"`
Errmsg
string
`json:"errmsg"`
}
func
Send
(
textMsg
string
,
mobiles
[]
string
,
isAtAll
bool
)
(
jsonStr
string
)
{
var
msg
Msg
msg
=
Msg
{
Msgtype
:
"text"
}
msg
.
Text
.
Content
=
"监控告警: "
+
textMsg
// 固定标签 + 文本
msg
.
At
.
AtMobiles
=
mobiles
msg
.
At
.
IsAtAll
=
isAtAll
;
content
,
_
:=
json
.
Marshal
(
msg
)
// content := `{
// "msgtype": "text",
// "text": {
// "content": "`+ msg + `"
// }
// }`
ding_url
:=
util
.
Configs
.
Ding_msg
.
Webhook
// 钉钉请求接口
client
:=
&
http
.
Client
{}
req
,
_
:=
http
.
NewRequest
(
"POST"
,
ding_url
,
strings
.
NewReader
(
string
(
content
)))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json; charset=utf-8"
)
resp
,
err
:=
client
.
Do
(
req
);
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
logger
.
Info
(
err
.
Error
())
}
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
// 获取接口返回数据
res
:=
JosnResp
{}
if
err1
:=
json
.
Unmarshal
([]
byte
(
body
),
&
res
);
err1
!=
nil
{
// 将接口数据写入res
logger
.
Info
(
err1
.
Error
())
}
result
,
_
:=
json
.
Marshal
(
res
)
return
string
(
result
)
}
\ No newline at end of file
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