xuzhiheng 2 years ago
parent
commit
af191c128b
3 changed files with 227 additions and 144 deletions
  1. 11 0
      entity/entity.go
  2. 1 1
      rpc/internal/logic/drawcluelogic.go
  3. 215 143
      service/clue.go

+ 11 - 0
entity/entity.go

@@ -28,6 +28,17 @@ var (
 	AreaCode   = map[string]string{}
 	Hlyj       *HlyjS
 	DataLock   = sync.Mutex{}
+	CodeTrail  = map[string]string{
+		"00": "无意向客户",
+		"01": "商机线索",
+		"02": "空号停机",
+		"03": "沉睡客户",
+		"04": "潜在客户",
+		"05": "意向客户",
+		"06": "高意向客户",
+		"07": "待签署客户",
+		"08": "成交客户",
+	}
 )
 
 type HlyjS struct {

+ 1 - 1
rpc/internal/logic/drawcluelogic.go

@@ -26,5 +26,5 @@ func NewDrawClueLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DrawClue
 func (l *DrawClueLogic) DrawClue(in *pb.DrawClueReq) (*pb.AddProjectResp, error) {
 	// todo: add your logic here and delete this line
 
-	return service.DrawClue(in, l.svcCtx.Config.DrawCountLimit), nil
+	return service.DrawClue(in), nil
 }

+ 215 - 143
service/clue.go

@@ -11,8 +11,8 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
 )
 
-func DrawClue(this *biservice.DrawClueReq, countLimit int) *biservice.AddProjectResp {
-	count, status := DrawClueSync(this, countLimit)
+func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
+	count, status := DrawClueSync(this)
 	log.Println("领取数量 ", count)
 	return &biservice.AddProjectResp{
 		ErrorCode: 0,
@@ -23,7 +23,7 @@ func DrawClue(this *biservice.DrawClueReq, countLimit int) *biservice.AddProject
 	}
 }
 
-func DrawClueSync(this *biservice.DrawClueReq, countLimit int) (int, int) {
+func DrawClueSync(this *biservice.DrawClueReq) (int, int) {
 	if DataLock.TryLock() {
 		defer DataLock.Unlock()
 		count1 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 1})
@@ -52,13 +52,13 @@ func DrawClueSync(this *biservice.DrawClueReq, countLimit int) (int, int) {
 		}
 		log.Println(count1, count2)
 		log.Println(counts1, counts2, counts3)
-		return DrawClues(this.PositionId, counts1, counts2, counts3, int64(countLimit)), 1
+		return DrawClues(this.PositionId, counts1, counts2, counts3), 1
 	} else {
 		return 0, 2
 	}
 }
 
-func DrawClues(positionId, count1, count2, count3, countLimit int64) int {
+func DrawClues(positionId, count1, count2, count3 int64) int {
 	data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
 	if count1 > 0 {
 		data1 = JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 1}, "", "", 0, int(count1))
@@ -75,201 +75,273 @@ func DrawClues(positionId, count1, count2, count3, countLimit int64) int {
 		for _, v := range *data1 {
 			//update postionid and update record
 			clueId := common.Int64All(v["clue_id"])
-			if JyBiTidb.Count("dwd_f_crm_private_sea", map[string]interface{}{"position_id": positionId}) < countLimit {
-				if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-					ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber, "is_assign": 1, "trailstatus": "01", "updatetime": nowTime, "comeintime": nowTime})
-					ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
-					seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
-						"clue_id":      clueId,
-						"seatNumber":   seatNumber,
-						"position_id":  positionId,
-						"comeintime":   nowTime,
-						"comeinsource": 3,
-						"is_task":      1,
-						"task_time":    nowTime,
-						"tasktime":     nowTime,
-						"taskstatus":   0,
-						"tasksource":   "领取公海线索",
-					})
-					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,
+				}
+				if trailstatus != "08" {
+					updateClue["trailstatus"] = "01"
+				}
+				ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
+				ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
+				seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
+					"clue_id":      clueId,
+					"seatNumber":   seatNumber,
+					"position_id":  positionId,
+					"comeintime":   nowTime,
+					"comeinsource": 3,
+					"is_task":      1,
+					"task_time":    nowTime,
+					"tasktime":     nowTime,
+					"taskstatus":   0,
+					"tasksource":   "领取公海线索",
+				})
+				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,
-					})
-					recordId3 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 						"clue_id":      clueId,
 						"position_id":  positionId,
 						"change_field": "trailstatus",
 						"change_type":  "基本信息变更",
-						"new_value":    "新增",
+						"old_value":    CodeTrail[trailstatus],
+						"new_value":    "商机线索",
 						"createtime":   nowTime,
 						"BCPCID":       common.GetRandom(32),
 						"operator_id":  positionId,
 					})
