123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- package controllers
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/services"
- "hongze/hongze_clpt/utils"
- "strconv"
- "strings"
- "time"
- )
- type MobileResearchController struct {
- BaseAuthMobileController
- }
- // @Title 研选文章类型列表
- // @Description 研选文章类型列表接口
- // @Success 200 {object} models.CygxArticleTypeListResp
- // @router /article/typeList [get]
- func (this *MobileResearchController) ArticleType() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- var condition string
- condition = " AND is_show_yanx = 1 "
- list, err := models.GetCygxArticleTypeListCondition(condition)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- resp := new(models.CygxArticleTypeListResp)
- for _, v := range list {
- item := models.CygxArticleTypeResp{
- ArticleTypeId: v.ArticleTypeId,
- ArticleTypeName: v.ArticleTypeName,
- ButtonStyle: v.ButtonStyle,
- }
- resp.List = append(resp.List, &item)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 研选最新报告列表
- // @Description 研选最新报告列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ArticleTypeIds query array true "文章类型ID多个用 , 隔开"
- // @Success 200 {object} models.IndustrialManagementNewList
- // @router /article/newList [get]
- func (this *MobileResearchController) ArticleNewList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- articleTypeIds := this.GetString("ArticleTypeIds")
- 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{}
- condition = ` AND publish_status = 1 `
- if articleTypeIds == "" {
- var conditiontype string
- conditiontype = " AND is_show_yanx = 1 "
- listType, err := models.GetCygxArticleTypeListCondition(conditiontype)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- for _, v := range listType {
- articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
- }
- articleTypeIds = strings.TrimRight(articleTypeIds, ",")
- }
- condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
- total, err := models.GetArticleResearchCount(condition, pars)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
- return
- }
- list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- list, err = services.HandleArticleCategoryImg(list)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
- return
- }
- //处理对应的文章类型标签按钮
- nameMap, styleMap, err := services.GetArticleTypeMap()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.ArticleResearchListResp)
- for _, v := range list {
- item := models.ArticleResearchResp{
- ArticleId: v.ArticleId,
- ArticleTypeId: v.ArticleTypeId,
- Title: v.Title,
- PublishDate: v.PublishDate,
- DepartmentId: v.DepartmentId,
- NickName: v.NickName,
- IsCollect: v.IsCollect,
- Pv: v.Pv,
- CollectNum: v.CollectNum,
- Abstract: v.Abstract,
- Annotation: v.Annotation,
- ImgUrlPc: v.ImgUrlPc,
- ArticleTypeName: nameMap[v.ArticleTypeId],
- ButtonStyle: styleMap[v.ArticleTypeId],
- List: v.List,
- }
- resp.List = append(resp.List, &item)
- }
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title KOL榜列表
- // @Description KOL榜列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ThemeType query int true "主题类型,1关注度、2更新时间 "
- // @Success 200 {object} models.DepartmentListResp
- // @router /kolList [get]
- func (this *MobileResearchController) KolList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- themeType, _ := this.GetInt("ThemeType")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize15
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- total, err := models.GetDepartmentlistCount("")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var condition string
- if themeType != 2 {
- condition = `ORDER BY fllow_num DESC `
- } else {
- condition = `ORDER BY publish_date DESC `
- }
- list, err := models.GetDepartmentList(condition, user.UserId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- listIndustrial, err := models.GetIndustrialDepartmentList()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- departmentMap := make(map[string]string)
- for k, v := range list {
- if v.FllowNum > 0 {
- list[k].IsFollow = true
- }
- list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
- for _, v2 := range listIndustrial {
- if v2.DepartmentId == v.DepartmentId {
- if departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] == "" && len(list[k].List) < 4 {
- list[k].List = append(list[k].List, v2)
- departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] = v.NickName
- }
- }
- }
- }
- resp := new(models.DepartmentListResp)
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 主题热度/近期更新更多,列表
- // @Description 主题热度/近期更新更多,列表接口
- // @Param ThemeType query int true "主题类型,1主题热度、2近期更新 默认1"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.IndustrialManagementHotListResp
- // @router /hotList [get]
- func (this *MobileResearchController) HotList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- themeType, _ := this.GetInt("ThemeType", 1)
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize15
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- if themeType == 1 {
- condition = `ORDER BY publish_date DESC `
- } else {
- condition = `ORDER BY sum_num DESC `
- }
- total, err := models.GetThemeHeatListCount("")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetThemeHeatList(user.UserId, condition, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- condition = ` AND a.article_type_id > 0 `
- listSubjcet, err := models.GetThemeHeatSubjectList(condition)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
- return
- }
- mapHot := make(map[string]int)
- condition = ` ORDER BY sum_num DESC `
- listHot, err := models.GetThemeHeatList(user.UserId, condition, 0, 3)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- for _, v := range listHot {
- mapHot[v.IndustryName] = v.IndustrialManagementId
- }
- nowTime := time.Now().Local()
- threeMonBefore := nowTime.AddDate(0, -3, 0)
- for k, v := range list {
- if v.MinReportTime != "" {
- t, err := time.Parse(utils.FormatDateTime, v.MinReportTime)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "报告最早发布时间有误,Err:" + err.Error()
- return
- }
- if t.After(threeMonBefore) {
- list[k].IsNew = true
- }
- }
- if v.FllowNum > 0 {
- list[k].IsFollw = true
- }
- for _, v2 := range listSubjcet {
- if v2.IndustrialManagementId == v.IndustrialManagementId {
- list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
- }
- }
- if mapHot[v.IndustryName] > 0 {
- list[k].IsHot = true
- }
- list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.IndustrialManagementHotListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 主题详情
- // @Description 主题详情接口
- // @Param IndustrialManagementId query int true "分类ID"
- // @Success 200 {object} models.GetThemeDetailResp
- // @router /theme/detail [get]
- func (this *MobileResearchController) ThemeDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- industrialManagementId, _ := this.GetInt("IndustrialManagementId")
- if industrialManagementId < 1 {
- br.Msg = "请输入产业ID"
- return
- }
- detailIndustrial, err := models.GetIndustrialManagementDetail(industrialManagementId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- var condition string
- articleTypeIds, err := services.GetYanXuanArticleTypeIds()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
- return
- }
- if articleTypeIds != "" {
- condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "研选分类ID不能为空"
- return
- }
- resp := new(models.GetThemeDetailResp)
- list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- list, err = services.HandleArticleCategoryImg(list)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
- return
- }
- //处理对应的文章类型标签按钮
- nameMap, styleMap, err := services.GetArticleTypeMap()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
- return
- }
- var articleIds []int
- for _, v := range list {
- item := models.ArticleResearchResp{
- ArticleId: v.ArticleId,
- ArticleTypeId: v.ArticleTypeId,
- Title: v.Title,
- PublishDate: v.PublishDate,
- DepartmentId: v.DepartmentId,
- NickName: v.NickName,
- IsCollect: v.IsCollect,
- Pv: v.Pv,
- CollectNum: v.CollectNum,
- Abstract: v.Abstract,
- Annotation: v.Annotation,
- ImgUrlPc: v.ImgUrlPc,
- ArticleTypeName: nameMap[v.ArticleTypeId],
- ButtonStyle: styleMap[v.ArticleTypeId],
- List: v.List,
- }
- resp.List = append(resp.List, &item)
- articleIds = append(articleIds, v.ArticleId)
- }
- //处理用户数是否关注该产业
- userFollowIndustrialMap, err := services.GetUserFollowIndustrialMap(user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
- return
- }
- if _, ok := userFollowIndustrialMap[industrialManagementId]; ok {
- resp.IsFollw = true
- }
- //处理文章关联的标的
- articleGroupSubjectMap, listSubtect, err := services.GetArticleGroupSubjectMap(articleIds)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
- return
- }
- if len(articleGroupSubjectMap) > 0 {
- for k, v := range resp.List {
- resp.List[k].ListSubject = articleGroupSubjectMap[v.ArticleId]
- }
- resp.ListSubject = listSubtect
- }
- resp.IndustryName = detailIndustrial.IndustryName
- resp.IndustrialManagementId = detailIndustrial.IndustrialManagementId
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 研选作者详情
- // @Description 研选作者详情接口
- // @Param DepartmentId query int true "作者ID"
- // @Success 200 {object} models.DepartmentDetailResp
- // @router /departmentId/detail [get]
- func (this *MobileResearchController) DepartmentIdDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- departmentId, _ := this.GetInt("DepartmentId")
- if departmentId < 1 {
- br.Msg = "请输入作者ID"
- return
- }
- var condition string
- var pars []interface{}
- articleTypeIds, err := services.GetYanXuanArticleTypeIds()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
- return
- }
- if articleTypeIds != "" {
- condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "研选分类ID不能为空"
- return
- }
- resp := new(models.DepartmentDetailResp)
- detail, err := models.GetDepartmentDetail(user.UserId, departmentId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
- return
- }
- resp.DepartmentId = detail.DepartmentId
- resp.NickName = detail.NickName
- resp.ImgUrl = detail.ImgUrl
- resp.FllowNum = detail.FllowNum
- resp.ArticleNum = detail.ArticleNum
- resp.CollectNum = detail.CollectNum
- if detail.MyFllowNum > 0 {
- resp.IsFllow = true
- }
- condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
- condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
- total, err := models.GetArticleResearchCount(condition, pars)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
- return
- }
- list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- list, err = services.HandleArticleCategoryImg(list)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
- return
- }
- //处理对应的文章类型标签按钮
- nameMap, styleMap, err := services.GetArticleTypeMap()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
- return
- }
- //resp := new(models.ArticleResearchListResp)
- for _, v := range list {
- item := models.ArticleResearchResp{
- ArticleId: v.ArticleId,
- ArticleTypeId: v.ArticleTypeId,
- Title: v.Title,
- PublishDate: v.PublishDate,
- DepartmentId: v.DepartmentId,
- NickName: v.NickName,
- IsCollect: v.IsCollect,
- Pv: v.Pv,
- CollectNum: v.CollectNum,
- Abstract: v.Abstract,
- Annotation: v.Annotation,
- ImgUrlPc: v.ImgUrlPc,
- ArticleTypeName: nameMap[v.ArticleTypeId],
- ButtonStyle: styleMap[v.ArticleTypeId],
- List: v.List,
- }
- resp.List = append(resp.List, &item)
- }
- condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
- listIndustrial, err := models.GetIndustrialManagementNewList(condition)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.ListIndustrial = listIndustrial
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|