|
@@ -0,0 +1,355 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "hongze/hongze_api/models"
|
|
|
+ "hongze/hongze_api/utils"
|
|
|
+ "html"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+//报告
|
|
|
+type ReportController struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// @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()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var status int
|
|
|
+ var msg string
|
|
|
+ reportId, err := this.GetInt("ReportId")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数获取失败"
|
|
|
+ br.ErrMsg = "参数获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id小于等于0"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ report, err := models.GetReportById(reportId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告详情失败"
|
|
|
+ br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if report == nil {
|
|
|
+ status = 1
|
|
|
+ msg = "报告不存在"
|
|
|
+ }
|
|
|
+ report.ContentSub = html.UnescapeString(report.ContentSub)
|
|
|
+ report.Content = html.UnescapeString(report.Content)
|
|
|
+ company, err := models.GetCompanyById(user.CompanyId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ if err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取报告详情失败"
|
|
|
+ br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售"
|
|
|
+ report.Content = report.ContentSub
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if company == nil {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售"
|
|
|
+ report.Content = report.ContentSub
|
|
|
+ } else {
|
|
|
+ if company.CompanyType == 3 || company.CompanyType == 4 {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售"
|
|
|
+ report.Content = report.ContentSub
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reportType := "rddp"
|
|
|
+ reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取报告详情失败"
|
|
|
+ br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售"
|
|
|
+ report.Content = report.ContentSub
|
|
|
+ }
|
|
|
+ }
|
|
|
+ permissionMap := make(map[int]int)
|
|
|
+ for _, v := range reportPermissionList {
|
|
|
+ if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
|
|
|
+ permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if _, ok := permissionMap[reportId]; !ok {
|
|
|
+ tips := ""
|
|
|
+ status = 2
|
|
|
+ report.Content = report.ContentSub
|
|
|
+ classifyNameSecond := report.ClassifyNameSecond
|
|
|
+ if strings.Contains(classifyNameSecond, "宏观商品复盘") ||
|
|
|
+ strings.Contains(classifyNameSecond, "股债日评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "每日经济数据备忘录") {
|
|
|
+ tips = "宏观"
|
|
|
+ } else if strings.Contains(classifyNameSecond, "知白守黑日评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "动力煤数据点评") {
|
|
|
+ tips = "黑色"
|
|
|
+ } else if strings.Contains(classifyNameSecond, "化里化外日评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "EIA原油库存点评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "苯乙烯数据点评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "聚酯数据点评") {
|
|
|
+ tips = "化工"
|
|
|
+ } else if strings.Contains(classifyNameSecond, "有声有色日度闲篇") {
|
|
|
+ tips = "有色"
|
|
|
+ }
|
|
|
+ msg = "您还未开通" + tips + "权限,如有需要请联系对口销售"
|
|
|
+ }
|
|
|
+ resp := new(models.ReportDetailResp)
|
|
|
+ resp.Status = status
|
|
|
+ resp.Msg = msg
|
|
|
+ resp.Report = report
|
|
|
+ //新增阅读记录
|
|
|
+ if status == 0 {
|
|
|
+ record := new(models.ReportViewRecord)
|
|
|
+ record.UserId = user.UserId
|
|
|
+ record.ReportId = reportId
|
|
|
+ record.CreateTime = time.Now()
|
|
|
+ err = models.AddReportViewRecord(record)
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 ClassifyId query int true "分类id"
|
|
|
+// @Success 200 {object} models.ReportListResp
|
|
|
+// @router /list [get]
|
|
|
+func (this *ReportController) ListReport() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ classifyId, _ := this.GetInt("ClassifyId")
|
|
|
+ if classifyId <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,分类id小于等于0"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var startSize int
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = utils.StartIndex(currentIndex, pageSize)
|
|
|
+
|
|
|
+ total, err := models.GetReportListCount(classifyId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ list, err := models.GetReportList(classifyId, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ listLen := len(list)
|
|
|
+ for i := 0; i < listLen; i++ {
|
|
|
+ item := list[i]
|
|
|
+ list[i].Content = html.UnescapeString(item.Content)
|
|
|
+ list[i].ContentSub = html.UnescapeString(item.ContentSub)
|
|
|
+ count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if count > 0 {
|
|
|
+ list[i].HasPermission = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ page := models.GetPaging(currentIndex, pageSize, total)
|
|
|
+
|
|
|
+ resp := new(models.ReportListResp)
|
|
|
+ resp.Paging = page
|
|
|
+ resp.List = list
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 新增报告浏览记录
|
|
|
+// @Description 新增报告浏览记录接口
|
|
|
+// @Param ReportId query int true "报告id"
|
|
|
+// @Success 200 新增成功
|
|
|
+// @router /addUpdateLabel [post]
|
|
|
+func (this *HomeController) AddUpdateLabelReport() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportId, err := this.GetInt("ReportId")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数获取失败"
|
|
|
+ br.ErrMsg = "参数获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id小于等于0"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ record := new(models.ReportViewLog)
|
|
|
+ record.UserId = user.UserId
|
|
|
+ record.ReportId = reportId
|
|
|
+ record.CreateTime = time.Now()
|
|
|
+ err = models.AddReportViewLog(record)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "新增成功"
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 新增报告浏览记录
|
|
|
+// @Description 新增报告浏览记录接口
|
|
|
+// @Param ReportId query int true "报告id"
|
|
|
+// @Success 200 新增成功
|
|
|
+// @router /addViewRecord [post]
|
|
|
+func (this *HomeController) AddViewRecordReport() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportId, err := this.GetInt("ReportId")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数获取失败"
|
|
|
+ br.ErrMsg = "参数获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id小于等于0"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ record := new(models.ReportViewRecord)
|
|
|
+ record.UserId = user.UserId
|
|
|
+ record.ReportId = reportId
|
|
|
+ record.CreateTime = time.Now()
|
|
|
+ err = models.AddReportViewRecord(record)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "新增成功"
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 新增音频阅读记录
|
|
|
+// @Description 新增音频阅读记录接口
|
|
|
+// @Param ReportId query int true "报告id"
|
|
|
+// @Success 200 新增成功
|
|
|
+// @router /addAudioRecord [post]
|
|
|
+func (this *HomeController) AddAudioRecord() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportId, err := this.GetInt("ReportId")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数获取失败"
|
|
|
+ br.ErrMsg = "参数获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id小于等于0"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ record := new(models.ReportAudioRecord)
|
|
|
+ record.UserId = user.UserId
|
|
|
+ record.ReportId = reportId
|
|
|
+ record.CreateTime = time.Now()
|
|
|
+ err = models.AddReportAudioRecord(record)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "新增成功"
|
|
|
+}
|