瀏覽代碼

Merge branch 'main' of http://192.168.3.207:8080/jianyu/leadGeneration

duxin 2 年之前
父節點
當前提交
12949fde14

+ 1 - 0
config.json

@@ -7,6 +7,7 @@
     "dailyTimes": 1000
   },
   "custom": {
+    "prop": 1,
     "searchPool": 1,
     "updateCron": ""
   },

+ 2 - 2
db.json

@@ -37,9 +37,9 @@
 	    },
 		"active": {
 			"dbName": "useranaly",
-			"address": "192.168.3.11:3366",
+			"address": "192.168.3.217:4000",
 			"userName": "root",
-			"passWord": "Topnet123",
+			"passWord": "=PDT49#80Z!RVv52_z",
 			"maxOpenConns": 5,
 			"maxIdleConns": 5
 		}

+ 12 - 5
entity/activeUsers/activeUsers.go

@@ -3,6 +3,7 @@ package activeUsers
 import (
 	"leadGeneration/entity/power"
 	"leadGeneration/public"
+	"log"
 	"time"
 )
 
@@ -13,22 +14,25 @@ user_countbyhour 表只有一个月的数据
 
 // GetWeekActiveFreeUsers 获取周活无权限用户
 func GetWeekActiveFreeUsers() (rData []string) {
+	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers start\n")
 	now := time.Now()
-	_, start_m, start_d := now.Date()
-	_, end_m, end_d := now.AddDate(0, 0, -7).Date()
+	_, 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 = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? OR day < ?"
-		param = []interface{}{start_d, end_d}
+		param = []interface{}{end_d, start_d}
 	} else {
 		//非跨月
 		sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? AND day < ?"
 		param = []interface{}{start_d, end_d}
 	}
-	res := public.ActiveMysql.SelectBySql(sql, param...)
+	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers search sql:%s value:%v start\n", sql, param)
+	res := public.UserAnalyseDb.SelectBySql(sql, param...)
+	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers search end\n")
 
 	if res == nil || len(*res) == 0 {
 		return
@@ -41,14 +45,16 @@ func GetWeekActiveFreeUsers() (rData []string) {
 			}
 		}
 	}
+	log.Printf("[ACTIVE-USER-INFO]GetWeekActiveFreeUsers start Finished Total %d\n", len(rData))
 	return rData
 }
 
 // GetMonthActiveFreeUsers 获取月活用户
 // 有订阅或有搜索词的周活用户+最近7天注册的新用户无条件生
 func GetMonthActiveFreeUsers() (rData []string) {
+	log.Printf("[ACTIVE-USER-INFO]GetMonthActiveFreeUsers start\n")
 	//表数据为近一个月,所以直接查询全部
-	res := public.ActiveMysql.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 {
 		return
 	}
@@ -73,5 +79,6 @@ func GetMonthActiveFreeUsers() (rData []string) {
 		}
 		rData = append(rData, userId)
 	}
+	log.Printf("[ACTIVE-USER-INFO]GetMonthActiveFreeUsers start Finished Total %d\n", len(rData))
 	return rData
 }

+ 43 - 0
entity/activeUsers/groupSave.go

