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 = "获取成功" }