|
@@ -1,12 +1,14 @@
|
|
package util
|
|
package util
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "context"
|
|
"fmt"
|
|
"fmt"
|
|
"jyBXBase/rpc/bxbase"
|
|
"jyBXBase/rpc/bxbase"
|
|
IC "jyBXBase/rpc/init"
|
|
IC "jyBXBase/rpc/init"
|
|
"log"
|
|
"log"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "sync"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
@@ -28,7 +30,7 @@ const (
|
|
TopTypesLeadingProject = "拟建,采购意向"
|
|
TopTypesLeadingProject = "拟建,采购意向"
|
|
)
|
|
)
|
|
|
|
|
|
-//是否是付费用户 -bool: true:是 fasle:不是
|
|
|
|
|
|
+// 是否是付费用户 -bool: true:是 fasle:不是
|
|
func Power(userid string) (bool, map[string]interface{}) {
|
|
func Power(userid string) (bool, map[string]interface{}) {
|
|
isVip, isMember, isEnt := false, false, false
|
|
isVip, isMember, isEnt := false, false, false
|
|
vipstatus := 0
|
|
vipstatus := 0
|
|
@@ -77,7 +79,7 @@ func Power(userid string) (bool, map[string]interface{}) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//招标信息是否被收藏
|
|
|
|
|
|
+// 招标信息是否被收藏
|
|
func IsCollByBids(bids, userid string) []string {
|
|
func IsCollByBids(bids, userid string) []string {
|
|
res := []string{}
|
|
res := []string{}
|
|
collBidMap := map[string]bool{}
|
|
collBidMap := map[string]bool{}
|
|
@@ -128,8 +130,10 @@ func IsCollByBids(bids, userid string) []string {
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
- isColl int: 收藏条数的状态 (是否超过100条 超过:2 没超过:1)
|
|
|
|
|
|
+ isColl int: 收藏条数的状态 (是否超过100条 超过:2 没超过:1)
|
|
|
|
+
|
|
return
|
|
return
|
|
|
|
+
|
|
[]string:收藏的id
|
|
[]string:收藏的id
|
|
*/
|
|
*/
|
|
func GetCollRedis(userid string, isColl int) []string {
|
|
func GetCollRedis(userid string, isColl int) []string {
|
|
@@ -150,7 +154,7 @@ func GetCollRedis(userid string, isColl int) []string {
|
|
return redisArr
|
|
return redisArr
|
|
}
|
|
}
|
|
|
|
|
|
-//招标信息 bid&userid 唯一
|
|
|
|
|
|
+// 招标信息 bid&userid 唯一
|
|
type BidInfo struct {
|
|
type BidInfo struct {
|
|
Bid string `json:"bid"` //招标信息id 加密后
|
|
Bid string `json:"bid"` //招标信息id 加密后
|
|
Buyerclass string `json:"buyerclass"` //采购单位类型
|
|
Buyerclass string `json:"buyerclass"` //采购单位类型
|
|
@@ -367,7 +371,7 @@ type InfoList struct {
|
|
FileExists bool `json:"fileExists"`
|
|
FileExists bool `json:"fileExists"`
|
|
}
|
|
}
|
|
|
|
|
|
-//根据id取内容
|
|
|
|
|
|
+// 根据id取内容
|
|
func GetInfoById(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, idlist []map[string]interface{}) []*InfoList {
|
|
func GetInfoById(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, idlist []map[string]interface{}) []*InfoList {
|
|
array := make([]*InfoList, len(idlist))
|
|
array := make([]*InfoList, len(idlist))
|
|
if len(idlist) == 0 {
|
|
if len(idlist) == 0 {
|
|
@@ -455,7 +459,7 @@ func GetInfoById(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, i
|
|
return array
|
|
return array
|
|
}
|
|
}
|
|
|
|
|
|
-//列表单条信息格式化
|
|
|
|
|
|
+// 列表单条信息格式化
|
|
func InfoFormat(p string, info *map[string]interface{}) *InfoList {
|
|
func InfoFormat(p string, info *map[string]interface{}) *InfoList {
|
|
area := common.ObjToString((*info)["area"])
|
|
area := common.ObjToString((*info)["area"])
|
|
if area == "A" {
|
|
if area == "A" {
|
|
@@ -505,7 +509,7 @@ func InfoFormat(p string, info *map[string]interface{}) *InfoList {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//搜藏列表
|
|
|
|
|
|
+// 搜藏列表
|
|
func CollListSql(c *bxbase.ListReq, isPay bool, userid string) string {
|
|
func CollListSql(c *bxbase.ListReq, isPay bool, userid string) string {
|
|
sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, "bdcollection", userid)
|
|
sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, "bdcollection", userid)
|
|
limit := 10
|
|
limit := 10
|
|
@@ -590,3 +594,56 @@ func CollListSql(c *bxbase.ListReq, isPay bool, userid string) string {
|
|
sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
return sql
|
|
return sql
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//并发限制
|
|
|
|
+
|
|
|
|
+type reqLimit struct {
|
|
|
|
+ doPool chan struct{}
|
|
|
|
+ waitPool chan struct{}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var (
|
|
|
|
+ ReqLimitInit *reqLimit
|
|
|
|
+ ReqLimitLock *sync.Mutex
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func NewLimit(num int) {
|
|
|
|
+ doPool := make(chan struct{}, num)
|
|
|
|
+ for i := 0; i < num; i++ {
|
|
|
|
+ doPool <- struct{}{}
|
|
|
|
+ }
|
|
|
|
+ waitPool := make(chan struct{}, num)
|
|
|
|
+ for i := 0; i < num; i++ {
|
|
|
|
+ waitPool <- struct{}{}
|
|
|
|
+ }
|
|
|
|
+ ReqLimitInit = &reqLimit{
|
|
|
|
+ doPool: doPool,
|
|
|
|
+ waitPool: waitPool,
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// -2 等待池已满
|
|
|
|
+// -1 超时
|
|
|
|
+// 1:可以执行查询
|
|
|
|
+func (r *reqLimit) Limit(ctx context.Context) int {
|
|
|
|
+ ctx, cancel := context.WithTimeout(ctx, 30*time.Second) //30秒
|
|
|
|
+ defer cancel()
|
|
|
|
+ select {
|
|
|
|
+ case <-r.waitPool:
|
|
|
|
+ defer func() {
|
|
|
|
+ r.waitPool <- struct{}{}
|
|
|
|
+ }()
|
|
|
|
+ select {
|
|
|
|
+ case <-r.doPool:
|
|
|
|
+ return 1
|
|
|
|
+ case <-ctx.Done(): //超时
|
|
|
|
+ return -1
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ return -2
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (r *reqLimit) Release() {
|
|
|
|
+ r.doPool <- struct{}{}
|
|
|
|
+}
|