Commit 6084d865 by 孙龙

自营

parent 903a5a80
......@@ -59,6 +59,28 @@ func Aggs(ctx *gin.Context){
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
}
//统计样片一级分类总条数
func AggSample(ctx *gin.Context){
zyhRequest := make(map[string]string,0);
ctx.MultipartForm()
for requestName, requstValue := range ctx.Request.Form {
if requstValue[0] != "" {
zyhRequest[requestName] = strings.TrimSpace(requstValue[0])
}
}
//fmt.Println(zyhRequest)
zyServiceImpl := service.NewZyServiceImpl()
zyhResponse := &model.ZyhResponse{}
zyhResponse = zyServiceImpl.AggSample(ctx,zyhRequest)
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
}
func Index(ctx *gin.Context){
zyhRequest := make(map[string]string,0);
zyhResponse := &model.ZyhResponse{}
......
package model
//type ZyhRequest struct {
// Yo4tewUid string `form:"Yo4teW_uid"`
// ClassIdcondition int64 `form:"class_id/condition"`
// ClassId2condition int64 `form:"class_id2/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 int `form:"p"`
// NeedAggs string `form:"need_aggs"`
// GoodsNameCondition string `form:"goods_name/condition"`
//
//}
import (
"search_server/pkg/mysql"
)
type ZhyClassListModel struct {
ClassID1Name string `json:"class_id1_name"`
......@@ -47,3 +29,16 @@ type ZyhResponse struct {
}
type LieXinData struct {
Id int `json:"id" xorm:"id"`
Sort int `json:"sort" xorm:"sort"`
}
func GetSampleClass () ( sample_class_data []LieXinData) {
sample_class_data = make([]LieXinData,0)
spuMsql := mysql.Conn("liexin_data")
sql := "select id,sort from lie_sample_class where status = 1 order by sort asc "
_ = spuMsql.SQL(sql).Find(&sample_class_data)
return
}
\ No newline at end of file
......@@ -34,5 +34,12 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
Database: Get("cms.database").String(),
Prefix: Get("cms.table_prefix").String(),
},
"liexin_data": {
UserName: Get("liexin_data.user_name").String(),
Password: Get("liexin_data.password").String(),
Host: Get("liexin_data.host").String(),
Database: Get("liexin_data.database").String(),
Prefix: Get("liexin_data.table_prefix").String(),
},
}
}
......@@ -21,6 +21,8 @@ func InitRouter() *gin.Engine {
r.POST("search/ZiYing/index", controller.Index)
r.GET("search/ZiYing/aggs", controller.Aggs)
r.POST("search/ZiYing/aggs", controller.Aggs)
r.GET("search/ZiYing/aggSample", controller.AggSample)
r.POST("search/ZiYing/aggSample", controller.AggSample)
r.POST("search/mouser/a", controller.GetMouserData)
r.GET("search/mouser/a", controller.GetMouserData)
......
......@@ -638,6 +638,7 @@ func makePageInfo(paginator map[string]interface{},currentPage int) string{
return pageHtml
}
func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions []string,goods_temp_status *int,searchValue *string,
keyword *string,is_sample *bool,goods_name_arr *[]string) bool{
......@@ -1100,3 +1101,121 @@ func ziyingCache(req map[string]string,_type byte) (*model.ZyhResponse, bool){
return rsp, true
}
/*
统计样片一级分类总条数
*/
func(this *ZyServiceImpl)AggSample(ctx *gin.Context, req map[string]string) (rsp *model.ZyhResponse){
rsp = &model.ZyhResponse{ErrorCode:-1}
dataJson := `{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"status": "1"
}
},
{
"term": {
"sample_status": "1"
}
},
{
"range": {
"sample_class_id": {
"gte": 1
}
}
}
]
}
}
, "aggs": {
"sample_class_id": {
"terms": {
"size": 500,
"field":"sample_class_id"
}
}
}
}`
reg := regexp.MustCompile("# #")
dataJson = reg.ReplaceAllString(dataJson,"")
for _,v := range []string{"\r\n","\r","\n"}{
dataJson = strings.ReplaceAll(dataJson,v,"")
}
esIndex := config.Get("ZIYING_CONFIG.Index").String()
result,err :=es.CurlES(esIndex,dataJson)
if err != nil{
return rsp
}
redisConn := gredis.Conn("search_r")
defer func(){
redisConn.Close()
}()
aggsSampleBuckets := gjson.Get(result,"aggregations.sample_class_id.buckets").Array()
if len(aggsSampleBuckets) <= 0{
return rsp
}
type classInfoStruct struct {
SmapleClassId int64
SmapleClassName string
Count int64
Sort int
}
temp := make(map[string]classInfoStruct,0)
for _,item:= range aggsSampleBuckets{
itemMap := item.Map()
keyGjsonResult,ok:= itemMap["key"]
if !ok{
continue
}
key := keyGjsonResult.String()
if key == ""{
continue
}
classInfo,err := redis.String(redisConn.Do("Hget","Self_sample_class_list",key))
if err != nil{
continue
}
fmt.Println("classInfo",classInfo)
tempClassInfoStruct := classInfoStruct{
SmapleClassId:keyGjsonResult.Int(),
SmapleClassName:gjson.Get(classInfo,"class_name").String(),
Count:itemMap["doc_count"].Int(),
}
temp[key] = tempClassInfoStruct
}
fmt.Println(temp)
//排序
sample_class_data := model.GetSampleClass()
fmt.Println("sample_class_data",sample_class_data)
res :=make([]classInfoStruct,0)
for _,val:=range sample_class_data{
sample_class_id := val.Id
sample_class_id_str := strconv.FormatInt(int64(sample_class_id),10)
//array_key_exists
bb,ok:= temp[sample_class_id_str]
if ok{
bb.Sort = val.Sort
//temp[sample_class_id_str] = bb
res = append(res,bb)
}
}
if len(res) > 0{
rsp.ErrorCode=0
rsp.Data = res
return
}
return
}
\ 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