Commit 7adf944a by 孙龙

Merge branch 'dev' of http://119.23.72.7/mushishixian/search_server into dev

parents 0c6e58d4 9663227e
......@@ -4,7 +4,6 @@ import (
"flag"
"os"
"search_server/boot"
"search_server/pkg/es"
)
func main() {
......@@ -32,12 +31,17 @@ func main() {
//fmt.Println(attrName)
//os.Exit(1)
//dd := service.OutLink("LM358","-1")
result,err := es.BulkES(`{ "index":{"_index":"hcy1","_type":"goods","_id":"8888888"} }
{ "name":"john doe","age":25 }
{ "index":{"_index":"hcy1","_type":"goods","_id":"9999999"} }
{ "name":"mary smith","age":32 }`)
println(result,err)
//lines := []string{
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`,
// `{"name":"john doe","age":25 }`,
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`,
// `{"name":"mary smith","age":32 }`,
//}
//param := strings.Join(lines, "\n")+"\n"
//
//result,err := es.BulkES(param)
//println(result,err)
os.Exit(1)
}
......
[DINGDING]
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
\ No newline at end of file
[rabmq]
url = amqp://guest:guest@192.168.2.232:5672/
;存放本系统所有的队列名称
[rabmq_all]
;联营数据推送入队列-》go后台任务消费(斌哥脚本)
......
[supplier_all]
[SUPPLIER_ALL]
1 = future
2 = powerandsignal
3 = rochester
......@@ -21,15 +21,28 @@
21 = rs
1676 = buerklin
[SEARCH_SUPPLIER_MERGE]
17 = zhuanmai
1 = future
3 = rochester
6 = element14
7 = digikey
8 = chip1stop
9 = aipco
12 = alliedelec
13 = avnet
19 = peigenesis
20 = powell
21 = rs
#相似物料供应商
[alike_supplier]
1 = "ti"
[ALIKE_SUPPLIER]
1 = ti
[common]
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser'
[brand]
[BRAND]
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_ZY_BRAND_IDS = 23
......@@ -40,30 +53,30 @@ SUPPLIER_REDIS_PRE = SUPPLIER_REDIS_INFO_
[ZIYING_BRAND_REPLACE]
FH=FH(风华)
BL=BL(上海贝岭)
TE=TE(泰科)
FM=FM(富满)
CJ=CJ(长电)
ST=ST(意法)
SK=SK(时科)
ON=ON(安森美)
TM=TM(天微)
TP=TP(拓微)
TI=TI(德州仪器)
MD=MD(明达)
EG=EG(屹晶微)
HF=HF(宏发)
DY=DY(迪一)
MK=MK(米客方德)
国民=Nationz(国民技术)
中芯=SMIC(中芯国际)
富士=Fuji Electric(富士电机)
国星=Nationstar(国星光电)
贝岭=BL(上海贝岭)
FH = FH(风华)
BL = BL(上海贝岭)
TE = TE(泰科)
FM = FM(富满)
CJ = CJ(长电)
ST = ST(意法)
SK = SK(时科)
ON = ON(安森美)
TM = TM(天微)
TP = TP(拓微)
TI = TI(德州仪器)
MD = MD(明达)
EG = EG(屹晶微)
HF = HF(宏发)
DY = DY(迪一)
MK = MK(米客方德)
国民 = Nationz(国民技术)
中芯 = SMIC(中芯国际)
富士 = Fuji Electric(富士电机)
国星 = Nationstar(国星光电)
贝岭 = BL(上海贝岭)
[ZIYING_CONFIG]
Index=liexin_ziying
Index = liexin_ziying
[SEARCH_KEYWORD_MAPPING]
`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$` = ${1}${2}Ω${4}
......@@ -107,7 +120,7 @@ Index=liexin_ziying
8=kw
[official_website]
[OFFICIAL_WEBSITE]
1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
3 = https://www.rocelec.com/search?q=liexin
......
package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/requests"
"search_server/service"
"search_server/service/transformer"
"strings"
)
func GetDataIndex(c *gin.Context) {
var r requests.GetDataIndexRequest
_ = c.ShouldBind(&r)
if r.Keyword != "" {
word, _ := php2go.URLDecode(r.Keyword)
r.Keyword = strings.ToUpper(word)
}
if r.KNums != 0 {
r.Stock = r.KNums
}
//获取所有合并供应商列表
supplierList := config.GetSectionValues("SEARCH_SUPPLIER_MERGE")
supplierName := config.Get("SUPPLIER_ALL." + r.SupplierId).String()
if supplierName == "" && r.IsSort != 2 {
c.JSON(200, common.ErrorResponse(1, "供应商id有误"))
return
}
if r.SupplierId != "" && r.IsSort == 2 {
//所有供应商列表
//如果供应商不在合并供应商列表,则实时更新数据
if supplierName != "" && !php2go.InArray(r.SupplierName, supplierList) {
redisCon := gredis.Conn("search_w")
defer redisCon.Close()
//获取stockFlag
res, err := redis.Bool(redisCon.Do("SADD", "search_keyword_member", r.Keyword+"_"+r.SupplierName))
if err != nil {
fmt.Println(err)
}
if res {
_, err := redis.Bool(redisCon.Do("INCR", config.Get("redis_all.SEARCH_API_TOTAL_PRE").String()+r.SupplierName))
if err != nil {
fmt.Println(err)
}
}
r.FirstSearchPage = 2
quoteService := service.QuoteService{}
result, _ := quoteService.GetGoodsBySupplier(r.GetGoodsBySupplierRequest)
c.JSON(200, common.SuccessResponse(1, "", result))
return
}
}
//查询并输出数据
//获取除了专卖的供应商组装查询条件
queryStr := getDataQueryStr(r, supplierList)
esResult, err := es.CurlESMSearch(queryStr)
if err != nil {
return
}
goodsIds := service.GetGoodsIdsByEsMsearch(esResult)
goodsList, err := service.GetGoodsInfo(goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList)
result := service.GetReturnSupplierData(dullData)
result["total"] = gjson.Get(esResult, "hits.total").Int()
result["took"] = gjson.Get(esResult, "took").Int()
c.JSON(200, common.SuccessResponse(0, "", result))
}
//获取查询es的条件语句
func getDataQueryStr(r requests.GetDataIndexRequest, supplierList []string) string {
getDataService := service.GetDataService{}
query, _ := getDataService.GetQuery(r.Keyword, r.SupplierName, r.BrandId, r.GoodsNameEq, r.Stock)
//获取专卖的组装查询条件
zhuanmaiQuery, _ := getDataService.GetQuery(r.Keyword, "zhuanmai", "", r.GoodsNameEq, r.Stock)
//类似物料搜索的组装查询条件
alikeQuery, _ := getDataService.GetQuery(r.Keyword, "alike", "", r.GoodsNameEq, r.Stock)
//类似物料供应商列表
alikeSuppliers := config.GetSectionValues("ALIKE_SUPPLIER")
//构建msearch搜索json
var queryStr string
for _, supplierName := range supplierList {
indexQueryStr := `{"index":"` + supplierName + `","type":"goods","preference":"_primary_first"}`
if php2go.InArray(supplierName, alikeSuppliers) {
queryStr = queryStr + indexQueryStr + "\n" + alikeQuery + "\n"
}
if supplierName == "zhuanmai" {
queryStr = queryStr + indexQueryStr + "\n" + zhuanmaiQuery + "\n"
} else {
queryStr = queryStr + indexQueryStr + "\n" + query + "\n"
}
}
return queryStr
}
......@@ -33,7 +33,7 @@ func QuoteIndex(c *gin.Context) {
flag := 1
var res map[string]interface{}
if r.FollowHit != 0 && r.FollowHit != 1 {
res, _ = quoteService.GetGoodsBySupplier(r)
res, _ = quoteService.GetGoodsBySupplier(r.GetGoodsBySupplierRequest)
if len(res) > 0 {
flag = 0
}
......@@ -41,7 +41,7 @@ func QuoteIndex(c *gin.Context) {
return
}
//获取供应商名称
supplierNameMap := config.Cfg.Section("supplier_all").KeysHash()
supplierNameMap := config.Cfg.Section("SUPPLIER_ALL").KeysHash()
supplierName, exist := supplierNameMap[r.SupplierId]
if !exist {
c.JSON(200, common.ErrorResponse(1, "供应商有误"))
......@@ -51,7 +51,7 @@ func QuoteIndex(c *gin.Context) {
//mouser同步请求搜索
res, _ = mouserOrg(r.Keyword, r.SupplierId)
} else {
res, _ = quoteService.GetGoodsBySupplierName(r)
res, _ = quoteService.GetGoodsBySupplierName(r.GetGoodsBySupplierRequest)
}
if len(res) > 0 {
flag = 0
......
......@@ -3,12 +3,10 @@ module search_server
go 1.14
require (
github.com/basgys/goxml2json v1.1.0
github.com/coreos/etcd v3.3.18+incompatible
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3
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-xorm/xorm v0.7.9
github.com/gogo/protobuf v1.3.1 // indirect
......@@ -18,39 +16,28 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // 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/idoubi/goz v1.0.0
github.com/imroc/req v0.3.0
github.com/jinzhu/gorm v1.9.12
github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 // indirect
github.com/mholt/certmagic v0.9.3 // indirect
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/micro/go-micro v1.16.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/common v0.10.0
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/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.0
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
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/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
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
)
......
......@@ -7,20 +7,20 @@ import (
//获取需要排除的品牌id
//branType = 1 : 联营 2 : 自营
func GetExcludeBrandIds(brandType int) (excludeBrandIds []int) {
isNoTi := config.Get("brand.IS_NOT_TI").String()
isNoTi := config.Get("BRAND.IS_NOT_TI").String()
//如果关闭,直接返回空数据
if isNoTi == "1" {
if isNoTi == "0" {
return
}
//返回联营的brand_id切片
if brandType == 1 {
tiLyBrandIds := config.Get("brand.TI_LY_BRAND_IDS").Ints(",")
tiLyBrandIds := config.Get("BRAND.TI_LY_BRAND_IDS").Ints(",")
excludeBrandIds = tiLyBrandIds
//获取的是字符串
return
}
//返回自营的ti的brand_id切片
tiZyBrandId := config.Get("brand.TI_ZY_BRAND_IDS").Ints(",")
tiZyBrandId := config.Get("BRAND.TI_ZY_BRAND_IDS").Ints(",")
excludeBrandIds = tiZyBrandId
return
......
......@@ -92,6 +92,8 @@ type DullGoodsData struct {
Alike string `json:"alike"`
BrandUrl string `json:"brand_url"`
GoodsUrl string `json:"goods_url"`
CompanyName string `json:"-"`
ProviderName string `json:"-"`
}
type Attr struct {
......
......@@ -2,6 +2,7 @@ package model
//联营请求外链后格式化数据
type LyClearGoodsList struct {
GoodsId string `json:"goods_name"` //型号id
GoodsName string `json:"goods_name"` //型号名称
BrandName string `json:"brand_name"` //品牌名称
Desc string `json:"desc"` //描述
......@@ -10,8 +11,9 @@ type LyClearGoodsList struct {
Url string `json:"url"` //sku对应供应商的商品详情
GoodsImg string `json:"goods_img"` //sku图片
Cat string `json:"cat"` //分类
Encoded string `json:"encoded"` //内部编码
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
SinglePrice float64 `json:"single_price"` //最小单价
Stock int64 `json:"increment"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量
......@@ -51,7 +53,7 @@ Array
)
*/
type SUPPLIER_REDIS_INFO_ struct {
SupplierId int64 `json:"supplier_id"` //供应商id
SupplierId int64 `json:"supplier_id"` //供应商id
SupplierNickname string `json:"supplier_nickname"` //供应商名称
AdText string `json:"ad_text"` //供应商描述
CnDelivery string `json:"cn_delivery"` //国内交货时间
......@@ -117,22 +119,22 @@ Array
)
*/
type LySkuInfo struct {
SpuId string `json:"spu_id"` //spu_id
Encoded string `json:"encoded"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
OldGoodsId int64 `json:"old_goods_id"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
BatchSn string `json:"batch_sn"`
Stock int64 `json:"stock"`
UpdateTime int64 `json:"update_time"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
SupplierId int64 `json:"supplier_id"`
IsExpire string `json:"is_expire"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
SpuId string `json:"spu_id"` //spu_id
Encoded string `json:"encoded"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
OldGoodsId int64 `json:"old_goods_id"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
BatchSn string `json:"batch_sn"`
Stock int64 `json:"stock"`
UpdateTime int64 `json:"update_time"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
SupplierId int64 `json:"supplier_id"`
IsExpire string `json:"is_expire"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []*TierItem `json:"ladder_price"`
}
......
......@@ -26,7 +26,7 @@ type PriceJson struct {
func getSupplier(supplierId string) {
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
supplierInfoStr, _ := redis.String(redisCon.Do("HGET", config.Get("supplier.SUPPLIER_REDIS_PRE")))
supplierInfoStr, _ := redis.String(redisCon.Do("HGET", config.Get("supplier.SUPPLIER_REDIS_PRE"),supplierId))
if supplierInfoStr != "" {
//序列化出来使用
} else {
......
......@@ -12,7 +12,7 @@ var (
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",
path+"/redis_config.ini")
path+"/redis_config.ini", path+"/message.ini")
return
}
......
......@@ -3,6 +3,7 @@ package es
import (
"github.com/imroc/req"
"math/rand"
"net/http"
"search_server/pkg/config"
)
......@@ -40,20 +41,45 @@ POST /_bulk
{ "index":{"_index":"hcy1","_type":"goods","_id":"6666"} }
{ "name":"mary smith","age":32 }
eg:
es.BulkES(`{"index":{"_index":"hcy1","_type":"goods","_id":"8888888"} }
{ "name":"john doe","age":25 }
{ "index":{"_index":"hcy1","_type":"goods","_id":"9999999"} }
{ "name":"mary smith","age":32 }`)
方法一:
param := `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`+"\n"+`{"name":"john doe","age":25 }`+"\n"+`{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`+"\n"+`{"name":"john doe","age":25 }`+"\n"
result,err := es.BulkES(param)
println(result,err)
方法二:
lines := []string{
`{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`,
`{"name":"john doe","age":25 }`,
`{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`,
`{"name":"mary smith","age":32 }`,
}
param := strings.Join(lines, "\n")+"\n"
*/
*/
func BulkES(param string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
esUrl := endpoints[rand.Intn(len(endpoints))] //随机获取一个节点进行请求
params := req.BodyJSON(param)
resp, err := req.Post(esUrl+"/_bulk", params)
esUrl := endpoints[rand.Intn(len(endpoints))] //随机获取一个节点进行请求
//params := req.BodyJSON(param)
//req.Debug = true
header := make(http.Header)
header.Set("Content-Type", "application/x-ndjson")
resp, err := req.Post(esUrl+"/_bulk", header, param)
if err != nil {
return
}
result = resp.String()
return
}
\ No newline at end of file
}
func CurlESMSearch(queryJson string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
req.Debug = true
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(queryJson)
resp, err := req.Post(esUrl+"/_msearch", params)
if err != nil {
return
}
result = resp.String()
return
}
package message
import (
"encoding/json"
"fmt"
"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 {
IsAtAll bool `json:"isAtAll"`
}
func SendDingdingMessage(content string) {
var (
requestData DingDingRequest
apiUrl, token string
//resp *req.Resp
err error
)
//todo: 需要配置一个搜索服务的专属警告
content = "仓储同步告警 : " + content
requestData.MsgType = "text"
requestData.Text = map[string]string{
type DingDingResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
func DingDingPush(content string) (result DingDingResponse, err error) {
accessToken := config.Get("DINGDING.SEARCH_API_MONITOR").String()
webhook := "https://oapi.dingtalk.com/robot/send?access_token=" + accessToken
data := make(map[string]interface{})
data["msgtype"] = "text"
data["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)
_, err = req.Post(apiUrl, params)
if err != nil {
log.Error(err)
dataStrByte, _ := json.Marshal(data)
dataStr := string(dataStrByte)
fmt.Println(dataStr)
dataStr = strings.Replace(dataStr, "\\", "\\\\", -1)
params := req.BodyJSON(dataStr)
resp, err := req.Post(webhook, params, req.Header{
"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)
}
......@@ -44,11 +44,13 @@ mgo包的文档 : https://godoc.org/gopkg.in/mgo.v2
#### 5.钉钉群消息以及短信
直接在pkg/message包调用对应的函数即可:
钉钉的为```message.SendDingdingMessage```
短信为```message.SendMessage```
钉钉的为```message.DingDingPush```
#### 6.商品信息获取
直接调用```service.GetGoodsInfo```函数即可,传入goods_id的字符串,多个goods_id用逗号隔开(商品服务的请求本来亦是如此),会返回json字符串,然后可以根据自己的需求用gjson获取对应的信息即可
#### 7.ES的基本请求
直接调用```es.CurlES```函数即可,传入索引名称和请求的json参数即可,得到的返回结果是ES的原生结果,可以根据自己的需求用gjson获取对应的信息
#### 7.队列推送
直接调用```mq.PushMsg("xian_test","test")```函数即可(调用方式保持和PHP一致),第一个参数队列名同时也是路由名,第二个是要传的值
package requests
//使用根据供应商获取商品信息方法的通用请求
type GetGoodsBySupplierRequest struct {
Keyword string `form:"keyword"`
SupplierName string `form:"supplier_name"`
Stock int `form:"stock"`
SupplierId string `form:"supplier_id"`
Offset int `form:"offset"`
FollowHit int `form:"follow_hit"`
CheckButton int `form:"check_button"`
GoodsNameEq string `form:"goods_name/eq"`
IsExact int `form:"is_exact"`
BrandId string `form:"brand_id"`
AvailRank int `form:"avail_rank"`
SingleRank int `form:"single_rank"`
StockRank int `form:"stock_rank"`
ComRank int `form:"com_rank"`
FirstSearchPage int `form:"first_search_page"`
P int `form:"p"`
Topic int `form:"topic"`
K1 int `form:"k1"`
K2 int `form:"k2"`
}
package requests
type GetDataIndexRequest struct {
//Keyword string `form:"keyword"`
KNums int `form:"kNums"`
IsSort int `form:"is_sort"`
//SupplierId string `form:"supplier_id"`
//SupplierName string `form:"supplier_name"`
//GoodsNameEq string `form:"goods_name/eq"`
//BrandId string `form:"brand_id"`
//Offset int `form:"offset"`
//FollowHit int `form:"follow_hit"`
//Stock int `form:"stock"`
//IsExact int `form:"is_exact"`
//AvailRank int `form:"avail_rank"`
//SingleRank int `form:"single_rank"`
//StockRank int `form:"stock_rank"`
//ComRank int `form:"com_rank"`
//FirstSearchPage int `form:"first_search_page"`
//P int `form:"p"`
//Topic int `form:"topic"`
//K1 int `form:"k1"`
//K2 int `form:"k2"`
//Keyword string `form:"keyword"`
//SupplierId string `form:"supplier_id"`
//SupplierName string `form:"supplier_name"`
//Stock int `form:"stock"`
GetGoodsBySupplierRequest
}
......@@ -6,30 +6,12 @@ import (
)
type QuoteIndexRequest struct {
Keyword string `form:"keyword"`
CheckButton int `form:"check_button"`
SupplierId string `form:"supplier_id"`
SupplierName string `form:"supplier_name"`
Offset int `form:"offset"`
FollowHit int `form:"follow_hit"`
Stock int `form:"stock"`
GoodsNameEq string `form:"goods_name/eq"`
IsExact int `form:"is_exact"`
BrandId string `form:"brand_id"`
AvailRank int `form:"avail_rank"`
SingleRank int `form:"single_rank"`
StockRank int `form:"stock_rank"`
ComRank int `form:"com_rank"`
FirstSearchPage int `form:"first_search_page"`
P int `form:"p"`
Topic int `form:"topic"`
K1 int `form:"k1"`
K2 int `form:"k2"`
GetGoodsBySupplierRequest
}
type QuoteGetDataRequest struct {
Keyword string `form:"keyword"`
SupplierName string `form:"supplier_name"`
Keyword string `form:"keyword"`
SupplierName string `form:"supplier_name"`
}
func CheckQuoteRequest(r QuoteIndexRequest) (errCode int, errMsg string) {
......@@ -46,9 +28,8 @@ func CheckQuoteRequest(r QuoteIndexRequest) (errCode int, errMsg string) {
return 1, "缺少参数"
}
//判断供应商
if config.Get("supplier_all."+r.SupplierId).String() == "" {
if config.Get("SUPPLIER_ALL."+r.SupplierId).String() == "" {
return 1, "供应商id有误"
}
return
}
......@@ -27,5 +27,9 @@ func InitRouter() *gin.Engine {
r.GET("/search/quote/getDataPur", controller.GetDataPur)
r.POST("/search/quote/getDataPur", controller.GetDataPur)
//GetData控制器相关
r.GET("/search/get_data/index", controller.GetDataIndex)
r.POST("/search/get_data/index", controller.GetDataIndex)
return r
}
......@@ -21,9 +21,7 @@ type CommonLyService struct {
supplier_over_time map[string]int64
supplierId int64 //调用当前方法的供应商ID
supplierName string //调用当前方法的供应商名称
skuEsUpdataList []map[string]interface{} //组装批量更新es数据
spuId string //spuId
skuId string //skuId
skuEsUpdataList []string //组装批量更新es数据
}
//初始化类
......@@ -207,7 +205,57 @@ func (t *CommonLyService) writeBrandInfo(skuInfo *model.LyClearGoodsList) int64
/*
组装推送到es数据
*/
func esSkuInfo(skuInfo *model.LyClearGoodsList,brandId *string) {
func (t * CommonLyService) EsSkuInfo(skuInfo *model.LyClearGoodsList,spuId * string,brandId *string) {
sort := 1; //排序
if skuInfo.SinglePrice >0 && skuInfo.Stock >0 && skuInfo.Stock >= skuInfo.Increment && skuInfo.Stock >= skuInfo.Moq {
sort = 31;
}else if skuInfo.SinglePrice >0 && skuInfo.Stock >0 {
sort = 30;
}else if skuInfo.SinglePrice > 0 {
sort = 28;
}else if skuInfo.Stock >0 {
sort = 29;
}
stock_sort := 1;
if skuInfo.Stock > 0 {
stock_sort = 3;
}
single_price_sort := 1;
if skuInfo.SinglePrice > 0 {
single_price_sort = 3;
}
nowTime := php2go.Time()
param := map[string]interface{}{
"goods_id":skuInfo.GoodsId,
"goods_name":skuInfo.GoodsName,
"auto_goods_name":php2go.Strtoupper(skuInfo.GoodsName),
"brand_id":*brandId,
"brand_name":skuInfo.BrandName,
"supplier_name":t.supplierName,
"class_id1":0,
"class_id2":0,
"class_id3":0,
"spu_id":*spuId,
"sale_time":nowTime,
"create_time":nowTime,
"update_time":nowTime,
"single_price":skuInfo.SinglePrice,
"stock":skuInfo.Stock,
"goods_status":1,
"status":1,
"sort":sort,
"encoded": "",
"encap":"",
"canal_new":"",
"stock_sort":stock_sort, //主要为库存为0的往后排服务
"single_price_sort":single_price_sort, //主要为单价为0的往后排服务
}
paramjson,_ := json.Marshal(param)
_ = append(t.skuEsUpdataList,`{"index":{"_index":"`+t.supplierName+`","_type":"goods","_id":"`+skuInfo.GoodsId+`"}}`)
_ = append(t.skuEsUpdataList,string(paramjson))
}
......
package service
import (
"github.com/gomodule/redigo/redis"
"github.com/uniplaces/carbon"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
"search_server/pkg/gredis"
"strings"
)
type GetDataService struct {
}
func (gs *GetDataService) GetQuery(originKeyword, supplierName, brandId, goodsNameEq string, stock int) (string, error) {
query := elastic.NewBoolQuery()
rex, _ := regexp.Compile(`/[^A-Za-z0-9]+/`)
keyword := rex.ReplaceAllString(originKeyword, "")
keyword = strings.ToUpper(keyword)
//只显示更新时间在一个月内的数据
oneMonthTimeStamp := carbon.Now().SubMonth().Timestamp()
query.Must(elastic.NewRangeQuery("update_time").Gte(oneMonthTimeStamp))
//类似物料搜索
if supplierName == "alike" && keyword != "" {
subQuery := elastic.NewBoolQuery()
subQuery.Should(elastic.NewTermQuery("goods_name_alike", strings.ToUpper(originKeyword)))
subQuery.Should(elastic.NewTermQuery("goods_name", keyword))
} else if supplierName != "zhuanmai" && keyword != "" {
//增加联营精确搜索
if goodsNameEq != "" {
query.Must(elastic.NewTermQuery("auto_goods_name.raw", keyword))
} else {
query.Must(elastic.NewTermQuery("goods_name", keyword))
}
} else {
if keyword != "" {
subQuery := elastic.NewBoolQuery()
subQuery.Should(elastic.NewTermQuery("goods_name", keyword))
}
}
//根据品牌id查找
if brandId != "" {
brandIdSlice := strings.Split(brandId, ",")
var brandIdsParams []interface{}
for _, brandId := range brandIdSlice {
brandIdsParams = append(brandIdsParams, strings.TrimSpace(brandId))
}
query.Must(elastic.NewTermsQuery("brand_id", brandIdsParams...))
}
//去除status=10
query.MustNot(elastic.NewTermQuery("status", 10))
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
//获取stockFlag
stockFlag, _ := redis.Int(redisCon.Do("GET", "StockSwitch"))
//判断库存
if stock > 0 {
limitNumber := 1000000
if stock > 1000000 {
stock = limitNumber
}
query.Must(elastic.NewRangeQuery("stock").Gte(stock))
} else if stockFlag == 1 && supplierName == "zhuanmai" {
query.MustNot(elastic.NewRangeQuery("stock").Gt(0))
}
//是否排除某些品牌数据
excludeBrandIds := model.GetExcludeBrandIds(1)
if len(excludeBrandIds) > 0 {
for _, brandId := range excludeBrandIds {
query.MustNot(elastic.NewTermQuery("brand_id", brandId))
}
}
source := elastic.NewSearchSource()
//source.StoredFields("goods_id", "old_goods_id", "status")
//综合排序
source.Sort("status", false)
source.Sort("sort", false)
source.Sort("_score", false)
source.Sort("update_time", false)
source.Sort("stock", false)
source.Sort("single_price", true)
source.From(0)
source.Size(2)
source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source)
return searchRequest.Body()
}
package service
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/imroc/req"
"github.com/tidwall/gjson"
......@@ -230,5 +231,18 @@ func GetGoodsIdsByEs(res string) (goodsIds []string) {
for _, item := range gjArray {
goodsIds = append(goodsIds, item.String())
}
fmt.Println(goodsIds)
return
}
func GetGoodsIdsByEsMsearch(res string) (goodsIds []string) {
//直接用gjson去获取goods_id列表
gjArray := gjson.Get(res, "responses.hits.hits.#._source.goods_id").Array()
for _, item := range gjArray {
goodsIds = append(goodsIds, item.String())
}
fmt.Println(goodsIds)
return
}
......@@ -14,7 +14,7 @@ import (
)
func GetSupplierIndex(supplierId string) (supplierIndex string) {
supplierIndexMap := config.Cfg.Section("supplier_all").KeysHash()
supplierIndexMap := config.Cfg.Section("SUPPLIER_ALL").KeysHash()
if index, exist := supplierIndexMap[supplierId]; exist {
return index
}
......@@ -33,7 +33,7 @@ func GetSupplierIndex(supplierId string) (supplierIndex string) {
return
}
func GetGoodsBySupplierNameQuery(r requests.QuoteIndexRequest) (string, error) {
func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string, error) {
query := elastic.NewBoolQuery()
subQuery := elastic.NewBoolQuery()
subQuery2 := elastic.NewBoolQuery()
......@@ -172,7 +172,7 @@ func GetGoodsBySupplierNameQuery(r requests.QuoteIndexRequest) (string, error) {
return searchRequest.Body()
}
func GetGoodsBySupplierIdQuery(r requests.QuoteIndexRequest) (string, error) {
func GetGoodsBySupplierIdQuery(r requests.GetGoodsBySupplierRequest) (string, error) {
r.SupplierId = strings.TrimSpace(r.SupplierId)
source := elastic.NewSearchSource()
query := elastic.NewBoolQuery()
......@@ -214,7 +214,7 @@ func GetGoodsBySupplierIdQuery(r requests.QuoteIndexRequest) (string, error) {
//判断是否存在类似物料搜索
supplierIndexName := GetSupplierIndex(r.SupplierId)
//获取相似物料供应商列表
alikeSuppliers := config.Cfg.Section("alike_supplier").KeyStrings()
alikeSuppliers := config.Cfg.Section("ALIKE_SUPPLIER").KeyStrings()
if php2go.InArray(supplierIndexName, alikeSuppliers) && keyword != "" {
query.Should(elastic.NewTermQuery("goods_name_alike", keyword))
}
......
......@@ -5,7 +5,7 @@ import (
"fmt"
"github.com/imroc/req"
"github.com/syyongx/php2go"
. "github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/es"
......@@ -19,7 +19,7 @@ type QuoteService struct {
}
//根据供应商获取商品信息
func (qs *QuoteService) GetGoodsBySupplier(r requests.QuoteIndexRequest) (result map[string]interface{}, err error) {
func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) {
//索引字典
supplierIndex := query.GetSupplierIndex(r.SupplierId)
//获取查询条件
......@@ -36,12 +36,12 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.QuoteIndexRequest) (result
goodsList, err := GetGoodsInfo(goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList)
result = GetReturnSupplierData(dullData)
result["total"] = Get(esResult, "hits.total").Int()
result["took"] = Get(esResult, "took").Int()
result["total"] = gjson.Get(esResult, "hits.total").Int()
result["took"] = gjson.Get(esResult, "took").Int()
return
}
func (qs *QuoteService) GetGoodsBySupplierName(r requests.QuoteIndexRequest) (result map[string]interface{}, err error) {
func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) {
supplierIndex := r.SupplierName
queryString, err := query.GetGoodsBySupplierNameQuery(r)
fmt.Println(supplierIndex)
......@@ -54,8 +54,8 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.QuoteIndexRequest) (re
goodsList, err := GetGoodsInfo(goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList)
result = GetReturnSupplierData(dullData)
result["total"] = Get(esResult, "hits.total").Int()
result["took"] = Get(esResult, "took").Int()
result["total"] = gjson.Get(esResult, "hits.total").Int()
result["took"] = gjson.Get(esResult, "took").Int()
return
}
......
package service
import (
"search_server/middleware"
"search_server/model"
"strings"
)
//推送搜索关键词
func ShowSku() {
func ShowSku(goods model.DullGoodsData) {
goodsIdLen := len(goods.GoodsId)
if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" {
return
}
referer := middleware.Context.Request.Header.Get("referer")
if strings.Contains(referer, "www.ichunt.com/s/?k") {
if goods.ProviderName != "" {
goods.BrandName = goods.ProviderName
}
if goods.CompanyName != "" {
goods.SupplierName = goods.CompanyName
}
result := make(map[string]string)
result["goods_id"] = goods.GoodsId
//todo : brand_name正则转换
result["brand_name"] = goods.BrandName
if goods.SupplierId == 17 {
result["supplier_name"] = goods.SupplierName + "-" + goods.Canal
result["supplier_type"] = goods.SupplierName
} else if goods.CompanyName != "" && goods.ProviderName != "" {
result["supplier_name"] = "撮合-" + goods.SupplierName
result["supplier_type"] = "撮合"
} else {
result["supplier_name"] = goods.SupplierName
result["supplier_type"] = goods.SupplierName
}
//todo : goods_name正则替换
result["goods_name"] = goods.GoodsName
if (goodsIdLen < 19 || goods.SupplierId == 10000) && result["supplier_type"] != "撮合" {
result["keyword"] = strings.TrimSpace("keyword")
}
result["adtag"], _ = middleware.Context.Cookie("adtag")
if goodsIdLen < 19 {
result["status"] = "1"
}
}
\ No newline at end of file
}
}
......@@ -123,7 +123,7 @@ func getSupplierInfo(goods model.DullGoodsData) (model.DullGoodsData, error) {
}
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 {
goods.SupplierWebsite = strings.Replace(website, "liexin", goods.SupplierName, -1)
} else {
......
......@@ -5,7 +5,7 @@ import (
"fmt"
"github.com/syyongx/php2go"
"search_server/boot"
"search_server/controller"
"search_server/pkg/mq"
)
func StrRandom(lenNum int) string {
......@@ -29,6 +29,5 @@ func main() {
if err := boot.Boot(path); err != nil {
fmt.Println(err)
}
fmt.Println(controller.GetData("lm358","arrow"))
mq.PushMsg("xian_test","test")
}
......@@ -38,4 +38,4 @@ func FloatRound(f float64, n int) float64 {
//fmt.Println(format)
res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64)
return res
}
\ No newline at end of file
}
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