Commit 3cb876c1 by mushishixian

fix

parents 02711508 9c68f844
......@@ -8,3 +8,4 @@ cmd.exe~
/cmd/logs/
/cmd/*.exe~
/cmd/logs
/bat/logs/
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/search_server.go -config=../conf/config.ini
\ No newline at end of file
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/search_http_server.go -config=../conf/config.ini
\ No newline at end of file
::set MICRO_REGISTRY=etcd
::set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/search_http_server.go -config=../conf
\ No newline at end of file
......@@ -10,7 +10,7 @@ import (
func main() {
cService:=micro.NewService(
micro.Name("go.micro.server.search"))
micro.Name("go.micro.grpc.search"))
cService.Init()
err:=bom.RegisterBomServiceHandler(cService.Server(),service.NewBomServiceImpl())
......
package main
import (
"flag"
"fmt"
"os"
"search_server/boot"
"search_server/pkg/gredis"
"search_server/service"
)
func main() {
//MouserService := service.NewMouserServiceImpl()
//MouserGetData(MouserService)
var path string
flag.StringVar(&path, "config", "conf", "配置文件")
flag.Parse()
if err := boot.Boot(path); err != nil {
panic(err)
}
lock_key := "searchapi_6666";
//flag := gredis.Set(lock_key,php2go.Time()+2)
flag := gredis.Setnx(lock_key,2222)
fmt.Println(flag)
os.Exit(1)
dd := service.OutLink("LM358","-1")
print("niin")
print(dd)
......
package controller
import (
"github.com/gin-gonic/gin"
"net/http"
"search_server/model"
"search_server/service"
)
func Zyh(ctx *gin.Context){
zyServiceImpl := service.NewZyServiceImpl()
zyhRequest := &model.ZyhRequest{}
zyhResponse := &model.ZyhResponse{}
if err := ctx.ShouldBind(zyhRequest); err != nil{
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err := zyServiceImpl.Zyh(ctx,zyhRequest,zyhResponse)
if err != nil{
}
}
......@@ -33,6 +33,7 @@ require (
github.com/stretchr/testify v1.5.1 // indirect
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.0
github.com/urfave/cli v1.22.4 // indirect
github.com/uniplaces/carbon v0.1.6
go.etcd.io/bbolt v1.3.4
go.uber.org/zap v1.14.1 // indirect
......
package model
type ZyhRequest struct {
Yo4tewUid string `form:"Yo4teW_uid"`
ClassIdcondition int64 `form:"class_id/condition"`
Brand_idCondition string `form:"brand_id/condition"`
StockRank string `form:"stock_rank"` //库存排序
AvailRank string `form:"avail_rank"` //显示有货的
ComRank string `form:"com_rank"` //综合排序
SingleRank string `form:"single_rank"` //价格排序
PackingCondition string `form:"packing/condition"`
EncapCondition string `form:"encap/condition"`
P string `form:"p"`
NeedAggs string `form:"need_aggs"`
}
type ZyhResponse struct {
error_code int64 `json:"error_code"`
error_msg string `json:"error_msg"`
data interface{}
}
\ No newline at end of file
......@@ -71,6 +71,24 @@ func Set(key string, data interface{}) error {
return nil
}
//Redis Setnx(SET if Not eXists) 命令在指定的 key 不存在时,为 key 设置指定的值。
func Setnx(key string, data interface{}) error {
conn := writeConn.Get()
defer conn.Close()
value, err := json.Marshal(data)
if err != nil {
return err
}
_, err = conn.Do("SETNX", key, value)
if err != nil {
return err
}
return nil
}
func Exists(key string) bool {
conn := readConn.Get()
defer conn.Close()
......
......@@ -14,6 +14,7 @@ func InitRouter() *gin.Engine {
//路由
r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend)
r.POST("search/ZiYing/zyh", controller.Zyh)
//快手平台相关
r.GET("/search/quote", controller.QuoteIndex)
......
package service
import (
"fmt"
"github.com/syyongx/php2go"
_ "github.com/tidwall/gjson"
"search_server/model"
"search_server/pkg/config"
"search_server/pkg/gredis"
"strings"
)
//关键词搜索过期时间
......@@ -35,7 +40,27 @@ func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList, supplier_inf
//
//fmt.Println(productList)
//return productList
return nil
originGoods := make(map[string]interface{}, 0)
sku_uique_judge := config.Get("redis_all.SKU_UNIQUE_JUDGE").String()
for goods_sn, info := range goods_list {
sn_sku := php2go.Md5(strings.ToLower(goods_sn))
sku_id, _ := gredis.HGet(sku_uique_judge, sn_sku) //查询唯一值,反查sku_id
if sku_id == "" { //为空,先创建sku
//lock_key := "searchapi_"+sn_sku;
//flag := gredis.Setnx(lock_key,php2go.Time()+2)
//if flag { //存在锁
//
//}
}
print(info)
//productList[goodsSn] = &LyClearGoodsList
}
fmt.Println(originGoods)
return originGoods
}
/*
......
package service
import (
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"search_server/model"
"search_server/pkg/config"
)
type ZyServiceImpl struct{}
/*
自营搜索
*/
func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req *model.ZyhRequest, rsp *model.ZyhResponse) error {
//fmt.Printf("%+v",req)
fmt.Println(req.NeedAggs)
fmt.Println(5566)
var (
need_aggs bool
_type byte
)
if req.NeedAggs != ""{
need_aggs = false
}else{
need_aggs = true
}
need_aggs = need_aggs
if need_aggs {
_type = 1
}else{
_type = 1
}
//设置cookie
setCookie(ctx,req)
rsp = zy(ctx , req ,_type,0)
return nil
}
func NewZyServiceImpl() *ZyServiceImpl {
return &ZyServiceImpl{}
}
func setCookie(ctx *gin.Context, req *model.ZyhRequest) error{
//接收用户id
if req.Yo4tewUid != "" && req.Yo4tewUid != "false" {
domain := config.Get("web.domain").String()
ctx.SetCookie("Yo4teW_uid", req.Yo4tewUid, 3600, "/", domain, false, true)
}
return nil
}
//自营筛选接口数据输出
//@param _type 1:输出所有(属性统计+分类+数据详情),2 只输出属性(属性统计)
func zy(ctx *gin.Context, req *model.ZyhRequest,_type byte,isCheck byte) (rsp *model.ZyhResponse){
fmt.Printf("%+v",req)
fmt.Println(reflect.TypeOf(req.ClassIdcondition))
fmt.Println(req.ClassIdcondition)
return nil
}
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