Browse Source

feat:增加周活月活配置

fuwencai 1 year ago
parent
commit
b19468c9d4

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 *.data
 *.data
 .idea/*
 .idea/*
+*.exe

+ 4 - 2
config.json

@@ -4,7 +4,8 @@
     "prop": 0.1,
     "prop": 0.1,
     "updateCron": "0 30 0 ? * 0",
     "updateCron": "0 30 0 ? * 0",
     "saveClickTimes": 2,
     "saveClickTimes": 2,
-    "dailyTimes": 1000
+    "dailyTimes": 1000,
+    "mode":1
   },
   },
   "custom": {
   "custom": {
     "open": true,
     "open": true,
@@ -16,7 +17,8 @@
       },
       },
       "timeOver": 10,
       "timeOver": 10,
       "waitTime": 30
       "waitTime": 30
-    }
+    },
+    "mode":1
   },
   },
   "testUid": [
   "testUid": [
   ],
   ],

+ 3 - 3
db.json

@@ -26,15 +26,15 @@
 	},
 	},
     "redis": {
     "redis": {
     	"main":{
     	"main":{
-			"address": "other=192.168.3.206:1712,newother=192.168.3.206:1712,session=192.168.3.206:1712"
+			"address": "other=192.168.3.149:1712,newother=192.168.3.149:1712,session=192.168.3.149:1712"
 		}
 		}
     },
     },
     "mysql": {
     "mysql": {
 	    "main": {
 	    "main": {
 	        "dbName": "jianyu",
 	        "dbName": "jianyu",
-	        "address": "192.168.3.11:3366",
+	        "address": "192.168.3.14:3366",
 	        "userName": "root",
 	        "userName": "root",
-	        "passWord": "Topnet123",
+	        "passWord": "=PDT49#80Z!RVv52_z",
 			"maxOpenConns": 5,
 			"maxOpenConns": 5,
 			"maxIdleConns": 5
 			"maxIdleConns": 5
 	    },
 	    },

+ 96 - 8
entity/activeUsers/activeUsers.go

@@ -1,6 +1,7 @@
 package activeUsers
 package activeUsers
 
 
 import (
 import (
+	"fmt"
 	"leadGeneration/entity/power"
 	"leadGeneration/entity/power"
 	"leadGeneration/public"
 	"leadGeneration/public"
 	"log"
 	"log"
@@ -12,9 +13,25 @@ import (
 user_countbyhour 表只有一个月的数据
 user_countbyhour 表只有一个月的数据
 */
 */
 
 
+// 超前项目
+type aheadActiveFreeUser struct {
+}
+
+func NewAheadActiveFreeUser() *aheadActiveFreeUser {
+	return &aheadActiveFreeUser{}
+}
+
+// 定制化分析报告
+type customerActiveFreeUser struct {
+}
+
+func NewCustomerActiveFreeUser() *customerActiveFreeUser {
+	return &customerActiveFreeUser{}
+}
+
 // GetWeekActiveFreeUsers 获取周活无权限用户
 // GetWeekActiveFreeUsers 获取周活无权限用户
-func GetWeekActiveFreeUsers() (rData []string) {
-	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers start\n")
+func (a *aheadActiveFreeUser) GetWeekActiveFreeUsers() (rData []string) {
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetWeekActiveFreeUsers start\n")
 	now := time.Now()
 	now := time.Now()
 	_, end_m, end_d := now.Date()
 	_, end_m, end_d := now.Date()
 	_, start_m, start_d := now.AddDate(0, 0, -7).Date()
 	_, start_m, start_d := now.AddDate(0, 0, -7).Date()
@@ -30,9 +47,33 @@ func GetWeekActiveFreeUsers() (rData []string) {
 		sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? AND day < ?"
 		sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? AND day < ?"
 		param = []interface{}{start_d, end_d}
 		param = []interface{}{start_d, end_d}
 	}
 	}
-	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers search sql:%s value:%v start\n", sql, param)
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetWeekActiveFreeUsers search sql:%s value:%v start\n", sql, param)
 	res := public.UserAnalyseDb.SelectBySql(sql, param...)
 	res := public.UserAnalyseDb.SelectBySql(sql, param...)
-	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers search end\n")
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetWeekActiveFreeUsers search end\n")
+
+	if res == nil || len(*res) == 0 {
+		return
+	}
+	rData = make([]string, 0, len(*res))
+	for _, v := range *res {
+		if userId, _ := v["user_mongoid"].(string); userId != "" {
+			if !power.HasAheadPower(userId) {
+				rData = append(rData, userId)
+			}
+		}
+	}
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetWeekActiveFreeUsers start Finished Total %d\n", len(rData))
+	return rData
+}
+
+// GetMonthActiveFreeUsers 获取月活无权限用户
+func (a *aheadActiveFreeUser) GetMonthActiveFreeUsers() (rData []string) {
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetMonthActiveFreeUsers start\n")
+	var sql string
+	sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour "
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetMonthActiveFreeUsers search sql:%s value:%v start\n", sql)
+	res := public.UserAnalyseDb.SelectBySql(sql)
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetMonthActiveFreeUsers search end\n")
 
 
 	if res == nil || len(*res) == 0 {
 	if res == nil || len(*res) == 0 {
 		return
 		return
@@ -45,14 +86,14 @@ func GetWeekActiveFreeUsers() (rData []string) {
 			}
 			}
 		}
 		}
 	}
 	}
