Jianghan 11 달 전
부모
커밋
7aca7937b3
4개의 변경된 파일61개의 추가작업 그리고 56개의 파일을 삭제
  1. 31 34
      telemarketingEtl/entity/Voiced.go
  2. 15 9
      telemarketingEtl/entity/dwd_f_userbase_visit_info.go
  3. 13 13
      telemarketingEtl/main.go
  4. 2 0
      telemarketingEtl/timetask/task.go

+ 31 - 34
telemarketingEtl/entity/Voiced.go

@@ -3,6 +3,7 @@ package entity
 import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
+	"fmt"
 	"go.mongodb.org/mongo-driver/bson"
 	"log"
 	"strings"
@@ -51,7 +52,9 @@ func CountCalled() {
 
 	for _, s := range callPhone {
 		uid := userPhone[s]
-		mUser[uid].frequency += 1
+		if uid != "" {
+			mUser[uid].frequency += 1
+		}
 	}
 	log.Println("CountCalled 通话次数匹配结束...")
 	for k, v := range mUser {
@@ -66,6 +69,7 @@ func CountCalled() {
 			}
 		}
 	}
+	mUser = make(map[string]*Called)
 
 }
 
@@ -102,7 +106,7 @@ func getUser() {
 			}
 		}
 		count++
-		if count%2000 == 0 {
+		if count%10000 == 0 {
 			log.Println("CountCalled current-------", count)
 		}
 		uid := common.ObjToString(ret["baseinfo_id"])
@@ -134,8 +138,8 @@ func getRecord() {
 		countSql = "SELECT COUNT(id) FROM voice_record WHERE DATE(createTime) BETWEEN DATE(NOW() - INTERVAL 7 DAY) AND DATE(NOW())"
 	} else {
 		aTime := time.Now().Add(-1 * time.Hour)
-		sql = "SELECT createTime, CallNo, CalledNo FROM voice_record WHERE createTime >= " + aTime.Format(time.DateTime) + " ORDER BY createTime ASC"
-		countSql = "SELECT COUNT(id) FROM voice_record WHERE createTime >= " + aTime.Format(time.DateTime)
+		sql = fmt.Sprintf("SELECT createTime, CallNo, CalledNo FROM voice_record WHERE createTime >= '%s' ORDER BY createTime ASC", aTime.Format(time.DateTime))
+		countSql = fmt.Sprintf("SELECT COUNT(id) FROM voice_record WHERE createTime >= '%s'", aTime.Format(time.DateTime))
 	}
 	total = config.VoicedRecordDb.CountBySql(countSql)
 	log.Println("CountCalled getRecord---", total)
@@ -192,6 +196,7 @@ func MissedCalls() {
 			})
 		}
 	}
