classify.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/company_product"
  8. "hongze/hongze_yb/models/tables/rddp/classify"
  9. "hongze/hongze_yb/services/company"
  10. "hongze/hongze_yb/services/user"
  11. "hongze/hongze_yb/utils"
  12. "sort"
  13. "strings"
  14. )
  15. // GetClassifyFirstList 获取一级分类列表
  16. func GetClassifyFirstList(user user.UserInfo) (resp pc.ClassifyFirstList, err error) {
  17. var errMsg string
  18. defer func() {
  19. if err != nil {
  20. global.LOG.Critical(fmt.Sprintf("GetClassifyFirstList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
  21. }
  22. }()
  23. classifyParents, err := classify.GetParentList()
  24. if err != nil {
  25. errMsg = err.Error()
  26. err = errors.New("分类查询出错")
  27. return
  28. }
  29. if len(classifyParents) == 0 {
  30. err = errors.New("分类不存在")
  31. return
  32. }
  33. classifyIconMap := make(map[string]string)
  34. classifySortMap := make(map[string]int)
  35. var names []string
  36. for _, v := range classifyParents {
  37. classifyIconMap[v.ClassifyName] = v.YbFiccPcIcon
  38. classifySortMap[v.ClassifyName] = v.YbFiccSort
  39. names = append(names, v.ClassifyName)
  40. }
  41. reportList, err := pc.GetLatestStage(names)
  42. if err != nil {
  43. errMsg = err.Error()
  44. err = errors.New("报告查询出错")
  45. return
  46. }
  47. var list pc.ClassifyFirstList
  48. for _, item := range classifyParents {
  49. temp := new(pc.ClassifyFirstListItem)
  50. temp.ClassifyIdFirst = item.Id
  51. temp.ClassifyNameFirst = item.ClassifyName
  52. temp.BackImgUrl = classifyIconMap[item.ClassifyName]
  53. temp.Sort = classifySortMap[item.ClassifyName]
  54. //if temp.Sort == 0 {
  55. // continue
  56. //}
  57. // ShowType展示类型:1-列表 2-专栏 3-品种; RedirectType跳转类型:1-专栏列表 2-报告列表 3-专栏详情 4-品种类型列表
  58. temp.RedirectType = 2
  59. if item.ShowType == 2 {
  60. temp.RedirectType = 1
  61. classifyChild, _ := classify.GetChildByPid(item.Id)
  62. if classifyChild != nil && len(classifyChild) == 1 {
  63. // 存在二级分类且仅有一个时直接跳转专栏详情
  64. temp.ClassifyIdSecond = classifyChild[0].Id
  65. temp.ClassifyNameSecond = classifyChild[0].ClassifyName
  66. temp.RedirectType = 3
  67. }
  68. } else if item.ShowType == 3 {
  69. temp.RedirectType = 4
  70. }
  71. list = append(list, temp)
  72. }
  73. // 判断用户状态是否是正常和永续
  74. var productAuthOk bool
  75. companyProduct, err := company_product.GetByCompany2ProductId(user.CompanyID, 1)
  76. if err == utils.ErrNoRow {
  77. err = nil
  78. }
  79. if err != nil && err != utils.ErrNoRow {
  80. errMsg = err.Error()
  81. err = errors.New("查询用户购买产品出错")
  82. return
  83. }
  84. if companyProduct != nil {
  85. // 无FICC权限的客户不可见
  86. if companyProduct.CompanyProductID > 0 {
  87. // 已购或者试用用户可见
  88. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  89. productAuthOk = true
  90. }
  91. }
  92. }
  93. // 获取有效的权限id列表
  94. var validPermissionIdList []int
  95. //var allClassifySecondIds []int
  96. if productAuthOk {
  97. validPermissionIdList, err = company.GetValidPermissionIdListByCompany2ProductId(user.CompanyID, 1)
  98. if err != nil && err != utils.ErrNoRow {
  99. errMsg = err.Error()
  100. err = errors.New("查询分类出错")
  101. return
  102. }
  103. }
  104. //classifyNames, err := chart_permission_search_key_word_mapping.GetKeyWordsByChartPermissionByIds(validPermissionIdList)
  105. //if err != nil {
  106. // errMsg = err.Error()
  107. // err = errors.New("查询权限对应的分类出错")
  108. // return
  109. //}
  110. //
  111. //if len(classifyNames) > 0 {
  112. // allClassifySecondIds, err = classify.GetSecondIdsByClassifyNames(classifyNames)
  113. // if err != nil {
  114. // errMsg = err.Error()
  115. // err = errors.New("查询分类出错")
  116. // return
  117. // }
  118. //}
  119. for _, item := range list {
  120. //无权限用户关闭品种类别入口
  121. if item.RedirectType == 4 && !productAuthOk {
  122. continue
  123. }
  124. //只有宏观经济权限的用户关闭品种类别入口
  125. if len(validPermissionIdList) == 1 && validPermissionIdList[0] == 1 && item.RedirectType == 4 {
  126. continue
  127. }
  128. for _, report := range reportList {
  129. if report.ClassifyNameFirst == item.ClassifyNameFirst {
  130. item.Latest = report.Stage
  131. }
  132. }
  133. resp = append(resp, item)
  134. }
  135. if len(resp) > 0 {
  136. sort.Sort(resp)
  137. }
  138. return
  139. }