diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 6b1b66c84..6e949dd93 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -279,11 +279,11 @@ func postDeal(userMetricsList []*UserMetrics) []*UserMetrics { return duplicateRemovalUserMetricsList } -func QueryMetricsForAll() []*UserMetrics { +func QueryMetricsForAll(start int64, end int64) []*UserMetrics { statictisSess := xStatistic.NewSession() defer statictisSess.Close() userMetricsList := make([]*UserMetrics, 0) - if err := statictisSess.Table(new(UserMetrics)).OrderBy("count_date desc"). + if err := statictisSess.Table(new(UserMetrics)).Where("count_date >" + fmt.Sprint(start) + " and count_date<" + fmt.Sprint(end)).OrderBy("count_date desc"). Find(&userMetricsList); err != nil { return nil } @@ -291,11 +291,9 @@ func QueryMetricsForAll() []*UserMetrics { return makeResultForMonth(duplicateRemovalUserMetricsList, len(duplicateRemovalUserMetricsList)) } -func QueryMetricsForYear() []*UserMetrics { - currentTimeNow := time.Now() - currentYearEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) - currentYearStartTime := time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) - allUserInfo, count := QueryMetrics(currentYearStartTime.Unix(), currentYearEndTime.Unix()) +func QueryMetricsForYear(start int64, end int64) []*UserMetrics { + + allUserInfo, count := QueryMetrics(start, end) return makeResultForMonth(allUserInfo, count) } @@ -792,7 +790,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, statictisSess := xStatistic.NewSession() defer statictisSess.Close() - cond := "type != 1 and is_active=true" + cond := "type != 1" count, err := sess.Where(cond).Count(new(User)) if err != nil { log.Info("query user error. return.") @@ -814,8 +812,6 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, log.Info("i=" + fmt.Sprint(i) + " userName=" + userRecord.Name) dateRecord.CountDate = CountDate.Unix() - statictisSess.Delete(&dateRecord) - dateRecord.Email = userRecord.Email dateRecord.RegistDate = userRecord.CreatedUnix dateRecord.Name = userRecord.Name @@ -873,6 +869,10 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, if getUserActivate(dateRecord) > 0 { addUserToMap(userNewAddActivity, userRecord.CreatedUnix, dateRecord.ID) } + if userRecord.IsActive { + continue + } + statictisSess.Delete(&dateRecord) _, err = statictisSess.Insert(&dateRecord) if err != nil { log.Info("insert daterecord failed." + err.Error()) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 9707f8df2..e81601331 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -47,9 +47,7 @@ func writeUserMetricsExcel(row int, xlsx *excelize.File, sheetName string, userM rows := fmt.Sprint(row) var tmp byte tmp = 0 - dateTime := time.Unix(userMetrics.CountDate, 0) - //dateTime.Format("2006-01-02 15:04:05") - xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, dateTime.Format("2006-01-02 15:04:05")) + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userMetrics.DisplayDate) tmp = tmp + 1 xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userMetrics.ActivateRegistUser+userMetrics.NotActivateRegistUser) tmp = tmp + 1 @@ -267,10 +265,10 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e var count int64 result := make([]*models.UserMetrics, 0) if tableName == "public.user_business_analysis_current_year" { - result = models.QueryMetricsForYear() + result = models.QueryMetricsForYear(startTime.Unix(), endTime.Unix()) count = int64(len(result)) } else if tableName == "public.user_business_analysis_all" { - result = models.QueryMetricsForAll() + result = models.QueryMetricsForAll(startTime.Unix(), endTime.Unix()) count = int64(len(result)) } else { result, count = models.QueryMetricsPage(startTime.Unix(), endTime.Unix(), page, pageSize) @@ -331,14 +329,25 @@ func QueryRankingList(ctx *context.Context) { } func QueryUserMetricsCurrentMonth(ctx *context.Context) { + currentTimeNow := time.Now() pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) + pageStartTime = getStartTime(pageStartTime) queryMetrics(ctx, "public.user_business_analysis_current_month", pageStartTime, pageEndTime) } func QueryUserStaticCurrentMonth(ctx *context.Context) { queryUserDataPage(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) } + +func getStartTime(pageStartTime time.Time) time.Time { + t, _ := time.Parse("2006-01-02", setting.RadarMap.GrowthBeginTime) + if pageStartTime.Before(t) { + pageStartTime = t + } + return pageStartTime +} + func QueryUserMetricsCurrentWeek(ctx *context.Context) { currentTimeNow := time.Now() offset := int(time.Monday - currentTimeNow.Weekday()) @@ -346,6 +355,7 @@ func QueryUserMetricsCurrentWeek(ctx *context.Context) { offset = -6 } pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) + pageStartTime = getStartTime(pageStartTime) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) queryMetrics(ctx, "public.user_business_analysis_current_week", pageStartTime, pageEndTime) } @@ -355,6 +365,7 @@ func QueryUserStaticCurrentWeek(ctx *context.Context) { func QueryUserMetricsCurrentYear(ctx *context.Context) { currentTimeNow := time.Now() pageStartTime := time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) + pageStartTime = getStartTime(pageStartTime) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) queryMetrics(ctx, "public.user_business_analysis_current_year", pageStartTime, pageEndTime) } @@ -364,6 +375,7 @@ func QueryUserStaticCurrentYear(ctx *context.Context) { func QueryUserMetricsLast30Day(ctx *context.Context) { currentTimeNow := time.Now() pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) + pageStartTime = getStartTime(pageStartTime) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) queryMetrics(ctx, "public.user_business_analysis_last30_day", pageStartTime, pageEndTime) } @@ -374,6 +386,7 @@ func QueryUserMetricsLastMonth(ctx *context.Context) { currentTimeNow := time.Now() thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) pageStartTime := thisMonth.AddDate(0, -1, 0) + pageStartTime = getStartTime(pageStartTime) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) queryMetrics(ctx, "public.user_business_analysis_last_month", pageStartTime, pageEndTime) } @@ -383,6 +396,7 @@ func QueryUserStaticLastMonth(ctx *context.Context) { func QueryUserMetricsYesterday(ctx *context.Context) { currentTimeNow := time.Now() pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local) + pageStartTime = getStartTime(pageStartTime) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) queryMetrics(ctx, "public.user_business_analysis_yesterday", pageStartTime, pageEndTime) } @@ -392,6 +406,7 @@ func QueryUserStaticYesterday(ctx *context.Context) { func QueryUserMetricsAll(ctx *context.Context) { currentTimeNow := time.Now() pageStartTime := time.Date(2022, 4, 5, 0, 0, 0, 0, currentTimeNow.Location()) + pageStartTime = getStartTime(pageStartTime) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) queryMetrics(ctx, "public.user_business_analysis_all", pageStartTime, pageEndTime) }