Commit 9a741cea by mushishixian
parents c6c884f9 5f5216e7
[rabmq]
url = amqp:;guest:guest@192.168.2.232:5672/
url = amqp://guest:guest@192.168.2.232:5672/
;存放本系统所有的队列名称
[rabmq_all]
; bom任务id
......
package controller
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"search_server/model"
"search_server/pkg/common"
"search_server/service/ly"
)
//搜索型号
func GetMouserData(c *gin.Context) {
goodsName, _ := c.GetPostForm("goods_name")
lycon := new(ly.CommonLyService)
//lycon := new(ly.CommonLyService)
//调外链拿数据
apiData := ly.OutLinkMouser(&goodsName,"1")
//供应商详情
supplierInfo := model.SUPPLIER_REDIS_INFO_{
SupplierId:14,
SupplierNickname: "mouser",
}
err := lycon.GetSkuByGoodsSn(apiData,&supplierInfo)
var errCode int
if !err {
errCode = 1
}
res := common.BomResponse{
ErrCode: errCode,
ErrMsg: "",
Data: "",
apiData := ly.OutLinkMouser(&goodsName,"-1")
//var shu string
//for _, info := range apiData {
//
// //PrintHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info",info)
// //jsonDatas,_ := json.Marshal(map[string]interface{}{
// // "dddd":"333333",
// // "ninifa":"333333",
// // "3333":"333333",
// // "gagaga":"333333",
// //})
// //fmt.Println(len(info))
// josn, errs := json.Marshal(info)
// if errs != nil {
// fmt.Println("错误")
// }
// shu += string(josn)
//}
// jsonDatas,_ := json.Marshal(map[string]interface{}{
// "dddd":"333333",
// "ninifa":"333333",
// "3333":"333333",
// "gagaga":"333333",
// })
josn, errs := json.Marshal(apiData)
if errs != nil {
fmt.Println("错误")
}
c.JSON(200,res)
c.JSON(200,string(josn))
//供应商详情
//supplierInfo := model.SUPPLIER_REDIS_INFO{
// SupplierId:14,
// SupplierNickname: "mouser",
//}
//err := lycon.GetSkuByGoodsSn(apiData,&supplierInfo)
//var errCode int
//if !err {
// errCode = 1
//}
//res := common.BomResponse{
// ErrCode: errCode,
// ErrMsg: "",
// Data: "",
//}
//c.JSON(200, map[string]interface{}{
// "error_code":777777,
// "err_msg":"ddddd2",
//})
}
......@@ -31,7 +31,6 @@ func Zyh(ctx *gin.Context){
ctx.JSON(200,zyhResponse)
}
fmt.Println("6666666666666")
fmt.Printf("%+v",zyhResponse)
//fmt.Printf("%+v",zyhResponse)
ctx.JSON(200,zyhResponse)
}
......@@ -70,6 +70,11 @@ type ApiGoods struct {
ActivityEndTime int64 `json:"activity_end_time,omitempty"`
}
type ZiyinGoodsInfo struct {
GoodsNameOrg string `json:"goods_name_org"`
DullGoodsData
}
//经过处理后的商品数据
type DullGoodsData struct {
ApiGoods
......
......@@ -60,7 +60,7 @@ Array
)
)
*/
type SUPPLIER_REDIS_INFO_ struct {
type SUPPLIER_REDIS_INFO struct {
SupplierId int64 `json:"supplier_id"` //供应商id
SupplierNickname string `json:"supplier_nickname"` //供应商名称
AdText string `json:"ad_text"` //供应商描述
......
......@@ -267,8 +267,8 @@ func auth() bool {
return false
}
// interface{}转为 []interface{}
//將任意類型的切片轉為 []interface{}
func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool) {
val, ok := isSlice(slice)
......@@ -312,3 +312,14 @@ func StrPadLeft(input string, padLength int, padString string) string {
return output[:padLength-len(input)] + input
}
//移除字符串切片中某個元素
func RemoveSliceString(s []string, i string) []string {
b := make([]string,0)
for _,v:=range s{
if v != i{
b= append(b,v)
}
}
return b
}
......@@ -21,6 +21,7 @@ func InitRouter() *gin.Engine {
r.POST("/search/bom/recommend", controller.Recommend)
r.POST("search/ZiYing/zyh", controller.Zyh)
r.POST("search/mouser/GetMouserData", controller.GetMouserData)
r.GET("search/mouser/GetMouserData", controller.GetMouserData)
//快手平台相关
r.GET("/search/quote", controller.QuoteIndex)
......
......@@ -50,6 +50,27 @@ func (t *CommonLyService) LyServerRun(){
t.flag = strings.TrimSpace(requstValue[0])
}
}
if t.flag == "101" {
t.ctx.Header("Content-Type", "text/html; charset=utf-8")
}
}
/*
格式化数据直接输出浏览器
*/
func PrintHtml(ctx *gin.Context,flag *string,data string,jsondata interface{}) {
if *flag == "101" {
if jsondata != "" {
jsonData,err := json.Marshal(jsondata)
if err != nil {
fmt.Println("错误:-----",err)
}else{
ctx.JSON(200,data+"</br>"+string(jsonData))
}
}else{
ctx.JSON(200,data+"</br>")
}
}
}
/*
......@@ -58,9 +79,14 @@ func (t *CommonLyService) LyServerRun(){
@param goods_list 请求联营格式化后的数据
@param supplier_info 供应商商品详情
*/
func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoodsList,supplierInfo *model.SUPPLIER_REDIS_INFO_) bool {
func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoodsList,supplierInfo *model.SUPPLIER_REDIS_INFO) bool {
t.LyServerRun(); //初始化变量
if len(goodsList) == 0 {
PrintHtml(t.ctx,&t.flag,"没有数据","")
return true
}
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
......@@ -73,6 +99,21 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
snSku := php2go.Md5(strings.ToLower(goodsSn))
skuId,_ := gredis.String(redisWrite.Do("HGET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),snSku)) //查询唯一值,反查sku_id
//PrintHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info",info)
//jsonData,err := json.Marshal(map[string]interface{}{
// "dddd":"333333",
// "ninifa":"333333",
// "3333":"333333",
// "gagaga":"333333",
//})
jsonData,err := json.Marshal(info)
if err != nil {
fmt.Println("错误:-----",err)
}else{
t.ctx.JSON(200,string(jsonData))
}
continue;
/**********新增sku**************/
skuFlag := false; //是否新增或者更新db+redis,为true则新增
if skuId == "" { //redis没有此sku,创建
......@@ -150,6 +191,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
}
t.pushEs(); //最后推送ES
return true
}
......
......@@ -11,11 +11,13 @@ import (
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/middleware"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/service/transformer"
"strconv"
"strings"
)
......@@ -140,7 +142,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
*/
func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassList,classLight []*model.ZhyClassListModel,aType byte) (rsp *model.ZyhResponse){
var (
goods_name_arr []map[string]string
goods_name_arr []string
keyword string
is_sample bool
redisConn redis.Conn
......@@ -157,12 +159,12 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
response = make(map[string]interface{},0)
keyword = ""
goods_name_arr = make([]map[string]string,0)
goods_name_arr = make([]string,0)
if req["goods_name/condition"] != "" {
goodsNameCondition := strings.ToUpper(req["goods_name/condition"])
ziyingBrandReplace := config.Cfg.Section("ZIYING_BRAND_REPLACE").KeysHash()
if ziyingBrandReplace != nil && ziyingBrandReplace[goodsNameCondition] != "" {
goods_name_arr = append(goods_name_arr,map[string]string{"brand_name/condition":ziyingBrandReplace[goodsNameCondition]})
goods_name_arr = append(goods_name_arr,req["brand_name/condition"])
delete(req,"goods_name/condition")
}
}
......@@ -398,6 +400,34 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
return rsp
}
hits2_source := gjson.Get(result, "hits.hits.#._source").Array()
hitsTotal := gjson.Get(result, "hits.total").Int()
hitsHits := gjson.Get(result, "hits.hits").Array()
if hitsTotal > 0 && len(hits2_source) > 0{
goodsIds := gjson.Get(result, "hits.hits.#._id").Array()
fmt.Println("goodsIds",goodsIds)
goodsIdsStrArr := make([]string,0)
for _,v := range goodsIds{
goodsIdsStrArr = append(goodsIdsStrArr,v.String())
}
goodsList,_ := GetGoodsInfo(goodsIdsStrArr)
flag = 0
response["total"] = gjson.Get(result,"hits.total").String()
for _ ,esGoodsInfo := range hitsHits{
source := esGoodsInfo.Map()["_source"].Map()
source = source
//goods_id := esGoodsInfo.Map()["_id"].Int()
goods_id_str := esGoodsInfo.Map()["_id"].String()
//整理自营数据参数
_,ok := dullZiYingGoodsInfo(goods_id_str,keyword,goods_name_arr,goodsList)
if ok {
}
}
}
rsp.Data = response
return rsp
}
......@@ -456,7 +486,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
}
fmt.Println(*searchValue)
//fmt.Println(*searchValue)
keywordUper := strings.ToUpper(*searchValue)
mathExactGoodsName := config.Cfg.Section("mathExactGoodsName").KeysHash()
......@@ -507,6 +537,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
if len(goods_name_arr) > 0{
query.Must(elastic.NewMatchQuery("goods_name_cn",strings.Join(goods_name_cn," ")).MinimumShouldMatch("100%"))
}
case "brand_name":
term_v = strings.Split(*searchValue,",")
*searchValue = strings.ToUpper(strings.TrimSpace(*searchValue))
......@@ -639,4 +670,102 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
}
return true
}
\ No newline at end of file
}
//整理自营数据参数
func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []string,goods_list []model.ApiGoods) (ziyinGoodsInfo model.ZiyinGoodsInfo, ok bool){
isHas := false
for _,goods_info:= range goods_list{
if goods_info.GoodsId == goods_id_str{
isHas = true
ziyinGoodsInfo.ApiGoods = goods_info
ziyinGoodsInfo.GoodsNameOrg = goods_info.GoodsName
break
}
}
if !isHas{
return ziyinGoodsInfo,false
}
//高亮
if len(goods_name_arr) > 0{
goods_name_arr_tmp := goods_name_arr
for _,v:= range goods_name_arr{
if strings.TrimSpace(v) == ""{
goods_name_arr_tmp = common.RemoveSliceString(goods_name_arr_tmp,v)
}
}
goods_name_arr = goods_name_arr_tmp
str_temp :=strings.Join(goods_name_arr,"|")
str_temp = strings.ToUpper(strings.ReplaceAll(str_temp,"Μ","μ"))
str_temp = regexp.QuoteMeta(str_temp)
str_temp = strings.ToUpper(strings.ReplaceAll(str_temp,"/","\\/"))
reg := regexp.MustCompile(`(`+str_temp+`)`)
for k,v := range []string{ziyinGoodsInfo.SkuName,ziyinGoodsInfo.BrandName,ziyinGoodsInfo.GoodsName,ziyinGoodsInfo.GoodsBrief}{
re_temp := reg.ReplaceAllString(v,"<b class='f-red'>${1}</b>")
if re_temp != ""{
switch k {
case 0:
ziyinGoodsInfo.SkuName = re_temp
case 1:
ziyinGoodsInfo.BrandName = re_temp
case 2:
ziyinGoodsInfo.GoodsName = re_temp
case 3:
ziyinGoodsInfo.GoodsBrief = re_temp
}
}
}
}
if keyword != ""{
if ziyinGoodsInfo.SkuName != ""{
//如果是属性搜索
if (php2go.Strpos(keyword,",",0)) >= 0{
keywordSlice := strings.Split(keyword,",")
for _,v := range keywordSlice{
reg := regexp.MustCompile("(?i)"+v)
ziyinGoodsInfo.SkuName = reg.ReplaceAllString(ziyinGoodsInfo.SkuName,"<b class='f-red'>"+strings.ToUpper(v)+"</b>")
}
}
}else{
reg := regexp.MustCompile("(?i)"+keyword)
ziyinGoodsInfo.SkuName = reg.ReplaceAllString(ziyinGoodsInfo.GoodsName,"<b class='f-red'>"+strings.ToUpper(keyword)+"</b>")
}
}else{
if ziyinGoodsInfo.SkuName != ""{
ziyinGoodsInfo.SkuName =ziyinGoodsInfo.GoodsName
}else{
ziyinGoodsInfo.SkuName = ziyinGoodsInfo.SkuName
}
}
referer := middleware.Context.GetHeader("Referer")
if referer != ""{
dome := strings.Split(referer,".com")
if len(dome) > 0{
ziyinGoodsInfo.GoodsUrl = dome[0]+".com/item/"+ziyinGoodsInfo.GoodsId+".html"
ziyinGoodsInfo.BrandUrl = dome[0]+".com/v3/brand/list/"+strconv.Itoa(ziyinGoodsInfo.BrandId)+".html"
}
}
///立创商品增加编码L
if ziyinGoodsInfo.Encoded != "" && ziyinGoodsInfo.SelfSupplierType == 2{
ziyinGoodsInfo.Encoded = ziyinGoodsInfo.Encoded+"-L"
}
ziyinGoodsInfo.LastSearchTime = common.GetLastSearchTime(goods_id_str)
go transformer.ShowSku(model.DullGoodsData{ApiGoods:ziyinGoodsInfo.ApiGoods})
if keyword != "---"{
dullGoodsData,err:= transformer.MetGoodsInfo(ziyinGoodsInfo.DullGoodsData)
if err == nil{
ziyinGoodsInfo.DullGoodsData = dullGoodsData
}
}
return ziyinGoodsInfo,true
}
package main
import (
"fmt"
"reflect"
"regexp"
"strings"
)
func remove2(s interface{}, deleteVal int) []interface{} {
val := reflect.ValueOf(s)
sliceLen := val.Len()
out := make([]interface{}, sliceLen)
if val.Kind() == reflect.Slice {
sliceLen := val.Len()
for i := 0; i < sliceLen; i++ {
if val.Index(i).Int() != int64(deleteVal){
out[i] = val.Index(i).Interface()
}
}
}
return out
}
func main(){
a := []int{1,2,3,4,5}
fmt.Println(remove2(a,3))
test := "a,b,c,d,e"
aaa := test
keywordSlice := strings.Split(test,",")
for _,v := range keywordSlice{
reg := regexp.MustCompile("(?i)"+v)
aaa = reg.ReplaceAllString(aaa,"<b class='f-red'>"+strings.ToUpper(v)+"</b>")
fmt.Println(aaa)
}
}
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