-	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers start Finished Total %d\n", len(rData))
+	log.Printf("[ACTIVE-USER-INFO]AheadActiveFreeUser GetMonthActiveFreeUsers start Finished Total %d\n", len(rData))
 	return rData
 	return rData
 }
 }
 
 
 // GetMonthActiveFreeUsers 获取月活用户
 // GetMonthActiveFreeUsers 获取月活用户
 // 有订阅或有搜索词的周活用户+最近7天注册的新用户无条件生
 // 有订阅或有搜索词的周活用户+最近7天注册的新用户无条件生
-func GetMonthActiveFreeUsers() (rData []string) {
-	log.Printf("[ACTIVE-USER-INFO]GetMonthActiveFreeUsers start\n")
+func (c *customerActiveFreeUser) GetMonthActiveFreeUsers() (rData []string) {
+	log.Printf("[ACTIVE-USER-INFO]CustomerActiveFreeUser GetMonthActiveFreeUsers start\n")
 	//表数据为近一个月,所以直接查询全部
 	//表数据为近一个月,所以直接查询全部
 	res := public.UserAnalyseDb.SelectBySql("SELECT user_mongoid,sum(search) AS total FROM user_countbyhour group by user_mongoid")
 	res := public.UserAnalyseDb.SelectBySql("SELECT user_mongoid,sum(search) AS total FROM user_countbyhour group by user_mongoid")
 	if res == nil || len(*res) == 0 {
 	if res == nil || len(*res) == 0 {
@@ -79,6 +120,53 @@ func GetMonthActiveFreeUsers() (rData []string) {
 		}
 		}
 		rData = append(rData, userId)
 		rData = append(rData, userId)
 	}
 	}
-	log.Printf("[ACTIVE-USER-INFO]GetMonthActiveFreeUsers start Finished Total %d\n", len(rData))
+	log.Printf("[ACTIVE-USER-INFO]CustomerActiveFreeUser GetMonthActiveFreeUsers start Finished Total %d\n", len(rData))
+	return rData
+}
+
+// GetWeekActiveFreeUsers 获取周活用户
+func (c *customerActiveFreeUser) GetWeekActiveFreeUsers() (rData []string) {
+	log.Printf("[ACTIVE-USER-INFO]CustomerActiveFreeUser GetWeekActiveFreeUsers start\n")
+	now := time.Now()
+	_, end_m, end_d := now.Date()
+	_, start_m, start_d := now.AddDate(0, 0, -7).Date()
+	var sql string
+	var param []interface{}
+	if start_m != end_m {
+		//跨月
+		sql = " WHERE day >= ? OR day < ? "
+		param = []interface{}{end_d, start_d}
+	} else {
+		//非跨月
+		sql = " WHERE day >= ? AND day < ? "
+		param = []interface{}{start_d, end_d}
+	}
+	query := fmt.Sprintf("SELECT user_mongoid,sum(search) AS total FROM user_countbyhour %s group by user_mongoid", sql)
+	res := public.UserAnalyseDb.SelectBySql(query, param...)
+	if res == nil || len(*res) == 0 {
+		return
+	}
+	rData = make([]string, 0, len(*res))
+	for _, v := range *res {
+		userId, _ := v["user_mongoid"].(string)
+		if userId == "" {
+			continue
+		}
+
+		//非会员
+		if hasPower := power.HasPower(userId); hasPower {
+			continue
+		}
+
+		//无搜索记录、无关键词
+		if searchTotal, _ := v["total"].(int); searchTotal == 0 {
+			//无订阅词
+			if !power.HasSubscribe(userId) {
+				continue
+			}
+		}
+		rData = append(rData, userId)
+	}
+	log.Printf("[ACTIVE-USER-INFO]CustomerActiveFreeUser GetWeekActiveFreeUsers start Finished Total %d\n", len(rData))
 	return rData
 	return rData
 }
 }

+ 6 - 1
entity/mananger/aheadManager.go

@@ -150,6 +150,7 @@ func (this *AheadManager) getUserGroup() (userIds []string) {
 			}
 			}
 		}
 		}
 	}
 	}
