variety_tag.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_yb/models/tables/research_variety_tag_relation"
  6. "hongze/hongze_yb/models/tables/variety_classify"
  7. "hongze/hongze_yb/models/tables/variety_tag"
  8. "hongze/hongze_yb/models/tables/yb_community_question_process"
  9. "hongze/hongze_yb/models/tables/yb_price_driven_tag"
  10. )
  11. // TagTreeItem 标签树
  12. type TagTreeItem struct {
  13. ClassifyId int `json:"classify_id" description:"分类ID"`
  14. ClassifyName string `json:"classify_name" description:"分类名称"`
  15. //TagId int `json:"tag_id" description:"分类ID(用于前端组件)"`
  16. //TagName string `json:"tag_name" description:"分类名称(用于前端组件)"`
  17. Sort int `json:"sort" description:"排序"`
  18. Tags []*TagItem `json:"tags" description:"标签"`
  19. }
  20. // TagItem 标签
  21. type TagItem struct {
  22. TagId int `json:"tag_id" description:"标签ID"`
  23. TagName string `json:"tag_name" description:"标签名称"`
  24. Sort int `json:"sort" description:"排序"`
  25. ClassifyId int `json:"classify_id" description:"分类ID"`
  26. ChartPermissionId int `json:"chart_permission_id" description:"品种权限ID"`
  27. PriceDrivenState int `json:"price_driven_state" description:"价格驱动状态:0-关闭 1-开启"`
  28. ResearcherList []*TagResearcher `json:"researcher_list" description:"研究员列表"`
  29. }
  30. // TagResearcher 研究员信息
  31. type TagResearcher struct {
  32. AdminId int `json:"admin_id"`
  33. AdminName string `json:"admin_name"`
  34. AllowSelect bool `json:"allow_select" description:"是否允许选中"`
  35. }
  36. // GetTagTree 获取标签树
  37. func GetTagTree(questionId int) (respList []*TagTreeItem, err error) {
  38. respList = make([]*TagTreeItem, 0)
  39. // 获取标签分类
  40. classifyList, e := variety_classify.GetVarietyClassifyList()
  41. if e != nil {
  42. err = errors.New("获取标签分类列表失败, Err: " + e.Error())
  43. return
  44. }
  45. classifyLen := len(classifyList)
  46. if classifyLen == 0 {
  47. return
  48. }
  49. // 获取标签列表
  50. tagList, e := variety_tag.GetVarietyTagList()
  51. if e != nil {
  52. err = errors.New("获取标签列表失败, Err: " + e.Error())
  53. return
  54. }
  55. // 标签研究员组
  56. relationList := make([]*research_variety_tag_relation.ResearchVarietyTagRelationItem, 0)
  57. relationList, e = research_variety_tag_relation.GetResearchVarietyTagRelationList()
  58. if e != nil {
  59. err = errors.New("获取研究员标签关系失败, Err:" + e.Error())
  60. return
  61. }
  62. // 价格驱动标签
  63. priceTagList, e := yb_price_driven_tag.GetPriceDrivenTagList()
  64. if e != nil {
  65. err = errors.New("获取价格驱动标签列表失败, Err:" + e.Error())
  66. return
  67. }
  68. priceTagLen := len(priceTagList)
  69. priceTagMap := make(map[int]int, 0)
  70. for i := 0; i < priceTagLen; i++ {
  71. priceTagMap[priceTagList[i].VarietyTagID] = priceTagList[i].State
  72. }
  73. // 问答社区-研究员是否允许被二次选中
  74. processMap := make(map[string]bool)
  75. if questionId > 0 {
  76. processList, e := yb_community_question_process.GetListByQuestionId(questionId)
  77. if e != nil {
  78. err = errors.New("获取问答流程列表失败, Err:" + e.Error())
  79. return
  80. }
  81. for i := range processList {
  82. k := fmt.Sprintf("%d-%d", processList[i].VarietyTagID, processList[i].ReplierAdminID)
  83. processMap[k] = true
  84. }
  85. }
  86. // 研究员、价格驱动状态
  87. tagsArr := make([]*TagItem, 0)
  88. tagLen := len(tagList)
  89. for i := 0; i < tagLen; i++ {
  90. item := tagList[i]
  91. priceState := priceTagMap[item.VarietyTagID]
  92. tmp := &TagItem{
  93. TagId: item.VarietyTagID,
  94. TagName: item.TagName,
  95. Sort: item.Sort,
  96. ClassifyId: item.VarietyClassifyID,
  97. ChartPermissionId: item.ChartPermissionID,
  98. PriceDrivenState: priceState,
  99. }
  100. members := make([]*TagResearcher, 0)
  101. for _, r := range relationList {
  102. if item.VarietyTagID == r.VarietyTagId {
  103. k := fmt.Sprintf("%d-%d", item.VarietyTagID, r.AdminId)
  104. as := true
  105. if processMap[k] {
  106. as = false
  107. }
  108. members = append(members, &TagResearcher{
  109. AdminId: r.AdminId,
  110. AdminName: r.AdminName,
  111. AllowSelect: as,
  112. })
  113. }
  114. }
  115. tmp.ResearcherList = members
  116. tagsArr = append(tagsArr, tmp)
  117. }
  118. // 分类标签
  119. for i := 0; i < classifyLen; i++ {
  120. classifyItem := new(TagTreeItem)
  121. classifyItem.ClassifyId = classifyList[i].VarietyClassifyID
  122. classifyItem.ClassifyName = classifyList[i].ClassifyName
  123. //classifyItem.TagId = classifyList[i].VarietyClassifyID
  124. //classifyItem.TagName = classifyList[i].ClassifyName
  125. classifyItem.Sort = classifyList[i].Sort
  126. classifyItem.Tags = make([]*TagItem, 0)
  127. for _, t := range tagsArr {
  128. if classifyItem.ClassifyId == t.ClassifyId {
  129. classifyItem.Tags = append(classifyItem.Tags, t)
  130. }
  131. }
  132. respList = append(respList, classifyItem)
  133. }
  134. return
  135. }