Quellcode durchsuchen

优化领取线索速度

xuzhiheng vor 1 Jahr
Ursprung
Commit
32515f03f2
1 geänderte Dateien mit 108 neuen und 95 gelöschten Zeilen
  1. 108 95
      service/clue.go

+ 108 - 95
service/clue.go

@@ -588,6 +588,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 	//
 	if count1 > 0 {
 		counts, counts1 := 0, 0
+		logx.Info("等级3线索领取", count1, counts1, counts)
 		for {
 			counts1++
 			data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
@@ -611,6 +612,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 	}
 	if count2 > 0 {
 		counts, counts1 := 0, 0
+		logx.Info("等级3线索领取", count2, counts1, counts)
 		for {
 			counts1++
 			data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a 
@@ -634,6 +636,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 	}
 	if count3 > 0 {
 		counts, counts1 := 0, 0
+		logx.Info("等级3线索领取", count3, counts1, counts)
 		for {
 			counts1++
 			data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a 
@@ -659,116 +662,126 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 }
 
 func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string, positionId int64, dataType string) int {
-	count := 0
+	count := make(chan bool, 2000)
+	wg := new(sync.WaitGroup)
+	ch := make(chan bool, 20)
 	for _, v := range data {
-		clueId := common.Int64All(v["id"])
-		cluename := common.ObjToString(v["cluename"])
-		if dataType == "2" {
-			cdata := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1, "company_nature": 0, "company_verification": 1}, "", "")
-			if cdata != nil && len(*cdata) > 0 {
-				salePositionId := common.Int64All((*cdata)["position_id"])
-				if pcount := JyBiMysql.Count("dwd_f_crm_personnel_management", map[string]interface{}{"resign": 0, "position_id": salePositionId}); pcount > 0 {
-					return count
-				} else {
-					saledata := JyBiMysql.SelectBySql(`SELECT position_id from dwd_d_crm_department_level_succbi WHERE bi_pcode in (SELECT bi_pcode from dwd_d_crm_department_level_succbi WHERE position_id = ?) AND resign = 0`, salePositionId)
-					if saledata != nil && len(*saledata) > 0 {
-						isOk := false
-						for _, s := range *saledata {
-							sid := common.Int64All(s["position_id"])
-							if sid == positionId {
-								isOk = true
+		wg.Add(1)
+		ch <- true
+		go func(v map[string]interface{}) {
+			defer func() {
+				wg.Done()
+				<-ch
+			}()
+			clueId := common.Int64All(v["id"])
+			cluename := common.ObjToString(v["cluename"])
+			if dataType == "2" {
+				cdata := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1, "company_nature": 0, "company_verification": 1}, "", "")
+				if cdata != nil && len(*cdata) > 0 {
+					salePositionId := common.Int64All((*cdata)["position_id"])
+					if pcount := JyBiMysql.Count("dwd_f_crm_personnel_management", map[string]interface{}{"resign": 0, "position_id": salePositionId}); pcount > 0 {
+						return
+					} else {
+						saledata := JyBiMysql.SelectBySql(`SELECT position_id from dwd_d_crm_department_level_succbi WHERE bi_pcode in (SELECT bi_pcode from dwd_d_crm_department_level_succbi WHERE position_id = ?) AND resign = 0`, salePositionId)
+						if saledata != nil && len(*saledata) > 0 {
+							isOk := false
+							for _, s := range *saledata {
+								sid := common.Int64All(s["position_id"])
+								if sid == positionId {
+									isOk = true
+								}
+							}
+							if !isOk {
+								return
 							}
-						}
-						if !isOk {
-							return count
 						}
 					}
 				}
 			}
-		}
-		trailstatus := common.ObjToString(v["trailstatus"])
-		if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-			updateClue := map[string]interface{}{
-				"position_id":          positionId,
-				"seatNumber":           seatNumber,
-				"is_assign":            1,
-				"updatetime":           nowTime,
-				"comeintime":           nowTime,
-				"comeinsource_private": 3,
-				"is_task":              1,
-				"task_time":            nowTime,
-				"tasktime":             nowTime,
-				"taskstatus":           0,
-				"tasksource":           "领取公海线索",
-				"level_open":           nil,
-				"clue_level":           nil,
-			}
-			if trailstatus != "08" {
-				updateClue["trailstatus"] = "01"
-			}
-			ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
-			recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":      clueId,
-				"position_id":  positionId,
-				"change_field": "position_id",
-				"change_type":  "所属人变更",
-				"old_value":    "/",
-				"new_value":    name,
-				"createtime":   nowTime,
-				"BCPCID":       common.GetRandom(32),
-				"operator_id":  positionId,
-			})
-			recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":     clueId,
-				"position_id": positionId,
-				"change_type": "领取公海线索",
-				"createtime":  nowTime,
-				"BCPCID":      common.GetRandom(32),
-				"operator_id": positionId,
-			})
-			recordId2 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-				"clue_id":     clueId,
-				"position_id": positionId,
-				"change_type": "加入任务车",
-				"new_value":   "领取公海线索",
-				"createtime":  nowTime,
-				"BCPCID":      common.GetRandom(32),
-				"operator_id": positionId,
-			})
-			recordId3, recordId4 := int64(0), int64(0)
-			if trailstatus != "08" {
-				recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+			trailstatus := common.ObjToString(v["trailstatus"])
+			if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
+				updateClue := map[string]interface{}{
+					"position_id":          positionId,
+					"seatNumber":           seatNumber,
+					"is_assign":            1,
+					"updatetime":           nowTime,
+					"comeintime":           nowTime,
+					"comeinsource_private": 3,
+					"is_task":              1,
+					"task_time":            nowTime,
+					"tasktime":             nowTime,
+					"taskstatus":           0,
+					"tasksource":           "领取公海线索",
+					"level_open":           nil,
+					"clue_level":           nil,
+				}
+				if trailstatus != "08" {
+					updateClue["trailstatus"] = "01"
+				}
+				ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
+				recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
 					"position_id":  positionId,
-					"change_field": "trailstatus",
-					"change_type":  "基本信息变更",
-					"old_value":    "商机线索",
-					"new_value":    "新增",
+					"change_field": "position_id",
+					"change_type":  "所属人变更",
+					"old_value":    "/",
+					"new_value":    name,
 					"createtime":   nowTime,
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  positionId,
 				})
