Commit 3e7012c7 by huangchengyi

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

# Conflicts:
#	service/common_ly_service.go
parents e76f9d77 578ce9ad
...@@ -15,7 +15,7 @@ func AutoSpu(c *gin.Context) { ...@@ -15,7 +15,7 @@ func AutoSpu(c *gin.Context) {
if len(goods) == 0 { if len(goods) == 0 {
errCode = 1 errCode = 1
} }
res := common.Response{ res := common.BomResponse{
ErrCode: errCode, ErrCode: errCode,
ErrMsg: "", ErrMsg: "",
Data: goods, Data: goods,
......
package middleware
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"search_server/pkg/config"
"time"
)
func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",")
return cors.New(cors.Config{
AllowOrigins: corsDomain,
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
})
}
package model package model
type ApiGoods struct { type ApiGoods struct {
GoodsID string `json:"goods_id"` PickType int `json:"pick_type"`
GoodsName string `json:"goods_name"` BarCode string `json:"bar_code"`
GoodsType int `json:"goods_type"` GoodsId string `json:"goods_id"`
SupplierID int `json:"supplier_id"` GoodsName string `json:"goods_name"`
Moq int `json:"moq"` GoodsType int `json:"goods_type"`
Mpq int `json:"mpq"` SupplierId int `json:"supplier_id"`
Stock int `json:"stock"` Moq int `json:"moq"`
HkDeliveryTime string `json:"hk_delivery_time"` Mpq int `json:"mpq"`
CnDeliveryTime string `json:"cn_delivery_time"` Stock int `json:"stock"`
LadderPrice []LadderPrice `json:"ladder_price"` HkDeliveryTime string `json:"hk_delivery_time"`
BrandName string `json:"brand_name"` CnDeliveryTime string `json:"cn_delivery_time"`
SupplierName string `json:"supplier_name"` LadderPrice []LadderPrice `json:"ladder_price"`
BrandID int `json:"brand_id"` BrandName string `json:"brand_name"`
IsBuy int `json:"is_buy"` SupplierName string `json:"supplier_name"`
Mpl int `json:"mpl"` BrandId int `json:"brand_id"`
Status int `json:"status"` ClassId1 int `json:"class_id1"`
Pdf string `json:"pdf"` ClassId2 int `json:"class_id2"`
Encap string `json:"encap"` Encoded string `json:"encoded"`
AcType int `json:"ac_type"` Packing string `json:"packing"`
//ErpTax bool `json:"erp_tax"` GoodsUnit string `json:"goods_unit"`
GoodsImages string `json:"goods_images"`
GoodsBrief string `json:"goods_brief"`
IsBuy int `json:"is_buy"`
Mpl int `json:"mpl"`
Status int `json:"status"`
Pdf string `json:"pdf"`
Encap string `json:"encap"`
AcType int `json:"ac_type"`
OtherAttrs OtherAttrs `json:"other_attrs"`
UpdateTime int `json:"update_time"`
SkuName string `json:"sku_name"`
Attrs Attrs `json:"attrs"`
Cost string `json:"cost"`
NewCost string `json:"new_cost"`
SupplierStock int `json:"supplier_stock"`
SelfSupplierType int `json:"self_supplier_type"`
GoodsUnitName string `json:"goods_unit_name"`
PackingName string `json:"packing_name"`
MpgUnitName string `json:"mpg_unit_name"`
ScmBrandName string `json:"scm_brand_name"`
AllowCoupon int `json:"allow_coupon"`
ClassId1Name string `json:"class_id1_name"`
CLassId2Name string `json:"c_lass_id2_name"`
SpuId string `json:"spu_id,omitempty"`
BatchSn string `json:"batch_sn,omitempty"`
Canal string `json:"canal,omitempty"`
CpTime int `json:"cp_time,omitempty"`
Coefficient Coefficient `json:"coefficient,omitempty"`
OriginalPrice []OriginalPrice `json:"original_price,omitempty"`
SuppExtendFee SuppExtendFee `json:"supp_extend_fee,omitempty"`
ClassId3 int `json:"class_id3,omitempty"`
SpuName string `json:"spu_name,omitempty"`
ImagesL string `json:"images_l,omitempty"`
SpuBrief string `json:"spu_brief,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
ClassName3 string `json:"class_name3,omitempty"`
ErpTax bool `json:"erp_tax,omitempty"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"`
}
type Attr struct {
AttrName string
AttrValue string
}
type Attrs map[string]Attr
type OtherAttrs struct {
GrossWeight string `json:"gross_weight"`
} }
type LadderPrice struct { type LadderPrice struct {
Purchases int `json:"purchases"` Purchases int `json:"purchases"`
PriceUs float64 `json:"price_us"` PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"` PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac"` PriceAc float64 `json:"price_ac"`
} }
\ No newline at end of file
type Coefficient struct {
Cn string `json:"cn"`
Hk string `json:"hk"`
ExtraRatio string `json:"extra_ratio"`
Ratio string `json:"ratio"`
Tax float64 `json:"tax"`
}
type OriginalPrice struct {
Purchases int `json:"purchases"`
PriceCn float64 `json:"price_cn"`
PriceUs float64 `json:"price_us"`
}
type SuppExtendFee struct {
Cn struct {
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"cn,omitempty"`
Hk struct{
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"hk,omitempty"`
}
type ScmBrand struct {
ErpBrandName string `json:"erp_brand_name"`
ErpBrandId string `json:"erp_brand_id"`
ScmBrandId string `json:"scm_brand_id"`
}
package common package common
type Response struct { type Response struct {
ErrCode int `json:"err_code"` ErrCode int `json:"error_code"`
ErrMsg string `json:"err_msg"` ErrMsg string `json:"err_msg"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
type BomResponse struct { type BomResponse struct {
ErrCode int `json:"err_code"` ErrCode int `json:"error_code"`
ErrMsg string `json:"err_msg"` ErrMsg string `json:"error_msg"`
Flag int `json:"flag"` Flag int `json:"flag"`
Total int `json:"total"` Total int `json:"total"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
......
...@@ -13,42 +13,17 @@ type RedisDatabase struct { ...@@ -13,42 +13,17 @@ type RedisDatabase struct {
//多数据库配置 //多数据库配置
func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) { func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) {
return map[string]RedisDatabase{ return map[string]RedisDatabase{
"search_read": { "search_r": {
Host: Get("default_redis_read.host").String(), Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(), Password: Get("default_redis_read.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(), MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(), MaxActive: Get("default_redis_read.max_active").String(),
}, },
"search_write": { "search_w": {
Host: Get("default_redis_write.host").String(), Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(), Password: Get("default_redis_write.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(), MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(), MaxActive: Get("default_redis_read.max_active").String(),
}, },
"spu_read": {
Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"spu_write": {
Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"api_read": {
Host: Get("api_redis_read.host").String(),
Password: Get("api_redis_read.password").String(),
MaxIdle: Get("api_redis_read.max_idle").String(),
MaxActive: Get("api_redis_read.max_active").String(),
},
"api_write": {
Host: Get("api_redis_write.host").String(),
Password: Get("api_redis_write.password").String(),
MaxIdle: Get("api_redis_write.max_idle").String(),
MaxActive: Get("api_redis_write.max_active").String(),
},
} }
} }
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
) )
type ichuntRedis struct { type ichuntRedis struct {
RedisList map[string]*redis.Pool RedisList map[string]*redis.Pool
} }
...@@ -30,11 +29,9 @@ func Setup() (err error) { ...@@ -30,11 +29,9 @@ func Setup() (err error) {
panic(err) panic(err)
} }
} }
return nil return nil
} }
func getConn(writeHost, password string) (pool *redis.Pool, err error) { func getConn(writeHost, password string) (pool *redis.Pool, err error) {
maxIdle, _ := config.Get("redis.max_idle").Int() maxIdle, _ := config.Get("redis.max_idle").Int()
maxActive, _ := config.Get("redis.max_active").Int() maxActive, _ := config.Get("redis.max_active").Int()
...@@ -60,6 +57,4 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) { ...@@ -60,6 +57,4 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) {
}, },
} }
return return
} }
\ No newline at end of file
package mysql package mysql
import ( import (
"fmt"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"search_server/pkg/config" "search_server/pkg/config"
...@@ -12,7 +13,7 @@ var DatabaseConMap map[string]*xorm.Engine ...@@ -12,7 +13,7 @@ var DatabaseConMap map[string]*xorm.Engine
func _setup() error{ func Setup() error{
DatabaseConMap = make(map[string]*xorm.Engine,0) DatabaseConMap = make(map[string]*xorm.Engine,0)
DatabaseList := config.BuildDatabaseList() DatabaseList := config.BuildDatabaseList()
var err error var err error
...@@ -23,7 +24,7 @@ func _setup() error{ ...@@ -23,7 +24,7 @@ func _setup() error{
host := db.Host host := db.Host
database := db.Database database := db.Database
dataSourceName := userName + ":" + password + "@tcp(" + host + ")/" + database + "?charset=utf8" dataSourceName := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",userName,password,host,database)
DatabaseConMap[conName], err = xorm.NewEngine("mysql", dataSourceName) DatabaseConMap[conName], err = xorm.NewEngine("mysql", dataSourceName)
if err!=nil{ if err!=nil{
......
...@@ -3,6 +3,7 @@ package routes ...@@ -3,6 +3,7 @@ package routes
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"search_server/controller" "search_server/controller"
"search_server/middleware"
) )
//初始化路由 //初始化路由
...@@ -10,11 +11,11 @@ func InitRouter() *gin.Engine { ...@@ -10,11 +11,11 @@ func InitRouter() *gin.Engine {
r := gin.New() r := gin.New()
r.Use(gin.Logger()) r.Use(gin.Logger())
r.Use(gin.Recovery()) r.Use(gin.Recovery())
r.Use(middleware.Cors())
//路由 //路由
r.POST("/search/bom/autospu", controller.AutoSpu) r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend) r.POST("/search/bom/recommend", controller.Recommend)
//r.POST("search/ZiYing/zyh", controller.Zyh) r.POST("search/ZiYing/zyh", controller.Zyh)
//快手平台相关 //快手平台相关
//r.GET("/search/quote", controller.QuoteIndex) //r.GET("/search/quote", controller.QuoteIndex)
......
...@@ -3,6 +3,7 @@ package service ...@@ -3,6 +3,7 @@ package service
import ( import (
"fmt" "fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
_ "github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp" "regexp"
...@@ -10,6 +11,7 @@ import ( ...@@ -10,6 +11,7 @@ import (
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/es" "search_server/pkg/es"
"search_server/pkg/gredis" "search_server/pkg/gredis"
_ "search_server/pkg/gredis"
"strconv" "strconv"
"strings" "strings"
) )
...@@ -46,7 +48,9 @@ func SearchAttr(attrOrigin, encap string) (goodsName string, err error) { ...@@ -46,7 +48,9 @@ func SearchAttr(attrOrigin, encap string) (goodsName string, err error) {
numberR, _ := regexp.Compile(common.PureNumberRegular) numberR, _ := regexp.Compile(common.PureNumberRegular)
pureNumber := numberR.FindString(encap) pureNumber := numberR.FindString(encap)
//再去找对应属性 //再去找对应属性
attrName, _ := redis.String(gredis.HGet("sku_map2", pureNumber)) redisConn := gredis.Conn("default_redis_read")
defer redisConn.Close()
attrName, _ := redis.String(redisConn.Do("HGET", "sku_map2", pureNumber))
if attrName != "" { if attrName != "" {
attrValue := attrName + "€" + pureNumber attrValue := attrName + "€" + pureNumber
attrsSlice = append(attrsSlice, attrValue) attrsSlice = append(attrsSlice, attrValue)
...@@ -199,7 +203,9 @@ func getAttrValueByAttr(attr string) (attrValue string) { ...@@ -199,7 +203,9 @@ func getAttrValueByAttr(attr string) (attrValue string) {
} }
} else { } else {
//再去找没有单位的对应属性 //再去找没有单位的对应属性
attrName, _ = redis.String(gredis.HGet("sku_map2", attr)) redisConn := gredis.Conn("default_redis_read")
defer redisConn.Close()
attrName, _ := redis.String(redisConn.Do("HGET", "sku_map2", pureNumber))
if attrName != "" { if attrName != "" {
attrValue = attrName + "€" + attr attrValue = attrName + "€" + attr
} else { } else {
......
...@@ -101,7 +101,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) { ...@@ -101,7 +101,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) {
goodsIdList = append(goodsIdList, goodsId) goodsIdList = append(goodsIdList, goodsId)
} }
goodsIdListStr = strings.Join(goodsIdList, ",") goodsIdListStr = strings.Join(goodsIdList, ",")
goodsList, err := GetGoodsInfo(goodsIdListStr) goodsService := GoodsService{}
goodsList, err := goodsService.GetGoodsInfoByApi(goodsIdListStr)
response.Data = goodsList response.Data = goodsList
response.Flag = req.Flag response.Flag = req.Flag
return &response return &response
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"reflect" "reflect"
"search_server/model" "search_server/model"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/gredis"
) )
type ZyServiceImpl struct{} type ZyServiceImpl struct{}
...@@ -59,5 +60,12 @@ func zy(ctx *gin.Context, req *model.ZyhRequest,_type byte,isCheck byte) (rsp *m ...@@ -59,5 +60,12 @@ func zy(ctx *gin.Context, req *model.ZyhRequest,_type byte,isCheck byte) (rsp *m
fmt.Printf("%+v",req) fmt.Printf("%+v",req)
fmt.Println(reflect.TypeOf(req.ClassIdcondition)) fmt.Println(reflect.TypeOf(req.ClassIdcondition))
fmt.Println(req.ClassIdcondition) fmt.Println(req.ClassIdcondition)
redis_s_r :=gredis.Conn("search_r")
defer func(){
redis_s_r.Close()
}()
return nil return nil
} }
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"search_server/boot" "search_server/boot"
"search_server/pkg/mysql" "search_server/service"
) )
func main() { func main() {
...@@ -14,20 +14,6 @@ func main() { ...@@ -14,20 +14,6 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
fmt.Println(err) fmt.Println(err)
} }
type Result struct { service1:= service.GoodsService{}
BinId int `json:"bin_id"` fmt.Println(service1.GetGoodsInfoByApi("1151005920927710088,1150961641855982990,1150961724815213435"))
Bin string `json:"bin"`
}
var result []Result
mysql.Connection("bom").Raw("SELECT * FROM lie_bin").Scan(&result)
//mysql.Connection()("bom").Table("bin").Find(&result)
fmt.Println(result)
type Result2 struct {
BusinessName string `json:"business_name"`
}
var result2 []Result2
mysql.Connection("mysql").Raw("SELECT * FROM lie_business").Scan(&result2)
//mysql.GetDB("bom").Table("bin").Find(&result)
fmt.Println(result2)
} }
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