|
@@ -0,0 +1,240 @@
|
|
|
+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
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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 != 2 {
|
|
|
+ br.Msg = "该用户没有收藏权限"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err := models.GetMyReportListCountByUserId(user.UserId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取我的报告列表失败"
|
|
|
+ br.ErrMsg = "获取我的报告列表失败,系统异常,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(response.MyReportListResp)
|
|
|
+ if total == 0 {
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "暂无数据"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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.Page = page
|
|
|
+
|
|
|
+ br.Data = resp
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取我的报告列表成功"
|
|
|
+ br.Ret = 200
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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 != 2 {
|
|
|
+ br.Msg = "用户没有权限收藏"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := models.GetMyReportByUserIdAndReportId(user.UserId, req.ReportId)
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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 != 2 {
|
|
|
+ br.Msg = "用户没有权限收藏"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := models.GetMyReportByUserIdAndReportId(user.UserId, req.ReportId)
|
|
|
+ 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()
|
|
|
+
|
|
|
+ }
|
|
|
+ if reportResp.Ret != 200 {
|
|
|
+ br.Msg = "收藏失败"
|
|
|
+ br.ErrMsg = "获取研报详情失败,Err:" + reportResp.ErrMsg
|
|
|
+ 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(),
|
|
|
+ }
|
|
|
+ err = myChart.Insert()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "收藏失败"
|
|
|
+ br.ErrMsg = "收藏失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Msg = "收藏成功"
|
|
|
+ br.Success = true
|
|
|
+ br.Ret = 200
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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 != 2 {
|
|
|
+ br.Msg = "用户没有权限收藏"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := models.GetMyReportByUserIdAndReportId(user.UserId, req.ReportId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "取消收藏失败"
|
|
|
+ br.ErrMsg = "获取收藏信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if count == 0 {
|
|
|
+ br.Msg = "该研报已取消收藏,请重新刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = models.DeleteMyReportByUserIdAndReportId(user.UserId, req.ReportId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "取消收藏失败"
|
|
|
+ br.ErrMsg = "取消收藏失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Msg = "取消收藏成功"
|
|
|
+ br.Success = true
|
|
|
+ br.Ret = 200
|
|
|
+}
|