+	userIds = []string{}
 	//无数据则重新生成用户群组数据
 	//无数据则重新生成用户群组数据
 	if len(userIds) == 0 {
 	if len(userIds) == 0 {
 		log.Printf("[MANAGER-INFO]AheadManager getUserGroup createNewGroup start\n")
 		log.Printf("[MANAGER-INFO]AheadManager getUserGroup createNewGroup start\n")
@@ -162,7 +163,11 @@ func (this *AheadManager) getUserGroup() (userIds []string) {
 		//新活跃用户
 		//新活跃用户
 		go func() {
 		go func() {
 			defer wg.Done()
 			defer wg.Done()
-			newActiveGroup = this.sortUserByBatchAndGetFinal(activeUsers.GetWeekActiveFreeUsers())
+			if this.Conf.Mode == ModeMonth { // 月活
+				newActiveGroup = this.sortUserByBatchAndGetFinal(AheadActiveFreeUser.GetMonthActiveFreeUsers())
+			} else { // 周活
+				newActiveGroup = this.sortUserByBatchAndGetFinal(AheadActiveFreeUser.GetWeekActiveFreeUsers())
+			}
 			activeUsers.SaveBatchGroup(newActiveGroup, 0, this.BatchFlag, "newActive")
 			activeUsers.SaveBatchGroup(newActiveGroup, 0, this.BatchFlag, "newActive")
 		}()
 		}()
 
 

+ 6 - 2
entity/mananger/customManager.go

@@ -143,7 +143,7 @@ func (this *CustomManager) UpdateUserGroupJob() {
 	go this.newUserQueue(this.BatchFlag)
 	go this.newUserQueue(this.BatchFlag)
 }
 }
 
 
-//getUserGroup 获取用户群组
+// getUserGroup 获取用户群组
 func (this *CustomManager) getUserGroup() (userIds []string) {
 func (this *CustomManager) getUserGroup() (userIds []string) {
 	//当前批次是否已有数据
 	//当前批次是否已有数据
 	rData := public.UserAnalyseDb.SelectBySql("SELECT user_mongoid AS uid FROM user_leadGeneration_group WHERE group_type = 1 AND group_name=?", this.BatchFlag)
 	rData := public.UserAnalyseDb.SelectBySql("SELECT user_mongoid AS uid FROM user_leadGeneration_group WHERE group_type = 1 AND group_name=?", this.BatchFlag)
@@ -199,7 +199,11 @@ func (this *CustomManager) getUserGroup() (userIds []string) {
 		//新活跃用户
 		//新活跃用户
 		go func() {
 		go func() {
 			defer wg.Done()
 			defer wg.Done()
-			newActiveGroup = activeUsers.GetMonthActiveFreeUsers()
+			if this.Conf.Mode == ModeMonth { // 月活
+				newActiveGroup = CustomerActiveFreeUser.GetMonthActiveFreeUsers()
+			} else { // 周活
+				newActiveGroup = CustomerActiveFreeUser.GetWeekActiveFreeUsers()
+			}
 			activeUsers.SaveBatchGroup(newActiveGroup, 1, this.BatchFlag, "newActive")
 			activeUsers.SaveBatchGroup(newActiveGroup, 1, this.BatchFlag, "newActive")
 		}()
 		}()
 		wg.Wait()
 		wg.Wait()

+ 13 - 3
entity/mananger/init.go

@@ -1,10 +1,20 @@
 package mananger
 package mananger
 
 
-import "leadGeneration/vars"
+import (
+	"leadGeneration/entity/activeUsers"
+	"leadGeneration/vars"
+)
 
 
 var (
 var (
-	JyAheadManager  = &AheadManager{}
-	JyCustomManager = &CustomManager{}
+	JyAheadManager         = &AheadManager{}
+	JyCustomManager        = &CustomManager{}
+	AheadActiveFreeUser    = activeUsers.NewAheadActiveFreeUser()
+	CustomerActiveFreeUser = activeUsers.NewCustomerActiveFreeUser()
+)
+
+const (
+	ModeMonth = 1 // 月活
+	ModeWeek  = 2 // 周活
 )
 )
 
 
 func init() {
 func init() {

+ 2 - 0
vars/config.go

@@ -20,6 +20,7 @@ type AheadConfig struct {
 	DailyTimes     int     `json:"dailyTimes"`     //每日展示次数
 	DailyTimes     int     `json:"dailyTimes"`     //每日展示次数
 	SaveClickTimes int     `json:"saveClickTimes"` //保留用户的点击量
 	SaveClickTimes int     `json:"saveClickTimes"` //保留用户的点击量
 	UpdateCron     string  `json:"updateCron"`     //更新周活用户
 	UpdateCron     string  `json:"updateCron"`     //更新周活用户
+	Mode           int     `json:"mode"`           // 用户范围: 1-月活 2 周活
 }
 }
 
 
 type CustomConfig struct {
 type CustomConfig struct {
@@ -33,6 +34,7 @@ type CustomConfig struct {
 		TimeOver int `json:"timeOver"` //超时
 		TimeOver int `json:"timeOver"` //超时
 		WaitTime int `json:"waitTime"` //休息
 		WaitTime int `json:"waitTime"` //休息
 	} `json:"searchLimit"`
 	} `json:"searchLimit"`
+	Mode int `json:"mode"` // 用户范围: 1-月活 2 周活
 }
 }
 
 
 func init() {
 func init() {