|
@@ -1,109 +1,31 @@
|
|
|
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"
|
|
|
- "sort"
|
|
|
+ "fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "html"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
-
|
|
|
- "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
)
|
|
|
|
|
|
type ReportController struct {
|
|
|
BaseAuthController
|
|
|
}
|
|
|
|
|
|
-type ReportNoAuthController struct {
|
|
|
+type ReportOpenController 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
|
|
|
-}
|
|
|
-
|
|
|
+// List
|
|
|
// @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"
|
|
|
+// @Param request body request.ReportListForm true "type json string"
|
|
|
// @Success 200 {object} response.ReportList
|
|
|
// @router /list [get]
|
|
|
func (this *ReportController) List() {
|
|
@@ -112,851 +34,433 @@ func (this *ReportController) List() {
|
|
|
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
|
|
|
+ params := new(request.ReportListForm)
|
|
|
+ if e := this.ParseForm(params); e != nil {
|
|
|
+ br.Msg = "参数解析异常"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ reportCond, outsideCond string
|
|
|
+ reportPars, outsidePars []interface{}
|
|
|
+ )
|
|
|
+ // 仅取常规和智能布局的报告
|
|
|
+ reportCond += ` AND r.report_layout IN (1,2)`
|
|
|
+
|
|
|
+ params.Keywords = strings.TrimSpace(params.Keywords)
|
|
|
+ if params.Keywords != "" {
|
|
|
+ kw := fmt.Sprint("%", params.Keywords, "%")
|
|
|
+ reportCond += ` AND r.title LIKE ?`
|
|
|
+ reportPars = append(reportPars, kw)
|
|
|
+ outsideCond += ` AND o.title LIKE ?`
|
|
|
+ outsidePars = append(outsidePars, kw)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分类名称map
|
|
|
+ classifyOb := new(models.MiniClassify)
|
|
|
+ classifies, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifyMapping := make(map[int]*models.MiniClassify)
|
|
|
+ for _, v := range classifies {
|
|
|
+ classifyMapping[v.Id] = v
|
|
|
+ }
|
|
|
+ if params.ClassifyId > 0 {
|
|
|
+ classify := classifyMapping[params.ClassifyId]
|
|
|
+ if classify == nil || (classify != nil && classify.Enabled != 1) {
|
|
|
+ br.Msg = "分类不存在,请刷新页面"
|
|
|
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 {
|
|
|
+ switch classify.Level {
|
|
|
case 1:
|
|
|
- firstClassifyIds = append(firstClassifyIds, v)
|
|
|
+ reportCond += ` AND r.classify_id_first = ?`
|
|
|
case 2:
|
|
|
- secondClassifyIds = append(secondClassifyIds, v)
|
|
|
+ reportCond += ` AND r.classify_id_second = ?`
|
|
|
case 3:
|
|
|
- thirdClassifyIds = append(thirdClassifyIds, v)
|
|
|
+ reportCond += ` AND r.classify_id_third = ?`
|
|
|
+ default:
|
|
|
+ br.Msg = "分类异常"
|
|
|
+ return
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- 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
|
|
|
+ reportPars = append(reportPars, params.ClassifyId)
|
|
|
|
|
|
- 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)...)
|
|
|
- }
|
|
|
+ // 获取子分类IDs
|
|
|
+ childIds, e := classifyOb.GetChildClassifyIdsByParentId(params.ClassifyId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取子分类失败, %v", e)
|
|
|
+ return
|
|
|
}
|
|
|
- }
|
|
|
- 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
|
|
|
+ if len(childIds) > 0 {
|
|
|
+ outsideCond += fmt.Sprintf(` AND o.classify_id IN (%s)`, utils.GetOrmInReplace(len(childIds)))
|
|
|
+ outsidePars = append(outsidePars, childIds)
|
|
|
} else {
|
|
|
- // 不在有效期时间则设置为过期, 将用户状态禁用
|
|
|
- vailStatus = 1
|
|
|
- user.Status = utils.UserStatusNo
|
|
|
+ outsideCond += ` AND o.classify_id = ?`
|
|
|
+ outsidePars = append(outsidePars, params.ClassifyId)
|
|
|
}
|
|
|
}
|
|
|
- reportPdfId, _ := this.GetInt("ReportPdfId")
|
|
|
+ resp := new(response.ReportList)
|
|
|
|
|
|
- if reportPdfId <= 0 {
|
|
|
- br.Msg = "研报不存在或已删除"
|
|
|
- return
|
|
|
+ // 分页
|
|
|
+ var startSize int
|
|
|
+ if params.PageSize <= 0 {
|
|
|
+ params.PageSize = utils.PageSize20
|
|
|
}
|
|
|
-
|
|
|
- reportPdf, err := models.GetReportPdfById(reportPdfId)
|
|
|
- if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- br.Msg = "研报不存在或已删除"
|
|
|
- br.ErrMsg = "研报不存在或已删除,系统异常,Err:" + err.Error()
|
|
|
- return
|
|
|
+ if params.CurrentIndex <= 0 {
|
|
|
+ params.CurrentIndex = 1
|
|
|
}
|
|
|
- if reportPdf == nil {
|
|
|
- // 尝试删除收藏列表的记录
|
|
|
- models.DeleteMyReportByUserIdAndReportId(user.UserId, reportPdfId, utils.ReportTypePdf)
|
|
|
- br.Msg = "研报不存在或已删除"
|
|
|
- return
|
|
|
- }
|
|
|
- reportClassifyId := services.GetReportPdfClassify(reportPdf)
|
|
|
+ startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
|
|
|
|
|
|
- permissionResp, err := services.GetChartPermissionListByClassifyId(reportClassifyId, 0)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "研报不存在或已删除"
|
|
|
- br.ErrMsg = "获取权限失败,系统异常,Err:" + err.Error()
|
|
|
+ total, e := models.GetReportAndOutsideReportCount(reportCond, outsideCond, reportPars, outsidePars)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取报告总数失败, %v", e)
|
|
|
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
|
|
|
+ page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
|
|
|
+ resp.Paging = page
|
|
|
+
|
|
|
+ list, e := models.GetReportAndOutsideReportByCondition(reportCond, outsideCond, reportPars, outsidePars, startSize, params.PageSize)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取报告列表失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ t := new(models.UnionReportItem)
|
|
|
+ t.Id = v.Id
|
|
|
+ t.Title = v.Title
|
|
|
+ t.Abstract = v.Abstract
|
|
|
+ t.PublishTime = utils.TimeTransferString(utils.FormatDateTime, v.PublishTime)
|
|
|
+ t.ReportSource = v.ReportSource
|
|
|
+ t.ReportFile = v.ReportFile
|
|
|
+ t.Author = v.Author
|
|
|
+ // 报告分类名称
|
|
|
+ if v.ReportSource == utils.ReportSourceDefault {
|
|
|
+ if v.ClassifyIdThird > 0 {
|
|
|
+ t.ClassifyId = v.ClassifyIdThird
|
|
|
+ } else if v.ClassifyIdSecond > 0 {
|
|
|
+ t.ClassifyId = v.ClassifyIdSecond
|
|
|
+ } else {
|
|
|
+ t.ClassifyId = v.ClassifyIdFirst
|
|
|
}
|
|
|
}
|
|
|
- if !IsHas {
|
|
|
- resp.Report = reportPdf
|
|
|
- resp.Status = utils.ReportPermissionStatusNoPermission
|
|
|
- br.Ret = 200
|
|
|
- br.Data = resp
|
|
|
- br.Msg = "用户权限不足"
|
|
|
- return
|
|
|
+ if v.ReportSource == utils.ReportSourceOutside {
|
|
|
+ t.ClassifyId = v.ClassifyIdThird
|
|
|
}
|
|
|
- } 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
|
|
|
+ cs := classifyMapping[t.ClassifyId]
|
|
|
+ if cs != nil {
|
|
|
+ t.ClassifyName = cs.ClassifyName
|
|
|
+ }
|
|
|
+ resp.List = append(resp.List, t)
|
|
|
}
|
|
|
|
|
|
- resp.Report = reportPdf
|
|
|
- resp.Status = utils.ReportPermissionStatusHas
|
|
|
-
|
|
|
- br.Msg = "查询成功"
|
|
|
+ br.Data = resp
|
|
|
br.Ret = 200
|
|
|
+ br.Msg = "获取成功"
|
|
|
br.Success = true
|
|
|
- br.Data = resp
|
|
|
}
|
|
|
|
|
|
-// @Title 今日研报列表
|
|
|
-// @Description 今日研报列表
|
|
|
-// @Param PageSize query int true "每页数据条数"
|
|
|
-// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// Detail
|
|
|
+// @Title 研报详情H5
|
|
|
+// @Description 研报详情H5
|
|
|
+// @Param ReportId query int true "报告ID"
|
|
|
// @Success 200 {object} models.ReportDetailResp
|
|
|
-// @router /daily/list [get]
|
|
|
-func (this *ReportController) DailyList() {
|
|
|
+// @router /detail [get]
|
|
|
+func (this *ReportOpenController) Detail() {
|
|
|
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
|
|
|
+ reportId, _ := this.GetInt("ReportId")
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
return
|
|
|
}
|
|
|
- reportList := resp.Data
|
|
|
- for _, v := range reportList.List {
|
|
|
- v.ReportType = utils.ReportTypeEta
|
|
|
- }
|
|
|
|
|
|
- reportPdfList, err := models.GetReportPdfDailyList()
|
|
|
+ report, err := models.GetReportById(reportId)
|
|
|
if err != nil {
|
|
|
- br.Msg = "研报列表查询失败"
|
|
|
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Ret = 200
|
|
|
+ br.Data = new(response.ReportDetailResp)
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "该报告已删除或不存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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 report.HeadResourceId > 0 || report.EndResourceId > 0 {
|
|
|
+ headImg, err := models.GetSmartReportResourceById(report.HeadResourceId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ utils.FileLog.Warn("版头数据获取失败,Err:" + err.Error())
|
|
|
+ }
|
|
|
+ endImg, err := models.GetSmartReportResourceById(report.EndResourceId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ utils.FileLog.Warn("版尾数据获取失败,Err:" + err.Error())
|
|
|
}
|
|
|
- if v.ClassifyIdSecond != 0 {
|
|
|
- reportClassifyId = v.ClassifyIdSecond
|
|
|
+ if headImg != nil {
|
|
|
+ report.HeadResource = headImg
|
|
|
}
|
|
|
- if v.ClassifyIdThird != 0 {
|
|
|
- reportClassifyId = v.ClassifyIdThird
|
|
|
+ if endImg != nil {
|
|
|
+ report.EndResource = endImg
|
|
|
}
|
|
|
- classifyIds = append(classifyIds, reportClassifyId)
|
|
|
}
|
|
|
|
|
|
- if len(classifyIds) > 0 {
|
|
|
- classifyResp, err := services.GetFirstChartPermission(classifyIds)
|
|
|
+ if report.HasChapter == 1 {
|
|
|
+ chapterList, err := models.GetReportChapterList(report.Id)
|
|
|
if err != nil {
|
|
|
- br.Msg = "研报列表查询失败"
|
|
|
- br.ErrMsg = "研报列表查询失败,系统异常,Err:" + err.Error()
|
|
|
+ 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,
|
|
|
- })
|
|
|
+ for _, v := range chapterList {
|
|
|
+ v.Content = html.UnescapeString(v.Content)
|
|
|
}
|
|
|
+ report.ChapterContent = chapterList
|
|
|
}
|
|
|
-
|
|
|
- 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()
|
|
|
+ report.ContentSub = html.UnescapeString(report.ContentSub)
|
|
|
+ report.Content = html.UnescapeString(report.Content)
|
|
|
+ if report == nil {
|
|
|
+ br.Msg = "报告不存在"
|
|
|
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
|
|
|
- }
|
|
|
+ resp := new(response.ReportDetailResp)
|
|
|
+ resp.Report = report
|
|
|
|
|
|
- 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.Msg = "获取成功"
|
|
|
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() {
|
|
|
+// OutsideDetail
|
|
|
+// @Title 研报详情H5-文档管理库
|
|
|
+// @Description 研报详情H5-文档管理库
|
|
|
+// @Param ReportId query int true "报告ID"
|
|
|
+// @Success 200 {object} models.OutsideReportItem
|
|
|
+// @router /outside_detail [get]
|
|
|
+func (this *ReportOpenController) OutsideDetail() {
|
|
|
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()
|
|
|
+ reportId, _ := this.GetInt("ReportId")
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
return
|
|
|
}
|
|
|
- if reports.Ret != 200 {
|
|
|
- br.Msg = reports.Msg
|
|
|
- br.ErrMsg = reports.ErrMsg
|
|
|
+ outsideReport, e := models.GetOutsideReportById(reportId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "报告不存在,请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取外部报告失败, %v", e)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- br.Data = reports.Data
|
|
|
- br.Msg = "查询成功"
|
|
|
+ br.Data = outsideReport.Format2Item()
|
|
|
br.Ret = 200
|
|
|
+ br.Msg = "获取成功"
|
|
|
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() {
|
|
|
+// ReadRecord
|
|
|
+// @Title 新增报告阅读记录
|
|
|
+// @Description 新增报告阅读记录
|
|
|
+// @Param request body request.ReportReadRecordReq true "type json string"
|
|
|
+// @Success 200 操作成功
|
|
|
+// @router /read_record [post]
|
|
|
+func (this *ReportController) ReadRecord() {
|
|
|
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()
|
|
|
+ users := this.User
|
|
|
+ if users == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 403
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req request.ReportReadRecordReq
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数解析异常"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ReportId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ReportSource != utils.ReportSourceDefault && req.ReportSource != utils.ReportSourceOutside {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, ReportSource: %d", req.ReportSource)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取报告分类信息
|
|
|
+ var (
|
|
|
+ title string
|
|
|
+ classifyIdFirst int
|
|
|
+ classifyIdSecond int
|
|
|
+ classifyIdThird int
|
|
|
+ classifyNameFirst string
|
|
|
+ classifyNameSecond string
|
|
|
+ classifyNameThird string
|
|
|
+ )
|
|
|
+ if req.ReportSource == utils.ReportSourceDefault {
|
|
|
+ reportOb := new(models.Report)
|
|
|
+ report, e := reportOb.GetItemById(req.ReportId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "报告不存在,请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取报告失败, %v", e)
|
|
|
return
|
|
|
}
|
|
|
- if result.Ret != 200 {
|
|
|
- br.Msg = result.Msg
|
|
|
- br.ErrMsg = result.ErrMsg
|
|
|
+ title = report.Title
|
|
|
+ classifyIdFirst = report.ClassifyIdFirst
|
|
|
+ classifyIdSecond = report.ClassifyIdSecond
|
|
|
+ classifyIdThird = report.ClassifyIdThird
|
|
|
+ classifyNameFirst = report.ClassifyNameFirst
|
|
|
+ classifyNameSecond = report.ClassifyNameSecond
|
|
|
+ classifyNameThird = report.ClassifyNameThird
|
|
|
+ }
|
|
|
+ if req.ReportSource == utils.ReportSourceOutside {
|
|
|
+ outsideReport, e := models.GetOutsideReportById(req.ReportId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "报告不存在,请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取外部报告失败, %v", e)
|
|
|
return
|
|
|
}
|
|
|
+ title = outsideReport.Title
|
|
|
|
|
|
- if result.Ret == 200 && result.Data.Report == nil {
|
|
|
- // 报告不存在, 就尝试删除推送的记录
|
|
|
- models.DeleteReportPushStatusByReportId(reportId, utils.ReportTypeEta)
|
|
|
- br.Msg = "报告已删除或未发布,请刷新重试"
|
|
|
+ // 根据分类层级取出所有分类ID和名称
|
|
|
+ classifyOb := new(models.MiniClassify)
|
|
|
+ classifies, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取报告分类失败, %v", e)
|
|
|
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()
|
|
|
+ classifyMapping := make(map[int]*models.MiniClassify)
|
|
|
+ for _, v := range classifies {
|
|
|
+ classifyMapping[v.Id] = v
|
|
|
+ }
|
|
|
+ thisClassify := classifyMapping[outsideReport.ClassifyId]
|
|
|
+ if thisClassify == nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("报告分类不存在, ClassifyId: %d", outsideReport.ClassifyId)
|
|
|
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
|
|
|
+ levelArr := strings.Split(thisClassify.LevelPath, ",")
|
|
|
+ if len(levelArr) <= 0 {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("报告分类层级异常, ClassifyId: %d, LevelPath: %s", thisClassify.Id, thisClassify.LevelPath)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(levelArr) > 0 {
|
|
|
+ classifyIdFirst, _ = strconv.Atoi(levelArr[0])
|
|
|
+ firstClassify := classifyMapping[classifyIdFirst]
|
|
|
+ if firstClassify != nil {
|
|
|
+ classifyNameFirst = firstClassify.ClassifyName
|
|
|
+ }
|
|
|
+ // 测试环境统一放在了一个一级分类下
|
|
|
+ if classifyNameFirst == "" && utils.RunMode == "debug" {
|
|
|
+ classifyNameFirst = "金瑞小程序分类(勿删)"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(levelArr) > 1 {
|
|
|
+ classifyIdSecond, _ = strconv.Atoi(levelArr[1])
|
|
|
+ secondClassify := classifyMapping[classifyIdSecond]
|
|
|
+ if secondClassify != nil {
|
|
|
+ classifyNameSecond = secondClassify.ClassifyName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(levelArr) > 2 {
|
|
|
+ classifyIdThird, _ = strconv.Atoi(levelArr[2])
|
|
|
+ thirdClassify := classifyMapping[classifyIdThird]
|
|
|
+ if thirdClassify != nil {
|
|
|
+ classifyNameThird = thirdClassify.ClassifyName
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- 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,
|
|
|
+ // 记录不存在则新增,存在则更新结束阅读时间
|
|
|
+ var recordId int
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ if req.RecordId <= 0 {
|
|
|
+ newRecord := &models.UserReadRecord{
|
|
|
+ UserId: users.UserId,
|
|
|
+ ReportId: req.ReportId,
|
|
|
+ ReportTitle: title,
|
|
|
+ ClassifyIdFirst: classifyIdFirst,
|
|
|
+ ClassifyNameFirst: classifyNameFirst,
|
|
|
+ ClassifyIdSecond: classifyIdSecond,
|
|
|
+ ClassifyNameSecond: classifyNameSecond,
|
|
|
+ ClassifyIdThird: classifyIdThird,
|
|
|
+ ClassifyNameThird: classifyNameThird,
|
|
|
+ StartTimestamp: int(nowTime.Unix()),
|
|
|
+ CreateTime: nowTime,
|
|
|
+ ReportSource: req.ReportSource,
|
|
|
+ }
|
|
|
+ if e := newRecord.Create(); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("新增阅读记录失败, %v", e)
|
|
|
+ return
|
|
|
}
|
|
|
- if v.PublishTime.IsZero() {
|
|
|
- tmpReport.PublishTime = ""
|
|
|
+ recordId = newRecord.Id
|
|
|
+ } else {
|
|
|
+ recordOb := new(models.UserReadRecord)
|
|
|
+ readRecord, e := recordOb.GetItemById(req.RecordId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "阅读记录不存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取阅读记录失败, %v", e)
|
|
|
+ return
|
|
|
}
|
|
|
- list = append(list, tmpReport)
|
|
|
- }
|
|
|
+ readRecord.EndTimestamp = int(nowTime.Unix())
|
|
|
+ if e = readRecord.Update([]string{recordOb.Cols().EndTimestamp}); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("更新阅读记录失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ recordId = readRecord.Id
|
|
|
|
|
|
- page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
- resp.List = list
|
|
|
- resp.Paging = page
|
|
|
+ // 更新用户阅读次数
|
|
|
+ usersOb := new(models.Users)
|
|
|
+ if e = usersOb.UpdateUserReadTimes(users.UserId); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("更新用户阅读次数失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ resp := new(response.UserReadRecordResp)
|
|
|
+ resp.RecordId = recordId
|
|
|
br.Data = resp
|
|
|
- br.Msg = "查询成功"
|
|
|
br.Ret = 200
|
|
|
+ br.Msg = "操作成功"
|
|
|
br.Success = true
|
|
|
}
|