report.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package pc
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_yb/global"
  6. "hongze/hongze_yb/models/response/pc"
  7. "hongze/hongze_yb/models/tables/chart_permission_search_key_word_mapping"
  8. "hongze/hongze_yb/models/tables/rddp/chart_permission"
  9. "hongze/hongze_yb/models/tables/rddp/classify"
  10. "hongze/hongze_yb/models/tables/rddp/customer_comment"
  11. "hongze/hongze_yb/models/tables/rddp/report"
  12. "hongze/hongze_yb/services/company"
  13. "hongze/hongze_yb/services/user"
  14. "hongze/hongze_yb/utils"
  15. )
  16. func GetClassifyDetail(user user.UserInfo, classifyIdSecond int) (detail *pc.ClassifyDetail, err error) {
  17. var errMsg string
  18. defer func() {
  19. if err != nil {
  20. global.LOG.Critical(fmt.Sprintf("GetClassifyDetail: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
  21. }
  22. }()
  23. classifyInfo, err := classify.GetByClassifyId(classifyIdSecond)
  24. if err != nil {
  25. errMsg = err.Error()
  26. err = errors.New("分类查询出错")
  27. return
  28. }
  29. if classifyInfo.Id == 0 {
  30. err = errors.New("分类不存在")
  31. return
  32. }
  33. if classifyInfo.ParentId == 0 {
  34. err = errors.New("只允许查询二级分类")
  35. return
  36. }
  37. //查询权限, 查询当前分类下的最新的报告,
  38. permissionIds, err := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(classifyIdSecond)
  39. if err != nil {
  40. errMsg = err.Error()
  41. err = errors.New("分类权限查询出错")
  42. return
  43. }
  44. authOk, permissionCheckInfo, _, err := company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
  45. if err != nil && err != utils.ErrNoRow {
  46. errMsg = err.Error()
  47. err = errors.New("权限查询出错")
  48. return
  49. }
  50. comments, err := customer_comment.GetCustomerComment()
  51. if err != nil {
  52. errMsg = err.Error()
  53. err = errors.New("客户评价查询出错")
  54. return
  55. }
  56. detail = new(pc.ClassifyDetail)
  57. detail.ClassifyIdSecond = classifyInfo.Id
  58. detail.ParentId = classifyInfo.ParentId
  59. detail.AuthorDescript = classifyInfo.AuthorDescript
  60. detail.ReportAuthor = classifyInfo.ReportAuthor
  61. detail.AvatarImgUrl = classifyInfo.AvatarImgUrl
  62. detail.ClassifyNameSecond = classifyInfo.ClassifyName
  63. detail.Abstract = classifyInfo.Abstract
  64. detail.Descript = classifyInfo.Descript
  65. detail.VipTitle = classifyInfo.VipTitle
  66. detail.PermissionCheck = &permissionCheckInfo
  67. detail.AuthOk = authOk
  68. detail.Comments = comments
  69. return
  70. }
  71. // GetLatestReportList 首页最新资讯
  72. func GetLatestReportList(user user.UserInfo, chartPermissionId int) (ret []*pc.LatestReport, err error) {
  73. var errMsg string
  74. defer func() {
  75. if err != nil {
  76. global.LOG.Critical(fmt.Sprintf("GetCollectReportList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
  77. }
  78. }()
  79. // 查询权限的基本信息
  80. permissionInfo, err := chart_permission.GetByChartPermissionId(chartPermissionId)
  81. if err != nil {
  82. errMsg = err.Error()
  83. err = errors.New("查询权限出错")
  84. return
  85. }
  86. if permissionInfo.ChartPermissionID == 0 {
  87. err = errors.New("权限不存在")
  88. return
  89. }
  90. // 除了晨报和周报以外的其他报告
  91. classifySecondIds, err := chart_permission_search_key_word_mapping.GetClassifyIdsByChartPermissionId(chartPermissionId, "rddp")
  92. if err != nil {
  93. errMsg = err.Error()
  94. err = errors.New("查询权限对应的分类出错")
  95. return
  96. }
  97. //var classifySecondIds []int
  98. //if len(classifyNames) > 0 {
  99. // classifySecondIds, err = classify.GetSecondIdsByClassifyNames(classifyNames)
  100. // if err != nil {
  101. // errMsg = err.Error()
  102. // err = errors.New("查询分类出错")
  103. // return
  104. // }
  105. //}
  106. var reportList []*pc.LatestReport
  107. if len(classifySecondIds) > 0 {
  108. reportList, err = report.GetLatestReportByPermission(classifySecondIds)
  109. if err != nil {
  110. errMsg = err.Error()
  111. err = errors.New("查询报告信息出错")
  112. return
  113. }
  114. }
  115. //文章不足三篇时用下一品种补全
  116. //if len(reportList) < 3 {
  117. //
  118. // reportList, err = report.GetLatestReportByPermission(classifySecondIds)
  119. // if err != nil {
  120. // errMsg = err.Error()
  121. // err = errors.New("查询报告信息出错")
  122. // return
  123. // }
  124. //}
  125. ret = reportList
  126. return
  127. }