edb_info_share.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package data
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/utils"
  5. "sort"
  6. "strconv"
  7. "strings"
  8. )
  9. // GetAllShareEdbListByFromUserId
  10. // @Description: 根据共享人id获取所有的指标列表
  11. // @author: Roc
  12. // @datetime 2024-12-03 10:01:49
  13. // @param sysUserId int
  14. // @return item []*data_manage.ShareEdbInfoQuery
  15. // @return err error
  16. func GetAllShareEdbListByFromUserId(sysUserId int) (item []*data_manage.ShareEdbInfoQuery, err error) {
  17. obj := data_manage.EdbInfoShare{}
  18. item, err = obj.GetAllSharedEdbInfoListByFromUserId(sysUserId)
  19. if err != nil {
  20. return
  21. }
  22. return
  23. }
  24. // GetAllShareEdbListByReceivedUserId
  25. // @Description: 根据接收人id获取所有的指标列表
  26. // @author: Roc
  27. // @datetime 2024-12-03 10:01:49
  28. // @param sysUserId int
  29. // @return item []*data_manage.ShareEdbInfoQuery
  30. // @return err error
  31. func GetAllShareEdbListByReceivedUserId(sysUserId int) (item []*data_manage.ShareEdbInfoQuery, err error) {
  32. obj := data_manage.EdbInfoShare{}
  33. item, err = obj.GetAllSharedEdbInfoListByReceivedUserId(sysUserId)
  34. if err != nil {
  35. return
  36. }
  37. return
  38. }
  39. // GetEdbClassifyItemListByShareEdbInfoQueryList
  40. // @Description: 根据共享的指标来获取分类和指标的树形结构
  41. // @author: Roc
  42. // @datetime 2024-12-03 11:12:26
  43. // @param items []*data_manage.ShareEdbInfoQuery
  44. // @return item data_manage.EdbClassifyItemList
  45. // @return err error
  46. func GetEdbClassifyItemListByShareEdbInfoQueryList(items []*data_manage.ShareEdbInfoQuery) (item data_manage.UserShareEdbClassifyItemList, err error) {
  47. // 所有分类
  48. edbClassifyItemListMap := make(map[int][]*data_manage.EdbClassifyItems)
  49. classifyIdList := make([]int, 0)
  50. for _, v := range items {
  51. edbClassifyItem := &data_manage.EdbClassifyItems{
  52. ClassifyId: v.ClassifyId,
  53. EdbInfoId: v.EdbInfoId,
  54. //ParentId: v.ClassifyId,
  55. //ClassifyType: v.ClassifyT,
  56. ClassifyName: v.EdbName,
  57. ClassifyNameEn: v.EdbNameEn,
  58. Sort: v.Sort,
  59. UniqueCode: v.UniqueCode,
  60. Source: v.Source,
  61. SourceName: v.SourceName,
  62. SysUserId: v.SysUserId,
  63. SysUserRealName: v.SysUserRealName,
  64. StartDate: v.StartDate.Format(utils.FormatDate),
  65. EdbCode: v.EdbCode,
  66. EdbType: v.EdbType,
  67. //Children: nil,
  68. Button: data_manage.EdbClassifyItemsButton{},
  69. IsJoinPermission: v.IsJoinPermission,
  70. HaveOperaAuth: true,
  71. ClassifyIdPath: "",
  72. }
  73. edbClassifyItemList, ok := edbClassifyItemListMap[v.ClassifyId]
  74. if !ok {
  75. edbClassifyItemList = make([]*data_manage.EdbClassifyItems, 0)
  76. }
  77. edbClassifyItemListMap[v.ClassifyId] = append(edbClassifyItemList, edbClassifyItem)
  78. classifyIdList = append(classifyIdList, v.ClassifyId)
  79. }
  80. // 组成一个分类树形结构
  81. {
  82. // 根据分类id获取分类
  83. classifyItemsList, tmpErr := data_manage.GetEdbClassifyItemsByIdList(classifyIdList)
  84. if tmpErr != nil {
  85. err = tmpErr
  86. return
  87. }
  88. allClassifyIdList := make([]int, 0)
  89. // 获取分类的完整路径id集合(子级、父级、顶级)
  90. allClassifyIdStrList := make([]string, 0)
  91. for _, v := range classifyItemsList {
  92. allClassifyIdStrList = append(allClassifyIdStrList, v.ClassifyIdPath)
  93. }
  94. if len(allClassifyIdStrList) > 0 {
  95. allClassifyIdStrList = strings.Split(strings.Join(allClassifyIdStrList, ","), ",")
  96. }
  97. for _, v := range allClassifyIdStrList {
  98. classifyId, tmpErr := strconv.Atoi(v)
  99. if tmpErr != nil {
  100. err = tmpErr
  101. return
  102. }
  103. allClassifyIdList = append(allClassifyIdList, classifyId)
  104. }
  105. classifyItemsList, err = data_manage.GetEdbClassifyItemsByIdList(allClassifyIdList)
  106. if err != nil {
  107. return
  108. }
  109. tmpItem := GetClassifyTreeRecursiveAndInsert(classifyItemsList, 0, edbClassifyItemListMap)
  110. // 再转一下就好了
  111. obj := data_manage.EdbClassifyItems{}
  112. item = obj.ToUserShareEdbClassifyItemByList(tmpItem)
  113. //根据sort值排序
  114. sort.Sort(item)
  115. }
  116. return
  117. }