|
@@ -12,6 +12,7 @@ import (
|
|
"net/http"
|
|
"net/http"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "sync"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
@@ -459,15 +460,25 @@ func IsInArr(arr []string, s string) bool {
|
|
|
|
|
|
// 获取最新招标信息
|
|
// 获取最新招标信息
|
|
func (this *Tags) GetNewBidInfo() (list []map[string]interface{}) {
|
|
func (this *Tags) GetNewBidInfo() (list []map[string]interface{}) {
|
|
- rediskey := fmt.Sprintf("pcindex_newArticle")
|
|
|
|
- if l, ok := redis.Get("seoCache", rediskey).([]interface{}); ok && l != nil && len(l) > 0 {
|
|
|
|
- list = qu.ObjArrToMapArr(l)
|
|
|
|
- } else {
|
|
|
|
|
|
+ var (
|
|
|
|
+ redisKey = fmt.Sprintf("pcindex_newArticle")
|
|
|
|
+ redisKeySL = fmt.Sprintf("pcindex_newArticle_second_level") //二级缓存
|
|
|
|
+ redisLock = &sync.Mutex{}
|
|
|
|
+ )
|
|
|
|
+ var newBidInfos = func() (list []map[string]interface{}) {
|
|
// p397 未登录详情页最新招投标信息去掉拟建
|
|
// p397 未登录详情页最新招投标信息去掉拟建
|
|
- _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", "招标预告,招标公告,招标结果,招标信用信息", "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 50, "")
|
|
|
|
- if lists != nil && len(*lists) > 10 {
|
|
|
|
- *lists = (*lists)[0:10]
|
|
|
|
- for _, v := range *lists {
|
|
|
|
|
|
+ var (
|
|
|
|
+ now = time.Now()
|
|
|
|
+ startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix()) //最近7天
|
|
|
|
+ endTime = fmt.Sprint(now.Unix())
|
|
|
|
+ publishTime = fmt.Sprintf("%s_%s", startTime, endTime)
|
|
|
|
+ )
|
|
|
|
+ _, _, lists := bidsearch.GetPcBidSearchData("", "", "", publishTime, "招标预告,招标公告,招标结果,招标信用信息", "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 50, "")
|
|
|
|
+ if lists != nil && len(*lists) > 0 {
|
|
|
|
+ for k, v := range *lists {
|
|
|
|
+ if k >= 10 {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
v["_id"] = encrypt.CommonEncodeArticle("content", v["_id"].(string))
|
|
v["_id"] = encrypt.CommonEncodeArticle("content", v["_id"].(string))
|
|
delete(v, "toptype")
|
|
delete(v, "toptype")
|
|
delete(v, "s_subscopeclass")
|
|
delete(v, "s_subscopeclass")
|
|
@@ -481,9 +492,66 @@ func (this *Tags) GetNewBidInfo() (list []map[string]interface{}) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
list = *lists
|
|
list = *lists
|
|
- redis.Put("seoCache", rediskey, list, cacheTime)
|
|
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var bidInfosByCache = func(rk string) (list []map[string]interface{}) {
|
|
|
|
+ redisLock.Lock()
|
|
|
|
+ defer redisLock.Unlock()
|
|
|
|
+ if l, ok := redis.Get("seoCache", rk).([]interface{}); ok && l != nil && len(l) > 0 {
|
|
|
|
+ list = qu.ObjArrToMapArr(l)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var bidInfosToCache = func(list []map[string]interface{}) {
|
|
|
|
+ redisLock.Lock()
|
|
|
|
+ defer redisLock.Unlock()
|
|
|
|
+ redis.Put("seoCache", redisKey, list, cacheTime)
|
|
|
|
+ redis.Put("seoCache", redisKeySL, list, -1)
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ list = bidInfosByCache(redisKey)
|
|
|
|
+ if len(list) == 0 {
|
|
|
|
+ list = bidInfosByCache(redisKeySL)
|
|
|
|
+ if len(list) == 0 {
|
|
|
|
+ list = newBidInfos()
|
|
|
|
+ }
|
|
|
|
+ if len(list) > 0 {
|
|
|
|
+ bidInfosToCache(list)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //rediskey := fmt.Sprintf("pcindex_newArticle")
|
|
|
|
+ //if l, ok := redis.Get("seoCache", rediskey).([]interface{}); ok && l != nil && len(l) > 0 {
|
|
|
|
+ // list = qu.ObjArrToMapArr(l)
|
|
|
|
+ //} else {
|
|
|
|
+ // // p397 未登录详情页最新招投标信息去掉拟建
|
|
|
|
+ // var (
|
|
|
|
+ // now = time.Now()
|
|
|
|
+ // startTime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix()) //最近7天
|
|
|
|
+ // endTime = fmt.Sprint(now.Unix())
|
|
|
|
+ // publishTime = fmt.Sprintf("%s_%s", startTime, endTime)
|
|
|
|
+ // )
|
|
|
|
+ // _, _, lists := bidsearch.GetPcBidSearchData("", "", "", publishTime, "招标预告,招标公告,招标结果,招标信用信息", "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 50, "")
|
|
|
|
+ // if lists != nil && len(*lists) > 10 {
|
|
|
|
+ // *lists = (*lists)[0:10]
|
|
|
|
+ // for _, v := range *lists {
|
|
|
|
+ // v["_id"] = encrypt.CommonEncodeArticle("content", v["_id"].(string))
|
|
|
|
+ // delete(v, "toptype")
|
|
|
|
+ // delete(v, "s_subscopeclass")
|
|
|
|
+ // tmpdate := v["publishtime"]
|
|
|
|
+ // v["publishtime"] = qu.Int64All(tmpdate.(float64))
|
|
|
|
+ // v["date"] = time.Unix(qu.Int64All(tmpdate.(float64)), 0).Format(date.Date_Short_Layout)
|
|
|
|
+ // if v["budget"] != nil {
|
|
|
|
+ // v["budget"] = ConversionMoeny(v["budget"])
|
|
|
|
+ // } else if v["bidamount"] != nil {
|
|
|
|
+ // v["budget"] = ConversionMoeny(v["bidamount"])
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // list = *lists
|
|
|
|
+ // redis.Put("seoCache", rediskey, list, cacheTime)
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
return list
|
|
return list
|
|
}
|
|
}
|
|
|
|
|
|
@@ -655,13 +723,17 @@ func (r *reqLimit) Release() {
|
|
// GetBidding
|
|
// GetBidding
|
|
// 金额限制在"1000"~"100000000";需求因es压力过大,只返回60%的数据
|
|
// 金额限制在"1000"~"100000000";需求因es压力过大,只返回60%的数据
|
|
func (this *Tags) GetBidding(industry, area, city, stype, keyword string, request *http.Request, responseWriter http.ResponseWriter, session *httpsession.Session) ([]map[string]interface{}, int64, bool) {
|
|
func (this *Tags) GetBidding(industry, area, city, stype, keyword string, request *http.Request, responseWriter http.ResponseWriter, session *httpsession.Session) ([]map[string]interface{}, int64, bool) {
|
|
- rediskey := fmt.Sprintf("pcseo_getbidding_%s_%s_%s_%s_%s", industry, area, city, stype, keyword)
|
|
|
|
- rediskeyCount := fmt.Sprintf("pcseo_getbidding_count_%s_%s_%s_%s_%s", industry, area, city, stype, keyword)
|
|
|
|
-
|
|
|
|
- if l, ok := redis.Get("seoCache", rediskey).([]interface{}); ok && l != nil {
|
|
|
|
- count := redis.GetInt("seoCache", rediskeyCount)
|
|
|
|
- return qu.ObjArrToMapArr(l), int64(count), false
|
|
|
|
- } else {
|
|
|
|
|
|
+ var (
|
|
|
|
+ rediskey = fmt.Sprintf("pcseo_getbidding_%s_%s_%s_%s_%s", industry, area, city, stype, keyword)
|
|
|
|
+ rediskeyCount = fmt.Sprintf("pcseo_getbidding_count_%s_%s_%s_%s_%s", industry, area, city, stype, keyword)
|
|
|
|
+ redisKeySL = fmt.Sprintf("pcseo_getbidding_sl_%s_%s_%s_%s_%s", industry, area, city, stype, keyword)
|
|
|
|
+ redisKeyCountSL = fmt.Sprintf("pcseo_getbidding_count_sl_%s_%s_%s_%s_%s", industry, area, city, stype, keyword)
|
|
|
|
+ redisLock = &sync.Mutex{}
|
|
|
|
+ data []map[string]interface{}
|
|
|
|
+ count int64
|
|
|
|
+ b bool
|
|
|
|
+ )
|
|
|
|
+ var biddingData = func() ([]map[string]interface{}, int64, bool) {
|
|
if area != "" || stype != "" || industry != "" || city != "" || keyword != "" {
|
|
if area != "" || stype != "" || industry != "" || city != "" || keyword != "" {
|
|
if flag := reqLimitInit.Limit(context.Background()); flag == 1 {
|
|
if flag := reqLimitInit.Limit(context.Background()); flag == 1 {
|
|
defer reqLimitInit.Release()
|
|
defer reqLimitInit.Release()
|
|
@@ -683,21 +755,10 @@ func (this *Tags) GetBidding(industry, area, city, stype, keyword string, reques
|
|
starttime := fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
starttime := fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
endtime := fmt.Sprint(now.Unix())
|
|
endtime := fmt.Sprint(now.Unix())
|
|
var datas *[]map[string]interface{}
|
|
var datas *[]map[string]interface{}
|
|
- //var startPage int
|
|
|
|
var count int64
|
|
var count int64
|
|
- //currentPage := 5
|
|
|
|
limitCount := qu.IntAllDef(config.Seoconfig["tagsLimitCount"], 50)
|
|
limitCount := qu.IntAllDef(config.Seoconfig["tagsLimitCount"], 50)
|
|
if keyword == "" {
|
|
if keyword == "" {
|
|
query := bidsearch.GetSearchQuery("", industry, "0.1", "1000", "", "", "", "", bidsearch.GetBidSearchQuery(area, city, fmt.Sprintf("%s_%s", starttime, endtime), stype, "", ""), "", false, seoBidField)
|
|
query := bidsearch.GetSearchQuery("", industry, "0.1", "1000", "", "", "", "", bidsearch.GetBidSearchQuery(area, city, fmt.Sprintf("%s_%s", starttime, endtime), stype, "", ""), "", false, seoBidField)
|
|
- //count = elastic.Count(INDEX, TYPE, query)
|
|
|
|
- //if count == 0 {
|
|
|
|
- // return nil, 0, false
|
|
|
|
- //}
|
|
|
|
- //startPage = rand.New(rand.NewSource(time.Now().UnixNano())).Intn(currentPage * limitCount)
|
|
|
|
- //count1 := qu.IntAll(count)
|
|
|
|
- //if count1 < startPage || startPage < 0 {
|
|
|
|
- // startPage = 0
|
|
|
|
- //}
|
|
|
|
var countTmp int
|
|
var countTmp int
|
|
datas, countTmp = elastic.GetOAPage(INDEX, TYPE, query, bidSearch_sort, seoBidField, 0, limitCount)
|
|
datas, countTmp = elastic.GetOAPage(INDEX, TYPE, query, bidSearch_sort, seoBidField, 0, limitCount)
|
|
count = qu.Int64All(countTmp)
|
|
count = qu.Int64All(countTmp)
|
|
@@ -727,13 +788,121 @@ func (this *Tags) GetBidding(industry, area, city, stype, keyword string, reques
|
|
industry = strings.Split(industry, "_")[0]
|
|
industry = strings.Split(industry, "_")[0]
|
|
}
|
|
}
|
|
public.BidListConvert(industry, datas)
|
|
public.BidListConvert(industry, datas)
|
|
- redis.Put("seoCache", rediskey, datas, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
- redis.Put("seoCache", rediskeyCount, count, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
|
|
+ //redis.Put("seoCache", rediskey, datas, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
+ //redis.Put("seoCache", rediskeyCount, count, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
return *datas, count, false
|
|
return *datas, count, false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return nil, 0, false
|
|
|
|
+ }
|
|
|
|
+ var biddingByCache = func(rk, rc string) ([]map[string]interface{}, int64, bool) {
|
|
|
|
+ redisLock.Unlock()
|
|
|
|
+ defer redisLock.Unlock()
|
|
|
|
+ if l, ok := redis.Get("seoCache", rk).([]interface{}); ok && l != nil {
|
|
|
|
+ count := redis.GetInt("seoCache", rc)
|
|
|
|
+ return qu.ObjArrToMapArr(l), int64(count), false
|
|
|
|
+ }
|
|
|
|
+ return nil, 0, false
|
|
}
|
|
}
|
|
- return nil, 0, false
|
|
|
|
|
|
+ var biddingToCache = func(datas []map[string]interface{}, count int64) {
|
|
|
|
+ redisLock.Lock()
|
|
|
|
+ defer redisLock.Unlock()
|
|
|
|
+ redis.Put("seoCache", rediskey, datas, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
+ redis.Put("seoCache", rediskeyCount, count, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
+ redis.Put("seoCache", redisKeySL, datas, -1) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
+ redis.Put("seoCache", redisKeyCountSL, count, -1) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ //缓存数据
|
|
|
|
+ data, count, b = biddingByCache(rediskey, rediskeyCount)
|
|
|
|
+ if data == nil || len(data) == 0 || count == 0 {
|
|
|
|
+ data, count, b = biddingByCache(redisKeySL, redisKeyCountSL)
|
|
|
|
+ if data == nil || len(data) == 0 || count == 0 {
|
|
|
|
+ //获取数据库数据
|
|
|
|
+ data, count, b = biddingData()
|
|
|
|
+ }
|
|
|
|
+ //更新缓存
|
|
|
|
+ if data != nil && len(data) > 0 && count > 0 {
|
|
|
|
+ biddingToCache(data, count)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return data, count, b
|
|
|
|
+ //if l, ok := redis.Get("seoCache", rediskey).([]interface{}); ok && l != nil {
|
|
|
|
+ // count := redis.GetInt("seoCache", rediskeyCount)
|
|
|
|
+ // return qu.ObjArrToMapArr(l), int64(count), false
|
|
|
|
+ //} else {
|
|
|
|
+ // if area != "" || stype != "" || industry != "" || city != "" || keyword != "" {
|
|
|
|
+ // if flag := reqLimitInit.Limit(context.Background()); flag == 1 {
|
|
|
|
+ // defer reqLimitInit.Release()
|
|
|
|
+ // } else {
|
|
|
|
+ // if flag == -2 {
|
|
|
|
+ // log.Println("等待队列已满")
|
|
|
|
+ // } else if flag == -1 {
|
|
|
|
+ // log.Println("等待超时")
|
|
|
|
+ // }
|
|
|
|
+ // return nil, 0, true
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // if public.Lst.IsLimited(request, responseWriter, session, false) == 1 { //没有被限制
|
|
|
|
+ // defer public.Lst.Limit()
|
|
|
|
+ // } else {
|
|
|
|
+ // return nil, 0, true
|
|
|
|
+ // }
|
|
|
|
+ // now := time.Now()
|
|
|
|
+ // starttime := fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
|
|
|
|
+ // endtime := fmt.Sprint(now.Unix())
|
|
|
|
+ // var datas *[]map[string]interface{}
|
|
|
|
+ // //var startPage int
|
|
|
|
+ // var count int64
|
|
|
|
+ // //currentPage := 5
|
|
|
|
+ // limitCount := qu.IntAllDef(config.Seoconfig["tagsLimitCount"], 50)
|
|
|
|
+ // if keyword == "" {
|
|
|
|
+ // query := bidsearch.GetSearchQuery("", industry, "0.1", "1000", "", "", "", "", bidsearch.GetBidSearchQuery(area, city, fmt.Sprintf("%s_%s", starttime, endtime), stype, "", ""), "", false, seoBidField)
|
|
|
|
+ // //count = elastic.Count(INDEX, TYPE, query)
|
|
|
|
+ // //if count == 0 {
|
|
|
|
+ // // return nil, 0, false
|
|
|
|
+ // //}
|
|
|
|
+ // //startPage = rand.New(rand.NewSource(time.Now().UnixNano())).Intn(currentPage * limitCount)
|
|
|
|
+ // //count1 := qu.IntAll(count)
|
|
|
|
+ // //if count1 < startPage || startPage < 0 {
|
|
|
|
+ // // startPage = 0
|
|
|
|
+ // //}
|
|
|
|
+ // var countTmp int
|
|
|
|
+ // datas, countTmp = elastic.GetOAPage(INDEX, TYPE, query, bidSearch_sort, seoBidField, 0, limitCount)
|
|
|
|
+ // count = qu.Int64All(countTmp)
|
|
|
|
+ // if count == 0 {
|
|
|
|
+ // return nil, 0, false
|
|
|
|
+ // }
|
|
|
|
+ // } else {
|
|
|
|
+ // count, _, datas = bidsearch.GetPcBidSearchData(keyword, area, city, fmt.Sprintf("%s_%s", starttime, endtime), stype, industry, "", "", "", "", "", "", "", 0, true, []string{"title", "detail", "purchasing"}, seoBidField, "", false, false, "", limitCount, "")
|
|
|
|
+ // if datas != nil && len(*datas) > limitCount {
|
|
|
|
+ // *datas = (*datas)[0:limitCount]
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // if datas != nil && len(*datas) > 0 {
|
|
|
|
+ // for _, v := range *datas {
|
|
|
|
+ // v["_id"] = encrypt.CommonEncodeArticle("content", qu.ObjToString(v["_id"]))
|
|
|
|
+ // v["date"] = time.Unix(qu.Int64All(v["publishtime"]), 0).Format(date.Date_Short_Layout)
|
|
|
|
+ // highlight, _ := v["highlight"].(map[string][]string)
|
|
|
|
+ // detail := ""
|
|
|
|
+ // for _, val := range highlight["detail"] {
|
|
|
|
+ // detail += public.ClearHtml.ReplaceAllString(val, "")
|
|
|
|
+ // }
|
|
|
|
+ // if detail != "" {
|
|
|
|
+ // v["detail"] = detail
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // if strings.Contains(industry, "_") {
|
|
|
|
+ // industry = strings.Split(industry, "_")[0]
|
|
|
|
+ // }
|
|
|
|
+ // public.BidListConvert(industry, datas)
|
|
|
|
+ // redis.Put("seoCache", rediskey, datas, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
+ // redis.Put("seoCache", rediskeyCount, count, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
|
|
|
|
+ // return *datas, count, false
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //return nil, 0, false
|
|
}
|
|
}
|
|
|
|
|
|
// 获取关键词
|
|
// 获取关键词
|