xuzhiheng 2 年之前
父節點
當前提交
1a6fdc8b39
共有 3 個文件被更改,包括 302 次插入308 次删除
  1. 15 17
      clueSync/autoTask.go
  2. 103 107
      clueSync/job.go
  3. 184 184
      telemarketingEtl/entity/dwd_f_crm_open_sea.go

+ 15 - 17
clueSync/autoTask.go

@@ -59,9 +59,8 @@ func autoTask() {
 		"05": "", //意向客户
 		"04": "", //潜在客户
 	} {
-		sql := `SELECT a.clue_id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_private_sea a 
-				LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id 
-				WHERE b.trailstatus =?`
+		sql := `SELECT id,position_id,seatNumber,out_task_status FROM dwd_f_crm_clue_info 
+				WHERE trailstatus = ?`
 		argsSelect := []interface{}{trailstatus}
 		intime := ""
 		sql += " AND a.comeintime <?"
@@ -72,7 +71,7 @@ func autoTask() {
 		//
 		TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
 			for _, v := range *l {
-				clueId := common.Int64All(v["clue_id"])
+				clueId := common.Int64All(v["id"])
 				position_id := common.Int64All(v["position_id"])
 				out_task_status := common.IntAll(v["out_task_status"])
 				args2 := []interface{}{clueId}
@@ -124,11 +123,11 @@ func autoTasks() {
 	nextTime := time.Now().AddDate(0, 0, 1).Format(date.Date_Full_Layout)
 	TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
 		for _, v := range *l {
-			clueId := common.Int64All(v["clue_id"])
+			clueId := common.Int64All(v["id"])
 			position_id := common.Int64All(v["position_id"])
 			out_task_status := common.IntAll(v["out_task_status"])
 			if out_task_status != 1 {
-				if TiDb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
+				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
 					"is_task":    1,
 					"task_time":  nowTime2,
 					"tasktime":   nowTime2,
@@ -148,9 +147,8 @@ func autoTasks() {
 			}
 		}
 		return true
-	}, `SELECT a.clue_id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_private_sea a 
-				LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id 
-				LEFT JOIN dwd_f_crm_trail_content c ON c.clue_id=b.id 
+	}, `SELECT a.id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_clue_info a 
+				LEFT JOIN dwd_f_crm_trail_content c ON c.clue_id=a.id 
 				WHERE c.next_time >= "`+nowTime2+`" and c.next_time <= "`+nextTime+`"`)
 	log.Println("按照跟进时间提前一天进入任务车定时任务结束")
 }
@@ -164,15 +162,15 @@ func autoExitSea() {
 			positionId := common.Int64All(v["position_id"])
 			seatNumber := common.ObjToString(v["seatNumber"])
 			nowTime := time.Now().Format(date.Date_Full_Layout)
-			is_assign := common.IntAll(v["is_assign"])
+			// is_assign := common.IntAll(v["is_assign"])
 			if TiDb.ExecTx("退出线索", func(tx *sql.Tx) bool {
 				recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign = -1,position_id = null,seatNumber = null,updatetime = ? WHERE id = ?`, nowTime, clueId)
-				ok1 := true
-				if is_assign == 1 {
-					ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId})
-				} else if is_assign == 0 {
-					ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
-				}
+				// ok1 := true
+				// if is_assign == 1 {
+				// 	ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId})
+				// } else if is_assign == 0 {
+				// 	ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
+				// }
 				recordId1 := TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
 					"position_id":  positionId,
@@ -213,7 +211,7 @@ func autoExitSea() {
 					"BCPCID":      common.GetRandom(32),
 					"operator_id": -1,
 				})