-					return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > 0
-				}) {
-					drawCount++
-					log.Println("领取线索1成功")
-				} else {
-					log.Println("领取线索1失败")
 				}
+				return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
+			}) {
+				drawCount++
+				log.Println("领取线索1成功")
+			} else {
+				log.Println("领取线索1失败")
 			}
 		}
 	}
 	if data2 != nil && len(*data2) > 0 {
 		for _, v := range *data2 {
 			clueId := common.Int64All(v["clue_id"])
-			if JyBiTidb.Count("dwd_f_crm_private_sea", map[string]interface{}{"position_id": positionId}) < countLimit {
-				if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-					ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber, "is_assign": 1, "trailstatus": "01", "updatetime": nowTime, "comeintime": nowTime})
-					ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
-					seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
-						"clue_id":      clueId,
-						"seatNumber":   seatNumber,
-						"position_id":  positionId,
-						"comeintime":   nowTime,
-						"comeinsource": 3,
-						"is_task":      1,
-						"task_time":    nowTime,
-						"tasktime":     nowTime,
-						"taskstatus":   0,
-						"tasksource":   "领取公海线索",
-					})
-					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,
+				}
+				if trailstatus != "08" {
+					updateClue["trailstatus"] = "01"
+				}
+				ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
+				ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
+				seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
+					"clue_id":      clueId,
+					"seatNumber":   seatNumber,
+					"position_id":  positionId,
+					"comeintime":   nowTime,
+					"comeinsource": 3,
+					"is_task":      1,
+					"task_time":    nowTime,
+					"tasktime":     nowTime,
+					"taskstatus":   0,
+					"tasksource":   "领取公海线索",
+				})
+				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,
-					})
-					recordId3 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 						"clue_id":      clueId,
 						"position_id":  positionId,
 						"change_field": "trailstatus",
 						"change_type":  "基本信息变更",
-						"new_value":    "新增",
+						"old_value":    CodeTrail[trailstatus],
+						"new_value":    "商机线索",
 						"createtime":   nowTime,
 						"BCPCID":       common.GetRandom(32),
 						"operator_id":  positionId,
 					})
-					return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > 0
-				}) {
-					drawCount++
-					log.Println("领取线索2成功")
-				} else {
-					log.Println("领取线索2失败")
 				}
+				return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
+			}) {
+				drawCount++
+				log.Println("领取线索2成功")
+			} else {
+				log.Println("领取线索2失败")
 			}
 		}
 	}
 	if data3 != nil && len(*data3) > 0 {
 		for _, v := range *data3 {
 			clueId := common.Int64All(v["clue_id"])
-			if JyBiTidb.Count("dwd_f_crm_private_sea", map[string]interface{}{"position_id": positionId}) < countLimit {
-				if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-					ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber, "is_assign": 1, "trailstatus": "01", "updatetime": nowTime, "comeintime": nowTime})
-					ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
-					seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
-						"clue_id":      clueId,
-						"seatNumber":   seatNumber,
-						"position_id":  positionId,
-						"comeintime":   nowTime,
-						"comeinsource": 3,
-						"is_task":      1,
-						"task_time":    nowTime,
-						"tasktime":     nowTime,
-						"taskstatus":   0,
-						"tasksource":   "领取公海线索",
-					})
-					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,
+				}
+				if trailstatus != "08" {
+					updateClue["trailstatus"] = "01"
+				}
+				ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
+				ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
+				seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
+					"clue_id":      clueId,
+					"seatNumber":   seatNumber,
+					"position_id":  positionId,
+					"comeintime":   nowTime,
+					"comeinsource": 3,
+					"is_task":      1,
+					"task_time":    nowTime,
+					"tasktime":     nowTime,
+					"taskstatus":   0,
+					"tasksource":   "领取公海线索",
+				})
+				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,
-					})
-					recordId3 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 						"clue_id":      clueId,
 						"position_id":  positionId,
 						"change_field": "trailstatus",
 						"change_type":  "基本信息变更",
-						"new_value":    "新增",
+						"old_value":    CodeTrail[trailstatus],
+						"new_value":    "商机线索",
 						"createtime":   nowTime,
 						"BCPCID":       common.GetRandom(32),
 						"operator_id":  positionId,
 					})
-					return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > 0
-				}) {
-					drawCount++
-					log.Println("领取线索3成功")
-				} else {
-					log.Println("领取线索3失败")
 				}
+				return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
+			}) {
+				drawCount++
+				log.Println("领取线索3成功")
+			} else {
+				log.Println("领取线索3失败")
 			}
 		}
 	}