|
@@ -11,6 +11,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"
|
|
@@ -35,10 +36,17 @@ type Tags struct {
|
|
|
|
|
|
var LetterArr = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
|
|
var LetterArr = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
|
|
var bidField = `"_id","site","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","buyer","bidamount","budget","s_subscopeclass","projectname","detail"`
|
|
var bidField = `"_id","site","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","buyer","bidamount","budget","s_subscopeclass","projectname","detail"`
|
|
|
|
+var (
|
|
|
|
+ BeExecuting int
|
|
|
|
+ NeedWait chan int
|
|
|
|
+ NotificationWait = make(chan int, 1)
|
|
|
|
+ syw, rwm = &sync.RWMutex{}, &sync.RWMutex{}
|
|
|
|
+)
|
|
var seoBidField = `"_id","title","publishtime","subtype","area","href","bidamount","budget","s_subscopeclass","projectname"`
|
|
var seoBidField = `"_id","title","publishtime","subtype","area","href","bidamount","budget","s_subscopeclass","projectname"`
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
xweb.AddAction(&Tags{})
|
|
xweb.AddAction(&Tags{})
|
|
|
|
+ NeedWait = make(chan int, qu.IntAll(config.Sysconfig["awaitNum"]))
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -600,6 +608,33 @@ func GetBiddingPlatformType() (nameToCode map[string]int64, codeToName map[int64
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func LimitedConcurrency() int {
|
|
|
|
+ var ExecutionState int //执行状态 0 直接执行 1 等待执行 -1 已达上线
|
|
|
|
+ executionNum := qu.IntAll(config.Sysconfig["executionNum"])
|
|
|
|
+ awaitNum := qu.IntAll(config.Sysconfig["awaitNum"])
|
|
|
|
+ var wg sync.WaitGroup
|
|
|
|
+ wg.Add(1)
|
|
|
|
+ go func() {
|
|
|
|
+ defer wg.Done()
|
|
|
|
+ if BeExecuting < executionNum { //并发数不足 直接执行
|
|
|
|
+ ExecutionState = 0
|
|
|
|
+ BeExecuting++
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ syw.Lock()
|
|
|
|
+ defer syw.Unlock()
|
|
|
|
+ if len(NeedWait) < awaitNum { //等待人数不足 加入等待队列
|
|
|
|
+ ExecutionState = 1
|
|
|
|
+ NeedWait <- 1
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ ExecutionState = -1 //并发数与等待数以达到上线 直接结束
|
|
|
|
+ return
|
|
|
|
+ }()
|
|
|
|
+ wg.Wait()
|
|
|
|
+ return ExecutionState
|
|
|
|
+}
|
|
|
|
+
|
|
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)
|
|
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)
|
|
rediskeyCount := fmt.Sprintf("pcseo_getbidding_count_%s_%s_%s_%s_%s", industry, area, city, stype, keyword)
|
|
@@ -609,6 +644,30 @@ func (this *Tags) GetBidding(industry, area, city, stype, keyword string, reques
|
|
return qu.ObjArrToMapArr(l), int64(count), false
|
|
return qu.ObjArrToMapArr(l), int64(count), false
|
|
} else {
|
|
} else {
|
|
if area != "" || stype != "" || industry != "" || city != "" || keyword != "" {
|
|
if area != "" || stype != "" || industry != "" || city != "" || keyword != "" {
|
|
|
|
+ // 限制并发数
|
|
|
|
+ executionState := LimitedConcurrency()
|
|
|
|
+ env:
|
|
|
|
+ switch executionState {
|
|
|
|
+ case 0:
|
|
|
|
+ defer func() {
|
|
|
|
+ BeExecuting-- //执行完成减去在执行数
|
|
|
|
+ rwm.Lock()
|
|
|
|
+ defer rwm.Unlock()
|
|
|
|
+ if len(NeedWait) > 0 { //查看是否有等待执行 有通知可以执行
|
|
|
|
+ NotificationWait <- 1
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ case 1:
|
|
|
|
+ select { //监听等待
|
|
|
|
+ case <-NotificationWait:
|
|
|
|
+ <-NeedWait
|
|
|
|
+ executionState = 0
|
|
|
|
+ BeExecuting++
|
|
|
|
+ goto env //可以开始执行
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ return nil, 0, true
|
|
|
|
+ }
|
|
if public.Lst.IsLimited(request, responseWriter, session, false) == 1 { //没有被限制
|
|
if public.Lst.IsLimited(request, responseWriter, session, false) == 1 { //没有被限制
|
|
defer public.Lst.Limit()
|
|
defer public.Lst.Limit()
|
|
} else {
|
|
} else {
|