+	missedPhone = make(map[string]*Voiced)
 }
 
 func getMissedCalls() {
@@ -201,15 +206,11 @@ func getMissedCalls() {
 		count    int
 		total    int64
 	)
-	if firstLoad1 {
-		sql = "SELECT createTime, CallNo, CalledNo, State FROM voice_record ORDER BY createTime ASC"
-		countSql = "SELECT COUNT(id) FROM voice_record"
-		firstLoad1 = false
-	} else {
-		aTime := time.Now().Add(-1 * time.Hour)
-		sql = "SELECT createTime, CallNo, CalledNo, State FROM voice_record WHERE createTime >= " + aTime.Format(time.DateTime) + " ORDER BY createTime ASC"
-		countSql = "SELECT COUNT(id) FROM voice_record WHERE createTime >= " + aTime.Format(time.DateTime)
-	}
+	//sql = "SELECT createTime, CallNo, CalledNo, State FROM voice_record ORDER BY createTime ASC"
+	//countSql = "SELECT COUNT(id) FROM voice_record"
+	aTime := time.Now().Add(-1 * time.Hour)
+	sql = fmt.Sprintf("SELECT createTime, CallNo, CalledNo, State FROM voice_record WHERE createTime >= '%s' ORDER BY createTime ASC", aTime.Format(time.DateTime))
+	countSql = fmt.Sprintf("SELECT COUNT(id) FROM voice_record WHERE createTime >= '%s'", aTime.Format(time.DateTime))
 	total = config.VoicedRecordDb.CountBySql(countSql)
 	log.Println("MissedCalls getMissedCalls---", total)
 	if total <= 0 {
@@ -247,31 +248,27 @@ func getMissedCalls() {
 		vdate := strings.Split(common.ObjToString(ret["createTime"]), " ")[0]
 		ctype := common.ObjToString(ret["State"])
 		uid := userPhone[phone]
-		if ctype != "dealing" {
-			if missedPhone[uid] != nil {
-				v := missedPhone[uid]
-				v.vDate = vdate
-				v.missed += 1
-				//if VerifyDate(v.vDate, vdate) <= 1 {
-				//	v.vDate = vdate
-				//	v.missed += 1
-				//} else {
-				//	v.missed = 1
-				//	v.vDate = vdate
-				//}
+		if uid != "" {
+			if ctype != "dealing" {
+				if missedPhone[uid] != nil {
+					v := missedPhone[uid]
+					v.vDate = vdate
+					v.missed += 1
+				} else {
+					missedPhone[uid] = &Voiced{
+						vDate:  vdate,
+						missed: 1,
+					}
+				}
 			} else {
-				missedPhone[uid] = &Voiced{
-					vDate:  vdate,
-					missed: 1,
+				if missedPhone[uid] != nil {
+					v := missedPhone[uid]
+					v.vDate = vdate
+					v.missed = 0
 				}
 			}
-		} else {
-			if uid != "" && missedPhone[uid] != nil {
-				v := missedPhone[uid]
-				v.vDate = vdate
-				v.missed = 0
-			}
 		}
+
 	}
 	_ = rows.Close()
 }

+ 15 - 9
telemarketingEtl/entity/dwd_f_userbase_visit_info.go

@@ -115,10 +115,13 @@ func VisitInfoAdd(start, end int64) {
 					if config.JianyuSubjectdb.CountBySql(`select count(1) from dwd_f_userbase_visit_info where userid = ? and createtime>= ? and createtime <?`, userid, starttime, endtime) > 0 {
 						if contentnum != 0 {
 							config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set number = number+1,contentnum = contentnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
+							//config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set contentnum = contentnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
 						} else if portraitnum != 0 {
-							config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set number = number+1,portraitnum = contentnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
+							config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set number = number+1,portraitnum = portraitnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
+							//config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set portraitnum = portraitnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
 						} else if searchnum != 0 {
-							config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set number = number+1,searchnum = contentnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
+							config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set number = number+1,searchnum = searchnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
+							//config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set searchnum = searchnum + 1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
 						} else {
 							config.JianyuSubjectdb.UpdateOrDeleteBySql(`update dwd_f_userbase_visit_info set number = number+1,date =?,platform=? where userid = ? and createtime>= ? and createtime <?`, craetetimeStr, platform, userid, starttime, endtime)
 						}
@@ -256,6 +259,7 @@ func CountMaxVisit() {
 			})
 		}
 	}
+	mData = make(map[string]*UserVisit)
 }
 
 // @Author jianghan
@@ -311,8 +315,8 @@ func Count3DaysSearch() {
 		countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_search_info v WHERE DATE(v.search_time) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW())"
 	} else {
 		aTime := time.Now().Add(-1 * time.Hour)
-		sql = "SELECT v.userid, b.uid, v.search_time FROM dwd_f_userbase_search_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE v.search_time >= " + aTime.Format(time.DateTime) + " ORDER BY v.date ASC"
-		countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_search_info v WHERE v.search_time >= " + aTime.Format(time.DateTime)
+		sql = fmt.Sprintf("SELECT v.userid, b.uid, v.search_time FROM dwd_f_userbase_search_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE v.search_time >= '%s' ORDER BY v.date ASC", aTime.Format(time.DateTime))
+		countSql = fmt.Sprintf("SELECT COUNT(v.id) FROM dwd_f_userbase_search_info v WHERE v.search_time >= '%s'", aTime.Format(time.DateTime))
 	}
 	total = config.JianyuSubjectdb.CountBySql(countSql)
 	log.Println("Count3DaysSearch total---", total)
@@ -364,6 +368,7 @@ func Count3DaysSearch() {
 			})
 		}
 	}
