xuzhiheng 2 жил өмнө
parent
commit
efc6f3c023

+ 3 - 1
src/client/customerRule.go

@@ -192,6 +192,8 @@ func (c *CustomerRule) ProductData() {
 		rep := false
 		id := c.GetString("id")
 		dataType := c.GetString("dataType")
+		user := c.GetSession("user").(map[string]interface{})
+		userId := qu.ObjToString(user["id"])
 		tag, ok := Mgo.FindById("cuserdepartrule", id, `{}`)
 		if !ok {
 			c.ServeJson(map[string]interface{}{
@@ -245,7 +247,7 @@ func (c *CustomerRule) ProductData() {
 		// var n int
 		// 小于1000的直接查
 		// if totalCount < 1000 {
-		err, dataTypes, count = UtilEsFind1(*tag, dataType)
+		err, dataTypes, count = UtilEsFind1(*tag, dataType, userId)
 		// } else {
 		// 	if totalCount >= 1000 && totalCount < 4000 {
 		// 		n = 3

+ 3 - 1
src/history/historytask.go

@@ -361,6 +361,8 @@ func (this *HistoryData) ProductData() {
 		id := this.GetString("id")
 		hid := this.GetString("hid")
 		dataType := this.GetString("dataType")
+		user := this.GetSession("user").(map[string]interface{})
+		userId := qu.ObjToString(user["id"])
 		dep_rules, _ := Mgo.FindById("historylog", hid, `{"dep_rules:1"}`)
 		var tag = map[string]interface{}{}
 		if len(*dep_rules) != 0 && dep_rules != nil {
@@ -416,7 +418,7 @@ func (this *HistoryData) ProductData() {
 		// var n int
 		// 小于1000的直接查
 		// if totalCount < 1000 {
-		err, dataTypes, count = UtilEsFind1(tag, dataType)
+		err, dataTypes, count = UtilEsFind1(tag, dataType, userId)
 		// } else {
 		// 	if totalCount >= 1000 && totalCount < 4000 {
 		// 		n = 3

+ 3 - 1
src/service/customer_service.go

@@ -790,6 +790,8 @@ func (c *Customer) ProductData() {
 		rep := false
 		id := c.GetString("id")
 		dataType := c.GetString("dataType")
+		user := c.GetSession("user").(map[string]interface{})
+		userId := qu.ObjToString(user["id"])
 		tag, ok := Mgo.FindById("cuserdepartrule", id, `{}`)
 		if !ok {
 			c.ServeJson(map[string]interface{}{
@@ -844,7 +846,7 @@ func (c *Customer) ProductData() {
 		// var n int
 		// 小于1000的直接查
 		// if totalCount < 1000 {
-		err, dataTypes, count = UtilEsFind1(*tag, dataType)
+		err, dataTypes, count = UtilEsFind1(*tag, dataType, userId)
 		// } else {
 		// 	if totalCount >= 1000 && totalCount < 4000 {
 		// 		n = 3

+ 17 - 4
src/util/utiltag.go

@@ -74,7 +74,7 @@ func UtilEsSaveData(sdataid, index string, datas *[]map[string]interface{}) erro
 }
 
 // 客户规则
-func UtilEsFind1(tags map[string]interface{}, dataType string) (error, string, int64) {
+func UtilEsFind1(tags map[string]interface{}, dataType, userId string) (error, string, int64) {
 	defer util.Catch()
 	sdataid := util.ObjToString(tags["s_dataid"])
 	esquery := util.ObjToString(tags["s_esquery"])
@@ -126,9 +126,9 @@ func UtilEsFind1(tags map[string]interface{}, dataType string) (error, string, i
 	}
 	// esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}`
 	log.Println("esquery", esquery)
-	err, counts := searchDataArr(index, esquery, sdataid, i_maxnum, tags, maths)
+	err, counts := searchDataArr(index, esquery, sdataid, userId, i_maxnum, tags, maths)
 	if counts == 0 && err == nil && index == InterimIndex {
-		err, counts = searchDataArr(TotalIndex, esquery, sdataid, i_maxnum, tags, maths)
+		err, counts = searchDataArr(TotalIndex, esquery, sdataid, userId, i_maxnum, tags, maths)
 		if counts > 0 {
 			dataTypes = "2"
 		}
@@ -136,7 +136,7 @@ func UtilEsFind1(tags map[string]interface{}, dataType string) (error, string, i
 	return err, dataTypes, counts
 }
 
-func searchDataArr(index, esquery, sdataid string, i_maxnum int64, tags map[string]interface{}, maths []map[string]string) (error, int64) {
+func searchDataArr(index, esquery, sdataid, userId string, i_maxnum int64, tags map[string]interface{}, maths []map[string]string) (error, int64) {
 	var (
 		err    error
 		counts = int64(0)
@@ -160,6 +160,19 @@ func searchDataArr(index, esquery, sdataid string, i_maxnum int64, tags map[stri
 	for {
 		listLens := int(redis.LLEN("datag", "jyqyfw_es_query"))
 		if listLens < 2 {
+			if isExists, _ := redis.Exists("datag", "jyqyfw_es_query_times_"+userId); isExists {
+				qt := redis.GetInt("datag", "jyqyfw_es_query_times_"+userId)
+				if qt > 2 {
+					log.Println("单个账号一分钟内超过3次 ", qt)
+					err = errors.New("系统繁忙,请稍后再试")
+					break
+				} else {
+					redis.Incr("datag", "jyqyfw_es_query_times_"+userId)
+				}
+			} else {
+				redis.Put("datag", "jyqyfw_es_query_times_"+userId, 1, 60)
+			}
+			log.Println("es空闲,当前进程数 ", listLens)
 			redis.RPUSH("datag", "jyqyfw_es_query", 1)
 			err, counts = searchData(index, esquery, sdataid, i_maxnum, tags, maths)
 			redis.LPOP("datag", "jyqyfw_es_query")