123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962 |
- package controllers
- import (
- "eta/eta_mini_api/models"
- "eta/eta_mini_api/models/response"
- "eta/eta_mini_api/services"
- "eta/eta_mini_api/utils"
- "sort"
- "strconv"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type ReportController struct {
- BaseAuthController
- }
- type ReportNoAuthController struct {
- BaseCommonController
- }
- // @Title 研报详情
- // @Description 研报详情接口
- // @Param ReportId query int true "报告id"
- // @Success 200 {object} models.ReportDetailResp
- // @router /detail [get]
- func (this *ReportController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportId, _ := this.GetInt("ReportId")
- if reportId <= 0 {
- br.Msg = "报告不存在"
- return
- }
- user := this.User
- if user == nil {
- // 如果没有用户没有绑定信息,单独处理
- resp, er := services.GetReportDetailNoUser(reportId)
- if er != nil {
- br.Msg = "查询报告详情失败"
- br.ErrMsg = "查询报告失败,系统异常,Err:" + er.Error()
- return
- }
- if resp.Ret != 200 {
- br.Msg = resp.Msg
- br.ErrMsg = resp.ErrMsg
- return
- }
- br.Msg = "查询成功"
- br.Data = resp.Data
- br.Success = true
- br.Ret = 200
- return
- }
- result, err := services.GetReportDetail(reportId, user.UserId)
- if err != nil {
- br.Msg = "查询报告详情失败"
- br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
- return
- }
- if result.Ret == 403 {
- br.Msg = result.Msg
- br.ErrMsg = result.ErrMsg
- return
- }
- if result.Ret == 200 && result.Data.Report == nil {
- // 后台没有这个报告,那么尝试删除我的收藏
- models.DeleteMyReportByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
- br.Msg = "该报告已删除或不存在,请刷新页面"
- return
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportId, utils.ReportTypeEta)
- if err != nil {
- br.Msg = "查询收藏数量失败"
- br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- result.Data.IsCollect = true
- } else {
- result.Data.IsCollect = false
- }
- if user.UserId != 0 {
- result.Data.IsSignIn = true
- }
- br.Msg = "查询成功"
- br.Success = true
- br.Ret = 200
- br.Data = result.Data
- }
- // @Title 研报列表
- // @Description 研报列表
- // @Param ChartPermissionId query int true "品种ID"
- // @Param Level query int true "品种层级"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} response.ReportList
- // @router /list [get]
- func (this *ReportController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- chartPermissionId, _ := this.GetInt("ChartPermissionId")
- level, _ := this.GetInt("Level")
- rangeType, _ := this.GetInt("RangeType")
- classifyId, _ := this.GetInt("ClassifyId")
- reports, err := services.GetReportList(chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- if reports.Ret != 200 {
- br.Msg = reports.Msg
- br.ErrMsg = reports.ErrMsg
- return
- }
- br.Data = reports.Data
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title pdf研报列表
- // @Description pdf研报列表
- // @Param ChartPermissionId query int true "品种ID"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param RangeType query int true "范围类型,1-一天内,2-一周内,3-半年内"
- // @Param ClassifyId query int true "二级分类id"
- // @Success 200 {object} response.ReportList
- // @router /pdf/list [get]
- func (this *ReportController) PdfList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- chartPermissionId, _ := this.GetInt("ChartPermissionId")
- classifyId, _ := this.GetInt("ClassifyId")
- rangeType, _ := this.GetInt("RangeType")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if chartPermissionId <= 0 {
- br.Msg = "请输入品种ID"
- return
- }
- var condition string
- switch rangeType {
- case 1:
- condition += ` AND DATE(publish_time)=DATE(NOW()) `
- case 2:
- condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
- case 3:
- condition += ` AND DATE(publish_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- var leafClassifyIds []int
- var leafClassifyIdMap map[int]struct{}
- var classifyMap map[int]*models.ClassifyView
- classifyResp, err := services.GetAllClassify()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if classifyResp.Ret != 200 {
- br.Msg = classifyResp.Msg
- br.ErrMsg = classifyResp.ErrMsg
- return
- }
- classifyList := classifyResp.Data
- classifyMap = make(map[int]*models.ClassifyView)
- isHas := false
- for _, v := range classifyList {
- if v.Id == classifyId && classifyId != 0 {
- isHas = true
- }
- classifyMap[v.Id] = v
- }
- if !isHas && classifyId != 0 {
- br.Msg = "分类不存在"
- return
- }
- if classifyId != 0 {
- leafClassifyIds = getLeafClassifyIds(classifyMap, classifyId)
- leafClassifyIdMap = make(map[int]struct{})
- for _, v := range leafClassifyIds {
- leafClassifyIdMap[v] = struct{}{}
- }
- }
- var permissionClassifyList []int
- if chartPermissionId != 0 {
- resp, err := services.GetClassifyListByChartPermission(chartPermissionId)
- if err != nil {
- br.Msg = "获取分类失败"
- br.ErrMsg = "获取分类失败,系统异常,Err:" + err.Error()
- return
- }
- if resp.Ret != 200 {
- br.Msg = resp.Msg
- br.ErrMsg = resp.ErrMsg
- return
- }
- classifyList := resp.Data
- if len(classifyList) == 0 {
- resp := new(response.ReportPdfResp)
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- for _, item := range classifyList {
- permissionClassifyList = append(permissionClassifyList, item.Id)
- }
- }
- queryClassifyIds := make([]int, 0)
- if classifyId > 0 {
- for _, v := range permissionClassifyList {
- if _, ok := leafClassifyIdMap[v]; ok {
- queryClassifyIds = append(queryClassifyIds, v)
- }
- }
- } else {
- queryClassifyIds = permissionClassifyList
- }
- firstClassifyIds := make([]int, 0)
- secondClassifyIds := make([]int, 0)
- thirdClassifyIds := make([]int, 0)
- for _, v := range queryClassifyIds {
- classify := classifyMap[v]
- if classify.HasChild == 1 {
- continue
- }
- switch classifyMap[v].Level {
- case 1:
- firstClassifyIds = append(firstClassifyIds, v)
- case 2:
- secondClassifyIds = append(secondClassifyIds, v)
- case 3:
- thirdClassifyIds = append(thirdClassifyIds, v)
- }
- }
- total, err := models.GetReportPdfCountByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds, condition)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表统计查询失败,系统异常,Err:" + err.Error()
- return
- }
- reportPdfList, err := models.GetReportPdfListByCondition(firstClassifyIds, secondClassifyIds, thirdClassifyIds, condition, startSize, pageSize)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.ReportPdfResp)
- resp.List = reportPdfList
- resp.Paging = page
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- func getLeafClassifyIds(classifyMap map[int]*models.ClassifyView, keyId int) []int {
- var leafClassifyIds []int
- curClassify := classifyMap[keyId]
- if curClassify.HasChild == 0 {
- leafClassifyIds = append(leafClassifyIds, curClassify.Id)
- return leafClassifyIds
- }
- for _, v := range classifyMap {
- if v.ParentId == curClassify.Id {
- if v.HasChild == 0 {
- leafClassifyIds = append(leafClassifyIds, v.Id)
- } else {
- leafClassifyIds = append(leafClassifyIds, getLeafClassifyIds(classifyMap, v.Id)...)
- }
- }
- }
- return leafClassifyIds
- }
- // @Title pdf研报详情
- // @Description pdf研报详情
- // @Param ReportPdfId query int true "品种ID"
- // @Success 200 {object} response.ReportList
- // @router /pdf/detail [get]
- func (this *ReportController) PdfDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- // 有效期是否到期
- var vailStatus int
- if user.Status == utils.UserStatusFormal {
- if user.ValidEndTime.After(time.Now()) && user.ValidStartTime.Before(time.Now()) {
- vailStatus = 2
- } else {
- // 不在有效期时间则设置为过期, 将用户状态禁用
- vailStatus = 1
- user.Status = utils.UserStatusNo
- }
- }
- reportPdfId, _ := this.GetInt("ReportPdfId")
- if reportPdfId <= 0 {
- br.Msg = "研报不存在或已删除"
- return
- }
- reportPdf, err := models.GetReportPdfById(reportPdfId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "研报不存在或已删除"
- br.ErrMsg = "研报不存在或已删除,系统异常,Err:" + err.Error()
- return
- }
- if reportPdf == nil {
- // 尝试删除收藏列表的记录
- models.DeleteMyReportByUserIdAndReportId(user.UserId, reportPdfId, utils.ReportTypePdf)
- br.Msg = "研报不存在或已删除"
- return
- }
- reportClassifyId := services.GetReportPdfClassify(reportPdf)
- permissionResp, err := services.GetChartPermissionListByClassifyId(reportClassifyId, 0)
- if err != nil {
- br.Msg = "研报不存在或已删除"
- br.ErrMsg = "获取权限失败,系统异常,Err:" + err.Error()
- return
- }
- if permissionResp.Ret != 200 {
- br.Msg = permissionResp.Msg
- br.ErrMsg = permissionResp.ErrMsg
- return
- }
- var IsHas bool
- var IsPublic bool
- permissionMap := make(map[int]struct{})
- for _, v := range permissionResp.Data {
- if v.IsPublic == 1 {
- IsPublic = true
- }
- permissionMap[v.ChartPermissionId] = struct{}{}
- }
- resp := new(response.ReportPdfDetailResp)
- if !IsPublic {
- // 如果是私有报告,用户权限过期直接返回有效期已过
- if vailStatus == 1 || user.Status == utils.UserStatusNo {
- resp.Report = reportPdf
- resp.Status = utils.ReportPermissionStatusExpired
- br.Ret = 200
- br.Data = resp
- br.Msg = "用户权限不足"
- return
- }
- // 如果被禁用或是潜在用户,直接返回无阅读报告权限
- if user.Status == utils.UserStatusPotential {
- resp.Report = reportPdf
- resp.Status = utils.ReportPermissionStatusNo
- br.Ret = 200
- br.Data = resp
- br.Msg = "用户权限不足"
- return
- }
- // 正式用户,判断是否有权限查看
- userChartPermissionIds, err := models.GetUserChartPermissionIdByUserId(user.UserId)
- if err != nil {
- br.Msg = "获取用户权限失败"
- br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
- return
- }
- if len(userChartPermissionIds) == 0 {
- resp.Report = reportPdf
- resp.Status = utils.ReportPermissionStatusNoPermission
- br.Ret = 200
- br.Data = resp
- br.Msg = "用户权限不足"
- return
- }
- for _, v := range userChartPermissionIds {
- if _, ok := permissionMap[v]; ok {
- IsHas = true
- break
- }
- }
- if !IsHas {
- resp.Report = reportPdf
- resp.Status = utils.ReportPermissionStatusNoPermission
- br.Ret = 200
- br.Data = resp
- br.Msg = "用户权限不足"
- return
- }
- } else {
- reportPdf.IsPublic = IsPublic
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, reportPdf.ReportPdfId, utils.ReportTypePdf)
- if err != nil {
- br.Msg = "获取研报详情失败"
- br.ErrMsg = "获取用户收藏记录失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- reportPdf.IsCollect = true
- } else {
- reportPdf.IsCollect = false
- }
- resp.Report = reportPdf
- resp.Status = utils.ReportPermissionStatusHas
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 今日研报列表
- // @Description 今日研报列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.ReportDetailResp
- // @router /daily/list [get]
- func (this *ReportController) DailyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- // 暂不使用分页
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- resp, err := services.GetReportDailyList()
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- if resp.Ret != 200 {
- br.Msg = resp.Msg
- br.ErrMsg = resp.ErrMsg
- return
- }
- reportList := resp.Data
- for _, v := range reportList.List {
- v.ReportType = utils.ReportTypeEta
- }
- reportPdfList, err := models.GetReportPdfDailyList()
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- var classifyIds []int
- for _, v := range reportPdfList {
- var reportClassifyId int
- if v.ClassifyIdFirst != 0 {
- reportClassifyId = v.ClassifyIdFirst
- }
- if v.ClassifyIdSecond != 0 {
- reportClassifyId = v.ClassifyIdSecond
- }
- if v.ClassifyIdThird != 0 {
- reportClassifyId = v.ClassifyIdThird
- }
- classifyIds = append(classifyIds, reportClassifyId)
- }
- if len(classifyIds) > 0 {
- classifyResp, err := services.GetFirstChartPermission(classifyIds)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- if classifyResp.Ret != 200 {
- br.Msg = classifyResp.Msg
- br.ErrMsg = classifyResp.ErrMsg
- return
- }
- classifyPermissionMap := make(map[int][]string)
- for _, v := range classifyResp.Data {
- classifyPermissionMap[v.ClassifyId] = v.PermissionNames
- }
- for _, v := range reportPdfList {
- var reportClassifyId int
- if v.ClassifyIdFirst != 0 {
- reportClassifyId = v.ClassifyIdFirst
- }
- if v.ClassifyIdSecond != 0 {
- reportClassifyId = v.ClassifyIdSecond
- }
- if v.ClassifyIdThird != 0 {
- reportClassifyId = v.ClassifyIdThird
- }
- // 过滤没有绑定品种的研报
- if classifyPermissionMap[reportClassifyId] == nil {
- continue
- }
- reportList.List = append(reportList.List, &models.ReportView{
- Id: v.ReportPdfId,
- ClassifyIdFirst: v.ClassifyIdFirst,
- ClassifyNameFirst: v.ClassifyNameFirst,
- ClassifyIdSecond: v.ClassifyIdSecond,
- ClassifyNameSecond: v.ClassifyNameSecond,
- ClassifyIdThird: v.ClassifyIdThird,
- ClassifyNameThird: v.ClassifyNameThird,
- PermissionNames: classifyPermissionMap[reportClassifyId],
- PdfUrl: v.PdfUrl,
- Title: v.Title,
- Abstract: v.Abstract,
- Stage: v.Stage,
- Author: v.Author,
- ReportType: utils.ReportTypePdf,
- PublishTime: v.PublishTime.Format(utils.FormatDateTime),
- ModifyTime: v.ModifyTime,
- })
- }
- }
- sort.Sort(models.ByPublishTimeReportView(reportList.List))
- br.Data = reportList
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 最新研报列表
- // @Description 最新研报列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.ReportDetailResp
- // @router /recent/list [get]
- func (this *ReportController) RecentList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- // 暂不使用分页
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = 3
- }
- resp, err := services.GetReportRecentList(currentIndex, pageSize)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- // 查询已发布的pdf
- reportPdfList, err := models.GetRecentReportPdfList(0, 3)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- reportList := resp.Data
- for _, v := range reportList.List {
- v.ReportType = utils.ReportTypeEta
- }
- var classifyIds []int
- for _, v := range reportPdfList {
- var reportClassifyId int
- if v.ClassifyIdFirst != 0 {
- reportClassifyId = v.ClassifyIdFirst
- }
- if v.ClassifyIdSecond != 0 {
- reportClassifyId = v.ClassifyIdSecond
- }
- if v.ClassifyIdThird != 0 {
- reportClassifyId = v.ClassifyIdThird
- }
- classifyIds = append(classifyIds, reportClassifyId)
- }
- classifyResp, err := services.GetFirstChartPermission(classifyIds)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- if classifyResp.Ret != 200 {
- br.Msg = classifyResp.Msg
- br.ErrMsg = classifyResp.ErrMsg
- }
- classifyPermissionMap := make(map[int][]string)
- for _, v := range classifyResp.Data {
- classifyPermissionMap[v.ClassifyId] = v.PermissionNames
- }
- for _, v := range reportPdfList {
- var reportClassifyId int
- if v.ClassifyIdFirst != 0 {
- reportClassifyId = v.ClassifyIdFirst
- }
- if v.ClassifyIdSecond != 0 {
- reportClassifyId = v.ClassifyIdSecond
- }
- if v.ClassifyIdThird != 0 {
- reportClassifyId = v.ClassifyIdThird
- }
- // 过滤没有绑定品种的研报
- if classifyPermissionMap[reportClassifyId] == nil {
- continue
- }
- reportList.List = append(reportList.List, &models.ReportView{
- Id: v.ReportPdfId,
- ClassifyIdFirst: v.ClassifyIdFirst,
- ClassifyNameFirst: v.ClassifyNameFirst,
- ClassifyIdSecond: v.ClassifyIdSecond,
- ClassifyNameSecond: v.ClassifyNameSecond,
- ClassifyIdThird: v.ClassifyIdThird,
- ClassifyNameThird: v.ClassifyNameThird,
- PermissionNames: classifyPermissionMap[reportClassifyId],
- PdfUrl: v.PdfUrl,
- Title: v.Title,
- Abstract: v.Abstract,
- Stage: v.Stage,
- Author: v.Author,
- ReportType: utils.ReportTypePdf,
- PublishTime: v.PublishTime.Format(utils.FormatDateTime),
- ModifyTime: v.ModifyTime,
- })
- }
- sort.Sort(models.ByPublishTimeReportView(reportList.List))
- endIdx := len(reportList.List)
- if endIdx > 3 {
- endIdx = 3
- }
- reportList.List = reportList.List[:endIdx]
- br.Data = reportList
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 研报列表
- // @Description 研报列表
- // @Param ReportId query int true "报告id"
- // @Param chartPermissionId query int true "品种ID"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.ReportDetailResp
- // @router /search [get]
- func (this *ReportController) Search() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize30
- }
- if keyWord == "" {
- br.Msg = "请输入关键字"
- return
- }
- reports, err := services.SearchReport(keyWord, currentIndex, pageSize)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- if reports.Ret != 200 {
- br.Msg = reports.Msg
- br.ErrMsg = reports.ErrMsg
- return
- }
- resp := new(response.ReportSearchViewResp)
- list := make([]*response.ReportSearchListView, 0)
- for _, v := range reports.Data.List {
- tmpReport := &response.ReportSearchListView{
- ReportId: v.ReportId,
- ReportChapterId: v.ReportChapterId,
- ClassifyIdFirst: v.ClassifyIdFirst,
- ClassifyNameFirst: v.ClassifyNameFirst,
- ClassifyIdSecond: v.ClassifyIdSecond,
- ClassifyNameSecond: v.ClassifyNameSecond,
- ClassifyIdThird: v.ClassifyIdThird,
- ClassifyNameThird: v.ClassifyNameThird,
- ReportChapterTypeId: v.ReportChapterTypeId,
- PublishTime: v.PublishTime.Format(utils.FormatDate),
- Title: v.Title,
- ContentSub: v.ContentSub,
- Abstract: v.Abstract,
- Stage: v.Stage,
- Author: v.Author,
- PdfUrl: v.PdfUrl,
- ReportType: v.ReportType,
- }
- if v.PublishTime.IsZero() {
- tmpReport.PublishTime = ""
- }
- list = append(list, tmpReport)
- }
- resp.List = list
- resp.Paging = reports.Data.Paging
- br.Data = resp
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 研报列表
- // @Description 研报列表
- // @Param ChartPermissionId query int true "品种ID"
- // @Param Level query int true "品种层级"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
- // @Param ReportType query string true "报告类型,1-eta报告,2-pdf报告"
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} response.ReportList
- // @router /list [get]
- func (this *ReportNoAuthController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- chartPermissionId, _ := this.GetInt("ChartPermissionId")
- level, _ := this.GetInt("Level")
- rangeType, _ := this.GetInt("RangeType")
- reportType, _ := this.GetInt("ReportType")
- classifyId, _ := this.GetInt("ClassifyId")
- switch rangeType {
- case 1, 2, 3:
- default:
- br.Msg = "查询失败"
- return
- }
- switch reportType {
- case utils.ReportTypeEta, utils.ReportTypePdf:
- default:
- br.Msg = "报告不存在"
- return
- }
- reports, err := services.GetNoAuthReportList(reportType, chartPermissionId, level, rangeType, classifyId, currentIndex, pageSize)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- if reports.Ret != 200 {
- br.Msg = reports.Msg
- br.ErrMsg = reports.ErrMsg
- return
- }
- br.Data = reports.Data
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 研报详情
- // @Description 研报详情接口
- // @Param ReportId query int true "报告id"
- // @Param ReportType query int true "报告类型:1-eta,2-pdf"
- // @Success 200 {object} models.ReportDetailResp
- // @router /detail [get]
- func (this *ReportNoAuthController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportId, _ := this.GetInt("ReportId")
- reportType, _ := this.GetInt("ReportType")
- if reportId <= 0 {
- br.Msg = "报告不存在"
- return
- }
- switch reportType {
- case utils.ReportTypeEta, utils.ReportTypePdf:
- default:
- br.Msg = "报告不存在"
- return
- }
- reportPush, err := models.GetReportPushStatusByReportId(reportId, reportType)
- if err != nil {
- br.Msg = "查询报告失败"
- br.ErrMsg = "查询报告推送状态失败,系统异常,Err:" + err.Error()
- return
- }
- if reportPush.State != utils.ReportStatePush {
- br.Msg = "报告未推送或已删除,请刷新重试"
- return
- }
- switch reportType {
- case utils.ReportTypeEta:
- result, err := services.GetNoAuthReportDetail(reportId)
- if err != nil {
- br.Msg = "查询报告详情失败"
- br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
- return
- }
- if result.Ret != 200 {
- br.Msg = result.Msg
- br.ErrMsg = result.ErrMsg
- return
- }
- if result.Ret == 200 && result.Data.Report == nil {
- // 报告不存在, 就尝试删除推送的记录
- models.DeleteReportPushStatusByReportId(reportId, utils.ReportTypeEta)
- br.Msg = "报告已删除或未发布,请刷新重试"
- return
- }
- br.Msg = "查询成功"
- br.Success = true
- br.Ret = 200
- br.Data = result.Data
- return
- case utils.ReportTypePdf:
- reportPdf, err := models.GetReportPdfById(reportId)
- if err != nil {
- br.Msg = "查询报告详情失败"
- br.ErrMsg = "查询报告失败,系统异常,Err:" + err.Error()
- return
- }
- br.Msg = "查询成功"
- br.Success = true
- br.Ret = 200
- br.Data = reportPdf
- return
- default:
- br.Msg = "报告不存在"
- return
- }
- }
- // @Title 研报搜索
- // @Description 研报搜索
- // @Param KeyWord query string true "每页数据条数"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.ReportDetailResp
- // @router /search [get]
- func (this *ReportNoAuthController) Search() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize30
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- if keyWord == "" {
- br.Msg = "请输入关键字"
- return
- }
- reports, total, err := services.SearchReportPush(keyWord, startSize, pageSize)
- if err != nil {
- br.Msg = "研报列表查询失败"
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
- return
- }
- resp := new(response.ReportSearchViewResp)
- list := make([]*response.ReportSearchListView, 0)
- for _, v := range reports {
- tmpReport := &response.ReportSearchListView{
- ReportId: v.ReportId,
- ClassifyIdFirst: v.ClassifyIdFirst,
- ClassifyNameFirst: v.ClassifyNameFirst,
- ClassifyIdSecond: v.ClassifyIdSecond,
- ClassifyNameSecond: v.ClassifyNameSecond,
- ClassifyIdThird: v.ClassifyIdThird,
- ClassifyNameThird: v.ClassifyNameThird,
- PublishTime: v.PublishTime.Format(utils.FormatDate),
- Title: v.Title,
- Abstract: v.Abstract,
- Stage: strconv.Itoa(v.Stage),
- Author: v.Author,
- ReportType: v.ReportType,
- }
- if v.PublishTime.IsZero() {
- tmpReport.PublishTime = ""
- }
- list = append(list, tmpReport)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = list
- resp.Paging = page
- br.Data = resp
- br.Msg = "查询成功"
- br.Ret = 200
- br.Success = true
- }
|