123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092 |
- package controllers
- import (
- "eta/eta_mini_bridge/models"
- "eta/eta_mini_bridge/models/response"
- "eta/eta_mini_bridge/services"
- "eta/eta_mini_bridge/utils"
- "fmt"
- "html"
- "strconv"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type ReportController struct {
- BaseAuthController
- }
- type ReportNoAuthController struct {
- BaseCommonController
- }
- // @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-半年内"
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} response.ReportListResp
- // @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")
- classifyId, _ := this.GetInt("ClassifyId")
- 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)
- classifyList, err := models.GetClassifyList()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- 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
- }
- classifyIdMap := make(map[int]struct{})
- if classifyId > 0 {
- leafClassifyIds := getLeafClassifyIds(classifyMap, classifyId)
- for _, v := range leafClassifyIds {
- classifyIdMap[v] = struct{}{}
- }
- }
- var total int
- var reportList []*models.ReportList
- classifyFirstIds := make([]int, 0)
- classifySecondIds := make([]int, 0)
- classifyThirdIds := make([]int, 0)
- 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
- }
- classifyIds = utils.Unique(classifyIds)
- // 根据分类筛选报告
- var selectedClassifyId []int
- if classifyId > 0 {
- for _, v := range classifyIds {
- if _, ok := classifyIdMap[v]; ok {
- selectedClassifyId = append(selectedClassifyId, v)
- }
- }
- } else {
- selectedClassifyId = classifyIds
- }
- classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- if v.HasChild == 1 {
- continue
- }
- switch v.Level {
- case 1:
- classifyFirstIds = append(classifyFirstIds, v.Id)
- case 2:
- classifySecondIds = append(classifySecondIds, v.Id)
- case 3:
- classifyThirdIds = append(classifyThirdIds, v.Id)
- }
- }
- tmptotal, err := models.GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- total = tmptotal
- tmpReportList, err := models.GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, 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
- }
- classifyIds = utils.Unique(classifyIds)
- // 根据分类筛选报告
- var selectedClassifyId []int
- if classifyId > 0 {
- for _, v := range classifyIds {
- if _, ok := classifyIdMap[v]; ok {
- selectedClassifyId = append(selectedClassifyId, v)
- }
- }
- } else {
- selectedClassifyId = classifyIds
- }
- classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- if v.HasChild == 1 {
- continue
- }
- switch v.Level {
- case 1:
- classifyFirstIds = append(classifyFirstIds, v.Id)
- case 2:
- classifySecondIds = append(classifySecondIds, v.Id)
- case 3:
- classifyThirdIds = append(classifyThirdIds, v.Id)
- }
- }
- tmptotal, err := models.GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- total = tmptotal
- tmpReportList, err := models.GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, 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
- }
- 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)...)
- }
- }
- }
- return leafClassifyIds
- }
- // @Title 研报详情
- // @Description 研报详情接口
- // @Param ReportId query int true "报告id"
- // @Param UserId query int true "用户id"
- // @Success 200 {object} response.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
- }
- // 有效期是否到期
- var vailStatus int
- if user.Status == utils.UserStatusFormal {
- if user.ValidEndTime.After(time.Now()) && user.ValidStartTime.Before(time.Now()) {
- vailStatus = 2
- } else {
- // 不在有效期时间则设置为过期, 将用户状态禁用
- vailStatus = 1
- user.Status = utils.UserStatusNo
- }
- }
- report, err := models.GetReportById(reportId)
- if err != nil {
- 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
- }
- 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 headImg != nil {
- report.HeadResource = headImg
- }
- if endImg != nil {
- report.EndResource = endImg
- }
- }
- if report.HasChapter == 1 {
- chapterList, err := models.GetReportChapterList(report.Id)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取章节列表失败,Err:" + err.Error()
- return
- }
- for _, v := range chapterList {
- v.Content = html.UnescapeString(v.Content)
- }
- report.ChapterContent = chapterList
- }
- 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.GetChartPermissionListByStrIds(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 vailStatus == 1 || user.Status == utils.UserStatusNo {
- resp.Report = report
- resp.Status = utils.ReportPermissionStatusExpired
- report.Content = ""
- br.Ret = 200
- br.Data = resp
- br.Msg = "用户权限不足"
- return
- }
- // 潜在用户,直接返回无阅读报告权限
- if user.Status == utils.UserStatusPotential {
- resp.Report = report
- resp.Status = utils.ReportPermissionStatusNo
- report.Content = ""
- br.Ret = 200
- 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.ReportPermissionStatusNoPermission
- report.Content = ""
- br.Ret = 200
- 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 = 200
- br.Data = resp
- br.Msg = "用户权限不足"
- return
- }
- var reportClassifyId int
- if report.ClassifyIdFirst > 0 {
- reportClassifyId = report.ClassifyIdFirst
- }
- if report.ClassifyIdSecond > 0 {
- reportClassifyId = report.ClassifyIdSecond
- }
- if report.ClassifyIdThird > 0 {
- reportClassifyId = report.ClassifyIdThird
- }
- for _, v := range classifyIds {
- if v == reportClassifyId {
- IsHas = true
- break
- }
- }
- if !IsHas {
- resp.Report = report
- resp.Status = utils.ReportPermissionStatusNoPermission
- report.Content = ""
- br.Ret = 200
- 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 研报详情
- // @Description 研报详情接口
- // @Param ReportId query int true "报告id"
- // @Success 200 {object} response.ReportDetailResp
- // @router /detail/noUser [get]
- func (this *ReportController) DetailNoUser() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- 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 {
- 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
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = ""
- if report == nil {
- br.Msg = "报告不存在"
- return
- }
- resp := new(response.ReportDetailResp)
- resp.Report = report
- resp.Status = utils.ReportPermissionStatusNoUser
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 今日研报列表
- // @Description 今日研报列表
- // @Success 200 {object} response.ReportListResp
- // @router /daily/list [get]
- func (this *ReportController) Today() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- total, err := models.GetReportDailyListCount()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list, err := models.GetReportDailyList(0, total)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- classifyIds := make([]string, 0)
- for _, v := range list {
- classifyIds = append(classifyIds, strconv.Itoa(v.ClassifyIdSecond))
- }
- classifyIds = utils.Unique(classifyIds)
- // 获取二级分类和二级品种权限的映射
- chartPermissionMapping, err := models.GetChartPermissionListByClassifyStrIds(classifyIds)
- if err != nil {
- br.Msg = "获取研报权限失败"
- br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
- return
- }
- classifyToPermissionMap2 := make(map[int][]int)
- chartPermissionIds := make([]string, 0)
- for _, v := range chartPermissionMapping {
- classifyToPermissionMap2[v.ClassifyId] = append(classifyToPermissionMap2[v.ClassifyId], v.ChartPermissionId)
- chartPermissionIds = append(chartPermissionIds, strconv.Itoa(v.ChartPermissionId))
- }
- // 获取二级品种的权限,并建立映射
- chartPermissionList2, err := models.GetChartPermissionListByStrIds(chartPermissionIds)
- if err != nil {
- br.Msg = "获取研报二级品种权限失败"
- br.ErrMsg = "获取研报二级品种权限失败,Err:" + err.Error()
- return
- }
- chartPermissionViewMap2 := make(map[int]*models.ChartPermission)
- for _, v := range chartPermissionList2 {
- chartPermissionViewMap2[v.ChartPermissionId] = v
- }
- // 获取一级品种的权限,并建立映射
- chartPermissionList1, err := models.GetChildChartPermissionListById(0)
- if err != nil {
- br.Msg = "获取研报一级品种权限失败"
- br.ErrMsg = "获取研报一级品种权限失败,Err:" + err.Error()
- return
- }
- chartPermissionMap1 := make(map[int]*models.ChartPermission)
- for _, v := range chartPermissionList1 {
- chartPermissionMap1[v.ChartPermissionId] = v
- }
- // 组合数据
- finalList := make([]*models.ReportList, 0)
- for _, v := range list {
- var permissionNames []string
- for _, vv := range classifyToPermissionMap2[v.ClassifyIdSecond] {
- if item, ok := chartPermissionViewMap2[vv]; ok {
- parent2 := item.ParentId
- permissionNames = append(permissionNames, chartPermissionMap1[parent2].PermissionName)
- }
- }
- v.PermissionNames = utils.Unique(permissionNames)
- if len(v.PermissionNames) != 0 {
- finalList = append(finalList, v)
- }
- }
- resp := new(response.ReportListResp)
- resp.List = finalList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 最新研报列表
- // @Description 最新研报列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} response.ReportListResp
- // @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")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize30
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- total, err := models.GetReportRecentListCount()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list, err := models.GetReportRecentList(startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- classifyIds := make([]string, 0)
- for _, v := range list {
- classifyIds = append(classifyIds, strconv.Itoa(v.ClassifyIdSecond))
- }
- classifyIds = utils.Unique(classifyIds)
- // 获取二级分类和二级品种权限的映射
- chartPermissionMapping, err := models.GetChartPermissionListByClassifyStrIds(classifyIds)
- if err != nil {
- br.Msg = "获取研报权限失败"
- br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
- return
- }
- classifyToPermissionMap2 := make(map[int][]int)
- chartPermissionIds := make([]string, 0)
- for _, v := range chartPermissionMapping {
- classifyToPermissionMap2[v.ClassifyId] = append(classifyToPermissionMap2[v.ClassifyId], v.ChartPermissionId)
- chartPermissionIds = append(chartPermissionIds, strconv.Itoa(v.ChartPermissionId))
- }
- // 获取二级品种的权限,并建立映射
- chartPermissionList2, err := models.GetChartPermissionListByStrIds(chartPermissionIds)
- if err != nil {
- br.Msg = "获取研报二级品种权限失败"
- br.ErrMsg = "获取研报二级品种权限失败,Err:" + err.Error()
- return
- }
- chartPermissionViewMap2 := make(map[int]*models.ChartPermission)
- for _, v := range chartPermissionList2 {
- chartPermissionViewMap2[v.ChartPermissionId] = v
- }
- // 获取一级品种的权限,并建立映射
- chartPermissionList1, err := models.GetChildChartPermissionListById(0)
- if err != nil {
- br.Msg = "获取研报一级品种权限失败"
- br.ErrMsg = "获取研报一级品种权限失败,Err:" + err.Error()
- return
- }
- chartPermissionMap1 := make(map[int]*models.ChartPermission)
- for _, v := range chartPermissionList1 {
- chartPermissionMap1[v.ChartPermissionId] = v
- }
- // 组合数据
- finalList := make([]*models.ReportList, 0)
- for _, v := range list {
- var permissionNames []string
- for _, vv := range classifyToPermissionMap2[v.ClassifyIdSecond] {
- if item, ok := chartPermissionViewMap2[vv]; ok {
- parent2 := item.ParentId
- permissionNames = append(permissionNames, chartPermissionMap1[parent2].PermissionName)
- }
- }
- v.PermissionNames = utils.Unique(permissionNames)
- if len(v.PermissionNames) != 0 {
- finalList = append(finalList, v)
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.ReportListResp)
- resp.Paging = page
- resp.List = finalList
- 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} response.ReportSearchResp
- // @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
- }
- // @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-半年内"
- // @Param ClassifyId query int true "分类id"
- // @Param ReportType query int true "报告类型:1-eta报告,2-pdf报告"
- // @Success 200 {object} response.ReportListResp
- // @router /list [get]
- func (this *ReportNoAuthController) 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")
- classifyId, _ := this.GetInt("ClassifyId")
- reportType, _ := this.GetInt("ReportType")
- now := time.Now()
- todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
- var condition string
- switch rangeType {
- case 1:
- condition += fmt.Sprintf(` AND modify_time >= '%s' `, todayStart.Format(utils.FormatDateTime))
- case 2:
- oneWeekAgo := now.AddDate(0, 0, -7)
- condition += fmt.Sprintf(` AND modify_time >= '%s' `, oneWeekAgo.Format(utils.FormatDateTime))
- case 3:
- sixMonthAgo := now.AddDate(0, -6, 0)
- condition += fmt.Sprintf(` AND modify_time >= '%s' `, sixMonthAgo.Format(utils.FormatDateTime))
- }
- switch reportType {
- case utils.ReportTypeEta:
- if chartPermissionId < 0 {
- br.Msg = "品种参数错误"
- return
- }
- case utils.ReportTypePdf:
- default:
- br.Msg = "报告类型参数错误"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- classifyList, err := models.GetClassifyList()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- 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
- }
- classifyIdMap := make(map[int]struct{})
- if classifyId > 0 {
- leafClassifyIds := getLeafClassifyIds(classifyMap, classifyId)
- for _, v := range leafClassifyIds {
- classifyIdMap[v] = struct{}{}
- }
- }
- var total int
- var reportList []*models.ReportPushView
- classifyFirstIds := make([]int, 0)
- classifySecondIds := make([]int, 0)
- classifyThirdIds := make([]int, 0)
- 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
- }
- classifyIds = utils.Unique(classifyIds)
- // 根据分类筛选报告
- var selectedClassifyId []int
- if classifyId > 0 {
- for _, v := range classifyIds {
- if _, ok := classifyIdMap[v]; ok {
- selectedClassifyId = append(selectedClassifyId, v)
- }
- }
- } else {
- selectedClassifyId = classifyIds
- }
- classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- if v.HasChild == 1 {
- continue
- }
- switch v.Level {
- case 1:
- classifyFirstIds = append(classifyFirstIds, v.Id)
- case 2:
- classifySecondIds = append(classifySecondIds, v.Id)
- case 3:
- classifyThirdIds = append(classifyThirdIds, v.Id)
- }
- }
- tmptotal, err := models.GetPushReportCountByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- total = tmptotal
- tmpReportList, err := models.GetPushReportListByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, 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
- }
- classifyIds = utils.Unique(classifyIds)
- // 根据分类筛选报告
- var selectedClassifyId []int
- if classifyId > 0 {
- for _, v := range classifyIds {
- if _, ok := classifyIdMap[v]; ok {
- selectedClassifyId = append(selectedClassifyId, v)
- }
- }
- } else {
- selectedClassifyId = classifyIds
- }
- classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- if v.HasChild == 1 {
- continue
- }
- switch v.Level {
- case 1:
- classifyFirstIds = append(classifyFirstIds, v.Id)
- case 2:
- classifySecondIds = append(classifySecondIds, v.Id)
- case 3:
- classifyThirdIds = append(classifyThirdIds, v.Id)
- }
- }
- tmptotal, err := models.GetPushReportCountByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- total = tmptotal
- tmpReportList, err := models.GetPushReportListByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
- if err != nil {
- br.Msg = "获取报告列表失败"
- br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- return
- }
- reportList = tmpReportList
- case 0:
- var selectedClassifyIds []int
- for k := range classifyIdMap {
- selectedClassifyIds = append(selectedClassifyIds, k)
- }
- tmptotal, err := models.GetPushReportCount(reportType, selectedClassifyIds, condition)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- total = tmptotal
- tmpReportList, err := models.GetPushReportListByPage(reportType, selectedClassifyIds, 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.ReportPushListResp)
- 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} response.ReportDetailResp
- // @router /detail [get]
- func (this *ReportNoAuthController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- 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 {
- 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
- }
- 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 headImg != nil {
- report.HeadResource = headImg
- }
- if endImg != nil {
- report.EndResource = endImg
- }
- }
- if report.HasChapter == 1 {
- chapterList, err := models.GetReportChapterList(report.Id)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取章节列表失败,Err:" + err.Error()
- return
- }
- for _, v := range chapterList {
- v.Content = html.UnescapeString(v.Content)
- }
- report.ChapterContent = chapterList
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = html.UnescapeString(report.Content)
- if report == nil {
- br.Msg = "报告不存在"
- return
- }
- resp := new(response.ReportDetailResp)
- resp.Report = report
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
|