-				recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  positionId,
-					"change_field": "trailstatus",
-					"change_type":  "基本信息变更",
-					"old_value":    CodeTrail[trailstatus],
-					"new_value":    "商机线索",
-					"createtime":   nowTime,
-					"BCPCID":       common.GetRandom(32),
-					"operator_id":  positionId,
+				recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":     clueId,
+					"position_id": positionId,
+					"change_type": "领取公海线索",
+					"createtime":  nowTime,
+					"BCPCID":      common.GetRandom(32),
+					"operator_id": positionId,
+				})
+				recordId2 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":     clueId,
+					"position_id": positionId,
+					"change_type": "加入任务车",
+					"new_value":   "领取公海线索",
+					"createtime":  nowTime,
+					"BCPCID":      common.GetRandom(32),
+					"operator_id": positionId,
 				})
+				recordId3, recordId4 := int64(0), int64(0)
+				if trailstatus != "08" {
+					recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "trailstatus",
+						"change_type":  "基本信息变更",
+						"old_value":    "商机线索",
+						"new_value":    "新增",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  positionId,
+					})
+					recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+						"clue_id":      clueId,
+						"position_id":  positionId,
+						"change_field": "trailstatus",
+						"change_type":  "基本信息变更",
+						"old_value":    CodeTrail[trailstatus],
+						"new_value":    "商机线索",
+						"createtime":   nowTime,
+						"BCPCID":       common.GetRandom(32),
+						"operator_id":  positionId,
+					})
+				}
+				return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
+			}) {
+				logx.Info("领取线索成功")
+				count <- true
+			} else {
+				logx.Info("领取线索失败")
 			}
-			return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
-		}) {
-			logx.Info("领取线索成功")
-			count++
-		} else {
-			logx.Info("领取线索失败")
-		}
+		}(v)
 	}
-	return count
+	return len(count)
 }
 
 func getSeatNumber(positionId int64) (seatNumber, name string) {