123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/services"
- "hongze/hongze_clpt/utils"
- "strconv"
- "strings"
- "time"
- )
- //报告
- type ReportController struct {
- BaseAuthController
- }
- type ReportCommonController struct {
- BaseCommonController
- }
- type MobileReportController struct {
- BaseAuthMobileController
- }
- // @Title 行业报告分类列表接口
- // @Description 获取行业报告分类列表接口
- // @Param ChartPermissionId query int true "分类ID"
- // @Success 200 {object} models.TradeReportMappingResp
- // @router /tradeList [get]
- func (this *MobileReportController) TradeList() {
- 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
- }
- fmt.Println(user)
- uid := user.UserId
- ChartPermissionId, _ := this.GetInt("ChartPermissionId")
- if ChartPermissionId < 1 {
- br.Msg = "请输入分类ID"
- return
- }
- //var result []*models.SearchItem
- var list []*models.TradeReportMapping
- var err error
- mapCategory := make(map[int]int)
- if ChartPermissionId == utils.CE_LUE_ID {
- listTrade, errTrade := models.GetReportMappingStrategyHomeAll()
- list = listTrade
- err = errTrade
- if user.Mobile != "" {
- //策略的处理
- categoryList, err := models.GetCygxXzsChooseCategoryList(user.Mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- for _, v := range categoryList {
- mapCategory[v.CategoryId] = v.CategoryId
- }
- }
- } else {
- listTrade, errTrade := models.GetTradeAll(ChartPermissionId)
- err = errTrade
- list = listTrade
- }
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- for k, v := range list {
- list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
- count, err := models.CheckThisCategoryNewArticleIsRead(uid, v.CategoryId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
- return
- }
- if count == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.UpdateTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.UpdateTime)) {
- list[k].IsRed = true
- }
- var condition string
- var pars []interface{}
- condition = " AND a.category_id_two = " + strconv.Itoa(v.CategoryId)
- if ChartPermissionId != utils.CE_LUE_ID {
- var pageSize int
- if ChartPermissionId == utils.KE_JI_ID {
- pageSize = 12
- } else {
- pageSize = 6
- }
- listArticle, err := models.GetHomeList(condition, pars, 0, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "GetHomeList,Err:" + err.Error()
- return
- }
- list[k].ListArticle = listArticle
- } else {
- if mapCategory[v.CategoryId] > 0 {
- list[k].IsFollow = true
- }
- list[k].ListArticle = make([]*models.HomeArticle, 0)
- }
- }
- resp := new(models.TradeReportMappingResp)
- if len(list) == 0 {
- list = make([]*models.TradeReportMapping, 0)
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 产业报告分类列表接口
- // @Description 获取产业报告分类列表接口
- // @Param ChartPermissionId query int true "分类ID"
- // @Param DeepCover query int false "是否选择深度覆盖,1是,0否 不填默认为0"
- // @Param RecommendFocus query int false "是否选择推荐关注,1是,0否 不填默认为0"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.IndustrialManagementList
- // @router /industryList [get]
- func (this *MobileReportController) IndustryList() {
- 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
- }
- uid := user.UserId
- ChartPermissionId, _ := this.GetInt("ChartPermissionId")
- orderColumn := this.GetString("OrderColumn")
- orderColumnNew := this.GetString("OrderColumn")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- deepCover, _ := this.GetInt("DeepCover")
- recommendFocus, _ := this.GetInt("RecommendFocus")
- var orderSrt string
- var condition string
- var startSize int
- resp := new(models.IndustrialManagementList)
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- if ChartPermissionId > 0 {
- condition += ` AND man.chart_permission_id IN (` + strconv.Itoa(ChartPermissionId) + `)`
- }
- // 深度覆盖
- if deepCover == 1 {
- // 查询深标签产业报告数
- var deepCondition string
- var deepPars []interface{}
- deepCondition += ` AND man.is_deep_label = 1`
- if ChartPermissionId > 0 {
- deepCondition += ` AND man.chart_permission_id = ?`
- deepPars = append(deepPars, ChartPermissionId)
- }
- industryCountList, e := models.GetIndustryArtCountByCondition(deepCondition, deepPars)
- if e != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取深标签产业报告数失败, Err: " + e.Error()
- return
- }
- deepIdArr := make([]string, 0)
- for i := range industryCountList {
- if industryCountList[i].ArtNum > 10 {
- deepIdArr = append(deepIdArr, strconv.Itoa(industryCountList[i].IndustrialManagementId))
- }
- }
- deepIds := strings.Join(deepIdArr, ",")
- if deepIds != "" {
- condition = `AND man.industrial_management_id IN (` + deepIds + `)`
- }
- }
- // 推荐关注
- if recommendFocus == 1 {
- condition += ` AND man.recommended_index >= 50`
- }
- var list []*models.IndustrialManagement
- total, err := models.GetIndustrialManagementAllCount(condition)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取数量失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- if orderColumn == "" {
- orderColumn = "NewTime"
- }
- if orderColumn == "NewTime" {
- orderSrt = "update_time DESC"
- } else {
- orderSrt = "man.recommended_index DESC,update_time DESC"
- }
- if ChartPermissionId == 0 {
- ChartPermissionId = 20
- }
- //获取产业下阅读数量第三的产业详情
- detailHot3, err := models.GetIndustrialManagementHot3(ChartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- list, err = models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- industrialIdArr := make([]int, 0)
- for k, v := range list {
- industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
- if v.ArticleReadNum >= detailHot3.ArticleReadNum {
- list[k].IsHot = true
- }
- }
- mapUPdateTime := make(map[int]string)
- mapHistroyArticleId := make(map[int]int)
- articleIdArr := make([]int, 0)
- //获取这些产业下最新更新的文章
- fmt.Println(industrialIdArr)
- listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败 GetNewArticleDetailByIndustrialIds ,Err:" + err.Error()
- return
- }
- for _, v := range listUpdateTime {
- mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
- articleIdArr = append(articleIdArr, v.ArticleId)
- }
- if uid > 0 {
- listArticleHistory, err := models.GetUserToArticleHistory(uid, industrialIdArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败 GetUserToArticleHistory ,Err:" + err.Error()
- return
- }
- for _, v := range listArticleHistory {
- mapHistroyArticleId[v.ArticleId] = v.ArticleId
- }
- }
- for k, v := range list {
- list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
- if uid > 0 {
- //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
- if mapHistroyArticleId[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
- list[k].IsRed = true
- }
- } else {
- if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
- list[k].IsRed = true
- }
- list[k].IsFollow = false
- }
- //标的列表
- industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- list[k].IndustrialSubjectList = industrialSubjectList
- }
- //记录用户搜索的筛选条件
- if orderColumnNew != "" {
- //item := new(models.CygxReportIndustrialSeaarchHistory)
- //item.UserId = user.UserId
- //item.Mobile = user.Mobile
- //item.CompanyId = user.CompanyId
- //item.CompanyName = user.CompanyName
- //item.CreateTime = time.Now()
- //item.IsDeepLabel = isDeepLabel
- //item.IsNewLabel = isNewLabel
- //item.ChartPermissionId = ChartPermissionId
- //if orderColumnNew == "NewTime" {
- // item.OrderColumn = "0"
- //} else {
- // item.OrderColumn = "1"
- //}
- //go models.AddCygxReportIndustrialSeaarchHistory(item)
- }
- if len(list) == 0 {
- list = make([]*models.IndustrialManagement, 0)
- }
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 产业下所关联的文章分类列表
- // @Description 产业下所关联的文章分类列表接口
- // @Param IndustrialManagementId query int true "产业ID"
- // @Success 200 {object} models.IndustrialToArticleCategoryListRep
- // @router /toArticleCategoryList [get]
- func (this *MobileReportController) ArticleCategoryList() {
- 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
- }
- uid := user.UserId
- industrialManagementId, _ := this.GetInt("IndustrialManagementId")
- if industrialManagementId < 1 {
- br.Msg = "请输入分类ID"
- return
- }
- detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- list, err := models.IndustrialToArticleCategory(industrialManagementId, detail.ChartPermissionId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- for k, v := range list {
- recordCount, err := models.IndustrialUserRecordArticleCount(uid, industrialManagementId, v.CategoryId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- Newdetail, err := models.GetNewIndustrialUserRecordArticle(industrialManagementId, v.CategoryId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(Newdetail.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(Newdetail.PublishDate)) {
- list[k].IsRed = true
- }
- }
- //标的列表
- industrialSubjectList, err := models.GetIndustrialSubjectAll(industrialManagementId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- resp := new(models.IndustrialToArticleCategoryListRep)
- resp.List = list
- resp.ListSubject = industrialSubjectList
- resp.LayoutTime = utils.TimeRemoveHms(detail.LayoutTime)
- resp.IndustryName = detail.IndustryName
- resp.IndustrialManagementId = industrialManagementId
- 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 CategoryId query int true "分类ID"
- // @Success 200 {object} models.TacticsListResp
- // @router /articleList/byCategoryId [get]
- func (this *MobileReportController) List() {
- 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
- }
- //uid := user.UserId
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- categoryId, _ := this.GetInt("CategoryId")
- 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{}
- var total int
- resp := new(models.TacticsListResp)
- page := paging.GetPaging(currentIndex, pageSize, total)
- //获取该产业下所对应的行业图片
- detail, errCategory := models.GetdetailByCategoryIdOne(categoryId)
- if errCategory != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
- return
- }
- //对应行业的图片
- detailChartPermissionUrl, err := models.GetConfigByCode("category_chart_permissionimg_url")
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
- return
- }
- chartPermissionUrlList := strings.Split(detailChartPermissionUrl.ConfigValue, "{|}")
- mapChartPermission := make(map[string]string)
- var permissionName string
- var imgUrlChartPermission string
- for _, v := range chartPermissionUrlList {
- vslice := strings.Split(v, "_")
- permissionName = vslice[0]
- imgUrlChartPermission = vslice[len(vslice)-1]
- mapChartPermission[permissionName] = imgUrlChartPermission
- }
- //对应分类的所图片
- detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
- return
- }
- categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
- mapCategoryUrl := make(map[string]string)
- var categoryIdStr string
- var imgUrlChart string
- for _, v := range categoryUrlList {
- vslice := strings.Split(v, "_")
- categoryIdStr = vslice[0]
- imgUrlChart = vslice[len(vslice)-1]
- mapCategoryUrl[categoryIdStr] = imgUrlChart
- }
- condition += ` AND category_id_two=? `
- pars = append(pars, categoryId)
- total, err = models.GetHomeCount(condition, pars)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "获取帖子总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- list, err := models.GetHomeList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "获取帖子数据失败,Err:" + err.Error()
- return
- }
- for k, v := range list {
- list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
- }
- if categoryId > 0 {
- detail, errCategory := models.GetdetailByCategoryId(categoryId)
- if errCategory != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
- return
- }
- resp.MatchTypeName = detail.MatchTypeName
- }
- lenList := len(list)
- for i := 0; i < lenList; i++ {
- item := list[i]
- list[i].Body = ""
- list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
- list[i].Annotation, _ = services.GetReportContentTextSub(item.Annotation)
- //行业比较研究、资金流向,显示报告的摘要
- if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
- list[i].Annotation = list[i].Abstract
- }
- }
- resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
- if len(list) == 0 {
- list = make([]*models.HomeArticle, 0)
- }
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 产业关注/取消关注
- // @Description 产业关注/取消关注 接口
- // @Param request body models.CygxIndustryFllowRep true "type json string"
- // @Success 200
- // @router /industrial/fllow [post]
- func (this *ReportController) IndustrialFllow() {
- 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
- }
- uid := user.UserId
- var req models.CygxIndustryFllowRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- industrialManagementId := req.IndustrialManagementId
- var condition string
- countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if countIndustrial == 0 {
- br.Msg = "产业不存在!"
- br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
- return
- }
- count, err := models.GetCountCygxIndustryFllow(industrialManagementId, user.Mobile, condition)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(models.CygxIndustryFllowResp)
- if count == 0 {
- item := new(models.CygxIndustryFllow)
- item.IndustrialManagementId = industrialManagementId
- item.UserId = uid
- item.Email = user.Email
- item.Mobile = user.Mobile
- item.RealName = user.RealName
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.Type = 1
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- _, err = models.AddCygxIndustryFllow(item)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- resp.Status = 1
- br.Msg = "关注成功"
- } else {
- err = models.RemoveCygxIndustryFllow(uid, industrialManagementId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "取消关注失败,Err:" + err.Error()
- return
- }
- resp.Status = 2
- br.Msg = "已取消关注"
- }
- //处理是否关注全部赛道字段
- go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 行业关注/取消关注
- // @Description 行业关注/取消关注 接口
- // @Param request body models.CygxCategoryFllowRep true "type json string"
- // @Success 200
- // @router /category/fllow [post]
- func (this *ReportController) CategoryFllow() {
- 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
- }
- uid := user.UserId
- var req models.CygxCategoryFllowRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- categoryId := req.CategoryId
- var condition string
- countCategory, err := models.GetCategoryCount(categoryId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if countCategory == 0 {
- br.Msg = "产业不存在!"
- br.ErrMsg = "产业ID不存在:" + strconv.Itoa(categoryId)
- return
- }
- count, err := models.GetCountCategoryFllow(categoryId, user.Mobile, condition)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(models.CygxIndustryFllowResp)
- if count == 0 {
- item := new(models.CygxXzsChooseCategory)
- item.CategoryId = categoryId
- item.UserId = uid
- item.Email = user.Email
- item.Mobile = user.Mobile
- item.RealName = user.RealName
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- _, err = models.AddCygxCategoryFllow(item)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- resp.Status = 1
- br.Msg = "关注成功"
- } else {
- err = models.RemoveCygxCategoryFllow(user.Mobile, categoryId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "取消关注失败,Err:" + err.Error()
- return
- }
- resp.Status = 2
- br.Msg = "已取消关注"
- }
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 报告搜索
- // @Description 报告搜索接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.ReoprtSearchResp
- // @router /searchReport [get]
- func (this *MobileReportController) SearchReport() {
- 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")
- keyWord := this.GetString("KeyWord")
- var condition string
- var conditionSql string
- //var sqlGroup string
- var total int
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.ReoprtSearchResp)
- //匹配报告标题、
- condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
- conditionSql = ` AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + condition + ` OR ( article_type = 'lyjh' ` + condition + ` ) `
- total, err := models.GetReoprtSearchCount(conditionSql)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "获取总数失败,Err:" + err.Error()
- return
- }
- //listHz, err := models.GetReoprtSearchList(` AND a.article_id < `+strconv.Itoa(utils.SummaryArticleId)+condition+` OR ( article_type = 'lyjh' `+condition+` ) `+sqlGroup, user.UserId, startSize, pageSize)
- listHz, err := models.GetReoprtSearchList(conditionSql, user.UserId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
- return
- }
- for k, _ := range listHz {
- listHz[k].Source = 1
- }
- var articleIds string
- for _, v := range listHz {
- articleIds += strconv.Itoa(v.ArticleId) + ","
- }
- articleIds = strings.TrimRight(articleIds, ",")
- silcearticleIds := strings.Split(articleIds, ",")
- //获取文章关联的产业
- var pars []interface{}
- pars = make([]interface{}, 0)
- articleIdList := make([]string, 0)
- for _, v := range silcearticleIds {
- articleIdList = append(articleIdList, v)
- }
- condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(silcearticleIds)) + ` ) `
- pars = append(pars, articleIdList)
- industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
- return
- }
- industrialMap := make(map[int][]*models.IndustrialManagementResp)
- if len(industrialList) > 0 {
- for _, v := range industrialList {
- item := new(models.IndustrialManagementResp)
- //item.ArticleId = v.ArticleId
- item.IndustrialManagementId = v.IndustrialManagementId
- item.IndustryName = v.IndustryName
- item.ChartPermissionId = v.ChartPermissionId
- industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
- }
- }
- detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
- return
- }
- categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
- mapCategoryUrl := make(map[string]string)
- var categoryId string
- var imgUrlChart string
- for _, v := range categoryUrlList {
- vslice := strings.Split(v, "_")
- categoryId = vslice[0]
- imgUrlChart = vslice[len(vslice)-1]
- mapCategoryUrl[categoryId] = imgUrlChart
- }
- for k, v := range listHz {
- if len(industrialMap[v.ArticleId]) > 0 {
- listHz[k].List = industrialMap[v.ArticleId]
- } else {
- listHz[k].List = make([]*models.IndustrialManagementResp, 0)
- }
- listHz[k].Body = ""
- listHz[k].Abstract, _ = services.GetReportContentTextSub(v.Abstract)
- listHz[k].Annotation, _ = services.GetReportContentTextSub(v.Annotation)
- //行业比较研究、资金流向,显示报告的摘要
- if listHz[k].CategoryName == "行业比较研究" || listHz[k].CategoryName == "资金流向" {
- listHz[k].Annotation = listHz[k].Abstract
- }
- listHz[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
- }
- if keyWord != "" {
- go services.AddUserSearchLog(user, keyWord, 5)
- }
- if len(listHz) == 0 {
- listHz = make([]*models.ArticleCollectionResp, 0)
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.ListHz = listHz
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 资源包搜索
- // @Description 资源包搜索接口
- // @Param KeyWord query string true "搜索关键词"
- // @Success 200 {object} models.SearchResourceResp
- // @router /searchResource [get]
- func (this *MobileReportController) SearchResource() {
- 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
- }
- uid := user.UserId
- fllowList, err := models.GetUserFllowIndustrialList(uid)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetUserFllowIndustrialList Err:" + err.Error()
- return
- }
- fllowMap := make(map[int]int)
- if len(fllowList) > 0 {
- for _, v := range fllowList {
- fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
- }
- }
- keyWord := this.GetString("KeyWord")
- var condition string
- var conditionOr string
- conditionOr += ` OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + ` AND publish_status = 1 ) `
- condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
- listHz, err := models.GetSearchResourceList(condition)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- //合并产业关联的标的
- listSubjcet, err := models.GetThemeHeatSubjectList("")
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
- return
- }
- industrialIdArr := make([]int, 0)
- for k, v := range listHz {
- listHz[k].Source = 1
- if fllowMap[v.IndustrialManagementId] > 0 {
- listHz[k].IsFollow = true
- }
- industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
- }
- if len(industrialIdArr) > 0 {
- //合并产业关联的标的
- listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
- return
- }
- mapIndustrial := make(map[string]int)
- for _, v := range listSubjcet {
- for k2, v2 := range listHz {
- if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
- listHz[k2].IndustrialSubjectList = append(listHz[k2].IndustrialSubjectList, v)
- mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
- }
- }
- }
- }
- mapUPdateTime := make(map[int]string)
- articleIdArr := make([]int, 0)
- //获取这些产业下最新更新的文章
- fmt.Println(industrialIdArr)
- listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败 GetNewArticleDetailByIndustrialIds ,Err:" + err.Error()
- return
- }
- for _, v := range listUpdateTime {
- mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
- articleIdArr = append(articleIdArr, v.ArticleId)
- }
- for k, v := range listHz {
- listHz[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
- }
- if keyWord != "" {
- go services.AddUserSearchLog(user, keyWord, 4)
- }
- resp := new(models.SearchResourceResp)
- if len(listHz) == 0 {
- listHz = make([]*models.IndustrialManagement, 0)
- }
- resp.ListHz = listHz
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 报告搜索、资源包搜索接口
- // @Description 报告搜索、资源包搜索接口接口
- // @Param KeyWord query string true "搜索关键词"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param SearchType query int true "1:综合,2:全部"
- // @Success 200 {object} models.SearchReportAndResourceResp
- // @router /searchReportAndResource [get]
- func (this *MobileReportController) SearchReportAndResource() {
- 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
- }
- uid := user.UserId
- keyWord := this.GetString("KeyWord")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- searchType, _ := this.GetInt("SearchType")
- var total int
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- page := paging.GetPaging(currentIndex, pageSize, total)
- var condition string
- var conditionSql string
- //匹配报告标题、
- condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
- conditionSql = ` AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + condition + ` OR ( article_type = 'lyjh' ` + condition + ` ) `
- total, err := models.GetReoprtSearchCount(conditionSql)
- if err != nil {
- br.Msg = "获取信息失败"
- br.Msg = "获取总数失败,Err:" + err.Error()
- return
- }
- ListHzReport, err := services.GetReoprtSearchListHz(conditionSql, user.UserId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetReoprtSearchListHz Err:" + err.Error()
- return
- }
- if len(ListHzReport) == 0 {
- ListHzReport = make([]*models.ArticleCollectionResp, 0)
- }
- fllowList, err := models.GetUserFllowIndustrialList(uid)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetUserFllowIndustrialList Err:" + err.Error()
- return
- }
- fllowMap := make(map[int]int)
- if len(fllowList) > 0 {
- for _, v := range fllowList {
- fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
- }
- }
- var conditionOr string
- conditionOr += ` OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + ` AND publish_status = 1 ) `
- condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
- var pageSizeHzResource int
- if searchType == 1 {
- pageSizeHzResource = 5
- } else {
- pageSizeHzResource = 100
- }
- listHzResource, err := models.GetSearchResourceListHz(condition, 0, pageSizeHzResource)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- conditionOr = ` OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id >= ` + strconv.Itoa(utils.SummaryArticleId) + ` AND publish_status = 1 ) `
- condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id >= ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
- //合并产业关联的标的
- listSubjcet, err := models.GetThemeHeatSubjectList("")
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
- return
- }
- industrialIdArr := make([]int, 0)
- for k, v := range listHzResource {
- listHzResource[k].Source = 1
- if fllowMap[v.IndustrialManagementId] > 0 {
- listHzResource[k].IsFollw = true
- }
- industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
- }
- if len(industrialIdArr) > 0 {
- //合并产业关联的标的
- listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
- return
- }
- mapIndustrial := make(map[string]int)
- for _, v := range listSubjcet {
- for k2, v2 := range listHzResource {
- if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
- listHzResource[k2].IndustrialSubjectList = append(listHzResource[k2].IndustrialSubjectList, v)
- mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
- }
- }
- }
- }
- resp := new(models.SearchReportAndResourceResp)
- if len(listHzResource) == 0 {
- listHzResource = make([]*models.IndustrialManagementHotResp, 0)
- }
- if keyWord != "" {
- go services.AddUserSearchLog(user, keyWord, 5)
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.ListHzResource = listHzResource
- resp.ListHzReport = ListHzReport
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|