english_classify.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package english_report
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/utils"
  6. "sort"
  7. )
  8. // ListClassify
  9. // @Title 获取分类列表
  10. // @Description 获取分类列表
  11. // @Param PageSize query int true "每页数据条数"
  12. // @Param CurrentIndex query int true "当前页页码,从1开始"
  13. // @Param KeyWord query string true "检索关键词"
  14. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  15. // @Success 200 {object} models.EnglishClassifyListResp
  16. // @router /classify/list [get]
  17. func (this *EnglishReportController) ListClassify() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. keyWord := this.GetString("KeyWord")
  24. reqEnabled, _ := this.GetInt("Enabled", -1)
  25. enabled := -1
  26. if reqEnabled == 1 {
  27. enabled = reqEnabled
  28. }
  29. resp := new(models.EnglishClassifyListResp)
  30. // 处理一级分类分页的情况
  31. rootList, err := models.GetEnglishClassifyRootId(keyWord, enabled)
  32. if err != nil {
  33. br.Msg = "获取失败"
  34. br.ErrMsg = "获取失败,Err:" + err.Error()
  35. return
  36. }
  37. if len(rootList) == 0 {
  38. resp.List = make([]*models.EnglishClassifyList, 0)
  39. br.Data = resp
  40. br.Ret = 200
  41. br.Success = true
  42. br.Msg = "获取成功"
  43. return
  44. }
  45. var ids []int
  46. var rootIds []int
  47. rootMap := make(map[int]struct{}, 0)
  48. for _, v := range rootList {
  49. rootIds = append(rootIds, v.Id)
  50. rootMap[v.Id] = struct{}{}
  51. }
  52. //获取相关的分类ID
  53. idList, err := models.GetEnglishClassifyListByRootId(rootIds, keyWord, enabled)
  54. if err != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取失败,Err:" + err.Error()
  57. return
  58. }
  59. secondListMap := make(map[int][]*models.EnglishClassifyList)
  60. thirdListMap := make(map[int][]*models.EnglishClassifyList)
  61. var thirdIds []int
  62. var sortChildList models.RSChildClassifyList
  63. // 三级分类-品种权限
  64. permissionMap := make(map[int][]int)
  65. if len(idList) > 0 {
  66. childIdMap := make(map[int]struct{}, 0)
  67. for _, v := range idList {
  68. if _, ok := childIdMap[v.ParentId]; !ok {
  69. ids = append(ids, v.ParentId)
  70. childIdMap[v.ParentId] = struct{}{}
  71. }
  72. if _, ok := childIdMap[v.Id]; !ok {
  73. ids = append(ids, v.Id)
  74. childIdMap[v.Id] = struct{}{}
  75. }
  76. }
  77. tmpList, err := models.GetEnglishClassifyChildByIds(ids)
  78. if err != nil {
  79. br.Msg = "获取二级分类失败"
  80. br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
  81. return
  82. }
  83. for _, v := range tmpList {
  84. if _, ok := rootMap[v.ParentId]; !ok {
  85. thirdIds = append(thirdIds, v.Id)
  86. }
  87. }
  88. {
  89. classifyIds := thirdIds
  90. if len(classifyIds) > 0 {
  91. cond := fmt.Sprintf(` AND %s IN (%s)`, models.EnClassifyPermissionColumns.EnClassifyId, utils.GetOrmInReplace(len(classifyIds)))
  92. pars := make([]interface{}, 0)
  93. pars = append(pars, classifyIds)
  94. ob := new(models.EnClassifyPermission)
  95. items, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
  96. if e != nil {
  97. br.Msg = "获取失败"
  98. br.ErrMsg = "获取客户权限列表失败, Err: " + e.Error()
  99. return
  100. }
  101. for _, v := range items {
  102. if permissionMap[v.EnClassifyId] == nil {
  103. permissionMap[v.EnClassifyId] = make([]int, 0)
  104. }
  105. permissionMap[v.EnClassifyId] = append(permissionMap[v.EnClassifyId], v.EnPermissionId)
  106. }
  107. }
  108. }
  109. // 处理三级分类
  110. for _, v := range tmpList {
  111. if _, ok := rootMap[v.ParentId]; !ok {
  112. if p, ok1 := permissionMap[v.Id]; ok1 {
  113. v.EnPermissions = p
  114. }
  115. thirdListMap[v.ParentId] = append(thirdListMap[v.ParentId], v)
  116. }
  117. }
  118. //处理二级分类
  119. for _, v := range tmpList {
  120. if _, ok := rootMap[v.ParentId]; ok {
  121. if child, ok1 := thirdListMap[v.Id]; ok1 {
  122. sortChildList = child
  123. sort.Sort(sortChildList)
  124. v.Child = sortChildList
  125. }
  126. secondListMap[v.ParentId] = append(secondListMap[v.ParentId], v)
  127. }
  128. }
  129. }
  130. //处理一级分类
  131. var sortList models.RSClassifyList
  132. for _, v := range rootList {
  133. if child, ok := secondListMap[v.Id]; ok {
  134. sortChildList = child
  135. sort.Sort(sortChildList)
  136. v.Child = sortChildList
  137. }
  138. sortList = append(sortList, v)
  139. }
  140. sort.Sort(sortList)
  141. resp.List = sortList
  142. br.Data = resp
  143. br.Ret = 200
  144. br.Success = true
  145. br.Msg = "获取成功"
  146. }