@@ -0,0 +1,43 @@
+package activeUsers
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
+	"leadGeneration/public"
+	"log"
+	"time"
+)
+
+const batchNum = 100 //批次插入限制
+
+// SaveBatchGroup 保存批次分组信息
+func SaveBatchGroup(userIds []string, groupType int, groupName, from string) {
+	arrLen := len(userIds)
+	if arrLen == 0 {
+		return
+	}
+	now := time.Now().Format(date.Date_Full_Layout)
+	var finalCount int64 = 0
+	for i := 0; i < (arrLen/batchNum)+1; i++ {
+		start := i * batchNum
+		end := (i + 1) * batchNum
+		if end >= arrLen {
+			end = arrLen
+		}
+		values := make([]interface{}, 0, batchNum)
+		for _, uId := range userIds[start:end] {
+			values = append(values, uId, groupType, groupName, from, now)
+		}
+		if count, _ := public.UserAnalyseDb.InsertBatch("user_leadGeneration_group",
+			[]string{"user_mongoid", "group_type", "group_name", "source", "create_time"}, values); count > 0 {
+			finalCount += count
+		} else {
+			log.Printf("[MANAGER-ERR] SaveBatchGroup index:%d value:%v error\n", i, values)
+		}
+	}
+	if common.Int64All(arrLen) == finalCount {
+		log.Printf("[MANAGER-INFO] SaveBatchGroup save %v %s %s total %d finished:%d\n", common.If(groupType > 0, "定制化分析报告", "超前项目"), groupName, from, arrLen, finalCount)
+	} else {
+		log.Printf("[MANAGER-ERR] SaveBatchGroup save %v %s %s total %d finished:%d\n", common.If(groupType > 0, "定制化分析报告", "超前项目"), groupName, from, arrLen, finalCount)
+	}
+}

+ 132 - 27
entity/mananger/aheadManager.go

@@ -9,6 +9,7 @@ import (
 	"leadGeneration/public"
 	"leadGeneration/vars"
 	"log"
+	"sort"
 	"sync"
 	"time"
 )
