init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
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} webanalytics.AnalyticsStat "成功"
|
||||
// @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} webanalytics.AnalyticsDailyStat "成功"
|
||||
// @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)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package webanalytics
|
||||
|
||||
import "time"
|
||||
|
||||
type LastWebStatInfo struct {
|
||||
SumDate time.Time `json:"sumDate" bson:"sumDate"` // 时间半小时
|
||||
AppName string `json:"appName" bson:"appName"` // APP名称
|
||||
AppId int64 `json:"appId" bson:"appId"` // appId
|
||||
ActiveUsers int64 `json:"activeUsers" bson:"activeUsers"` // 最近半小时活跃数
|
||||
YestodayPV int64 `json:"yestodayPV" bson:"yestodayPV"` // 页面浏览量 (PV)
|
||||
YestodayUV int64 `json:"yestodayUV" bson:"yestodayUV"` // 独立用户数 (UV)
|
||||
YestodayActiveUsers int64 `json:"yestodayActiveUsers" bson:"yestodayActiveUsers"` // 活跃用户数
|
||||
YestodaySessions int64 `json:"yestodaySessions" bson:"yestodaySessions"` // 会话数
|
||||
YestodayNewUsers int64 `json:"yestodayNewUsers" bson:"yestodayNewUsers"` // 新增数量
|
||||
LeadNewCount float64 `json:"leadNewCount" bson:"leadNewCount"` // 日导量新增
|
||||
LeadAmount float64 `json:"leadAmount" bson:"leadAmount"` // 日导量充值
|
||||
}
|
||||
|
||||
type AnalyticsStat struct {
|
||||
TodayList []LastWebStatInfo `json:"todayList"` //当日数据
|
||||
WeekList []LastWebStatInfo `json:"weekList"` //环比数据
|
||||
YestodayList []LastWebStatInfo `json:"yestodayList"` //同比数据
|
||||
}
|
||||
type AnalyticsDailyStat struct {
|
||||
List []LastWebStatInfo `json:"list"` //当月数据
|
||||
}
|
||||
Reference in New Issue
Block a user