xuzhiheng 1 年之前
父节点
当前提交
2c8f77a382
共有 1 个文件被更改,包括 101 次插入109 次删除
  1. 101 109
      service/clue.go

+ 101 - 109
service/clue.go

@@ -586,10 +586,11 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 		drawCount += count
 	}
 	//
+	logx.Info("count1,count2,count3 ", count1, count2, count3, drawCount)
 	if count1 > 0 {
 		counts, counts1 := 0, 0
-		logx.Info("等级3线索领取", count1, counts1, counts)
 		for {
+			logx.Info("等级1线索领取", count1, counts1, counts)
 			counts1++
 			data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a 
 					LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
@@ -606,14 +607,15 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 			}
 			if counts1 > 5*int(count1) {
 				count2 += count1 - int64(counts)
+				drawCount += int(counts)
 				break
 			}
 		}
 	}
 	if count2 > 0 {
 		counts, counts1 := 0, 0
-		logx.Info("等级3线索领取", count2, counts1, counts)
 		for {
+			logx.Info("等级2线索领取", count2, counts1, counts)
 			counts1++
 			data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a 
 					LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
@@ -630,14 +632,15 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 			}
 			if counts1 > 5*int(count2) {
 				count3 += count2 - int64(counts)
+				drawCount += int(counts)
 				break
 			}
 		}
 	}
 	if count3 > 0 {
 		counts, counts1 := 0, 0
-		logx.Info("等级3线索领取", count3, counts1, counts)
 		for {
+			logx.Info("等级3线索领取", count3, counts1, counts)
 			counts1++
 			data := JyBiTidb.SelectBySql(`SELECT max(c.createTime) as ctime,a.id,a.trailstatus FROM dwd_f_crm_clue_info a 
 					LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = a.phone
@@ -662,127 +665,116 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
 }
 
 func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string, positionId int64, dataType string) int {
-	count := make(chan bool, 2000)
-	wg := new(sync.WaitGroup)
-	ch := make(chan bool, 20)
+	count := 0
 	for _, v := range data {
-		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
+		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
 							}
 						}
+						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{}{
+		}
+		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{}{
 					"clue_id":      clueId,
 					"position_id":  positionId,
-					"change_field": "position_id",
-					"change_type":  "所属人变更",
-					"old_value":    "/",
-					"new_value":    name,
+					"change_field": "trailstatus",
+					"change_type":  "基本信息变更",
+					"old_value":    "商机线索",
+					"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,
+				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,
 				})
-				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("领取线索失败")
 			}
-		}(v)
+			return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
+		}) {
+			logx.Info("领取线索成功")
+			count++
+		} else {
+			logx.Info("领取线索失败")
+		}
 	}
-	wg.Wait()
-	return len(count)
+	return count
 }
 
 func getSeatNumber(positionId int64) (seatNumber, name string) {