Commit 474a76e6 by mushishixian

切换钉钉消息方式

parent 4746e394
package main
import (
"fmt"
"strings"
"scm_server/internal/service"
)
func main() {
temp:=`{\"type\":\"save\",\"date\":{\"FID\":\"UxasZFrOQGC+oCfTmVSNuUQJ5/A=\",\"FBrand\":\"3M\",\"FModel\":\"aabbddcc\",\"FGoods\":\"\u4E8C\u6781\u7BA1\"}}`
temp = strings.ReplaceAll(temp,`\`,"")
fmt.Println(temp)
return
service.SendDingTalkRobotToApi("xxx")
}
......@@ -10,7 +10,6 @@ import (
"github.com/pkg/errors"
"scm_server/cmd/queue/sync_audit_status/product"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
"scm_server/internal/model"
"scm_server/internal/service"
......@@ -55,9 +54,9 @@ ERR:
//如果失败了,记录到表,并且发送钉钉消息
if err = logic.InsertAuditStatusLog(auditStatusLog); err != nil {
log.Error(err.Error())
service.SendMessage(common.ErrorSendPhone, err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
service.SendMessage(common.ErrorSendPhone, auditStatusLog.SyncError)
service.SendDingTalkRobotToApi(auditStatusLog.SyncError)
return nil
}
......
......@@ -76,7 +76,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
default:
err = errors.New("同步客户出现不存在的操作类型")
err = errors.New("同步客户出现不存在的操作类型" + operateType)
goto ERR
}
//操作成功后还要去请求后端接口同步数据
......@@ -99,12 +99,12 @@ ERR:
SyncName: "customer",
}
if err = logic.InsertSyncLog(syncLog); err != nil {
service.SendMessage(common.ErrorSendPhone, err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
//发送钉钉错误消息
msg, _ := json.Marshal(syncLog)
service.SendMessage(common.ErrorSendPhone, string(msg))
service.SendDingTalkRobotToApi(string(msg))
//保存日志
log.Error("%s", string(msg))
......
......@@ -79,7 +79,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
default:
err = errors.New("同步供应商出现不存在的操作类型")
err = errors.New("同步供应商出现不存在的操作类型" + operateType)
goto ERR
}
//操作成功后还要去请求后端接口同步数据
......@@ -103,12 +103,12 @@ ERR:
}
//错误日志插入错误,需要告警
if err = logic.InsertSyncLog(syncLog); err != nil {
service.SendMessage(common.ErrorSendPhone, err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
//发送钉钉错误消息
msg, _ := json.Marshal(syncLog)
service.SendMessage(common.ErrorSendPhone, string(msg))
service.SendDingTalkRobotToApi(string(msg))
//保存日志
log.Error("%s", string(msg))
return nil
......
......@@ -32,4 +32,4 @@ func main() {
}
rabbitmq.Send(queueExchange, body)
}
}
\ No newline at end of file
......@@ -97,7 +97,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
default:
err = errors.New("同步入货单出现不存在的操作类型")
err = errors.New("同步入货单出现不存在的操作类型" + operateType)
goto ERR
}
//操作成功后还要去请求后端接口同步数据
......@@ -105,7 +105,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
fmt.Println("同步成功,开始发送金蝶状态同步")
if err = product.SyncErpStatus("in_store", inStore.BillId); err != nil {
if err = product.SyncErpStatus("inStore", inStore.BillId); err != nil {
goto ERR
}
return nil
......@@ -121,11 +121,11 @@ ERR:
}
//错误日志插入错误,需要告警
if err = logic.InsertSyncLog(syncLog); err != nil {
service.SendMessage(common.ErrorSendPhone, err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
//发送钉钉错误消息
msg, _ = json.Marshal(syncLog)
service.SendMessage(common.ErrorSendPhone, string(msg))
service.SendDingTalkRobotToApi(string(msg))
//保存日志
log.Error("%s", string(msg))
return nil
......@@ -194,8 +194,8 @@ func TransformParams(message InStoreMessage) (result req.Param) {
detailPrefix = fmt.Sprintf("detail[%d][", key)
detailMap = map[string]interface{}{
detailPrefix + "erp_entry_sn]": entry.FSourceBillEntryID,
detailPrefix + "goods_erp_id]": entry.FMaterialID,
detailPrefix + "goods_name]": entry.FGoods,
detailPrefix + "erp_goods_id]": entry.FMaterialID,
detailPrefix + "goods_name]": entry.FModel,
detailPrefix + "brand_name]": entry.FBrand,
detailPrefix + "number]": entry.FQty,
detailPrefix + "country]": entry.FOriginCountry,
......
......@@ -98,7 +98,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
default:
err = errors.New("同步出货单出现不存在的操作类型")
err = errors.New("同步出货单出现不存在的操作类型" + operateType)
goto ERR
}
//操作成功后还要去请求后端接口同步数据
......@@ -106,7 +106,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
fmt.Println("同步成功,开始发送金蝶状态同步")
if err = product.SyncErpStatus("out_store", outStore.BillId); err != nil {
if err = product.SyncErpStatus("outStore", outStore.BillId); err != nil {
goto ERR
}
return nil
......@@ -122,11 +122,11 @@ ERR:
}
//错误日志插入错误,需要告警
if err = logic.InsertSyncLog(syncLog); err != nil {
service.SendMessage(common.ErrorSendPhone, err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
//发送钉钉错误消息
msg, _ = json.Marshal(syncLog)
service.SendMessage(common.ErrorSendPhone, string(msg))
service.SendDingTalkRobotToApi(string(msg))
//保存日志
log.Error("%s", string(msg))
......@@ -188,7 +188,7 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
for _, entry = range message.Data.FEntrys {
outStoreDetail = append(outStoreDetail, map[string]interface{}{
"erp_goods_id": entry.FMaterialID,
"goods_name": entry.FGoods,
"goods_name": entry.FModel,
"brand_name": entry.FBrand,
"number": entry.FQty,
"goods_unit": entry.FUnit,
......@@ -205,7 +205,7 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
"receive_address": message.Data.FRecPersonAddress,
"receive_user_name": message.Data.FRecPerson,
"receive_tel": message.Data.FRecPersonContact,
"erp_in_store_id": message.Data.FSourceBillID,
"erp_out_store_id": message.Data.FSourceBillID,
"erp_client_sn": message.Data.FPrincipalNo,
"remark": message.Data.Remark,
"erp_store_sn": message.Data.FWarehouseNo,
......
......@@ -9,7 +9,6 @@ import (
"github.com/mushishixian/gosoap"
"github.com/pkg/errors"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
"scm_server/internal/model"
"scm_server/internal/service"
......@@ -52,9 +51,9 @@ ERR:
syncStatusLog.AddTime = time.Now().Unix()
//如果失败了,记录到表,并且发送钉钉消息
if err = logic.InsertSyncStatusLog(syncStatusLog); err != nil {
service.SendMessage(common.ErrorSendPhone, err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
service.SendMessage(common.ErrorSendPhone, syncStatusLog.SyncError)
service.SendDingTalkRobotToApi(syncStatusLog.SyncError)
return nil
}
......@@ -114,11 +113,11 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) {
apiUrl = configs.ErpSyncBaseDataStatusApi
apiMethod = "synRewriteErpBaseDataStatus"
break
case "in_store":
case "inStore":
apiUrl = configs.ErpSyncBillStatusApi
apiMethod = "synErpInventoryStatus"
break
case "out_store":
case "outStore":
apiUrl = configs.ErpSyncBillStatusApi
apiMethod = "synErpInventoryStatus"
break
......@@ -163,6 +162,8 @@ func CheckBaseDataRequest(res *gosoap.Response) (err error) {
for key, value := range responseData {
//金蝶判断成功的标志
if key == "0000" {
//成功还要去修改记录表
fmt.Println("OK")
return
}
//金额判断失败的标志
......@@ -183,7 +184,6 @@ func CheckBillDataRequest(res *gosoap.Response) (err error) {
}
//没有这个xml节点代表金蝶报错了
root := doc.SelectElement("ns1:synErpInventoryStatusResponse")
fmt.Println(root)
if root == nil {
return errors.New(string(res.Body))
}
......@@ -194,6 +194,7 @@ func CheckBillDataRequest(res *gosoap.Response) (err error) {
for key, value := range responseData {
//金蝶判断成功的标志
if key == "0000" {
fmt.Println("OK")
return
}
//金额判断失败的标志
......
......@@ -77,7 +77,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
default:
err = errors.New("同步供应商出现不存在的操作类型")
err = errors.New("同步供应商出现不存在的操作类型" + operateType + operateType)
goto ERR
}
//操作成功后还要去请求后端接口同步数据
......@@ -100,11 +100,11 @@ ERR:
SyncName: "supplier",
}
if err = logic.InsertSyncLog(syncLog); err != nil {
service.SendMessage(common.ErrorSendPhone, err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
//发送钉钉错误消息
msg, _ := json.Marshal(syncLog)
service.SendMessage(common.ErrorSendPhone, string(msg))
service.SendDingTalkRobotToApi(string(msg))
//保存日志
log.Error("%s", string(msg))
......
......@@ -41,9 +41,6 @@ func Import() {
if key == 0 {
continue
}
if key == 100 {
break
}
goods.ErpId = row.Cells[0].String()
goods.GoodsName = row.Cells[1].String()
goods.BrandName = row.Cells[2].String()
......
package service
import (
"scm_server/internal/common"
"encoding/json"
"fmt"
"github.com/imroc/req"
"net/http"
"net/url"
"scm_server/internal/common"
"strconv"
"time"
)
const APIMD5STR string = "fh6y5t4rr351d2c3bryi"
const APIDOMAIN string = "http://api.ichunt.com/msg/sendMessageByAuto"
const ADMINTEL int64 = 18825159814
const ADMINTEL int64 = 18825159814
func AdminErr(err error) {
func AdminErr(err error) {
if err != nil {
fmt.Println(err)
SendMessage(ADMINTEL,err.Error())
SendMessage(ADMINTEL, err.Error())
}
}
func SendMessage(mobile int64 , content string){
func SendMessage(mobile int64, content string) {
if mobile != 0 {
timeNow := time.Now().Unix()
requestContent,_ := json.Marshal(map[string]string{"content":content})
requestTel,_ := json.Marshal([]int64{mobile})
resp,err := http.PostForm(APIDOMAIN,url.Values{
"data" : {string(requestContent)},
"touser" : {string(requestTel)},
"keyword" : {"register_nopay_notify"},
"k1" : {strconv.FormatInt(int64(timeNow),10)},
"k2" : {common.Md5(common.Md5(strconv.FormatInt(int64(timeNow),10))+APIMD5STR)},
"is_ignore" : {},
requestContent, _ := json.Marshal(map[string]string{"content": content})
requestTel, _ := json.Marshal([]int64{mobile})
resp, err := http.PostForm(APIDOMAIN, url.Values{
"data": {string(requestContent)},
"touser": {string(requestTel)},
"keyword": {"register_nopay_notify"},
"k1": {strconv.FormatInt(int64(timeNow), 10)},
"k2": {common.Md5(common.Md5(strconv.FormatInt(int64(timeNow), 10)) + APIMD5STR)},
"is_ignore": {},
})
if err != nil {
......@@ -46,3 +45,32 @@ func SendMessage(mobile int64 , content string){
}
}
type DingDingRequest struct {
MsgType string `json:"msgtype"`
Text map[string]string `json:"text"`
IsAtAll bool `json:"isAtAll"`
}
func SendDingTalkRobotToApi(content string) {
var (
requestData DingDingRequest
apiUrl, token string
resp *req.Resp
err error
)
content = "仓储同步告警 : " + content
requestData.MsgType = "text"
requestData.Text = map[string]string{
"content": content,
}
req.Debug = false
requestData.IsAtAll = false
token = "3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3"
apiUrl = "https://api.ichunt.com/public/dingtalkrobot?access_token=" + token
params := req.BodyJSON(requestData)
resp, err = req.Post(apiUrl, params)
if err != nil {
fmt.Println(err)
}
fmt.Println(resp)
}
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 sign in to comment