Sfoglia il codice sorgente

fix:新增useranaly配置 查询逻辑修改

duxin 1 anno fa
parent
commit
b605bff7e0
2 ha cambiato i file con 10 aggiunte e 17 eliminazioni
  1. 4 1
      doFreeClueSign/config.yaml
  2. 6 16
      doFreeClueSign/public/getNewActiveUser.go

+ 4 - 1
doFreeClueSign/config.yaml

@@ -29,7 +29,10 @@ database:
   subjectdb: #正式环境库名为Jianyu_subjectdb
     link: "mysql:readuser:jyTi_R202403@tcp(192.168.3.71:4003)/jianyu_subjectdb_test"
     debug: true
+  useranaly:
+    link: "mysql:root:=PDT49#80Z!RVv52_z@tcp(192.168.3.14:4000)/useranaly"
+    debug: true
 
 cron:
-  #activityUser: "# */30 * * * *" #更新新活跃用户
+#  activityUser: "# */30 * * * *" #更新新活跃用户
   bindPhoneAndSubAgain: "*/10 * * * * *" #再次关注&绑定手机号用户

+ 6 - 16
doFreeClueSign/public/getNewActiveUser.go

@@ -20,20 +20,14 @@ func GetNewActiveUser(st, ed time.Time) []*NewActiveMsg {
 		ctx    context.Context
 	)
 	stYear, stMonth, stDay := st.Date()
-	edYear, edMonth, edDay := ed.Date()
+	_, edMonth, edDay := ed.Date()
 	nst := st.AddDate(0, -1, 0)
 	_, nstMonth, nstDay := nst.Date()
-	var sql, nSql string
-	if stYear == edYear && stMonth == edMonth && stDay == edDay {
-		sql = fmt.Sprintf("month = %d and day = %d", int(stMonth), stDay)
-	} else if stMonth == edMonth {
-		sql = fmt.Sprintf("month = %d and day >= %d and day <= %d", int(stMonth), stDay, edDay)
-	} else {
-		sql = fmt.Sprintf("(month = %d and day >= %d) or (month = %d and day <= %d)", int(stMonth), stDay, int(edMonth), edDay)
-	}
 
 	//昨天所有活跃用户
-	res, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour WHERE %s `, sql))
+	res, err := g.DB("useranaly").Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour
+WHERE CONCAT(month, '-', day) >= '%s' AND  CONCAT(month, '-', day) <= '%s';`, fmt.Sprintf("%d-%d", int(stMonth), stDay), fmt.Sprintf("%d-%d", int(edMonth), edDay)))
+	//res, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour WHERE %s `, sql))
 	if err == nil && !res.IsEmpty() {
 		for _, m := range res.List() {
 			mongoid := gconv.String(m["user_mongoid"])
@@ -44,11 +38,6 @@ func GetNewActiveUser(st, ed time.Time) []*NewActiveMsg {
 		lock sync.Mutex
 		data []*NewActiveMsg
 	)
-	if nstMonth == stMonth {
-		nSql = fmt.Sprintf("month = %d and day >= %d and day < %d", int(stMonth), nstDay, stDay)
-	} else {
-		nSql = fmt.Sprintf("((month = %d and day >= %d) or (month = %d and day < %d))", int(nstMonth), nstDay, int(stMonth), stDay)
-	}
 	pool := make(chan bool, 5)
 	wait := &sync.WaitGroup{}
 	for _, id := range mgoIds {
@@ -59,7 +48,8 @@ func GetNewActiveUser(st, ed time.Time) []*NewActiveMsg {
 				wait.Done()
 				<-pool
 			}()
-			count, _ := g.DB().GetCount(ctx, fmt.Sprintf("user_mongoid = '%s' and  %s", mId, nSql))
+			count, _ := g.DB("useranaly").GetCount(ctx, fmt.Sprintf(`SELECT count(1) FROM user_countbyhour
+WHERE user_mongoid = '%s' and CONCAT(month, '-', day) >= '%s' AND  CONCAT(month, '-', day) < '%s';`, mId, fmt.Sprintf("%d-%d", int(nstMonth), nstDay), fmt.Sprintf("%d-%d", int(stMonth), stDay)))
 			if count == 0 { //统计昨天之前30天不活跃用户
 				lock.Lock()
 				data = append(data, &NewActiveMsg{