|
@@ -120,50 +120,57 @@ func (search *Search) SearchEntSer(id string) error {
|
|
|
func (search *Search) FindServiceByEntId() error {
|
|
|
if search.Method() == "POST" {
|
|
|
id := search.GetString("entId")
|
|
|
- limit, _ := search.GetInteger("pageSize")
|
|
|
currentPage, _ := search.GetInteger("currentPage")
|
|
|
- start := (currentPage - 1) * limit
|
|
|
- var count int64
|
|
|
- //分页
|
|
|
- mustnot := `{"term" : {"i_status" : 1 }}`
|
|
|
- var fields, collection, query, tempstrquery string
|
|
|
- collection = "service"
|
|
|
- tempstrquery = `{"query_string":{"default_field": "s_enterpriseid","query":"` + id + `"}}`
|
|
|
- servicequery := ""
|
|
|
- if search.GetSession("entid") == nil || search.GetSession("entid").(string) != id {
|
|
|
- servicequery = `,"must_not" : [` + mustnot + `]`
|
|
|
- }
|
|
|
- query = `{"query": {
|
|
|
+ var res map[string]interface{}
|
|
|
+ if ret := redis.Get("enterprise", "service-"+id+"-"+fmt.Sprint(currentPage)); ret != nil {
|
|
|
+ res = ret.(map[string]interface{})
|
|
|
+ } else {
|
|
|
+ limit, _ := search.GetInteger("pageSize")
|
|
|
+ start := (currentPage - 1) * limit
|
|
|
+ var count int64
|
|
|
+ //分页
|
|
|
+ mustnot := `{"term" : {"i_status" : 1 }}`
|
|
|
+ var fields, collection, query, tempstrquery string
|
|
|
+ collection = "service"
|
|
|
+ tempstrquery = `{"query_string":{"default_field": "s_enterpriseid","query":"` + id + `"}}`
|
|
|
+ servicequery := ""
|
|
|
+ if search.GetSession("entid") == nil || search.GetSession("entid").(string) != id {
|
|
|
+ servicequery = `,"must_not" : [` + mustnot + `]`
|
|
|
+ }
|
|
|
+ query = `{"query": {
|
|
|
"bool": {
|
|
|
"must":[` + tempstrquery + `]` + servicequery + `
|
|
|
}
|
|
|
}}`
|
|
|
- //需要查到的字段信息
|
|
|
- fields = `"_id","s_name","s_introduction","s_images","s_enterpriseid","s_isshow","i_status","s_pricemy","i_comments","f_price","i_sales"`
|
|
|
- if currentPage == 1 {
|
|
|
- count = elastic.Count("service", collection, query)
|
|
|
- }
|
|
|
- //查询服务列表数据
|
|
|
- result := elastic.Get("service", collection, `{"query":{"bool": {"must":[`+tempstrquery+`]`+servicequery+`}},
|
|
|
+ //需要查到的字段信息
|
|
|
+ fields = `"_id","s_name","s_introduction","s_images","s_enterpriseid","s_isshow","i_status","s_pricemy","i_comments","f_price","i_sales"`
|
|
|
+ if currentPage == 1 {
|
|
|
+ count = elastic.Count("service", collection, query)
|
|
|
+ }
|
|
|
+ //查询服务列表数据
|
|
|
+ result := elastic.Get("service", collection, `{"query":{"bool": {"must":[`+tempstrquery+`]`+servicequery+`}},
|
|
|
_source:[`+fields+`],
|
|
|
sort:{"l_createdate":"desc"},
|
|
|
from:`+fmt.Sprintf("%v", start)+`,
|
|
|
size:`+fmt.Sprintf("%v", limit)+`
|
|
|
}`)
|
|
|
- for _, v := range *result {
|
|
|
- b, _ := CheckAuth(v)
|
|
|
- if b {
|
|
|
- v["s_isEdit"] = "1"
|
|
|
- } else {
|
|
|
- v["s_isEdit"] = "0"
|
|
|
- }
|
|
|
- if IntAll(v["i_status"]) == 1 {
|
|
|
- v["s_remove"] = 1
|
|
|
- } else {
|
|
|
- v["s_remove"] = 0
|
|
|
+ for _, v := range *result {
|
|
|
+ b, _ := CheckAuth(v)
|
|
|
+ if b {
|
|
|
+ v["s_isEdit"] = "1"
|
|
|
+ } else {
|
|
|
+ v["s_isEdit"] = "0"
|
|
|
+ }
|
|
|
+ if IntAll(v["i_status"]) == 1 {
|
|
|
+ v["s_remove"] = 1
|
|
|
+ } else {
|
|
|
+ v["s_remove"] = 0
|
|
|
+ }
|
|
|
}
|
|
|
+ res = map[string]interface{}{"list": result, "count": count}
|
|
|
+ redis.Put("enterprise", "service-"+id+"-"+fmt.Sprint(currentPage), res, 7*24*60*60)
|
|
|
}
|
|
|
- search.ServeJson(&map[string]interface{}{"list": result, "count": count})
|
|
|
+ search.ServeJson(res)
|
|
|
}
|
|
|
return nil
|
|
|
}
|