+	mSearchMap = make(map[string]int)
 }
 
 func Count3DaysDetail() {
@@ -391,8 +396,8 @@ func Count3DaysDetail() {
 		countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_visit_info v WHERE DATE(date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW())"
 	} else {
 		aTime := time.Now().Add(-1 * time.Hour)
-		sql = "SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE v.date >= " + aTime.Format(time.DateTime) + " ORDER BY v.date ASC"
-		countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_visit_info v WHERE v.date >= " + aTime.Format(time.DateTime)
+		sql = fmt.Sprintf("SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE v.date >= '%s' ORDER BY v.date ASC", aTime.Format(time.DateTime))
+		countSql = fmt.Sprintf("SELECT COUNT(v.id) FROM dwd_f_userbase_visit_info v WHERE v.date >= '%s'", aTime.Format(time.DateTime))
 	}
 	total = config.JianyuSubjectdb.CountBySql(countSql)
 	log.Println("Count3DaysDetail total---", total)
@@ -445,6 +450,7 @@ func Count3DaysDetail() {
 			})
 		}
 	}
+	mDetailMap = make(map[string]int)
 }
 
 func VipExpire() {
@@ -460,8 +466,8 @@ func VipExpire() {
 	config.JianyuSubjectdb.ExecBySql("update dwd_f_crm_attribute_label set supersub = 0 where supersub = 1")
 	config.JianyuSubjectdb.ExecBySql("update dwd_f_crm_attribute_label set areasubpkg = 0 where areasubpkg = 1")
 
-	sql = fmt.Sprintf("select uid, product_type from dwd_f_data_equity_info WHERE product_type = '省份订阅包' or product_type = '超级订阅' AND endtime > %s", now.Format(date.Date_Short_Layout))
-	countSql = fmt.Sprintf("select count(id) from dwd_f_data_equity_info WHERE product_type = '省份订阅包' or product_type = '超级订阅' AND endtime > %s", now.Format(date.Date_Short_Layout))
+	sql = fmt.Sprintf("select uid, product_type from dwd_f_data_equity_info WHERE product_type = '省份订阅包' or product_type = '超级订阅' AND endtime > '%s'", now.Format(date.Date_Short_Layout))
+	countSql = fmt.Sprintf("select count(id) from dwd_f_data_equity_info WHERE product_type = '省份订阅包' or product_type = '超级订阅' AND endtime > '%s'", now.Format(date.Date_Short_Layout))
 
 	total = config.JianyuSubjectdb.CountBySql(countSql)
 	log.Println("VipExpire total---", total)
@@ -493,7 +499,7 @@ func VipExpire() {
 			}
 		}
 		count++
-		if count%2000 == 0 {
+		if count%5000 == 0 {
 			log.Println("VipExpire current-------", count)
 		}
 

+ 13 - 13
telemarketingEtl/main.go

@@ -6,20 +6,20 @@ import (
 )
 
 func main() {
-	t1 := timetask.TaskCountMaxVisit{}
-	t1.Run()
-	t2 := timetask.TaskCountCalled{}
-	t2.Run()
-	t3 := timetask.TaskMissedCalls{}
-	t3.Run()
-	t4 := timetask.TaskJyList{}
-	t4.Run()
-	t5 := timetask.TaskJyDetail{}
-	t5.Run()
-	t6 := timetask.TaskVipExpire{}
-	t6.Run()
+
+	//t1 := &timetask.TaskCountMaxVisit{}
+	//t1.Run()
+	//t2 := &timetask.TaskCountCalled{}
+	//t2.Run()
+	//t3 := &timetask.TaskMissedCalls{}
+	//t3.Run()
+	//t4 := &timetask.TaskVipExpire{}
+	//t4.Run()
+	//t := &timetask.TaskVisitInfo{}
+	//t.Run()
+
 	//定时任务开始
-	//timetask.Run()
+	timetask.Run()
 	select {}
 
 }

+ 2 - 0
telemarketingEtl/timetask/task.go

@@ -64,6 +64,7 @@ func (t *TaskSearchInfo) Run() {
 	start := now.Add(-time.Minute * time.Duration(min)).Unix()
 	//搜索事件
 	entity.SearchInfoAdd(start, end)
+	log.Println("结束TaskSearchInfo")
 }
 
 type TaskVisitInfo struct{}
@@ -75,6 +76,7 @@ func (t *TaskVisitInfo) Run() {
 	min := gcfg.Instance().MustGet(gctx.New(), "visitInfoTime", "").Int()
 	start := now.Add(-time.Minute * time.Duration(min)).Unix()
 	entity.VisitInfoAdd(start, end)
+	//entity.VisitInfoAdd(1721404800, 1724947200)
 	log.Println("结束TaskVisitInfo")
 }