123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- package controllers
- import (
- "eta/eta_forum_admin/models"
- "eta/eta_forum_admin/models/chart_collect"
- "eta/eta_forum_admin/models/eta_business"
- "eta/eta_forum_admin/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- "strings"
- "time"
- )
- type ChartCollectStatController struct {
- BaseAuthController
- }
- // UserStat
- // @Title 用户纬度统计收藏数据
- // @Description 用户纬度统计收藏数据
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /stat/user [get]
- func (this *ChartCollectStatController) UserStat() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- // 默认查一级分类和一级分类下的指标信息,
- // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
- // 增加标识判断是文件夹还是指标列表
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- etaBusinessIds := this.GetString("EtaBusinessIds")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- sortType := this.GetString("SortType")
- sortParam := this.GetString("SortParam")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if etaBusinessIds != "" {
- businessIdsSlice := make([]int, 0)
- businessIds := strings.Split(etaBusinessIds, ",")
- if len(businessIds) == 0 {
- br.Msg = "请选择正确的商家"
- return
- }
- for _, id := range businessIds {
- if id != "" {
- adminIdInt, e := strconv.Atoi(id)
- if e != nil {
- br.Msg = "请选择正确的商家"
- return
- }
- businessIdsSlice = append(businessIdsSlice, adminIdInt)
- }
- }
- if len(businessIdsSlice) > 0 {
- condition += ` AND eta_business_id IN (` + utils.GetOrmInReplace(len(businessIdsSlice)) + `) `
- pars = append(pars, businessIdsSlice)
- }
- }
- if startDate != "" {
- // 校验日期格式
- _, err := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- if err != nil {
- br.Msg = "请选择正确的开始日期"
- return
- }
- condition += ` AND collect_date >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- // 校验日期格式
- endTime, err := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- if err != nil {
- br.Msg = "请选择正确的结束日期"
- return
- }
- condition += ` AND collect_date < ? `
- nextDate := endTime.AddDate(0, 0, 1).Format(utils.FormatDate)
- pars = append(pars, nextDate)
- }
- order := ""
- if sortParam == "LastCollectChartTime" {
- if sortType == "desc" || sortType == "asc" {
- order = " last_collect_chart_time " + sortType
- }
- }
- statObj := new(chart_collect.UserCollectChartStat)
- total, err := statObj.GetGroupUserCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(chart_collect.UserStatListResp)
- list := make([]*chart_collect.UserCollectChartStatItem, 0)
- if total == 0 {
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- list, err = statObj.GetGroupUserPageListByCondition(condition, pars, order, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 查找商户信息
- businessCodeStr := make([]string, 0)
- businessCodeMap := make(map[string]string)
- for _, v := range list {
- businessCodeStr = append(businessCodeStr, v.BusinessCode)
- }
- obj := new(eta_business.EtaBusiness)
- condition1 := " AND business_code IN (" + utils.GetOrmInReplace(len(businessCodeStr)) + ") "
- var pars1 []interface{}
- pars1 = append(pars1, businessCodeStr)
- businessList, err := obj.GetItemsByCondition(condition1, pars1, []string{"business_code", "business_name"}, "")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取商户信息失败,Err:" + err.Error()
- return
- }
- for _, v := range businessList {
- businessCodeMap[v.BusinessCode] = v.BusinessName
- }
- for _, v := range list {
- if businessName, ok := businessCodeMap[v.BusinessCode]; ok {
- v.BusinessName = businessName
- }
- }
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ChartStat
- // @Title 图表纬度统计收藏数据
- // @Description 图表纬度统计收藏数据
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /stat/chart [get]
- func (this *ChartCollectStatController) ChartStat() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- statObj := new(chart_collect.ChartCollectStat)
- resp := new(chart_collect.ChartStatListResp)
- list, err := statObj.GetChartInfoStatusNum()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(list) == 0 {
- resp.List = make([]*chart_collect.ChartCollectChartStatItem, 0)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // 查询图表名称
- chartInfoIds := make([]int, 0)
- for _, v := range list {
- chartInfoIds = append(chartInfoIds, v.ChartInfoId)
- }
- chartList, err := models.GetChartInfoListByChartIds(chartInfoIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- chartInfoMap := make(map[int]string)
- for _, v := range chartList {
- chartInfoMap[v.ChartInfoId] = v.ChartName
- }
- for _, v := range list {
- if name, ok := chartInfoMap[v.ChartInfoId]; ok {
- v.ChartName = name
- }
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // UserDetailList
- // @Title 用户纬度统计收藏图表列表
- // @Description 用户纬度统计收藏图表列表
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /stat/user/detailList [get]
- func (this *ChartCollectStatController) UserDetailList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- // 默认查一级分类和一级分类下的指标信息,
- // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
- // 增加标识判断是文件夹还是指标列表
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- userId, _ := this.GetInt("UserId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyword := this.GetString("Keyword")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if userId == 0 {
- br.Msg = "请选择用户"
- return
- }
- condition += ` AND user_id = ? `
- pars = append(pars, userId)
- if startDate != "" {
- // 校验日期格式
- _, err := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- if err != nil {
- br.Msg = "请选择正确的开始日期"
- return
- }
- condition += ` AND a.collect_time >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- // 校验日期格式
- endTime, err := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- if err != nil {
- br.Msg = "请选择正确的结束日期"
- return
- }
- condition += ` AND a.collect_time < ? `
- nextDate := endTime.AddDate(0, 0, 1).Format(utils.FormatDate)
- pars = append(pars, nextDate)
- }
- if keyword != "" {
- // 根据空格拆分
- keys := strings.Split(keyword, " ")
- condition += ` AND ( `
- for _, v := range keys {
- if v != "" {
- condition += ` b.chart_name like ? and`
- pars = append(pars, "%"+v+"%")
- }
- }
- condition = condition[:len(condition)-3]
- condition += ` )`
- }
- total, err := chart_collect.GetChartCollectCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := new(chart_collect.ChartCollectListResp)
- list := make([]*chart_collect.ChartCollectView, 0)
- if total == 0 {
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- list, err = chart_collect.GetChartCollectPageByCondition(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|