-				return ok1 && recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1
+				return recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1
 			}) {
 				log.Println("自动退出线索成功")
 			} else {

+ 103 - 107
clueSync/job.go

@@ -130,26 +130,28 @@ func userbase() {
 						log.Println("userbase uid 注册时间 ", registedates)
 						if time.Now().Unix()-registedates.Unix() > int64(cfg.RegTimes)*86400 {
 							if count == 0 {
+								// TiDb.Insert("dwd_f_crm_open_sea", map[string]interface{}{
+								// 	"clue_id":      clueId,
+								// 	"comeintime":   nowTime,
+								// 	"comeinsource": 2,
+								// })
 								clueId := TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
-									"userid":       userId,
-									"uid":          uId,
-									"is_assign":    0,
-									"comeintime":   nowTime,
-									"createtime":   nowTime,
-									"updatetime":   nowTime,
-									"cluename":     phone,
-									"top_cluetype": "379",
-									"sub_cluetype": "380",
-									"trailstatus":  "01",
-									"name":         name,
-									"phone":        phone,
+									"userid":            userId,
+									"uid":               uId,
+									"is_assign":         0,
+									"comeintime":        nowTime,
+									"createtime":        nowTime,
+									"updatetime":        nowTime,
+									"cluename":          phone,
+									"top_cluetype":      "379",
+									"sub_cluetype":      "380",
+									"trailstatus":       "01",
+									"name":              name,
+									"phone":             phone,
+									"comeintime_open":   nowTime,
+									"comeinsource_open": 2,
 								})
 								if clueId > 0 {
-									TiDb.Insert("dwd_f_crm_open_sea", map[string]interface{}{
-										"clue_id":      clueId,
-										"comeintime":   nowTime,
-										"comeinsource": 2,
-									})
 									TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
 										"status":      1,
 										"is_delete":   1,
@@ -406,12 +408,6 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 	position_id, seatNumber, saleName, saleData := autoDraw(level)
 	log.Println("data -------", position_id, seatNumber, saleName)
 	if position_id > 0 && seatNumber != "" {
-		// if TiDb.Count("dwd_f_crm_private_sea", map[string]interface{}{"position_id": position_id}) >= cfg.CountLimit {
-		// 	log.Println("线索分配失败,私海线索数据超过限制", item, position_id, seatNumber, uId, userId, phone)
-		// 	TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where seatNumber = ? and clue_level = ?`, seatNumber, level)
-		// 	return false, false
-		// 	// position_id, seatNumber, saleName, saleData = autoDraw(level)
-		// }
 		uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true
 		if uCount != nil && len(*uCount) > 0 {
 			oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber, position_id, source)
@@ -431,43 +427,36 @@ func FormatData(data map[string]interface{}, item string) (bool, bool) {
 func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, industry, follow_project_area, role, seatNumber string, positionId int64, source int) bool {
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
-	clueId, seaId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
+	clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
 	// BCPCID := common.GetRandom(32)
 	if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
 		//线索
 		clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
-			"userid":              userId,
-			"uid":                 uId,
-			"seatNumber":          seatNumber,
-			"position_id":         positionId,
-			"is_assign":           1,
-			"comeintime":          nowTime,
-			"createtime":          nowTime,
-			"updatetime":          nowTime,
-			"cluename":            cluename,
-			"top_cluetype":        top_cluetype,
-			"sub_cluetype":        sub_cluetype,
-			"trailstatus":         "01",
-			"name":                name,
-			"phone":               phone,
-			"position":            position,
-			"department":          department,
-			"industry":            industry,
-			"follow_project_area": follow_project_area,
-			"role":                role,
-		})
-		//私海 --> 任务车
-		seaId = TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
-			"clue_id":      clueId,
-			"seatNumber":   seatNumber,
-			"position_id":  positionId,
-			"comeintime":   nowTime,
-			"comeinsource": 2,
-			"is_task":      1,
-			"task_time":    nowTime,
-			"tasktime":     common.If(item == "users", nowTimes, nowTime),
-			"taskstatus":   0,
-			"tasksource":   "线索自动分配" + "-" + topname + "-" + subname,
+			"userid":               userId,
+			"uid":                  uId,
+			"seatNumber":           seatNumber,
+			"position_id":          positionId,
+			"is_assign":            1,
+			"comeintime":           nowTime,
+			"createtime":           nowTime,
+			"updatetime":           nowTime,
+			"cluename":             cluename,
+			"top_cluetype":         top_cluetype,
+			"sub_cluetype":         sub_cluetype,
+			"trailstatus":          "01",
+			"name":                 name,
+			"phone":                phone,
+			"position":             position,
+			"department":           department,
+			"industry":             industry,
+			"follow_project_area":  follow_project_area,
+			"role":                 role,
+			"comeinsource_private": 2,
+			"is_task":              1,
+			"task_time":            nowTime,
+			"tasktime":             common.If(item == "users", nowTimes, nowTime),
+			"taskstatus":           0,
+			"tasksource":           "线索自动分配" + "-" + topname + "-" + subname,
 		})
 		//变更记录
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
@@ -532,7 +521,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"BCPCID":       common.GetRandom(32),
 			"operator_id":  -1,
 		})
