123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- package controllers
- import (
- "eta/eta_forum_hub/models"
- "eta/eta_forum_hub/models/chart_collect"
- "eta/eta_forum_hub/services"
- "eta/eta_forum_hub/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- "strings"
- )
- // 我的图库
- type ChartCollectController struct {
- BaseAuthController
- }
- // ClassifyList
- // @Title 收藏-分类列表接口
- // @Description 收藏-分类列表接口
- // @Success 200 {object} chart_collect.ChartCollectClassifyResp
- // @router /classify/list [get]
- func (this *ChartCollectController) ClassifyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- userMobile := this.GetString("UserMobile")
- businessCode := this.GetString("BusinessCode")
- userTelAreaCode := this.GetString("UserTelAreaCode")
- if userMobile == "" {
- br.Msg = "请选择用户"
- return
- }
- if businessCode == "" {
- br.Msg = "请选择商户"
- return
- }
- resp := new(chart_collect.ChartCollectClassifyResp)
- // 获取当前的客户信息
- sysUser, err := models.GetUserByBusinessCodeAndMobile(businessCode, userMobile, userTelAreaCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- items := make([]*chart_collect.ChartCollectClassifyItem, 0)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- br.Msg = "获取用户信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- // 获取有权限的分类ID
- permissionClassifyIds, err := services.GetPermissionClassifyIdByUserId(sysUser.UserId)
- if err != nil {
- br.Msg = "获取有权限的分类信息失败"
- br.ErrMsg = "获取有权限的分类信息失败,Err:" + err.Error()
- return
- }
- lenPermissionClassifyIds := len(permissionClassifyIds)
- if lenPermissionClassifyIds == 0 {
- items := make([]*chart_collect.ChartCollectClassifyItem, 0)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- //获取图表信息
- list, err := chart_collect.GetChartCollectClassifyAll(sysUser.UserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*chart_collect.ChartCollectClassifyItem, 0)
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- results := make([]*chart_collect.ChartCollectClassifyItem, 0)
- for _, v := range list {
- tmp := new(chart_collect.ChartCollectClassifyItem)
- tmp.ClassifyName = v.ClassifyName
- tmp.CollectClassifyId = v.CollectClassifyId
- tmp.UserId = v.UserId
- results = append(results, tmp)
- }
- resp.List = results
- language := `CN`
- // 指标显示的语言
- /*{
- configDetail, _ := system.GetConfigDetailByCode(system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- } else {
- configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- }
- }
- }*/
- resp.Language = language
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ChartList
- // @Title 收藏-列表接口
- // @Description 收藏-列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ChartCollectClassifyIds query int true "收藏分类id"
- // @Success 200 {object} chart_collect.MyChartListResp
- // @router /chart/list [get]
- func (this *ChartCollectController) ChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- collectClassifyIds := this.GetString("CollectClassifyIds")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyword := this.GetString("Keyword")
- userMobile := this.GetString("UserMobile")
- businessCode := this.GetString("BusinessCode")
- userTelAreaCode := this.GetString("UserTelAreaCode")
- if userMobile == "" {
- br.Msg = "请选择用户"
- return
- }
- if businessCode == "" {
- br.Msg = "请选择商户"
- return
- }
- // 获取当前的客户信息
- sysUser, err := models.GetUserByBusinessCodeAndMobile(businessCode, userMobile, userTelAreaCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "用户不存在"
- return
- }
- br.Msg = "获取用户信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- var total int64
- 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{}
- chartAdminId := sysUser.UserId
- condition += " AND (a.user_id = ?)"
- pars = append(pars, chartAdminId)
- collectClassifyIdSlice := make([]string, 0)
- if collectClassifyIds != "" {
- classifyIds := strings.Split(collectClassifyIds, ",")
- if len(classifyIds) == 0 {
- br.Msg = "请选择正确的分类"
- return
- }
- classifyIdSlice := make([]int, 0)
- for _, id := range classifyIds {
- if id != "" {
- collectClassifyIdSlice = append(collectClassifyIdSlice, id+",")
- tmp, e := strconv.Atoi(id)
- if e != nil {
- br.Msg = "请选择正确的分类"
- return
- }
- classifyIdSlice = append(classifyIdSlice, tmp)
- }
- }
- condition += " AND a.collect_classify_id in (" + utils.GetOrmInReplace(len(classifyIdSlice)) + ") "
- pars = append(pars, classifyIdSlice)
- }
- adminIdsSlice := make([]int, 0)
- // 获取有权限的分类ID
- permissionClassifyIds, err := services.GetPermissionClassifyIdByUserId(sysUser.UserId)
- if err != nil {
- br.Msg = "获取有权限的分类信息失败"
- br.ErrMsg = "获取有权限的分类信息失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := new(chart_collect.ChartCollectListResp)
- lenPermissionClassifyIds := len(permissionClassifyIds)
- if lenPermissionClassifyIds > 0 {
- condition += ` AND b.chart_classify_id in (` + utils.GetOrmInReplace(lenPermissionClassifyIds) + `) `
- pars = append(pars, permissionClassifyIds)
- } else {
- items := make([]*chart_collect.ChartCollectView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "获取成功"
- return
- }
- list := make([]*chart_collect.ChartCollectView, 0)
- if keyword != "" {
- // 从 es中查询收藏的图表列表
- chartList := make([]*chart_collect.ChartCollectEsItem, 0)
- chartList, total, err = services.EsSearchChartCollectData(keyword, chartAdminId, permissionClassifyIds, collectClassifyIdSlice, adminIdsSlice, startSize, pageSize)
- if err != nil {
- br.Msg = "获取收藏数据失败"
- br.ErrMsg = "获取收藏数据失败,Err:" + err.Error()
- return
- }
- for _, v := range chartList {
- tmp := &chart_collect.ChartCollectView{
- ChartInfoId: v.ChartInfoId,
- UserId: v.UserId,
- CreateTime: v.CreateTime,
- CollectTime: v.CollectTime,
- ChartName: v.ChartName,
- ChartNameEn: v.ChartNameEn,
- ChartImage: v.ChartImage,
- UniqueCode: v.UniqueCode,
- }
- list = append(list, tmp)
- }
- // 根据空格拆分
- /*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 += ` )`*/
- } else {
- total, err = chart_collect.GetChartCollectCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取收藏数据总数失败,Err:" + err.Error()
- return
- }
- //获取图表信息
- list, err = chart_collect.GetChartCollectPageByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*chart_collect.ChartCollectView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "获取成功"
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, int(total))
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|