package controllers import ( "eta/eta_mini_bridge/models" "eta/eta_mini_bridge/models/response" "eta/eta_mini_bridge/services" "eta/eta_mini_bridge/utils" "html" "strconv" "time" "github.com/rdlucklib/rdluck_tools/paging" ) type ReportController struct { BaseAuthController } // @Title List // @Description create users // @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-半年内" // @Success 200 {int} models.User.Id // @Failure 403 body is empty // @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") if chartPermissionId <= 0 { br.Msg = "品种参数错误" return } var condition string switch rangeType { case 1: condition += ` AND DATE(a.modify_time)=DATE(NOW()) ` case 2: condition += ` AND DATE(a.modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() ` case 3: condition += ` AND DATE(a.modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() ` } var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) var total int var reportList []*models.ReportList switch level { case 2: classifyIds, err := models.GetClassifyIdsListById(chartPermissionId) if err != nil { br.Msg = "获取报告列表失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } if len(classifyIds) == 0 { br.Msg = "该品种下没有绑定分类" br.ErrMsg = "获取数据失败,品种id:" + strconv.Itoa(chartPermissionId) return } tmptotal, err := models.GetReportCountByClassifyIds(classifyIds, condition) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } total = tmptotal tmpReportList, err := models.GetReportListByClassifyIds(classifyIds, condition, startSize, pageSize) if err != nil { br.Msg = "获取报告列表失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } reportList = tmpReportList case 1: chartPermissionIds, err := models.GetChildChartPermissionIdsById(chartPermissionId) if err != nil { br.Msg = "获取报告列表失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } if len(chartPermissionIds) == 0 { br.Msg = "该品种下没有绑定分类" br.ErrMsg = "获取数据失败,品种id:" + strconv.Itoa(chartPermissionId) return } classifyIds, err := models.GetClassifyIdsListByIds(chartPermissionIds) if err != nil { br.Msg = "获取报告列表失败" br.ErrMsg = "获取报告列表失败,Err:" + err.Error() return } if len(classifyIds) == 0 { br.Msg = "该品种下没有绑定分类" return } tmptotal, err := models.GetReportCountByClassifyIds(classifyIds, condition) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } total = tmptotal tmpReportList, err := models.GetReportListByClassifyIds(classifyIds, condition, startSize, pageSize) if err != nil { br.Msg = "获取报告列表失败" br.ErrMsg = "获取报告列表失败,Err:" + err.Error() return } reportList = tmpReportList default: br.Msg = "层级参数错误" return } page := paging.GetPaging(currentIndex, pageSize, total) resp := new(response.ReportListResp) resp.Paging = page resp.List = reportList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 研报详情 // @Description 研报详情接口 // @Param ReportId query int true "报告id" // @Param UserId 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, err := this.GetInt("ReportId") userId, err := this.GetInt("UserId") if err != nil { br.Msg = "参数获取失败" br.ErrMsg = "参数获取失败,Err:" + err.Error() return } if reportId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误,报告id小于等于0" return } if userId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误,用户id小于等于0" return } user, err := models.GetUserById(userId) if err != nil { br.Msg = "用户不存在" br.ErrMsg = "用户不存在,系统异常,Err:" + err.Error() return } // 有效期是否到期 IsVail := user.ValidEndTime.After(time.Now()) report, err := models.GetReportById(reportId) if err != nil { br.Msg = "该报告已删除" br.ErrMsg = "获取报告详情失败,Err:" + err.Error() return } report.ContentSub = html.UnescapeString(report.ContentSub) report.Content = html.UnescapeString(report.Content) if report == nil { br.Msg = "报告不存在" return } reportChartPermissionIds, err := models.GetChartPermissionIdsListByClassifyId(report.ClassifyIdSecond) if err != nil { br.Msg = "获取研报权限失败" br.ErrMsg = "获取研报权限失败,Err:" + err.Error() return } chartPermissionList, err := models.GetChartPermissionIdsByIds(reportChartPermissionIds) if err != nil { br.Msg = "获取研报权限失败" br.ErrMsg = "获取研报权限失败,Err:" + err.Error() return } var IsHas bool var IsPublic bool for _, v := range chartPermissionList { if v.IsPublic == 1 { IsPublic = true break } } resp := new(response.ReportDetailResp) if !IsPublic { // 如果被禁用或是潜在用户,直接返回无阅读报告权限 if user.Status == 0 || user.Status == 1 { resp.Report = report resp.Status = utils.ReportPermissionStatusNo report.Content = "" br.Ret = 408 br.Data = resp br.Msg = "用户权限不足" return } // 如果是私有报告,用户权限过期直接返回有效期已过 if !IsVail { resp.Report = report resp.Status = utils.ReportPermissionStatusExpired report.Content = "" br.Ret = 408 br.Data = resp br.Msg = "用户权限不足" return } chartPermissionIds, err := models.GetChartPermissionIdByUserId(userId) if err != nil { br.Msg = "获取用户权限失败" br.ErrMsg = "获取用户权限失败,Err:" + err.Error() return } if len(chartPermissionIds) <= 0 { resp.Report = report resp.Status = utils.ReportPermissionStatusNo report.Content = "" br.Ret = 408 br.Data = resp br.Msg = "用户权限不足" return } classifyIds, err := models.GetClassifyIdsListByIds(chartPermissionIds) if err != nil { br.Msg = "获取用户权限失败" br.ErrMsg = "获取用户分类权限失败,Err:" + err.Error() return } if len(classifyIds) <= 0 { resp.Report = report resp.Status = utils.ReportPermissionStatusNoPermission report.Content = "" br.Ret = 408 br.Data = resp br.Msg = "用户权限不足" return } reportClassifyIdStr := strconv.Itoa(report.ClassifyIdSecond) for _, v := range classifyIds { if v == reportClassifyIdStr { IsHas = true } } if !IsHas { resp.Report = report resp.Status = utils.ReportPermissionStatusNoPermission report.Content = "" br.Ret = 408 br.Data = resp br.Msg = "用户权限不足" return } } else { report.IsPublic = IsPublic } resp.Report = report resp.Status = utils.ReportPermissionStatusHas br.Data = resp br.Ret = 200 br.Success = true br.Msg = "获取成功" } // @Title List // @Description create users // @Param body body models.User true "body for user content" // @Success 200 {int} models.User.Id // @Failure 403 body is empty // @router /daily/list [get] func (this *ReportController) Today() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize30 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) total, err := models.GetReportDailyListCount() if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } list, err := models.GetReportDailyList(startSize, pageSize) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } page := paging.GetPaging(currentIndex, pageSize, total) resp := new(response.ReportListResp) resp.Paging = page resp.List = list 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 KeyWord query string true "关键字" // @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 currentIndex <= 0 { currentIndex = 1 } if keyWord == "" { br.Msg = "请输入关键字" return } reportList, err, errMsg := services.SearchReport(keyWord, currentIndex, pageSize) if err != nil { br.Msg = "研报搜索失败" br.ErrMsg = errMsg + ",Err:" + err.Error() return } br.Data = reportList br.Msg = "查询成功" br.Ret = 200 br.Success = true }