123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_mini_api/models"
- "eta/eta_mini_api/models/request"
- "eta/eta_mini_api/models/response"
- "eta/eta_mini_api/services"
- "eta/eta_mini_api/utils"
- "fmt"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type MyReportController struct {
- BaseAuthController
- }
- // @Title 获取我的报告列表
- // @Description 获取我的报告列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.MyReportResp
- // @router /list [get]
- func (this *MyReportController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if err := recover(); err != nil {
- fmt.Println(err)
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize30
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if user.Status != utils.UserStatusFormal {
- br.Msg = "该用户没有收藏权限"
- return
- }
- total, err := models.GetMyReportListCountByUserId(user.UserId)
- if err != nil {
- br.Msg = "获取我的报告列表失败"
- br.ErrMsg = "获取我的报告列表失败,系统异常,Err:" + err.Error()
- return
- }
- resp := new(response.MyReportListResp)
- startSize := utils.StartIndex(currentIndex, pageSize)
- reportList, err := models.GetMyReportListByUserId(user.UserId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取我的报告列表失败"
- br.ErrMsg = "获取我的报告列表失败,系统异常,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = reportList
- resp.Paging = page
- br.Data = resp
- br.Success = true
- br.Msg = "获取我的报告列表成功"
- br.Ret = 200
- }
- // @Title 收藏研报
- // @Description 收藏研报
- // @Success 200 {object} models.BaseResponse
- // @Failure 403 {object} models.BaseResponse
- // @router /collect [post]
- func (this *MyReportController) Collect() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.MyReportCollectReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- user := this.User
- if user.Status != utils.UserStatusFormal {
- br.Msg = "用户没有权限收藏"
- return
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, req.ReportId, utils.ReportTypeEta)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该研报已收藏,请重新刷新页面"
- return
- }
- reportResp, err := services.GetReportDetail(req.ReportId, user.UserId)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "获取研报详情失败,Err:" + err.Error()
- return
- }
- if reportResp.Ret != 200 {
- br.Msg = "收藏失败"
- br.ErrMsg = "获取研报详情失败,Err:" + reportResp.ErrMsg
- return
- }
- if reportResp.Data.Report == nil {
- br.Msg = "该研报已删除或不存在,请刷新页面"
- return
- }
- if reportResp.Data.Status != utils.ReportPermissionStatusHas {
- br.Msg = "用户权限不足,不能收藏"
- return
- }
- report := reportResp.Data.Report
- publishTime, err := time.Parse(utils.FormatDateTime, report.PublishTime)
- if err != nil {
- br.Msg = "时间格式不对"
- return
- }
- myChart := &models.MyReport{
- UserId: user.UserId,
- ReportId: req.ReportId,
- Title: report.Title,
- Abstract: report.Abstract,
- Author: report.Author,
- PublishTime: publishTime,
- Stage: report.Stage,
- CreateTime: time.Now(),
- ReportType: utils.ReportTypeEta,
- }
- err = myChart.Insert()
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "收藏失败,Err:" + err.Error()
- return
- }
- br.Msg = "收藏成功"
- br.Success = true
- br.Ret = 200
- }
- // @Title 收藏pdf研报
- // @Description 收藏pdf研报
- // @Success 200 {object} models.BaseResponse
- // @Failure 403 {object} models.BaseResponse
- // @router /pdf/collect [post]
- func (this *MyReportController) PdfCollect() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.MyReportPdfCollectReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- user := this.User
- if user.Status != utils.UserStatusFormal {
- br.Msg = "用户没有权限收藏"
- return
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, req.ReportPdfId, utils.ReportTypePdf)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该研报已收藏,请重新刷新页面"
- return
- }
- reportPdf, err := models.GetReportPdfById(req.ReportPdfId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "研报不存在或已删除"
- return
- }
- br.Msg = "收藏失败"
- br.ErrMsg = "获取研报详情失败,Err:" + err.Error()
- return
- }
- reportClassifyId := services.GetReportPdfClassify(reportPdf)
- chartPermissionResp, err := services.GetChartPermissionListByClassifyId(reportClassifyId, 0)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "获取研报详情失败,Err:" + err.Error()
- return
- }
- if chartPermissionResp.Ret != 200 {
- br.Msg = "收藏失败"
- br.ErrMsg = "获取研报详情失败,Err:" + chartPermissionResp.ErrMsg
- return
- }
- var IsPublic bool
- var permissionMap = make(map[int]struct{})
- for _, v := range chartPermissionResp.Data {
- if v.IsPublic == 1 {
- IsPublic = true
- }
- permissionMap[v.ChartPermissionId] = struct{}{}
- }
- // 校验是否有收藏权限
- var IsHas bool
- if !IsPublic {
- chartPermissionIds, err := models.GetUserChartPermissionIdByUserId(user.UserId)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
- return
- }
- if len(chartPermissionIds) == 0 {
- br.Msg = "用户没有权限收藏"
- return
- }
- for _, v := range chartPermissionIds {
- if _, ok := permissionMap[v]; ok {
- IsHas = true
- break
- }
- }
- if !IsHas {
- br.Msg = "用户没有权限收藏"
- return
- }
- }
- publishTime, err := time.Parse(utils.FormatDateTime, reportPdf.PublishTime)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "时间格式不对, err:" + err.Error()
- return
- }
- myChart := &models.MyReport{
- UserId: user.UserId,
- ReportId: req.ReportPdfId,
- Title: reportPdf.Title,
- Abstract: reportPdf.Abstract,
- Author: reportPdf.Author,
- PublishTime: publishTime,
- Stage: reportPdf.Stage,
- CreateTime: time.Now(),
- ReportType: utils.ReportTypePdf,
- }
- err = myChart.Insert()
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "收藏失败,Err:" + err.Error()
- return
- }
- br.Msg = "收藏成功"
- br.Success = true
- br.Ret = 200
- }
- // @Title 收藏pdf研报
- // @Description 收藏pdf研报
- // @Success 200 {object} models.BaseResponse
- // @Failure 403 {object} models.BaseResponse
- // @router /pdf/collectCancel [post]
- func (this *MyReportController) PdfCollectCancel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.MyReportPdfCollectReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- user := this.User
- if user.Status != utils.UserStatusFormal {
- br.Msg = "用户没有权限收藏"
- return
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, req.ReportPdfId, utils.ReportTypePdf)
- if err != nil {
- br.Msg = "取消收藏失败"
- br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
- return
- }
- if count == 0 {
- br.Msg = "该研报已取消收藏,请重新刷新页面"
- return
- }
- err = models.DeleteMyReportByUserIdAndReportId(user.UserId, req.ReportPdfId, utils.ReportTypePdf)
- if err != nil {
- br.Msg = "取消收藏失败"
- br.ErrMsg = "取消收藏失败,Err:" + err.Error()
- return
- }
- br.Msg = "取消收藏成功"
- br.Success = true
- br.Ret = 200
- }
- // @Title 取消收藏
- // @Description 取消收藏
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.BaseResponse
- // @Failure 403 {object} models.BaseResponse
- // @router /collectCancel [post]
- func (this *MyReportController) CollectCancel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.MyReportCollectReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- user := this.User
- if user.Status != utils.UserStatusFormal {
- br.Msg = "用户没有权限收藏"
- return
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, req.ReportId, utils.ReportTypeEta)
- if err != nil {
- br.Msg = "取消收藏失败"
- br.ErrMsg = "获取收藏信息失败,Err:" + err.Error()
- return
- }
- if count == 0 {
- br.Msg = "该研报已取消收藏,请重新刷新页面"
- return
- }
- err = models.DeleteMyReportByUserIdAndReportId(user.UserId, req.ReportId, utils.ReportTypeEta)
- if err != nil {
- br.Msg = "取消收藏失败"
- br.ErrMsg = "取消收藏失败,Err:" + err.Error()
- return
- }
- br.Msg = "取消收藏成功"
- br.Success = true
- br.Ret = 200
- }
- // @Title 是否收藏pdf研报
- // @Description 是否收藏pdf研报
- // @Param request body request.MyReportCollectReq true "type json string"
- // @Success 200 {object} models.BaseResponse
- // @router /pdf/isCollect [post]
- func (this *MyReportController) IsPdfCollect() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.MyReportPdfCollectReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- user := this.User
- if user.Status != utils.UserStatusFormal {
- br.Msg = "用户没有权限收藏"
- return
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, req.ReportPdfId, utils.ReportTypePdf)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
- return
- }
- resp := new(response.MyReportIsCollectResp)
- if count > 0 {
- resp.IsCollect = true
- } else {
- resp.IsCollect = false
- }
- br.Data = resp
- br.Msg = "获取成功"
- br.Success = true
- br.Ret = 200
- }
- // @Title 是否收藏研报
- // @Description 是否收藏研报
- // @Param request body request.MyReportCollectReq true "type json string"
- // @Success 200 {object} models.BaseResponse
- // @router /isCollect [post]
- func (this *MyReportController) IsCollect() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.MyReportCollectReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- user := this.User
- if user.Status != utils.UserStatusFormal {
- br.Msg = "用户没有权限收藏"
- return
- }
- count, err := models.GetMyReportCountByUserIdAndReportId(user.UserId, req.ReportId, utils.ReportTypeEta)
- if err != nil {
- br.Msg = "收藏失败"
- br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
- return
- }
- resp := new(response.MyReportIsCollectResp)
- if count > 0 {
- resp.IsCollect = true
- } else {
- resp.IsCollect = false
- }
- br.Data = resp
- br.Msg = "获取成功"
- br.Success = true
- br.Ret = 200
- }
|