Commit ad64d4ec by mushishixian

添加队列推送和钉钉发送消息

parent b47b2d33
[DINGDING]
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
\ No newline at end of file
[rabmq]
url = amqp://guest:guest@192.168.2.232:5672/
;存放本系统所有的队列名称 ;存放本系统所有的队列名称
[rabmq_all] [rabmq_all]
;联营数据推送入队列-》go后台任务消费(斌哥脚本) ;联营数据推送入队列-》go后台任务消费(斌哥脚本)
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser' MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser'
[brand] [BRAND]
IS_NOT_TI = 0 IS_NOT_TI = 0
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752 TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
TI_ZY_BRAND_IDS = 23 TI_ZY_BRAND_IDS = 23
...@@ -120,7 +120,7 @@ Index = liexin_ziying ...@@ -120,7 +120,7 @@ Index = liexin_ziying
8=kw 8=kw
[official_website] [OFFICIAL_WEBSITE]
1 = https://www.futureelectronics.cn/search/?text=liexin 1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin 2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
3 = https://www.rocelec.com/search?q=liexin 3 = https://www.rocelec.com/search?q=liexin
......
...@@ -3,12 +3,10 @@ module search_server ...@@ -3,12 +3,10 @@ module search_server
go 1.14 go 1.14
require ( require (
github.com/basgys/goxml2json v1.1.0 github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/coreos/etcd v3.3.18+incompatible
github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0 github.com/go-ini/ini v1.57.0
github.com/go-playground/locales v0.13.0
github.com/go-sql-driver/mysql v1.5.0 github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9 github.com/go-xorm/xorm v0.7.9
github.com/gogo/protobuf v1.3.1 // indirect github.com/gogo/protobuf v1.3.1 // indirect
...@@ -18,39 +16,28 @@ require ( ...@@ -18,39 +16,28 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/logger v1.0.5 github.com/ichunt2019/logger v1.0.5
github.com/idoubi/goz v1.0.0
github.com/imroc/req v0.3.0 github.com/imroc/req v0.3.0
github.com/jinzhu/gorm v1.9.12 github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 // indirect
github.com/mholt/certmagic v0.9.3 // indirect
github.com/micro/go-micro v1.16.0 github.com/micro/go-micro v1.16.0
github.com/micro/go-micro/v2 v2.9.0 github.com/micro/go-micro/v2 v2.9.0
github.com/micro/micro/v2 v2.9.1 // indirect
github.com/micro/protoc-gen-micro v1.0.0 // indirect
github.com/prometheus/client_golang v1.5.1 // indirect github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/common v0.10.0 github.com/prometheus/common v0.10.0
github.com/prometheus/procfs v0.0.11 // indirect github.com/prometheus/procfs v0.0.11 // indirect
github.com/silenceper/gowatch v0.0.0-20200624073703-8e473a9db258 // indirect
github.com/sirupsen/logrus v1.5.0 // indirect github.com/sirupsen/logrus v1.5.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect github.com/stretchr/testify v1.5.1 // indirect
github.com/syyongx/php2go v0.9.4 github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.0 github.com/tidwall/gjson v1.6.0
github.com/uniplaces/carbon v0.1.6 github.com/uniplaces/carbon v0.1.6
github.com/urfave/cli v1.22.4 // indirect
go.etcd.io/bbolt v1.3.4
go.uber.org/zap v1.14.1 // indirect go.uber.org/zap v1.14.1 // indirect
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0 google.golang.org/protobuf v1.24.0
gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85 gopkg.in/olivere/elastic.v5 v5.0.85
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
) )
......
...@@ -7,20 +7,20 @@ import ( ...@@ -7,20 +7,20 @@ import (
//获取需要排除的品牌id //获取需要排除的品牌id
//branType = 1 : 联营 2 : 自营 //branType = 1 : 联营 2 : 自营
func GetExcludeBrandIds(brandType int) (excludeBrandIds []int) { func GetExcludeBrandIds(brandType int) (excludeBrandIds []int) {
isNoTi := config.Get("brand.IS_NOT_TI").String() isNoTi := config.Get("BRAND.IS_NOT_TI").String()
//如果关闭,直接返回空数据 //如果关闭,直接返回空数据
if isNoTi == "0" { if isNoTi == "0" {
return return
} }
//返回联营的brand_id切片 //返回联营的brand_id切片
if brandType == 1 { if brandType == 1 {
tiLyBrandIds := config.Get("brand.TI_LY_BRAND_IDS").Ints(",") tiLyBrandIds := config.Get("BRAND.TI_LY_BRAND_IDS").Ints(",")
excludeBrandIds = tiLyBrandIds excludeBrandIds = tiLyBrandIds
//获取的是字符串 //获取的是字符串
return return
} }
//返回自营的ti的brand_id切片 //返回自营的ti的brand_id切片
tiZyBrandId := config.Get("brand.TI_ZY_BRAND_IDS").Ints(",") tiZyBrandId := config.Get("BRAND.TI_ZY_BRAND_IDS").Ints(",")
excludeBrandIds = tiZyBrandId excludeBrandIds = tiZyBrandId
return return
......
...@@ -12,7 +12,7 @@ var ( ...@@ -12,7 +12,7 @@ var (
func SetUp(path string) (err error) { func SetUp(path string) (err error) {
//引入多个文件 //引入多个文件
Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/search.ini", path+"/redis_key.ini", path+"/rabmq_key.ini", path+"/database.ini", Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/search.ini", path+"/redis_key.ini", path+"/rabmq_key.ini", path+"/database.ini",
path+"/redis_config.ini") path+"/redis_config.ini", path+"/message.ini")
return return
} }
......
package message package message
import ( import (
"encoding/json"
"fmt"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/prometheus/common/log" "github.com/tidwall/gjson"
"search_server/pkg/config"
"strings"
) )
//发送钉钉消息的包 //发送钉钉消息的包
...@@ -12,26 +16,33 @@ type DingDingRequest struct { ...@@ -12,26 +16,33 @@ type DingDingRequest struct {
IsAtAll bool `json:"isAtAll"` IsAtAll bool `json:"isAtAll"`
} }
func SendDingdingMessage(content string) { type DingDingResponse struct {
var ( Errcode int `json:"errcode"`
requestData DingDingRequest Errmsg string `json:"errmsg"`
apiUrl, token string }
//resp *req.Resp
err error func DingDingPush(content string) (result DingDingResponse, err error) {
) accessToken := config.Get("DINGDING.SEARCH_API_MONITOR").String()
//todo: 需要配置一个搜索服务的专属警告 webhook := "https://oapi.dingtalk.com/robot/send?access_token=" + accessToken
content = "仓储同步告警 : " + content data := make(map[string]interface{})
requestData.MsgType = "text" data["msgtype"] = "text"
requestData.Text = map[string]string{ data["text"] = map[string]string{
"content": content, "content": content,
} }
req.Debug = false req.Debug = false
requestData.IsAtAll = false dataStrByte, _ := json.Marshal(data)
token = "3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3" dataStr := string(dataStrByte)
apiUrl = "https://api.ichunt.com/public/dingtalkrobot?access_token=" + token fmt.Println(dataStr)
params := req.BodyJSON(requestData) dataStr = strings.Replace(dataStr, "\\", "\\\\", -1)
_, err = req.Post(apiUrl, params) params := req.BodyJSON(dataStr)
if err != nil { resp, err := req.Post(webhook, params, req.Header{
log.Error(err) "Content-Type": "application/json",
"charset": "UTF-8",
})
if resp==nil {
return
} }
result.Errcode = int(gjson.Get(resp.String(), "errcode").Int())
result.Errmsg = gjson.Get(resp.String(), "errmsg").String()
return
} }
package mq
import (
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"search_server/pkg/config"
)
func PushMsg(listName string, data string) {
queueExchange := rabbitmq.QueueExchange{
listName,
listName,
"",
"direct",
config.Get("rabmq.url").String(),
}
rabbitmq.Send(queueExchange, data)
}
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
//推送搜索关键词 //推送搜索关键词
func ShowSku(goods model.DullGoodsData) { func ShowSku(goods model.DullGoodsData) {
len := len(goods.GoodsId) goodsIdLen := len(goods.GoodsId)
if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" { if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" {
return return
} }
...@@ -36,11 +36,11 @@ func ShowSku(goods model.DullGoodsData) { ...@@ -36,11 +36,11 @@ func ShowSku(goods model.DullGoodsData) {
} }
//todo : goods_name正则替换 //todo : goods_name正则替换
result["goods_name"] = goods.GoodsName result["goods_name"] = goods.GoodsName
if (len < 19 || goods.SupplierId == 10000) && result["supplier_type"] != "撮合" { if (goodsIdLen < 19 || goods.SupplierId == 10000) && result["supplier_type"] != "撮合" {
result["keyword"] = strings.TrimSpace("keyword") result["keyword"] = strings.TrimSpace("keyword")
} }
result["adtag"], _ = middleware.Context.Cookie("adtag") result["adtag"], _ = middleware.Context.Cookie("adtag")
if len < 19 { if goodsIdLen < 19 {
result["status"] = "1" result["status"] = "1"
} }
......
...@@ -123,7 +123,7 @@ func getSupplierInfo(goods model.DullGoodsData) (model.DullGoodsData, error) { ...@@ -123,7 +123,7 @@ func getSupplierInfo(goods model.DullGoodsData) (model.DullGoodsData, error) {
} }
goods.PageFlag = 2 goods.PageFlag = 2
//获取官网信息 //获取官网信息
officialWebsites := config.Cfg.Section("official_website").KeysHash() officialWebsites := config.Cfg.Section("OFFICIAL_WEBSITE").KeysHash()
if website, exist := officialWebsites[common.ToString(goods.SupplierId)]; exist { if website, exist := officialWebsites[common.ToString(goods.SupplierId)]; exist {
goods.SupplierWebsite = strings.Replace(website, "liexin", goods.SupplierName, -1) goods.SupplierWebsite = strings.Replace(website, "liexin", goods.SupplierName, -1)
} else { } else {
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"search_server/boot" "search_server/boot"
"search_server/pkg/mq"
) )
func StrRandom(lenNum int) string { func StrRandom(lenNum int) string {
...@@ -28,4 +29,5 @@ func main() { ...@@ -28,4 +29,5 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
fmt.Println(err) fmt.Println(err)
} }
mq.PushMsg("xian_test","test")
} }
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