xuzhiheng vor 2 Jahren
Ursprung
Commit
1b94dada78
2 geänderte Dateien mit 40 neuen und 28 gelöschten Zeilen
  1. 3 0
      entity/entity.go
  2. 37 28
      service/clue.go

+ 3 - 0
entity/entity.go

@@ -6,6 +6,8 @@ import (
 
 
 	"encoding/json"
 	"encoding/json"
 
 
+	"sync"
+
 	util "app.yhyue.com/moapp/jybase/common"
 	util "app.yhyue.com/moapp/jybase/common"
 	elastic "app.yhyue.com/moapp/jybase/esv1"
 	elastic "app.yhyue.com/moapp/jybase/esv1"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mongodb"
@@ -25,6 +27,7 @@ var (
 	Es         *elastic.Elastic
 	Es         *elastic.Elastic
 	AreaCode   = map[string]string{}
 	AreaCode   = map[string]string{}
 	Hlyj       *HlyjS
 	Hlyj       *HlyjS
+	DataLock   = sync.Mutex{}
 )
 )
 
 
 type HlyjS struct {
 type HlyjS struct {

+ 37 - 28
service/clue.go

@@ -12,43 +12,52 @@ import (
 )
 )
 
 
 func DrawClue(this *biservice.DrawClueReq, countLimit int) *biservice.AddProjectResp {
 func DrawClue(this *biservice.DrawClueReq, countLimit int) *biservice.AddProjectResp {
-	count1 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 1})
-	count2 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 2})
-	// count3 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 3})
-	counts1, counts2, counts3 := int64(0), int64(0), int64(0)
-	counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 2))
-	if this.Count-counts1 == 0 {
-		counts2 = 0
-		counts3 = 0
-	} else {
-		counts2 = int64(math.Ceil(float64(this.Count) / float64(10) * 4))
-		if this.Count-counts1-counts2 == 0 {
-			counts3 = 0
-		} else {
-			counts3 = this.Count - counts1 - counts2
-		}
-	}
-	if counts1 > count1 {
-		counts2 += counts1 - count1
-		counts1 = count1
-	}
-	if counts2 > count2 {
-		counts3 += counts2 - count2
-		counts2 = count2
-	}
-	log.Println(count1, count2)
-	log.Println(counts1, counts2, counts3)
-	count := DrawClues(this.PositionId, counts1, counts2, counts3, int64(countLimit))
+	count, status := DrawClueSync(this, countLimit)
 	log.Println("领取数量 ", count)
 	log.Println("领取数量 ", count)
 	return &biservice.AddProjectResp{
 	return &biservice.AddProjectResp{
 		ErrorCode: 0,
 		ErrorCode: 0,
 		Data: &biservice.AddProject{
 		Data: &biservice.AddProject{
-			Status: 1,
+			Status: int64(status),
 			Count:  int64(count),
 			Count:  int64(count),
 		},
 		},
 	}
 	}
 }
 }
 
 
+func DrawClueSync(this *biservice.DrawClueReq, countLimit int) (int, int) {
+	if DataLock.TryLock() {
+		defer DataLock.Unlock()
+		count1 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 1})
+		count2 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 2})
+		// count3 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 3})
+		counts1, counts2, counts3 := int64(0), int64(0), int64(0)
+		counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 2))
+		if this.Count-counts1 == 0 {
+			counts2 = 0
+			counts3 = 0
+		} else {
+			counts2 = int64(math.Ceil(float64(this.Count) / float64(10) * 4))
+			if this.Count-counts1-counts2 == 0 {
+				counts3 = 0
+			} else {
+				counts3 = this.Count - counts1 - counts2
+			}
+		}
+		if counts1 > count1 {
+			counts2 += counts1 - count1
+			counts1 = count1
+		}
+		if counts2 > count2 {
+			counts3 += counts2 - count2
+			counts2 = count2
+		}
+		log.Println(count1, count2)
+		log.Println(counts1, counts2, counts3)
+		return DrawClues(this.PositionId, counts1, counts2, counts3, int64(countLimit)), 1
+	} else {
+		return 0, 2
+	}
+}
+
 func DrawClues(positionId, count1, count2, count3, countLimit int64) int {
 func DrawClues(positionId, count1, count2, count3, countLimit int64) int {
 	data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
 	data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
 	if count1 > 0 {
 	if count1 > 0 {