فهرست منبع

增加节假日判断

xuzhiheng 2 سال پیش
والد
کامیت
1b926fd537
5فایلهای تغییر یافته به همراه118 افزوده شده و 20 حذف شده
  1. 46 6
      clueSync/autoTask.go
  2. 7 0
      clueSync/config.go
  3. 1 2
      clueSync/main.go
  4. 8 0
      telemarketingEtl/config/config.go
  5. 56 12
      telemarketingEtl/entity/dwd_f_crm_open_sea.go

+ 46 - 6
clueSync/autoTask.go

@@ -12,11 +12,51 @@ func autoTask() {
 	log.Println("超时未跟进定时任务开始")
 	t := time.Now()
 	nowTime := time.Now().Format(date.Date_Full_Layout)
-	for trailstatus, nexttime := range map[string]interface{}{
-		"07": t.AddDate(0, 0, -5), //待签署客户
-		"06": t.AddDate(0, 0, -3), //高意向客户
-		"05": t.AddDate(0, 0, -5), //意向客户
-		"04": t.AddDate(0, 0, -7), //潜在客户
+	statusMap := map[string]int{
+		"07": 5, //待签署客户
+		"06": 3, //高意向客户
+		"05": 5, //意向客户
+		"04": 7, //潜在客户
+	}
+	//判断节假日
+	for status, statusInt := range statusMap {
+		count, counts := 0, 0
+		for {
+			count++
+			currentTime := t.AddDate(0, 0, -count)
+			currentTime.Format(date.Date_Short_Layout)
+			if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Sunday {
+				isok := false
+				for k, v := range DateMap {
+					if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
+						isok = true
+					}
+				}
+				if isok {
+					counts++
+				}
+			} else {
+				isok := true
+				for k, v := range DateMap {
+					if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
+						isok = false
+					}
+				}
+				if isok {
+					counts++
+				}
+			}
+			if counts >= statusInt {
+				break
+			}
+		}
+		statusMap[status] = counts
+	}
+	for trailstatus, _ := range map[string]string{
+		"07": "", //待签署客户
+		"06": "", //高意向客户
+		"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 
@@ -24,7 +64,7 @@ func autoTask() {
 		argsSelect := []interface{}{trailstatus}
 		intime := ""
 		sql += " AND a.comeintime <?"
-		nt, _ := nexttime.(time.Time)
+		nt := t.AddDate(0, 0, -statusMap[trailstatus])
 		intime = nt.Format(date.Date_Short_Layout) + " 00:00:00"
 		argsSelect = append(argsSelect, intime)
 		log.Println(sql)

+ 7 - 0
clueSync/config.go

@@ -76,6 +76,7 @@ type (
 var AreaCode = map[string]string{}
 var CodeArea = map[string]string{}
 var CodeTrail = map[string]string{}
+var DateMap = map[string]int{}
 
 func InitArea() {
 	info := TiDb.Find("d_area_code", nil, "", "", -1, -1)
@@ -93,4 +94,10 @@ func InitArea() {
 			CodeTrail[common.ObjToString(m["code"])] = common.ObjToString(m["name"])
 		}
 	}
+	holidayRecords := TiDb.Find("holiday_records", nil, "", "", -1, -1)
+	if holidayRecords != nil && len(*holidayRecords) > 0 {
+		for _, m := range *holidayRecords {
+			DateMap[common.ObjToString(m["date"])] = common.IntAll(m["change"])
+		}
+	}
 }

+ 1 - 2
clueSync/main.go

@@ -5,12 +5,11 @@ import (
 	"fmt"
 	"log"
 
-	"app.yhyue.com/moapp/jybase/redis"
-
 	"app.yhyue.com/moapp/jybase/common"
 	elastic "app.yhyue.com/moapp/jybase/esv1"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
+	"app.yhyue.com/moapp/jybase/redis"
 	"github.com/robfig/cron"
 )
 

+ 8 - 0
telemarketingEtl/config/config.go

@@ -3,6 +3,7 @@ package config
 import (
 	"log"
 
+	"app.yhyue.com/moapp/jybase/common"
 	mg "app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"github.com/gogf/gf/v2/frame/g"
@@ -17,6 +18,7 @@ var (
 	MgoLog          mg.MongodbSim
 	MgoBid          mg.MongodbSim
 	MgoEnt          mg.MongodbSim
+	DateMap         = map[string]int{}
 )
 
 func init() {
@@ -93,4 +95,10 @@ func init() {
 		}
 		MgoBid.InitPool()
 	}
+	holidayRecords := JianyuSubjectdb.Find("holiday_records", nil, "", "", -1, -1)
+	if holidayRecords != nil && len(*holidayRecords) > 0 {
+		for _, m := range *holidayRecords {
+			DateMap[common.ObjToString(m["date"])] = common.IntAll(m["change"])
+		}
+	}
 }

+ 56 - 12
telemarketingEtl/entity/dwd_f_crm_open_sea.go

@@ -425,14 +425,57 @@ func ReturnOpenSea() {
 
 	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)
+			currentTime.Format(date.Date_Short_Layout)
+			if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Sunday {
+				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] = counts
+	}
+	//
+
 	//2.“高意向客户”超过30天未更新跟进记录自动退回公海;
-	for trailstatus, nexttime := range map[string]interface{}{
-		"06": t.AddDate(0, 0, -highIntentionCustomer),
-		"05": t.AddDate(0, 0, -intentionCustomer),
-		"04": t.AddDate(0, 0, -latentCustomer),
-		"03": t.AddDate(0, 0, -sleepCustomer),
-		"01": t.AddDate(0, 0, -businessLeads),
-		"00": t,
+	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 
@@ -442,7 +485,8 @@ func ReturnOpenSea() {
 		intime := ""
 		if trailstatus != "00" {
 			sql += " AND a.comeintime <?"
-			nt, _ := nexttime.(time.Time)
+			nt := t.AddDate(0, 0, -statusMap[trailstatus])
+			// nt, _ := nexttime.(time.Time)
 			intime = nt.Format(date.Date_Full_Layout)
 			argsSelect = append(argsSelect, intime)
 		}
@@ -538,7 +582,7 @@ func ReturnOpenSea() {
 	log.Println("return sea end")
 }
 
-//2私海手动退回 3私海高意向客户自动退回 4私海意向客户退回 5私海潜在客户退回 6私海沉睡客户退回 7私海商机线索退回 8私海无意向客户退回
+// 2私海手动退回 3私海高意向客户自动退回 4私海意向客户退回 5私海潜在客户退回 6私海沉睡客户退回 7私海商机线索退回 8私海无意向客户退回
 func GetComeSource() map[string]int {
 	return map[string]int{
 		"06": 3,
@@ -584,9 +628,9 @@ func GetPositionName(seatNumber string) string {
 	return ""
 }
 
-//(4)回收站:
-//A.5个自然日内被销售人员手动退回公海的客户;
-//B.3个自然日内有过“已接听”的通话记录且仍处于“商机线索”状态下的客户。
+// (4)回收站:
+// A.5个自然日内被销售人员手动退回公海的客户;
+// B.3个自然日内有过“已接听”的通话记录且仍处于“商机线索”状态下的客户。
 func Recycle() {
 	log.Println("回收站开始")
 	ctx := gctx.New()