Browse Source

更新

master
huangjiajun 2 months ago
parent
commit
6496dee83a
4 changed files with 104 additions and 3 deletions
  1. +25
    -0
      app/hdl/hdl_index.go
  2. +5
    -0
      app/md/md_index.go
  3. +4
    -3
      app/router/router.go
  4. +70
    -0
      app/svc/svc_index.go

+ 25
- 0
app/hdl/hdl_index.go View File

@@ -87,3 +87,28 @@ func IndexAppList(c *gin.Context) {
e.OutSuc(c, res, nil)
return
}

// IndexAppListTable
// @Summary 应用数据-每个应用的折线图
// @Tags 首页------嘉俊
// @Description 首页-应用数据-每个应用的折线图
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.IndexAppListTableReq true "请求参数"
// @Success 200 {string} "具体看返回内容 "
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/index/app/list/table [POST]
func IndexAppListTable(c *gin.Context) {
var req md.IndexAppListTableReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
res := svc.BeforeSevenPoint(c, req)
e.OutSuc(c, res, nil)
return
}

+ 5
- 0
app/md/md_index.go View File

@@ -22,3 +22,8 @@ type IndexAppListDataList struct {
Type string `json:"type"`
Bili string `json:"bili"`
}
type IndexAppListTableReq struct {
StartDate string `json:"start_date" example:"2024-08-30"`
EndDate string `json:"end_date" example:"2024-08-30"`
AppId []string `json:"app_id"`
}

+ 4
- 3
app/router/router.go View File

@@ -126,9 +126,10 @@ func rDataCenter(r *gin.RouterGroup) {
r.POST("/record/output", hdl.DataCenterRecordOutPut) //数据中心-数据明细-导出
}
func rIndex(r *gin.RouterGroup) {
r.GET("/base", hdl.Base) //首页-基本信息
r.GET("/total", hdl.IndexTotal) //首页-统计数据
r.POST("/app/list", hdl.IndexAppList) //首页-应用数据
r.GET("/base", hdl.Base) //首页-基本信息
r.GET("/total", hdl.IndexTotal) //首页-统计数据
r.POST("/app/list", hdl.IndexAppList) //首页-应用数据
r.POST("/app/list/table", hdl.IndexAppListTable) // 首页-应用数据-每个应用的折线图
}
func rFinancialDynamics(r *gin.RouterGroup) {
r.POST("/medium/total", hdl.FinancialDynamicsMediumTotal) //资产动态-媒体预付统计


+ 70
- 0
app/svc/svc_index.go View File

@@ -167,3 +167,73 @@ func commTotalByApp(c *gin.Context, req md.IndexAppListReq, appId []string) []ma
nativeString, _ := db.QueryNativeString(db.Db, sql)
return nativeString
}

func BeforeSevenPoint(c *gin.Context, req md.IndexAppListTableReq) map[string][]string {

start := utils.TimeStdParseUnix(req.StartDate + " 00:00:00")
day := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00")-start)/86400 + 1
first := start - day*86400*6
dayAll := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00")-first)/86400 + 1

firstTime := time.Unix(first, 0).Format("2006-01-02")
appData := make(map[string][]string)
for _, v := range req.AppId {
appData[v] = make([]string, dayAll/day+1, dayAll/day+1)
}
dateList := make(map[int]string)
j := 1
for i := 0; i < int(dayAll); i++ {
if i >= (j-1)*int(day) && i < j*int(day) {
dateList[j-1] += "," + time.Unix(first+int64(i)*86400, 0).Format("2006-01-02")
continue
}
j++
dateList[j-1] += "," + time.Unix(first+int64(i)*86400, 0).Format("2006-01-02")
}
if len(req.AppId) > 0 {
date := commTotalByDate(c, firstTime, req.EndDate, req.AppId)
for _, v := range date {
for k1, v1 := range dateList {
if strings.Contains(v1, v["date"]) {
appData[v["app_id"]][k1] = utils.Float64ToStr(utils.StrToFloat64(appData[v["app_id"]][k1]) + utils.StrToFloat64(v["media_revenue"])/100)
}
}
}
}
for k, v := range appData {
for k1, v1 := range v {
if v1 == "" {
appData[k][k1] = "0"
}
}
}
return appData
}
func commTotalByDate(c *gin.Context, startDate, endDate string, appId []string) []map[string]string {
sql := `
SELECT
app_id as app_id,
date as date,
SUM(exposure_count) as exposure_count,
SUM(click_count) as click_count,
SUM(click_count)/SUM(exposure_count)*100 as click_rate,
SUM(ecpm) as ecpm,
SUM(media_revenue) as media_revenue
FROM generate_wx_ad_data
where %s group by date,app_id
`
where := "uuid=" + c.GetString("mid")
if startDate != "" {
where += " and date>='" + startDate + "'"
}
if endDate != "" {
where += " and date<='" + endDate + "'"
}
if len(appId) > 0 {
where += " and app_id in('" + strings.Join(appId, ",") + "')"
}
sql = fmt.Sprintf(sql, where)
nativeString, err := db.QueryNativeString(db.Db, sql)
fmt.Println(err)
return nativeString
}

Loading…
Cancel
Save