155 lines
5.4 KiB
Go
155 lines
5.4 KiB
Go
package webanalytics
|
|
|
|
import (
|
|
"time"
|
|
"videoweb/pub/common"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/common/utils"
|
|
"videoweb/pub/models/analyticsdailystat"
|
|
"videoweb/pub/models/analyticsstat"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
// @Tags 获取统计数据
|
|
// @Summary 统计数据
|
|
// @Description 统计数据
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} srv_translationcategory.TranslationCategoryResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/web/stat/analytics [POST]
|
|
func GetAnalyticsStat(ctx *gin.Context) {
|
|
// 当日数据
|
|
resp := AnalyticsStat{
|
|
TodayList: make([]LastWebStatInfo, 0),
|
|
WeekList: make([]LastWebStatInfo, 0),
|
|
YestodayList: make([]LastWebStatInfo, 0),
|
|
}
|
|
now := time.Now()
|
|
curStatTime := utils.RecentMinute(now, 30) // 按20分钟对齐
|
|
YestodayTime := curStatTime.AddDate(0, 0, -1)
|
|
WeekTime := curStatTime.AddDate(0, 0, -7)
|
|
|
|
dailyFilter := bson.M{
|
|
analyticsdailystat.FN.AnalyticsDailyInfo.SumDate: bson.M{"$gt": now.AddDate(0, -1, -1)},
|
|
}
|
|
dailyStatList, _ := analyticsdailystat.FindManyAnalyticsDailyInfo(ctx, dailyFilter)
|
|
|
|
curFilter := bson.M{
|
|
analyticsstat.FN.AnalyticsInfo.SumDate: curStatTime,
|
|
}
|
|
statList, _ := analyticsstat.FindManyAnalyticsInfo(ctx, curFilter)
|
|
for _, statInfo := range statList {
|
|
appStatInfo := LastWebStatInfo{
|
|
SumDate: statInfo.SumDate,
|
|
AppId: statInfo.AppId,
|
|
AppName: statInfo.AppName,
|
|
ActiveUsers: statInfo.ActiveUsers,
|
|
YestodayPV: statInfo.YestodayPV,
|
|
YestodayUV: statInfo.YestodayUV,
|
|
YestodayActiveUsers: statInfo.YestodayActiveUsers,
|
|
YestodaySessions: statInfo.YestodaySessions,
|
|
YestodayNewUsers: statInfo.YestodayNewUsers,
|
|
}
|
|
for _, dailyStatInfo := range dailyStatList {
|
|
if dailyStatInfo.SumDate.Equal(statInfo.DaySumDate) && dailyStatInfo.AppId == statInfo.AppId {
|
|
appStatInfo.LeadNewCount = dailyStatInfo.LeadNewCount
|
|
appStatInfo.LeadAmount = dailyStatInfo.LeadAmount
|
|
}
|
|
}
|
|
resp.TodayList = append(resp.TodayList, appStatInfo)
|
|
}
|
|
|
|
yesFilter := bson.M{
|
|
analyticsstat.FN.AnalyticsInfo.SumDate: YestodayTime,
|
|
}
|
|
statList, _ = analyticsstat.FindManyAnalyticsInfo(ctx, yesFilter)
|
|
for _, statInfo := range statList {
|
|
appStatInfo := LastWebStatInfo{
|
|
SumDate: statInfo.SumDate,
|
|
AppId: statInfo.AppId,
|
|
AppName: statInfo.AppName,
|
|
ActiveUsers: statInfo.ActiveUsers,
|
|
YestodayPV: statInfo.YestodayPV,
|
|
YestodayUV: statInfo.YestodayUV,
|
|
YestodayActiveUsers: statInfo.YestodayActiveUsers,
|
|
YestodaySessions: statInfo.YestodaySessions,
|
|
YestodayNewUsers: statInfo.YestodayNewUsers,
|
|
}
|
|
for _, dailyStatInfo := range dailyStatList {
|
|
if dailyStatInfo.SumDate.Equal(statInfo.DaySumDate) && dailyStatInfo.AppId == statInfo.AppId {
|
|
appStatInfo.LeadNewCount = dailyStatInfo.LeadNewCount
|
|
appStatInfo.LeadAmount = dailyStatInfo.LeadAmount
|
|
}
|
|
}
|
|
resp.YestodayList = append(resp.YestodayList, appStatInfo)
|
|
}
|
|
|
|
weekFilter := bson.M{
|
|
analyticsstat.FN.AnalyticsInfo.SumDate: WeekTime,
|
|
}
|
|
statList, _ = analyticsstat.FindManyAnalyticsInfo(ctx, weekFilter)
|
|
for _, statInfo := range statList {
|
|
appStatInfo := LastWebStatInfo{
|
|
SumDate: statInfo.SumDate,
|
|
AppId: statInfo.AppId,
|
|
AppName: statInfo.AppName,
|
|
ActiveUsers: statInfo.ActiveUsers,
|
|
YestodayPV: statInfo.YestodayPV,
|
|
YestodayUV: statInfo.YestodayUV,
|
|
YestodayActiveUsers: statInfo.YestodayActiveUsers,
|
|
YestodaySessions: statInfo.YestodaySessions,
|
|
YestodayNewUsers: statInfo.YestodayNewUsers,
|
|
}
|
|
for _, dailyStatInfo := range dailyStatList {
|
|
if dailyStatInfo.SumDate.Equal(statInfo.DaySumDate) && dailyStatInfo.AppId == statInfo.AppId {
|
|
appStatInfo.LeadNewCount = dailyStatInfo.LeadNewCount
|
|
appStatInfo.LeadAmount = dailyStatInfo.LeadAmount
|
|
}
|
|
}
|
|
resp.WeekList = append(resp.WeekList, appStatInfo)
|
|
}
|
|
|
|
common.ServerJSON(ctx, srvdef.Success, resp)
|
|
}
|
|
|
|
// @Tags 获取统计数据
|
|
// @Summary 统计数据
|
|
// @Description 统计数据
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} srv_translationcategory.TranslationCategoryResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /api/web/stat/daily/analytics [POST]
|
|
func GetAnalyticsDailyStat(ctx *gin.Context) {
|
|
// 当日数据
|
|
resp := AnalyticsDailyStat{
|
|
List: make([]LastWebStatInfo, 0),
|
|
}
|
|
now := time.Now()
|
|
|
|
curFilter := bson.M{
|
|
analyticsdailystat.FN.AnalyticsDailyInfo.SumDate: bson.M{"$gt": utils.BeginOfMonth(now.AddDate(0, 0, -1)), "$lte": now},
|
|
}
|
|
statList, _ := analyticsdailystat.FindManyAnalyticsDailyInfo(ctx, curFilter)
|
|
for _, statInfo := range statList {
|
|
appStatInfo := LastWebStatInfo{
|
|
SumDate: statInfo.SumDate,
|
|
AppId: statInfo.AppId,
|
|
AppName: statInfo.AppName,
|
|
YestodayPV: statInfo.YestodayPV,
|
|
YestodayUV: statInfo.YestodayUV,
|
|
YestodayActiveUsers: statInfo.YestodayActiveUsers,
|
|
YestodaySessions: statInfo.YestodaySessions,
|
|
YestodayNewUsers: statInfo.YestodayNewUsers,
|
|
LeadNewCount: statInfo.LeadNewCount,
|
|
LeadAmount: statInfo.LeadAmount,
|
|
}
|
|
resp.List = append(resp.List, appStatInfo)
|
|
}
|
|
common.ServerJSON(ctx, srvdef.Success, resp)
|
|
} |