Files
stat_center/api/statApi/stat.go
T
2026-05-20 16:13:58 +08:00

570 lines
16 KiB
Go

package statApi
import (
"fmt"
"net/http"
"path/filepath"
"stat/api/proto"
"stat/common/stdLog"
"stat/common/utils"
"stat/service/botser"
"stat/service/innerserverser"
"stat/service/landpageSer"
"stat/service/statSer"
"stat/statg"
"time"
"github.com/gin-gonic/gin"
)
// @Tags 渠道码统计
// @Summary 渠道码统计(集团)
// @Description 渠道码统计(集团)
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.BlocListChannelCodeStatReq true "参数列表"
// @Success 200 {object} proto.BlocListChannelCodeStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/blocChannelCodeStat/list [POST]
func ListBlocChannelCodeStat(ctx *gin.Context) {
param := &proto.BlocListChannelCodeStatReq{}
if err := ctx.ShouldBind(param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.ListBlocChannelCodeStat(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 渠道码统计
// @Summary 渠道码统计(集团)
// @Description 渠道码统计(集团)
// @Accept json
// @Produce json
// @Param param body proto.BlocListChannelCodeStatReq{} true "参数列表"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/blocChannelCodeStat/export [GET]
func ExportBlocChannelCodeStat(ctx *gin.Context) {
param := &proto.BlocListChannelCodeStatReq{}
if err := ctx.ShouldBind(param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
fPath, err := statSer.ListBlocChannelExport(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err.Error())
return
}
ctx.Writer.WriteHeader(http.StatusOK)
ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filepath.Base(fPath)))
ctx.Header("Content-Type", "application/octet-stream")
ctx.File(fPath)
}
// @Tags 日常统计
// @Summary 日常统计列表
// @Description 日常统计列表
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListDailyStatReq true "参数列表"
// @Success 200 {object} proto.ListDailyStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/dailyStat/list [POST]
func ListDailyStat(ctx *gin.Context) {
param := proto.ListDailyStatReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.ListDailyStat(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary 日常统计列表导出
// @Description 日常统计列表导出
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListDailyStatReq true "参数列表"
// @Success 200 {object} proto.ListDailyStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/dailyStat/export [POST]
func ListDailyStatExport(ctx *gin.Context) {
param := proto.ListDailyStatReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
fPath, serr := statSer.ListDailyStatExport(ctx, param)
if serr != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
return
}
ctx.Writer.WriteHeader(http.StatusOK)
ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filepath.Base(fPath)))
ctx.Header("Content-Type", "application/octet-stream")
ctx.File(fPath)
}
// @Tags 日常统计
// @Summary 日常统计列表
// @Description 日常统计列表
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListDailyHourStatReq true "参数列表"
// @Success 200 {object} proto.ListDailyHourStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/dailyhour/list [POST]
func ListDailyHourStat(ctx *gin.Context) {
param := &proto.ListDailyHourStatReq{}
if err := ctx.ShouldBind(param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.ListDailyHourStat(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary 日常统计导出
// @Description 日常统计导出
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListDailyHourStatReq true "参数列表"
// @Success 200 {object} proto.ListDailyHourStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/dailyhour/export [POST]
func ListDailyHourStatExport(ctx *gin.Context) {
param := &proto.ListDailyHourStatReq{}
if err := ctx.ShouldBind(param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
buf, err := statSer.ListDailyHourStatExport(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.DownloadFileError, err.Error())
return
}
header := map[string]string{
"Content-Disposition": fmt.Sprintf("attachment; filename=export.xlsx"),
}
ctx.DataFromReader(http.StatusOK, int64(buf.Len()), "application/octet-stream", buf, header)
}
// @Tags 日常统计
// @Summary 日常统计列表(集团)
// @Description 日常统计列表(集团)
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListBlocDailyStatReq true "参数列表"
// @Success 200 {object} proto.ListBlocDailyStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/blocDailyStat/list [POST]
func ListBlocDailyStat(ctx *gin.Context) {
param := proto.ListBlocDailyStatReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.BlocListDailyStat(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary 日常汇总列表(集团)
// @Description 日常统计列表(集团)
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListBlocDailyStatTotalReq true "参数列表"
// @Success 200 {object} proto.ListBlocDailyStatTotalRes "成功"
// @Failure 400 {string} string "失败"
// @Router /api/stat/blocDailyStatTotal/list [POST]
func ListBlocDailyTotalStat(ctx *gin.Context) {
param := proto.ListBlocDailyStatTotalReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.BlocListDailyTotalStat(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary日常统计注册详情(集团)
// @Description 日常统计列表
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListBlocRegisterDetailsReq true "参数列表"
// @Success 200 {object} proto.ListBlocRegisterDetailsRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/blocRegisterDetails/list [POST]
func ListBlocRegisterDetails(ctx *gin.Context) {
param := proto.ListBlocRegisterDetailsReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.BlocListRegisterDetailsInfo(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary日常统计注册详情(集团)
// @Description 日常统计列表
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListBlocWithdrawDetailsReq true "参数列表"
// @Success 200 {object} proto.ListBlocWithdrawDetailsRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/blocBlocWithdrawDetails/list [POST]
func ListBlocWithdrawDetails(ctx *gin.Context) {
param := proto.ListBlocWithdrawDetailsReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.BlocListWithdrawDetailsInfo(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary 支付渠道统计
// @Description 支付渠道统计
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListBlocRechargeChannelReq true "参数列表"
// @Success 200 {object} proto.ListBlocRechargeChannelRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/BlocRechargeChannel/list [POST]
func ListBlocRechargeChannel(ctx *gin.Context) {
param := proto.ListBlocRechargeChannelReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.ListBlocRechargeChannelInfo(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary日常统计充值详情(集团)
// @Description 日常统计列表
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListBlocRechargeDetailsReq true "参数列表"
// @Success 200 {object} proto.ListBlocRechargeDetailsRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/blocRechargeDetails/list [POST]
func ListBlocRechargerDetails(ctx *gin.Context) {
param := proto.ListBlocRechargeDetailsReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.BlocListRechargeDetailsInfo(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 主后台首页曲线图
// @Summary 曲线图列表数据
// @Description 曲线图列表数据
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListMinuteStatReq true "参数列表"
// @Success 200 {object} proto.ListMinuteStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/minuteStat/list [POST]
func ListMinuteStat(ctx *gin.Context) {
param := proto.ListMinuteStatReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.ListMinuteStat(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 主后台首页曲线图
// @Summary 曲线图列表数据
// @Description 曲线图列表数据
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListHourStatLineReq true "参数列表"
// @Success 200 {object} proto.ListHourStatLineResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/hourStat/list [POST]
func ListHourStatLine(ctx *gin.Context) {
param := proto.ListHourStatLineReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
code, data, err := statSer.ListHourStatLine(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, code, err.Error())
return
}
stdLog.ServerJSON(ctx, code, data)
}
// @Tags 日常统计
// @Summary 落地页每日统计
// @Description 落地页每日统计
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListDailyStatReq true "参数列表"
// @Success 200 {object} proto.ListLandPageStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/landPage/daily/list [POST]
func ListLandPageDailyStat(ctx *gin.Context) {
param := proto.ListDailyStatReq{}
if err := ctx.ShouldBind(&param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
data, err := landpageSer.ListDailyStat(ctx, &param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err.Error())
return
}
stdLog.ServerJSON(ctx, stdLog.Success, data)
}
// @Tags 日常统计
// @Summary 落地页小时统计
// @Description 落地页小时统计
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListDailyHourStatReq true "参数列表"
// @Success 200 {object} proto.ListLandPageStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/landPage/hour/list [POST]
func ListLandPageHourStat(ctx *gin.Context) {
param := &proto.ListDailyHourStatReq{}
if err := ctx.ShouldBind(param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
data, err := landpageSer.ListDailyHourStat(ctx, param)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err.Error())
return
}
stdLog.ServerJSON(ctx, stdLog.Success, data)
}
// @Tags 日常统计
// @Summary 落地页下载数统计
// @Description 落地下载数统计
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {object} proto.ListDownloadSummaryRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/landPage/summary/downTotal/list [POST]
func ListLandPageSummaryDownTotal(ctx *gin.Context) {
data, err := landpageSer.ListSummaryDownload(ctx)
if err != nil {
stdLog.ServerJSON(ctx, stdLog.Failure, err.Error())
return
}
stdLog.ServerJSON(ctx, stdLog.Success, data)
}
// @Tags 日常统计
// @Summary 日常统计导出
// @Description 日常统计导出
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param param body proto.ListDailyHourStatReq true "参数列表"
// @Success 200 {object} proto.ListDailyHourStatRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/daily-stat/jtspV2 [POST]
func GetBlocDailyStatTgbotInfo(ctx *gin.Context) {
param := &proto.BlocDailyStatReq{}
if err := ctx.ShouldBind(param); err != nil {
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
return
}
data := botser.GetBlocDailyStatTgbotInfo(ctx, *param.StartTime)
stdLog.ServerJSON(ctx, stdLog.Success, data)
}
// @Tags 日常统计
// @Summary 日常统计导出
// @Description 日常统计导出
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {object} proto.AppHourDataStatInfoRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/daily-stat/hour [POST]
func GetAppHourDataStatInfo(ctx *gin.Context) {
data := make([]proto.HourStatText, 0)
// 发送消息 统计数据
curStatTime := utils.RecentMinute(time.Now(), 60) // 按60分钟对齐
endpoints := statg.GlobalEndpoints.GetIndexEndpoints(statg.Conf.ServerIndex).GetBotStatEndpoints()
for _, end := range endpoints {
id := end.AppId
tm := curStatTime
text, title, desc, err := botser.DailyBotReportInfo(ctx, id, tm)
if err == nil {
data = append(data, proto.HourStatText{
Title: title,
Content: text,
Desc: desc,
})
}
}
stdLog.ServerJSON(ctx, stdLog.Success, data)
}
// @Tags 日常统计
// @Summary 日常统计导出
// @Description 日常统计导出
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {object} proto.AppHourDataStatInfoRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/daily-stat/rank [POST]
func GetAppHourDataStatInfoRank(ctx *gin.Context) {
curStatTime := utils.RecentMinute(time.Now(), 60)
// 发送消息 统计数据
_, buf, _ := botser.DailyBotRankTaskInfo(ctx, curStatTime)
if buf != nil {
stdLog.ServerJSON(ctx, stdLog.Success, buf)
} else {
stdLog.ServerJSON(ctx, stdLog.Success, "")
}
}
// @Tags 日常统计
// @Summary 日常统计导出
// @Description 日常统计导出
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {object} proto.AppHourDataStatInfoRes "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/stat/daily-stat/total [POST]
func GetTianyuAppDailyData(ctx *gin.Context) {
// 发送消息 统计数据
resp, _ := innerserverser.TianyuAppDailyData(ctx)
stdLog.ServerJSON(ctx, stdLog.Success, resp)
}