-		return clueId > -1 && seaId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1 && uodateId6 > -1
+		return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1 && uodateId6 > -1
 	}) {
 		log.Println("线索分配成功")
 		if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
@@ -548,7 +537,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 		}
 		return true
 	} else {
-		log.Println("线索分配失败!!!", clueId, seaId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
+		log.Println("线索分配失败!!!", clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
 		return false
 	}
 }
@@ -569,12 +558,12 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	oldsaleName, oldTaskTime, taskTime, is_task, taskstatus := "", "", "", 0, 0
 	old_position_id, old_seatNumber := common.Int64All(data["position_id"]), common.ObjToString(data["seatNumber"])
 	//已在任务车的判断任务时间
-	privateData := TiDb.FindOne("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, "", "")
-	if privateData != nil && len(*privateData) > 0 {
-		oldTaskTime = common.ObjToString((*privateData)["tasktime"])
-		is_task = common.IntAll(data["is_task"])
-		taskstatus = common.IntAll(data["taskstatus"])
-	}
+	// privateData := TiDb.FindOne("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, "", "")
+	// if privateData != nil && len(*privateData) > 0 {
+	oldTaskTime = common.ObjToString(data["tasktime"])
+	is_task = common.IntAll(data["is_task"])
+	taskstatus = common.IntAll(data["taskstatus"])
+	// }
 	if taskstatus == 1 || is_task == 0 {
 		taskTime = common.ObjToString(common.If(item != "users", nowTime, nowTimes))
 	} else {
@@ -622,25 +611,27 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	recordCount := TiDb.CountBySql(`select count(1) from dwd_f_crm_trail_content where clue_id = ? and createtime > ?`, clueId, t.AddDate(0, 0, -count).Format(date.Date_Full_Layout))
 	//
 	clueUpdateData := map[string]interface{}{
-		"updatetime":   nowTime,
-		"top_cluetype": top_cluetype,
-		"sub_cluetype": sub_cluetype,
-		"userid":       userId,
-	}
-	seaUpdateData := map[string]interface{}{
-		"comeinsource": 2,
-		"tasksource":   "线索来源自动更新" + "-" + topname + "-" + subname,
-	}
-	insertSeaData := map[string]interface{}{
-		"clue_id":      clueId,
-		"comeintime":   nowTime,
-		"comeinsource": 2,
-		"is_task":      1,
-		"task_time":    nowTime,
-		"tasktime":     taskTime,
-		"taskstatus":   0,
-		"tasksource":   "线索来源自动更新" + "-" + topname + "-" + subname,
+		"updatetime":           nowTime,
+		"top_cluetype":         top_cluetype,
+		"sub_cluetype":         sub_cluetype,
+		"userid":               userId,
+		"comeinsource_private": 2,
+		"tasksource":           "线索来源自动更新" + "-" + topname + "-" + subname,
 	}
+	// seaUpdateData := map[string]interface{}{
+	// 	"comeinsource": 2,
+	// 	"tasksource":   "线索来源自动更新" + "-" + topname + "-" + subname,
+	// }
+	// insertSeaData := map[string]interface{}{
+	// 	"clue_id":      clueId,
+	// 	"comeintime":   nowTime,
+	// 	"comeinsource": 2,
+	// 	"is_task":      1,
+	// 	"task_time":    nowTime,
+	// 	"tasktime":     taskTime,
+	// 	"taskstatus":   0,
+	// 	"tasksource":   "线索来源自动更新" + "-" + topname + "-" + subname,
+	// }
 	if cluename != "" {
 		clueUpdateData["cluename"] = cluename
 	}
@@ -659,11 +650,11 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 			clueUpdateData["position_id"] = positionId
 			clueUpdateData["comeintime"] = nowTime
 			clueUpdateData["is_assign"] = 1
-			seaUpdateData["seatNumber"] = seatNumber
-			seaUpdateData["position_id"] = positionId
-			seaUpdateData["comeintime"] = nowTime
-			insertSeaData["seatNumber"] = seatNumber
-			insertSeaData["position_id"] = positionId
+			// seaUpdateData["seatNumber"] = seatNumber
+			// seaUpdateData["position_id"] = positionId
+			// seaUpdateData["comeintime"] = nowTime
+			// insertSeaData["seatNumber"] = seatNumber
+			// insertSeaData["position_id"] = positionId
 			for _, v := range saleData {
 				if common.ObjToString(data["seatNumber"]) == common.ObjToString(v["seatNumber"]) {
 					oldsaleName = common.ObjToString(v["name"])
@@ -671,8 +662,11 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 			}
 		}
 	} else {
-		insertSeaData["seatNumber"] = old_seatNumber
-		insertSeaData["position_id"] = old_position_id
+		// insertSeaData["seatNumber"] = old_seatNumber
+		// insertSeaData["position_id"] = old_position_id
+		clueUpdateData["seatNumber"] = old_seatNumber
+		clueUpdateData["position_id"] = old_position_id
+		clueUpdateData["is_assign"] = 1
 	}
 	if trailstatus != "08" && is_assign == 0 {
 		if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
@@ -684,28 +678,32 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	if (trailstatus != "08" && recordCount <= 0) || is_assign == 0 {
 		if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
 		} else {
-			seaUpdateData["is_task"] = 1
-			seaUpdateData["task_time"] = nowTime
-			seaUpdateData["tasktime"] = taskTime
-			seaUpdateData["taskstatus"] = 0
+			// seaUpdateData["is_task"] = 1
+			// seaUpdateData["task_time"] = nowTime
+			// seaUpdateData["tasktime"] = taskTime
+			// seaUpdateData["taskstatus"] = 0
+			clueUpdateData["is_task"] = 1
+			clueUpdateData["task_time"] = nowTime
+			clueUpdateData["tasktime"] = taskTime
+			clueUpdateData["taskstatus"] = 0
 		}
 	}
-	ok, ok1, ok2, seaId := true, true, true, int64(0)
+	ok := true
 	updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
 	updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
 	updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
 	if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
 		//线索
 		ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
-		if is_assign == 1 {
-			ok1 = TiDb.UpdateByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, seaUpdateData)
-		} else {
-			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
-			} else {
-				ok2 = TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
-				seaId = TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", insertSeaData)
-			}
-		}
+		// if is_assign == 1 {
+		// 	ok1 = TiDb.UpdateByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId}, seaUpdateData)
+		// } else {
+		// 	if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
+		// 	} else {
+		// 		ok2 = TiDb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
+		// 		seaId = TiDb.InsertByTx(tx, "dwd_f_crm_private_sea", insertSeaData)
+		// 	}
+		// }
 		//变更记录
 		if (trailstatus == "00" || old_position_id == 0) && is_assign == 1 {
 			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
@@ -816,8 +814,6 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				})
 			}
 		}
