classify.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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/rddp/classify"
  8. "hongze/hongze_yb/services/user"
  9. "hongze/hongze_yb/utils"
  10. "sort"
  11. )
  12. // GetClassifyFirstList 获取一级分类列表
  13. func GetClassifyFirstList(user user.UserInfo) (list pc.ClassifyFirstList, err error) {
  14. var errMsg string
  15. defer func() {
  16. if err != nil {
  17. global.LOG.Critical(fmt.Sprintf("GetClassifyFirstList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
  18. }
  19. }()
  20. classifyParents, err := classify.GetParentList()
  21. if err != nil {
  22. errMsg = err.Error()
  23. err = errors.New("分类查询出错")
  24. return
  25. }
  26. if len(classifyParents) == 0 {
  27. err = errors.New("分类不存在")
  28. return
  29. }
  30. // 当前版本一级分类固定
  31. classifyIconMap := map[string]string{
  32. "晨报": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_blue.png",
  33. "周报": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_blue.png",
  34. "双周报": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_blue.png",
  35. "月报": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_blue.png",
  36. "草根调研": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_orange.png",
  37. "需求报告": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_green.png",
  38. "宏观报告": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_green.png",
  39. "日度点评": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_orange.png",
  40. "数据点评": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_green.png",
  41. "碳市场价格周报": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_blue.png",
  42. "行业调研": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_orange.png",
  43. "海外视角": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_orange.png",
  44. "百家谈": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_orange.png",
  45. "会议纪要": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_green.png",
  46. "大事点评": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_orange.png",
  47. "年报合集": utils.ALIYUN_YBIMG_HOST + "ficc_classify_bg_green.png",
  48. }
  49. classifySortMap := map[string]int{
  50. "晨报": 1,
  51. "周报": 2,
  52. "双周报": 3,
  53. "月报": 4,
  54. "草根调研": 5,
  55. "需求报告": 6,
  56. "宏观报告": 7,
  57. "日度点评": 8,
  58. "数据点评": 9,
  59. "碳市场价格周报": 10,
  60. "行业调研": 11,
  61. "海外视角": 12,
  62. "百家谈": 13,
  63. "会议纪要": 14,
  64. "大事点评": 15,
  65. "年报合集": 16,
  66. }
  67. names := []string{
  68. "晨报",
  69. "周报",
  70. "双周报",
  71. "月报",
  72. "草根调研",
  73. "需求报告",
  74. "宏观报告",
  75. "日度点评",
  76. "数据点评",
  77. "碳市场价格周报",
  78. "行业调研",
  79. "海外视角",
  80. "百家谈",
  81. "会议纪要",
  82. "大事点评",
  83. "年报合集",
  84. }
  85. reportList,err := pc.GetLatestStage(names)
  86. if err != nil {
  87. errMsg = err.Error()
  88. err = errors.New("报告查询出错")
  89. return
  90. }
  91. for _, item := range classifyParents {
  92. temp := new(pc.ClassifyFirstListItem)
  93. temp.ClassifyIdFirst = item.Id
  94. temp.ClassifyNameFirst = item.ClassifyName
  95. temp.BackImgUrl = classifyIconMap[item.ClassifyName]
  96. temp.Sort = classifySortMap[item.ClassifyName]
  97. if temp.Sort == 0 {
  98. continue
  99. }
  100. // ShowType展示类型:1-列表 2-专栏; RedirectType跳转类型:1-专栏列表 2-报告列表 3-专栏详情
  101. temp.RedirectType = 2
  102. if item.ShowType == 2 {
  103. temp.RedirectType = 1
  104. classifyChild, _ := classify.GetChildByPid(item.Id)
  105. if classifyChild != nil && len(classifyChild) == 1 {
  106. // 存在二级分类且仅有一个时直接跳转专栏详情
  107. temp.ClassifyIdSecond = classifyChild[0].Id
  108. temp.ClassifyNameSecond = classifyChild[0].ClassifyName
  109. temp.RedirectType = 3
  110. }
  111. }
  112. list = append(list, temp)
  113. }
  114. for _, item := range list {
  115. for _, report := range reportList {
  116. if report.ClassifyNameFirst == item.ClassifyNameFirst {
  117. item.Latest = report.Stage
  118. }
  119. }
  120. }
  121. if len(list) > 0 {
  122. sort.Sort(list)
  123. }
  124. return
  125. }