@@ -17,6 +18,7 @@ import (
 type AheadManager struct {
 	Conf      vars.AheadConfig
 	UserGroup map[string]int
+	BatchFlag string
 	sync.RWMutex
 }
 
@@ -49,10 +51,6 @@ func (this *AheadManager) GetData(userId, keyWords string, isNew bool) map[strin
 	}
 	//查询数据
 	rDate := search.AdvancedProject(userId, keyWords)
-	//if err != nil {
-	//	log.Printf("[ERROR]AheadManager %s %s GetData Error %v\n", userId, keyWords, err)
-	//	return nil
-	//}
 	//累计请求计数
 	if rDate != nil && len(rDate) > 0 {
 		if num := redis.Incr(AheadCacheDb, cacheKey); num == 1 {
@@ -62,6 +60,17 @@ func (this *AheadManager) GetData(userId, keyWords string, isNew bool) map[strin
 	return rDate
 }
 
+// Click 用户点击
+func (this *AheadManager) Click(userId string) bool {
+	this.Lock()
+	defer this.Unlock()
+	if v, ok := this.UserGroup[userId]; ok {
+		this.UserGroup[userId] = v
+		return true
+	}
+	return false
+}
+
 //CheckGroupUser 校验用户是否有资格展示
 func (this *AheadManager) checkGroupUser(userId string) (exists bool) {
 	this.RLock()
@@ -87,38 +96,134 @@ func (this *AheadManager) UpdateUserGroupJob() {
 	if this.Conf.Prop <= 0 {
 		return
 	}
+	log.Printf("[MANAGER-INFO]AheadManager UserGroup Change Start\n")
+	this.BatchFlag = getWeekBatchName(time.Now())
 
-	//查询上批次活跃用户
 	newMap := map[string]int{}
-	var userArr []string
-	//测试账户
-	if len(vars.Config.TestUid) > 0 {
-		for _, uid := range vars.Config.TestUid {
-			newMap[uid] = 0
-		}
-	} else {
-		//查询月活用户
-		userArr = activeUsers.GetWeekActiveFreeUsers()
-	}
-	this.Lock()
-	defer this.Unlock()
-	//if len(this.UserGroup) != 0 {
-	//	for uId, num := range this.UserGroup {
-	//		if num > this.Conf.SaveClickTimes {
-	//			newMap[uId] = 0
-	//		}
-	//	}
-	//}
 	//新圈用户
-	for _, uId := range userArr {
+	for _, uId := range this.getUserGroup() {
 		newMap[uId] = 0
 	}
+	this.Lock()
+	defer this.Unlock()
 	this.UserGroup = newMap
+	log.Printf("[MANAGER-INFO]AheadManager UserGroup Changed Finish Total is %d \n", len(this.UserGroup))
+}
+
+//getUserGroup 取用户
+func (this *AheadManager) getUserGroup() (userIds []string) {
+	//当前批次是否已有数据
+	rData := public.UserAnalyseDb.SelectBySql("SELECT user_mongoid AS uid FROM user_leadGeneration_group WHERE group_type = 0 AND group_name=?", this.BatchFlag)
+	if rData != nil || len(*rData) == 0 {
+		log.Printf("[MANAGER-INFO]AheadManager getUserGroup from Db Total is %d \n", len(*rData))
+		userIds = make([]string, 0, len(*rData))
+		for _, m := range *rData {
+			if uId, _ := m["uid"].(string); uId != "" {
+				userIds = append(userIds, uId)
+			}
+		}
+	}
+	//无数据则重新生成用户群组数据
+	if len(userIds) == 0 {
+		log.Printf("[MANAGER-INFO]AheadManager getUserGroup createNewGroup start\n")
+		var (
+			wg                                             sync.WaitGroup
+			newActiveGroup, lastActiveGroup, testUserGroup []string
+		)
+		wg.Add(3)
+
+		//新活跃用户
+		go func() {
+			defer wg.Done()
+			newActiveGroup = this.sortUserByBatchAndGetFinal(activeUsers.GetWeekActiveFreeUsers())
+			activeUsers.SaveBatchGroup(newActiveGroup, 0, this.BatchFlag, "newActive")
+		}()
 
-	log.Printf("AheadManager NewGroup %v\n", newMap)
+		//测试用户群组
+		go func() {
+			defer wg.Done()
+			if len(vars.Config.TestUid) > 0 {
+				for _, uid := range vars.Config.TestUid {
+					testUserGroup = append(testUserGroup, uid)
+				}
+			}
+			activeUsers.SaveBatchGroup(testUserGroup, 0, this.BatchFlag, "testUser")
+		}()
 
+		//查询上批次活跃用户(点击量满足用户)
+		go func() {
+			defer wg.Done()
+			this.RLock()
+			defer this.RUnlock()
+			for uId, clickNum := range this.UserGroup {
+				if clickNum > this.Conf.SaveClickTimes {
+					lastActiveGroup = append(lastActiveGroup, uId)
+				}
+			}
+			activeUsers.SaveBatchGroup(lastActiveGroup, 0, this.BatchFlag, "oldActive")
+		}()
+		wg.Wait()
+		userIds = make([]string, 0, len(newActiveGroup)+len(lastActiveGroup)+len(testUserGroup))
+		userIds = append(userIds, newActiveGroup...)
+		userIds = append(userIds, lastActiveGroup...)
+		userIds = append(userIds, testUserGroup...)
+
+		log.Printf("[MANAGER-INFO]AheadManager getUserGroup createNewGroup Total %d \n New:%d Old:%d Test:%d \n",
+			len(userIds), len(newActiveGroup), len(lastActiveGroup), len(testUserGroup))
+	}
+	return
 }
 
-func sortUserByBatchAndGetFinal() {
+// sortUserByBatchAndGetFinal 根据百分比取用户,优先级【没有参与>参与时间早的>参与时间晚的】
+func (this *AheadManager) sortUserByBatchAndGetFinal(userIds []string) (rData []string) {
+	log.Printf("[MANAGER-INFO]AheadManager sortUserByBatchAndGetFinal Begin\n")
+	total := int(this.Conf.Prop * float64(len(userIds)))
+	//查询历史分组情况
+	gData := public.UserAnalyseDb.SelectBySql("SELECT *  FROM ( SELECT user_mongoid AS uid, MAX( UNIX_TIMESTAMP(create_time) ) AS gTime FROM user_leadGeneration_group WHERE group_type = 0 GROUP BY user_mongoid ) AS groupData ORDER BY gTime ASC")
+	log.Printf("[MANAGER-INFO]AheadManager sortUserByBatchAndGetFinal Search Finished\n")
+	// 无记录直接返回数组前final_count个用户id
+	if gData == nil || len(*gData) == 0 {
+		return userIds[:total]
+	}
+	sortMap := map[string]int64{}
+	for _, m := range *gData {
+		if uId, _ := m["uid"].(string); uId != "" {
+			num, _ := m["gTime"].(int64)
+			sortMap[uId] = num
+		}
+	}
+	log.Printf("[MANAGER-INFO]AheadManager sortUserByBatchAndGetFinal Sort Begin\n")
+	// 有记录进行排序筛选
+	sort.Slice(userIds, func(i, j int) bool {
+		iNum, _ := sortMap[userIds[i]]
+		jNum, _ := sortMap[userIds[j]]
+		if iNum < jNum {
+			return true
+		}
+		return false
+	})
+	log.Printf("[MANAGER-INFO]AheadManager sortUserByBatchAndGetFinal Finished\n")
+	return userIds[:total]
+}
+
+//getWeekBatchName 返回周批次标识
+//return Example 2022Y73W
+func getWeekBatchName(t time.Time) string {
+	yearDay := t.YearDay()
+	yearFirstDay := t.AddDate(0, 0, -yearDay+1)
+	firstDayInWeek := int(yearFirstDay.Weekday())
+
+	//今年第一周有几天
+	firstWeekDays := 1
+	if firstDayInWeek != 0 {
+		firstWeekDays = 7 - firstDayInWeek + 1
+	}
+	var week int
+	if yearDay <= firstWeekDays {
+		week = 1
+	} else {
+		week = (yearDay-firstWeekDays)/7 + 2
+	}
 
+	return fmt.Sprintf("%dY%02dW", t.Year(), week)
 }

+ 70 - 25
entity/mananger/customManager.go

@@ -65,7 +65,7 @@ func (this *CustomManager) GetData(userId, keyWords string, isNew bool) map[stri
 	if bytes, err := redis.GetBytes(customCacheDb, fmt.Sprintf(customDataCacheKey, userId)); err == nil && bytes != nil {
 		rData := map[string]interface{}{}
 		if err := json.Unmarshal(*bytes, &rData); err != nil {
-			log.Printf("[ERROR]CustomManager %s GetData Error %v \n", userId, err)
+			log.Printf("[MANAGER-ERR]CustomManager %s GetData Error %v \n", userId, err)
 			return nil
 		}
 		return rData
@@ -95,50 +95,91 @@ func (this *CustomManager) ScheduledTasks() {
 
 // UpdateUserGroupJob 更新用户群组
 func (this *CustomManager) UpdateUserGroupJob() {
-	var userArr []string
-	newMap := map[string]int{}
-	//测试账户
-	if len(vars.Config.TestUid) > 0 {
-		for _, uid := range vars.Config.TestUid {
-			newMap[uid] = 0
-			userArr = append(userArr, uid)
-		}
+	if this.Conf.Prop <= 0 {
+		return
+	}
+	log.Printf("[MANAGER-INFO]CustomManager UserGroup Change Start\n")
+	//更新批次标识
+	this.BatchFlag = time.Now().Format(public.Date_Full_Layout)
 
-	} else {
-		//查询月活用户
-		userArr = activeUsers.GetMonthActiveFreeUsers()
-		for _, uId := range userArr {
-			newMap[uId] = 0
-		}
+	newMap := map[string]int{}
+	userArr := this.getUserGroup()
+	for _, uId := range userArr {
+		newMap[uId] = 0
 	}
 
 	//更新新用户群组
 	this.Lock()
 	defer this.Unlock()
 	this.UserGroup = newMap
-	//更新批次标识
-	batchFlag := time.Now().Format(public.Date_Full_Layout)
-	this.BatchFlag = batchFlag
-	log.Printf("CustomManager NewGroup %v\n", newMap)
-	go this.activityUserQueue(batchFlag, userArr)
+	log.Printf("[MANAGER-INFO]CustomManager UserGroup Changed Finish Total is %d \n", len(this.UserGroup))
+	go this.activityUserQueue(this.BatchFlag, userArr)
+}
+
+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)
+	if rData != nil || len(*rData) == 0 {
+		log.Printf("[MANAGER-INFO]CustomManager getUserGroup from Db Total is %d \n", len(*rData))
+		userIds = make([]string, 0, len(*rData))
+		for _, m := range *rData {
+			if uId, _ := m["uid"].(string); uId != "" {
+				userIds = append(userIds, uId)
+			}
+		}
+	}
+	//无数据则重新生成用户群组数据
+	if len(userIds) == 0 {
+		log.Printf("[MANAGER-INFO]CustomManager getUserGroup createNewGroup start\n")
+		var (
+			wg                            sync.WaitGroup
+			newActiveGroup, testUserGroup []string
+		)
+		wg.Add(2)
+		//新活跃用户
+		go func() {
+			defer wg.Done()
+			if len(vars.Config.TestUid) > 0 {
+				for _, uid := range vars.Config.TestUid {
+					testUserGroup = append(testUserGroup, uid)
+				}
+			}
+			activeUsers.SaveBatchGroup(testUserGroup, 1, this.BatchFlag, "testUser")
+		}()
+		//测试用户群组
+		go func() {
+			defer wg.Done()
+			newActiveGroup = activeUsers.GetMonthActiveFreeUsers()
+			activeUsers.SaveBatchGroup(newActiveGroup, 1, this.BatchFlag, "newActive")
+		}()
+		wg.Wait()
+
+		userIds = make([]string, 0, len(newActiveGroup)+len(testUserGroup))
+		userIds = append(userIds, newActiveGroup...)
+		userIds = append(userIds, testUserGroup...)
+
+		log.Printf("[MANAGER-INFO]CustomManager getUserGroup createNewGroup end Total %d\n", len(userIds))
+	}
+	return
+
 }
 
 // activityUserQueue 活跃用户查询队列
 func (this *CustomManager) activityUserQueue(batchFlag string, userIds []string) {
 	for i, userId := range userIds {
 		if i%100 == 0 {
-			log.Printf("[INFO]CustomManager Batch %s Now(%d/%d)\n", batchFlag, len(userIds), i)
+			log.Printf("[MANAGER-INFO]CustomManager Batch %s Now(%d/%d)\n", batchFlag, i, len(userIds))
 		}
 		//当批次更新时,上批次停止
 		if this.BatchFlag != batchFlag {
-			log.Printf("[INFO]CustomManager Batch %s Is END At (%d/%d) \n", batchFlag, i, len(userIds))
+			log.Printf("[MANAGER-INFO]CustomManager Batch %s Is END At (%d/%d) \n", batchFlag, i, len(userIds))
 			break
 		}
 		activityUserQueue <- &SearchEntity{
 			UserId: userId,
 		}
 	}
-	log.Printf("[INFO]CustomManager Batch %s Is Finished !!!\n", batchFlag)
+	log.Printf("[MANAGER-INFO]CustomManager Batch %s Is Finished !!!\n", batchFlag)
 }
 
 // DoSearch 定制化分析报告查询队列
@@ -146,7 +187,6 @@ func (this *CustomManager) DoSearch() {
 	for {
 		//是否在可执行时间段内
 		//???
-
 		var obj *SearchEntity
 		select { //优先级 newRegisterUserQueue > activityUserQueue
 		case obj = <-newRegisterUserQueue:
@@ -156,10 +196,15 @@ func (this *CustomManager) DoSearch() {
 			case obj = <-activityUserQueue:
 			}
 		}
+		//存在缓存直接跳过
+		key := fmt.Sprintf(customDataCacheKey, obj.UserId)
+		if has, err := redis.Exists(customCacheDb, key); has && err == nil {
+			continue
+		}
 		//查询结果处理
 		data := search.PotentialCustomizeAnalysis(obj.UserId, obj.Value)
 		if data == nil || len(data) == 0 {
-			log.Printf("[ERROR]CustomManager %s DoSearch %s Is Empty\n", obj.UserId, obj.Value)
+			log.Printf("[MANAGER-ERR]CustomManager %s DoSearch %s Is Empty\n", obj.UserId, obj.Value)
 			continue
 		}
 		//缓存结果

+ 5 - 5
entity/search/advancedProject.go

@@ -19,12 +19,12 @@ func AdvancedProject(userid, keyWord string) map[string]interface{} {
 	mae.Size = 2
 	mae.FormatParam.STime = time.Now().AddDate(0, -3, 0).Unix()
 	if !mae.KeyWordFormat(userid, keyWord) {
-		log.Printf("关键词格式化化失败 userid:%s,keyWord:%s", userid, keyWord)
+		log.Printf("[SEARCH-ERR]关键词格式化化失败 userid:%s,keyWord:%s", userid, keyWord)
 		return nil
 	}
-	log.Println("超前项目数据参数:", mae)
+	log.Println("[SEARCH-INFO]超前项目数据参数:", mae)
 	finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), projectsNumber, mae.Size, projectsSortSource)
-	log.Println("超前项目es查询:", finalSql)
+	log.Println("[SEARCH-INFO]超前项目es查询:", finalSql)
 	res, _, data := public.GetAggs("bidding", "bidding", finalSql)
 	if res == nil || len(res) == 0 || data == nil || len(data) == 0 {
 		return nil
@@ -89,7 +89,7 @@ func AdvancedProject(userid, keyWord string) map[string]interface{} {
 		//id加密
 		resData[i]["_id"] = public.EncodeId(qutil.InterfaceToStr(resData[i]["_id"]))
 	}
-	log.Println("AdvancedProject redis data :", resData)
+	log.Println("[SEARCH-INFO]AdvancedProject redis data :", resData)
 	return map[string]interface{}{
 		"projectTop2":  resData,
 		"subTypeCount": redisData,
@@ -134,7 +134,7 @@ func (mae *MarketAnalysisEntity) KeyWordFormat(userid, keyWord string) (ret bool
 		dataType, _ := json.Marshal(aItems)
 		key := string(dataType)
 		if err := json.Unmarshal([]byte(key), &mae.FormatParam.KeysItems); err != nil {
-			log.Println("关键词格式化失败", aItems)
+			log.Println("[SEARCH-ERR]关键词格式化失败", aItems)
 			return false
 		}
 	}

+ 3 - 4
entity/search/customizedAnalysis.go

@@ -5,7 +5,6 @@ import (
 	"encoding/json"
 	"fmt"
 	"leadGeneration/public"
-	"log"
 	"strings"
 	"sync"
 	"time"
@@ -22,13 +21,13 @@ func PotentialCustomizeAnalysis(userid, keyWord string) map[string]interface{} {
 	aggs = append(aggs, aggs_buyerclass, buyer_procurement_scale, winner_procurement_scale)
 	mae.Types = 1
 	mae.FormatParam.STime = time.Now().AddDate(-1, 0, 0).Unix()
-	log.Println("定制化分析报告数据参数:", mae)
+	//log.Println("[SEARCH-INFO]定制化分析报告数据参数:", mae)
 	if !mae.KeyWordFormat(userid, keyWord) {
-		log.Printf("关键词格式化化失败 userid:%s,keyWord:%s", userid, keyWord)
+		//log.Printf("[SEARCH-ERR]关键词格式化化失败 userid:%s,keyWord:%s", userid, keyWord)
 		return nil
 	}
 	finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(aggs, ","), mae.Size, "")
-	log.Println("定制化分析报告es查询:", finalSql)
+	//log.Println("[SEARCH-INFO]定制化分析报告es查询:", finalSql)
 	res, _, _ := public.GetAggs("projectset", "projectset", finalSql)
 	if res == nil || len(res) == 0 {
 		return nil

+ 3 - 3
public/aggsSearchUtil.go

@@ -19,19 +19,19 @@ func GetAggs(index, itype, query string) (aggs elastic2.Aggregations, count int6
 	if client != nil {
 		defer func() {
 			if r := recover(); r != nil {
-				log.Println("[E]", r)
+				log.Println("[SEARCH-ERR]", r)
 				for skip := 1; ; skip++ {
 					_, file, line, ok := runtime.Caller(skip)
 					if !ok {
 						break
 					}
-					go log.Printf("%v,%v\n", file, line)
+					go log.Printf("[SEARCH-INFO]%v,%v\n", file, line)
 				}
 			}
 		}()
 		searchResult, err := client.Search().Index(index).Type(itype).Source(query).Do()
 		if err != nil {
-			log.Println("从ES查询出错", err.Error())
+			log.Println("[SEARCH-ERR]从ES查询出错", err.Error())
 		}
 		count = searchResult.Hits.TotalHits
 		hist = searchResult.Hits.Hits

+ 13 - 14
public/db.go

@@ -10,11 +10,11 @@ import (
 )
 
 var (
-	DbConf      *dbConf
-	MainMysql   *mysql.Mysql
-	ActiveMysql *mysql.Mysql
-	MQFW        m.MongodbSim
-	Mgo_Log     m.MongodbSim
+	DbConf        *dbConf
+	MainMysql     *mysql.Mysql //主程序订单表
+	UserAnalyseDb *mysql.Mysql //用户分析
+	MQFW          m.MongodbSim
+	Mgo_Log       m.MongodbSim
 )
 
 type dbConf struct {
@@ -68,16 +68,16 @@ func init() {
 	if DbConf != nil {
 		if DbConf.Elasticsearch.Main != nil {
 			elastic.InitElasticSize(DbConf.Elasticsearch.Main.Address, DbConf.Elasticsearch.Main.Size)
-			log.Println("初始化 elasticsearch")
+			log.Println("[SYSTEM]初始化 elasticsearch")
 		}
 		//初始化redis
 		if DbConf.Redis.Main != nil {
-			log.Println("初始化 redis")
+			log.Println("[SYSTEM]初始化 redis")
 			redis.InitRedisBySize(DbConf.Redis.Main.Address, 100, 30, 300)
 		}
 		//
 		if DbConf.Mongodb.Main != nil {
-			log.Println("初始化 mongodb main")
+			log.Println("[SYSTEM]初始化 mongodb main")
 			MQFW = m.MongodbSim{
 				MongodbAddr: DbConf.Mongodb.Main.Address,
 				Size:        DbConf.Mongodb.Main.Size,
@@ -87,7 +87,7 @@ func init() {
 			MQFW.InitPool()
 		}
 		if DbConf.Mongodb.Log != nil {
-			log.Println("初始化 mongodb log")
+			log.Println("[SYSTEM]初始化 mongodb log")
 			Mgo_Log = m.MongodbSim{
 				MongodbAddr: DbConf.Mongodb.Log.Address,
 				Size:        DbConf.Mongodb.Log.Size,
@@ -100,7 +100,7 @@ func init() {
 		}
 
 		if DbConf.Mysql.Main != nil {
-			log.Println("初始化 main mysql")
+			log.Println("[SYSTEM]初始化 main mysql")
 			MainMysql = &mysql.Mysql{
 				Address:      DbConf.Mysql.Main.Address,
 				UserName:     DbConf.Mysql.Main.UserName,
@@ -113,8 +113,8 @@ func init() {
 		}
 
 		if DbConf.Mysql.Active != nil {
-			log.Println("初始化 active mysql")
-			ActiveMysql = &mysql.Mysql{
+			log.Println("[SYSTEM]初始化 active mysql")
+			UserAnalyseDb = &mysql.Mysql{
 				Address:      DbConf.Mysql.Active.Address,
 				UserName:     DbConf.Mysql.Active.UserName,
 				PassWord:     DbConf.Mysql.Active.PassWord,
@@ -122,8 +122,7 @@ func init() {
 				MaxOpenConns: DbConf.Mysql.Active.MaxOpenConns,
 				MaxIdleConns: DbConf.Mysql.Active.MaxIdleConns,
 			}
-			ActiveMysql.Init()
+			UserAnalyseDb.Init()
 		}
-
 	}
 }

+ 1 - 1
public/vars.go

@@ -2,5 +2,5 @@ package public
 
 const (
 	TimeFormat       = "20060102"
-	Date_Full_Layout = "200601021504"
+	Date_Full_Layout = "200601"
 )

+ 6 - 3
services/action.go

@@ -43,7 +43,7 @@ func (this *LeadGeneration) GetDate() {
 		return rData, nil
 	}()
 	if errMsg != nil {
-		log.Printf("%s LeadGeneration GetDate 异常:%s\n", userId, errMsg.Error())
+		log.Printf("[ACTION]%s LeadGeneration GetDate 异常:%s\n", userId, errMsg.Error())
 	}
 	this.ServeJson(NewResult(rData, errMsg))
 }
@@ -52,11 +52,14 @@ func (this *LeadGeneration) GetDate() {
 func (this *LeadGeneration) ClickRecord() {
 	userId := qutil.ObjToString(this.GetSession("userId"))
 	rData, errMsg := func() (interface{}, error) {
+		switch this.GetString("t") {
+		case "A":
+			return mananger.JyAheadManager.Click(userId), nil
+		}
 		return true, nil
-		//return map[string]interface{}{}, nil
 	}()
 	if errMsg != nil {
-		log.Printf("%s LeadGeneration ClickRecord 异常:%s\n", userId, errMsg.Error())
+		log.Printf("[ACTION]%s LeadGeneration ClickRecord 异常:%s\n", userId, errMsg.Error())
 	}
 	this.ServeJson(NewResult(rData, errMsg))
 }

+ 2 - 2
services/filter/logfilter.go

@@ -51,7 +51,7 @@ func SaveLogTask() {
 		tmp := arr
 		arr = make([]map[string]interface{}, 0)
 		go func() {
-			log.Println("timer..save..visit..log", len(tmp))
+			log.Println("[SYSTEM]timer..save..visit..log", len(tmp))
 			public.Mgo_Log.SaveBulk("jy_logs", tmp...)
 		}()
 	}
@@ -93,7 +93,7 @@ func (l *logFilter) addLog() {
 		tmp := arr
 		arr = make([]map[string]interface{}, 0)
 		go func() {
-			log.Println("save..visit..log", len(tmp))
+			log.Println("[SYSTEM]save..visit..log", len(tmp))
 			public.Mgo_Log.SaveBulk("jy_logs", tmp...)
 		}()
 	}

+ 3 - 2
vars/config.go

@@ -21,8 +21,9 @@ type AheadConfig struct {
 }
 
 type CustomConfig struct {
-	SearchPool int    `json:"searchPool"` //检索并发池
-	UpdateCron string `json:"updateCron"` //更新周活用户
+	Prop       float64 `json:"prop"`       //月活用户百分比
+	SearchPool int     `json:"searchPool"` //检索并发池
+	UpdateCron string  `json:"updateCron"` //更新周活用户
 }
 
 func init() {