-		log.Println("trailstatusTime ", trailstatusTime)
-		log.Println("trailstatusTimes.Unix() ", trailstatusTimes.Unix(), time.Now().Unix()-trailstatusTimes.Unix())
 		if trailstatus != "08" && recordCount <= 0 {
 			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
 			} else {
@@ -970,7 +966,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				"operator_id":  -1,
 			})
 		}
-		return ok && ok1 && seaId > -1 && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1 && updateId11 > -1 && updateId12 > -1 && updateId13 > -1
+		return ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1 && updateId11 > -1 && updateId12 > -1 && updateId13 > -1
 	}) {
 		log.Println("线索更新成功")
 		if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
@@ -986,7 +982,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		}
 		return true
 	} else {
-		log.Println("线索更新失败!!!", ok, ok1, ok2, seaId, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
+		log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
 		return false
 	}
 }

+ 184 - 184
telemarketingEtl/entity/dwd_f_crm_open_sea.go

@@ -374,7 +374,7 @@ func ThreeOpenSea(oneA, oneB, oneC, twoA, twoB, twoC, twoD map[string]bool) map[
 			if count%5000 == 0 {
 				log.Println("三级公海加载:", count)
 			}
-			clubId := gconv.String(v["clue_id"])
+			clubId := gconv.String(v["id"])
 			userid := gconv.String(v["userid"])
 			// q := fmt.Sprintf("SELECT count(1)  FROM dwd_f_userbase_visit_info WHERE  createtime > '%s' AND contentnum >0 and userid = '%s'", t.Format(date.Date_Full_Layout), userid)
 			// if config.JianyuSubjectdb.CountBySql(q) > 0 {
@@ -394,9 +394,9 @@ func ThreeOpenSea(oneA, oneB, oneC, twoA, twoB, twoC, twoD map[string]bool) map[
 			whs = append(whs, "?")
 		}
 		wh := strings.Join(whs, ",")
-		config.JianyuSubjectdb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_open_sea SET level = 3,clue_level='D' WHERE clue_id in (`+wh+`)`, ids...)
+		config.JianyuSubjectdb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET level_open = 3,clue_level='D' WHERE id in (`+wh+`)`, ids...)
 		return true
