123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- package report
- import (
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- "hongze/hongze_yb/models/request"
- "hongze/hongze_yb/models/tables/user_report_chapter_set"
- "hongze/hongze_yb/services"
- "hongze/hongze_yb/services/report"
- userService "hongze/hongze_yb/services/user"
- "hongze/hongze_yb/utils"
- "strconv"
- )
- // Detail 报告详情
- func Detail(c *gin.Context) {
- reqReportId := c.DefaultQuery("report_id", "")
- if reqReportId == "" {
- response.Fail("请输入报告ID", c)
- return
- }
- reportId, err := strconv.Atoi(reqReportId)
- if err != nil {
- response.Fail("报告ID格式有误", c)
- return
- }
- userinfo := userService.GetInfoByClaims(c)
- reportDetail, err := report.GetReportDetail(userinfo, reportId)
- if err != nil {
- if err.Error() == "报告未发布" {
- response.NotReleaseMsg("您查看的报告不存在,请试试其他报告吧", err.Error(), c)
- return
- } else {
- response.FailMsg(err.Error(), err.Error(), c)
- return
- }
- }
- response.OkData("查询成功", reportDetail, c)
- return
- }
- // ChapterDetail 章节详情
- func ChapterDetail(c *gin.Context) {
- reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
- if reqReportChapterId == "" {
- response.Fail("请输入章节ID", c)
- return
- }
- reportChapterId, err := strconv.Atoi(reqReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- userinfo := userService.GetInfoByClaims(c)
- chapterDetail, err := report.GetChapterDetail(userinfo, reportChapterId)
- if err != nil {
- response.FailMsg("查看章节详情出错", err.Error(), c)
- return
- }
- response.OkData("查询成功", chapterDetail, c)
- return
- }
- // List 研报列表
- func List(c *gin.Context) {
- var req request.ReportListReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.ClassifyIdFirst <= 0 {
- response.Fail("分类ID有误", c)
- return
- }
- if req.CurrentIndex == 0 {
- req.CurrentIndex = 1
- }
- if req.PageSize == 0 {
- req.PageSize = utils.PageSize20
- }
- userInfo := userService.GetInfoByClaims(c)
- list, err := report.GetReportList(userInfo, req.KeyWord, req.ClassifyIdFirst, req.ClassifyIdSecond, req.CurrentIndex, req.PageSize, req.ClassifyMenuId)
- if err != nil {
- response.FailMsg("查看研报列表出错", err.Error(), c)
- return
- }
- response.OkData("查询成功", list, c)
- return
- }
- // CollectReportList 首页研报汇总
- func CollectReportList(c *gin.Context) {
- reqChartPermissionId := c.DefaultQuery("chart_permission_id", "")
- reqPageIndex := c.DefaultQuery("current_index", "1")
- reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
- pageIndex, err := strconv.Atoi(reqPageIndex)
- if err != nil {
- response.Fail("请输入正确的条数限制", c)
- return
- }
- pageSize, err := strconv.Atoi(reqPageSize)
- if err != nil {
- response.Fail("请输入正确的页码", c)
- return
- }
- if reqChartPermissionId == "" {
- response.Fail("请输入权限ID", c)
- return
- }
- chartPermissionId, err := strconv.Atoi(reqChartPermissionId)
- if err != nil {
- response.Fail("权限ID格式错误", c)
- return
- }
- userinfo := userService.GetInfoByClaims(c)
- list, err := report.GetCollectReportList(userinfo, chartPermissionId, pageIndex, pageSize)
- if err != nil {
- response.FailMsg("汇总报告查询出错", err.Error(), c)
- return
- }
- response.OkData("查询成功", list, c)
- return
- }
- // Search 首页研报搜索
- func Search(c *gin.Context) {
- keyWord := c.DefaultQuery("key_word", "")
- reqPageIndex := c.DefaultQuery("current_index", "1")
- reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
- pageIndex, err := strconv.Atoi(reqPageIndex)
- if err != nil {
- response.Fail("请输入正确的条数限制", c)
- return
- }
- pageSize, err := strconv.Atoi(reqPageSize)
- if err != nil {
- response.Fail("请输入正确的页码", c)
- return
- }
- if keyWord == "" {
- response.Fail("请输入搜索词", c)
- return
- }
- userinfo := userService.GetInfoByClaims(c)
- data, err := report.SearchReport(userinfo, keyWord, pageIndex, pageSize)
- if err != nil {
- response.FailMsg("搜索报告出错", err.Error(), c)
- return
- }
- response.OkData("查询成功", data, c)
- return
- }
- // TickerData 报告详情获取指标数据
- func TickerData(c *gin.Context) {
- reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
- if reqReportChapterId == "" {
- response.Fail("请输入章节ID", c)
- return
- }
- reportChapterId, err := strconv.Atoi(reqReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- userinfo := userService.GetInfoByClaims(c)
- chapterDetail, err := report.GetTickerData(userinfo, reportChapterId)
- if err != nil {
- response.Fail(err.Error(), c)
- return
- }
- response.OkData("查询成功", chapterDetail, c)
- return
- }
- // RddpShareImg 获取报告分享图
- func RddpShareImg(c *gin.Context) {
- var req request.RddpReportShareImgReq
- if c.ShouldBind(&req) != nil {
- response.Fail("参数异常", c)
- return
- }
- defaultImg := utils.DEFAULT_REPORT_SHARE_BG_IMG
- if req.Source == "" {
- response.OkData("获取成功", defaultImg, c)
- return
- }
- imgUrl, err := services.GetDynamicShareImg(req.Source, req.Pars)
- if err != nil {
- response.FailData("获取分享海报失败", "获取分享海报失败, Err: "+err.Error(), c)
- return
- }
- if imgUrl == "" {
- imgUrl = defaultImg
- }
- response.OkData("获取成功", imgUrl, c)
- }
- // ReportPptImgList 报告中的ppt图片列表
- func ReportPptImgList(c *gin.Context) {
- reqReportId := c.DefaultQuery("report_id", "")
- if reqReportId == "" {
- response.Fail("请输入报告ID", c)
- return
- }
- reportId, err := strconv.Atoi(reqReportId)
- if err != nil {
- response.Fail("报告ID格式有误", c)
- return
- }
- reqReportChapterId := c.DefaultQuery("report_chapter_id", "0")
- reportChapterId, err := strconv.Atoi(reqReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- pptImgList, err := report.GetReportPptImgListByReportIdAndReportChapterId(reportId, reportChapterId)
- if err != nil {
- response.FailMsg("获取ppt图片成功", err.Error(), c)
- return
- }
- response.OkData("获取成功", pptImgList, c)
- return
- }
- // VarietyReportList 品种类型研报列表
- func VarietyReportList(c *gin.Context) {
- reqClassifyId := c.DefaultQuery("classify_id", "")
- reqChartPermissionId := c.DefaultQuery("chart_permission_id", "")
- reqPageIndex := c.DefaultQuery("current_index", "1")
- reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
- pageIndex, err := strconv.Atoi(reqPageIndex)
- if err != nil {
- response.Fail("请输入正确的条数限制", c)
- return
- }
- pageSize, err := strconv.Atoi(reqPageSize)
- if err != nil {
- response.Fail("请输入正确的页码", c)
- return
- }
- if reqChartPermissionId == "" {
- response.Fail("请输入权限ID", c)
- return
- }
- chartPermissionId, err := strconv.Atoi(reqChartPermissionId)
- if err != nil {
- response.Fail("权限ID格式错误", c)
- return
- }
- classifyId, err := strconv.Atoi(reqClassifyId)
- if err != nil {
- response.Fail("种类ID格式错误", c)
- return
- }
- userinfo := userService.GetInfoByClaims(c)
- list, err := report.GetVarietyReportList(userinfo, classifyId, chartPermissionId, pageIndex, pageSize)
- if err != nil {
- response.FailMsg("查看研报列表出错", err.Error(), c)
- return
- }
- response.OkData("查询成功", list, c)
- return
- }
- // RddpShareImg 获取报告分享图
- func ReportChapterSet(c *gin.Context) {
- var req request.ReportChapterSetReq
- if c.ShouldBind(&req) != nil {
- response.Fail("参数异常", c)
- return
- }
- userinfo := userService.GetInfoByClaims(c)
- err := user_report_chapter_set.ModifyReportChapterSet(req.IsClose, userinfo.UserID, req.TypeId)
- if err != nil {
- response.Fail("保存失败,err:"+err.Error(), c)
- return
- }
- response.Ok("保存成功", c)
- }
|