-	}, `SELECT a.clue_id,b.userid FROM dwd_f_crm_open_sea a LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id`)
+	}, `SELECT id,userid FROM dwd_f_crm_clue_info`)
 	log.Println("三级公海end")
 	return m
 }
@@ -420,9 +420,9 @@ func AddOpenSea(m map[string]bool, level int, clue_level string) {
 	// createtime := time.Now().Format(date.Date_Full_Layout)
 	if len(m) > 0 {
 		for k, _ := range m {
-			config.JianyuSubjectdb.Update("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": k}, map[string]interface{}{
+			config.JianyuSubjectdb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": k}, map[string]interface{}{
 				"clue_level": clue_level,
-				"LEVEL":      level,
+				"level_open": level,
 			})
 		}
 	}
@@ -461,182 +461,182 @@ func DeleteOpenSea() {
 6.“商机线索”超过2天未更新跟进记录自动退回公海;
 7.“无意向客户”自动退回公海;
 */
-func ReturnOpenSea() {
-	ctx := gctx.New()
-	t := time.Now()
-	t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
-	//高意向客户
-	highIntentionCustomer := g.Cfg().MustGet(ctx, "highIntentionCustomer").Int() //30
-	//意向客户
-	intentionCustomer := g.Cfg().MustGet(ctx, "intentionCustomer").Int() //30
-	//潜在客户
-	latentCustomer := g.Cfg().MustGet(ctx, "latentCustomer").Int() //60
-	//沉睡客户
-	sleepCustomer := g.Cfg().MustGet(ctx, "sleepCustomer").Int() //90
-	//商机线索
-	businessLeads := g.Cfg().MustGet(ctx, "businessLeads").Int() //2
-	//无意向客户
-	// noIdeaCustomer := g.Cfg().MustGet(ctx, "noIdeaCustomer").Int() //
-
-	codeMap := dwd_d_crm_trailstatus_code()
-
-	now := time.Now().Format(date.Date_Full_Layout)
-
-	//判断节假日
-	statusMap := map[string]int{
-		"06": highIntentionCustomer,
-		"05": intentionCustomer,
-		"04": latentCustomer,
-		"03": sleepCustomer,
-		"01": businessLeads,
-	}
-	for status, statusInt := range statusMap {
-		count, counts := 0, 0
-		for {
-			count++
-			currentTime := t.AddDate(0, 0, -count)
-			if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
-				isok := false
-				for k, v := range config.DateMap {
-					if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
-						isok = true
-					}
-				}
-				if isok {
-					counts++
-				}
-			} else {
-				isok := true
-				for k, v := range config.DateMap {
-					if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
-						isok = false
-					}
-				}
-				if isok {
-					counts++
-				}
-			}
-			if counts >= statusInt {
-				break
-			}
-		}
-		statusMap[status] = count
-	}
-	//
-
-	//2.“高意向客户”超过30天未更新跟进记录自动退回公海;
-	for trailstatus, _ := range map[string]string{
-		"06": "",
-		"05": "",
-		"04": "",
-		"03": "",
-		"01": "",
-		"00": "",
-	} {
-		sql := `SELECT a.clue_id,a.position_id,a.seatNumber FROM dwd_f_crm_private_sea a 
-				LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id 
-				WHERE a.position_id is not null and b.trailstatus =?`
-		argsSelect := []interface{}{trailstatus}
-
-		intime := ""
-		if trailstatus != "00" {
-			sql += " AND a.comeintime <?"
-			nt := t.AddDate(0, 0, -statusMap[trailstatus])
-			// nt, _ := nexttime.(time.Time)
-			intime = nt.Format(date.Date_Full_Layout)
-			argsSelect = append(argsSelect, intime)
-		}
-		log.Println(sql)
-		log.Println(argsSelect)
-		//
-		config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
-			//1新增 2私海手动退回 3私海高意向客户自动退回 4私海意向客户退回 5私海潜在客户退回 6私海沉睡客户退回 7私海商机线索退回 8私海无意向客户退回
-			comeinsource := GetComeSource()[trailstatus]
-			ids := []interface{}{}
-			args := []interface{}{}
-			changeArgs1 := []interface{}{}
-			changeArgs2 := []interface{}{}
-			changeArgs3 := []interface{}{}
-			changeArgs4 := []interface{}{}
-			for _, v := range *l {
-				id := v["clue_id"] //
-				position_id := v["position_id"]
-				seatNumber := gconv.String(v["seatNumber"])
-
-				args2 := []interface{}{id}
-				//获取跟进内容
-				sql2 := `SELECT COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id = ? and position_id = ?`
-				if intime != "" {
-					sql2 += ` and createtime > ?`
-					args2 = append(args2, intime)
-					args2 = append(args2, position_id)
-				}
-				//保留未跟进线索
-				if config.JianyuSubjectdb.CountBySql(sql2, args2...) > 0 {
-					log.Println("不满足线索过滤", id)
-					continue
-				}
-
-				ids = append(ids, id)
-				//
-				args = append(args, id, now, comeinsource)
-				changeArgs1 = append(changeArgs1, id, position_id, "trailstatus", "线索状态变更", codeMap[trailstatus], "流失", now, -1)
-				changeArgs2 = append(changeArgs2, id, position_id, "position_id", "所属人变更", GetPositionName(seatNumber), "/", now, -1)
-				changeArgs3 = append(changeArgs3, id, position_id, "退出任务车", "未更新跟进记录自动退回公海", now, -1)
-				changeArgs4 = append(changeArgs3, id, position_id, "退回公海", "未更新跟进记录自动退回公海", now, -1)
-
-			}
-			whs := []string{}
-			for i := 0; i < len(ids); i++ {
-				whs = append(whs, "?")
-			}
-			wh := strings.Join(whs, ",")
-			//退出私海
-			if len(ids) > 0 {
-				config.JianyuSubjectdb.UpdateOrDeleteBySql(`delete from dwd_f_crm_private_sea  where clue_id in (`+wh+`)`, ids...)
-				//改线索表 职位id  坐席号 弄成空 分配状态改成未分配
-				up1 := config.JianyuSubjectdb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET seatNumber ='',position_id=0,is_assign=0  WHERE id in (`+wh+`)`, ids...)
-				if up1 == -1 {
-					log.Println("修改记录失败", `UPDATE dwd_f_crm_clue_info SET seatNumber ='',position_id=0,is_assign=0  WHERE id in (`+wh+`)`, ids)
-				}
-			}
-			//进入公海
-			if len(args) > 0 {
-				config.JianyuSubjectdb.InsertIgnoreBatch("dwd_f_crm_open_sea", []string{"clue_id", "comeintime", "comeinsource"}, args)
-			}
-
-			// 添加线索修改记录
-
-			//线索状态变更记录
-			if len(changeArgs1) > 0 {
-				i1, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_field", "change_type", "old_value", "new_value", "createtime", "operator_id"}, changeArgs1)
-				if i1 <= 0 {
-					log.Println("i1失败", changeArgs1)
-				}
-			}
-			if len(changeArgs1) > 0 {
-				i2, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_field", "change_type", "old_value", "new_value", "createtime", "operator_id"}, changeArgs2)
-				if i2 <= 0 {
-					log.Println("i2失败", changeArgs2)
-				}
-			}
-			if len(changeArgs1) > 0 {
-				i3, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_type", "new_value", "createtime", "operator_id"}, changeArgs3)
-				if i3 <= 0 {
-					log.Println("i3失败", changeArgs3)
-				}
-			}
-			if len(changeArgs1) > 0 {
-				i4, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_type", "new_value", "createtime", "operator_id"}, changeArgs4)
-				if i4 <= 0 {
-					log.Println("i4失败", changeArgs4)
-				}
-			}
-			return true
-		}, sql, argsSelect...)
-	}
-	log.Println("return sea end")
-}
+// func ReturnOpenSea() {
+// 	ctx := gctx.New()
+// 	t := time.Now()
+// 	t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
+// 	//高意向客户
+// 	highIntentionCustomer := g.Cfg().MustGet(ctx, "highIntentionCustomer").Int() //30
+// 	//意向客户
+// 	intentionCustomer := g.Cfg().MustGet(ctx, "intentionCustomer").Int() //30
+// 	//潜在客户
+// 	latentCustomer := g.Cfg().MustGet(ctx, "latentCustomer").Int() //60
+// 	//沉睡客户
+// 	sleepCustomer := g.Cfg().MustGet(ctx, "sleepCustomer").Int() //90
+// 	//商机线索
+// 	businessLeads := g.Cfg().MustGet(ctx, "businessLeads").Int() //2
+// 	//无意向客户
+// 	// noIdeaCustomer := g.Cfg().MustGet(ctx, "noIdeaCustomer").Int() //
+
+// 	codeMap := dwd_d_crm_trailstatus_code()
+
+// 	now := time.Now().Format(date.Date_Full_Layout)
+
+// 	//判断节假日
+// 	statusMap := map[string]int{
+// 		"06": highIntentionCustomer,
+// 		"05": intentionCustomer,
+// 		"04": latentCustomer,
+// 		"03": sleepCustomer,
+// 		"01": businessLeads,
+// 	}
+// 	for status, statusInt := range statusMap {
+// 		count, counts := 0, 0
+// 		for {
+// 			count++
+// 			currentTime := t.AddDate(0, 0, -count)
+// 			if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
+// 				isok := false
+// 				for k, v := range config.DateMap {
+// 					if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
+// 						isok = true
+// 					}
+// 				}
+// 				if isok {
+// 					counts++
+// 				}
+// 			} else {
+// 				isok := true
+// 				for k, v := range config.DateMap {
+// 					if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
+// 						isok = false
+// 					}
+// 				}
+// 				if isok {
+// 					counts++
+// 				}
+// 			}
+// 			if counts >= statusInt {
+// 				break
+// 			}
+// 		}
+// 		statusMap[status] = count
+// 	}
+// 	//
+
+// 	//2.“高意向客户”超过30天未更新跟进记录自动退回公海;
+// 	for trailstatus, _ := range map[string]string{
+// 		"06": "",
+// 		"05": "",
+// 		"04": "",
+// 		"03": "",
+// 		"01": "",
+// 		"00": "",
+// 	} {
+// 		sql := `SELECT a.clue_id,a.position_id,a.seatNumber FROM dwd_f_crm_private_sea a
+// 				LEFT JOIN dwd_f_crm_clue_info b ON a.clue_id=b.id
+// 				WHERE a.position_id is not null and b.trailstatus =?`
+// 		argsSelect := []interface{}{trailstatus}
+
+// 		intime := ""
+// 		if trailstatus != "00" {
+// 			sql += " AND a.comeintime <?"
+// 			nt := t.AddDate(0, 0, -statusMap[trailstatus])
+// 			// nt, _ := nexttime.(time.Time)
+// 			intime = nt.Format(date.Date_Full_Layout)
+// 			argsSelect = append(argsSelect, intime)
+// 		}
+// 		log.Println(sql)
+// 		log.Println(argsSelect)
+// 		//
+// 		config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
+// 			//1新增 2私海手动退回 3私海高意向客户自动退回 4私海意向客户退回 5私海潜在客户退回 6私海沉睡客户退回 7私海商机线索退回 8私海无意向客户退回
+// 			comeinsource := GetComeSource()[trailstatus]
+// 			ids := []interface{}{}
+// 			args := []interface{}{}
+// 			changeArgs1 := []interface{}{}
+// 			changeArgs2 := []interface{}{}
+// 			changeArgs3 := []interface{}{}
+// 			changeArgs4 := []interface{}{}
+// 			for _, v := range *l {
+// 				id := v["clue_id"] //
+// 				position_id := v["position_id"]
+// 				seatNumber := gconv.String(v["seatNumber"])
+
+// 				args2 := []interface{}{id}
+// 				//获取跟进内容
+// 				sql2 := `SELECT COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id = ? and position_id = ?`
+// 				if intime != "" {
+// 					sql2 += ` and createtime > ?`
+// 					args2 = append(args2, intime)
+// 					args2 = append(args2, position_id)
+// 				}
+// 				//保留未跟进线索
+// 				if config.JianyuSubjectdb.CountBySql(sql2, args2...) > 0 {
+// 					log.Println("不满足线索过滤", id)
+// 					continue
+// 				}
+
+// 				ids = append(ids, id)
+// 				//
+// 				args = append(args, id, now, comeinsource)
+// 				changeArgs1 = append(changeArgs1, id, position_id, "trailstatus", "线索状态变更", codeMap[trailstatus], "流失", now, -1)
+// 				changeArgs2 = append(changeArgs2, id, position_id, "position_id", "所属人变更", GetPositionName(seatNumber), "/", now, -1)
+// 				changeArgs3 = append(changeArgs3, id, position_id, "退出任务车", "未更新跟进记录自动退回公海", now, -1)
+// 				changeArgs4 = append(changeArgs3, id, position_id, "退回公海", "未更新跟进记录自动退回公海", now, -1)
+
+// 			}
+// 			whs := []string{}
+// 			for i := 0; i < len(ids); i++ {
+// 				whs = append(whs, "?")
+// 			}
+// 			wh := strings.Join(whs, ",")
+// 			//退出私海
+// 			if len(ids) > 0 {
+// 				config.JianyuSubjectdb.UpdateOrDeleteBySql(`delete from dwd_f_crm_private_sea  where clue_id in (`+wh+`)`, ids...)
+// 				//改线索表 职位id  坐席号 弄成空 分配状态改成未分配
+// 				up1 := config.JianyuSubjectdb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET seatNumber ='',position_id=0,is_assign=0  WHERE id in (`+wh+`)`, ids...)
+// 				if up1 == -1 {
+// 					log.Println("修改记录失败", `UPDATE dwd_f_crm_clue_info SET seatNumber ='',position_id=0,is_assign=0  WHERE id in (`+wh+`)`, ids)
+// 				}
+// 			}
+// 			//进入公海
+// 			if len(args) > 0 {
+// 				config.JianyuSubjectdb.InsertIgnoreBatch("dwd_f_crm_clue_info", []string{"clue_id", "comeintime", "comeinsource"}, args)
+// 			}
+
+// 			// 添加线索修改记录
+
+// 			//线索状态变更记录
+// 			if len(changeArgs1) > 0 {
+// 				i1, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_field", "change_type", "old_value", "new_value", "createtime", "operator_id"}, changeArgs1)
+// 				if i1 <= 0 {
+// 					log.Println("i1失败", changeArgs1)
+// 				}
+// 			}
+// 			if len(changeArgs1) > 0 {
+// 				i2, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_field", "change_type", "old_value", "new_value", "createtime", "operator_id"}, changeArgs2)
+// 				if i2 <= 0 {
+// 					log.Println("i2失败", changeArgs2)
+// 				}
+// 			}
+// 			if len(changeArgs1) > 0 {
+// 				i3, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_type", "new_value", "createtime", "operator_id"}, changeArgs3)
+// 				if i3 <= 0 {
+// 					log.Println("i3失败", changeArgs3)
+// 				}
+// 			}
+// 			if len(changeArgs1) > 0 {
+// 				i4, _ := config.JianyuSubjectdb.InsertBatch("dwd_f_crm_clue_change_record", []string{"clue_id", "position_id", "change_type", "new_value", "createtime", "operator_id"}, changeArgs4)
+// 				if i4 <= 0 {
+// 					log.Println("i4失败", changeArgs4)
+// 				}
+// 			}
+// 			return true
+// 		}, sql, argsSelect...)
+// 	}
+// 	log.Println("return sea end")
+// }
 
 // 2私海手动退回 3私海高意向客户自动退回 4私海意向客户退回 5私海潜在客户退回 6私海沉睡客户退回 7私海商机线索退回 8私海无意向客户退回
 func GetComeSource() map[string]int {
@@ -654,14 +654,14 @@ func GetOneSeaC(oneClassA, oneClassB map[string]bool) map[string]bool {
 	m := map[string]bool{}
 	config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
 		for _, v := range *l {
-			clueid := gconv.String(v["clue_id"])
+			clueid := gconv.String(v["id"])
 			if oneClassA[clueid] || oneClassB[clueid] {
 				continue
 			}
 			m[clueid] = true
 		}
 		return true
-	}, `select clue_id from dwd_f_crm_open_sea where comeinsource in(2,3,4)`)
+	}, `select id from dwd_f_crm_clue_info where comeinsource_open in(2,3,4)`)
 	return m
 }
 
@@ -697,7 +697,7 @@ func Recycle() {
 	recycleB := g.Cfg().MustGet(ctx, "recycleB").Int()
 	tB := t.AddDate(0, 0, -recycleB)
 	for sql, clue_level := range map[string]interface{}{
-		fmt.Sprintf(`select id from dwd_f_crm_open_sea where comeinsource=%v and comeintime > "%s" ;`, 2, tA.Format(date.Date_Full_Layout)): "A",
+		fmt.Sprintf(`select id from dwd_f_crm_clue_info where comeinsource_open=%v and comeintime_open > "%s" ;`, 2, tA.Format(date.Date_Full_Layout)): "A",
 		fmt.Sprintf(`SELECT a.uid,b.phone,c.createTime,a.id FROM dwd_f_crm_clue_info a 
 					LEFT JOIN dwd_f_userbase_contacts b ON b.baseinfo_id=a.uid
 					LEFT JOIN Call_Accounting.voice_record c ON c.CalledNo = b.phone