chart_info_share.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package data
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "strconv"
  5. "strings"
  6. )
  7. // GetAllShareChartListByFromUserId
  8. // @Description: 根据共享人id获取所有的指标列表
  9. // @author: Roc
  10. // @datetime 2024-12-03 10:01:49
  11. // @param sysUserId int
  12. // @return item []*data_manage.ShareChartInfoQuery
  13. // @return err error
  14. func GetAllShareChartListByFromUserId(sysUserId int) (item []*data_manage.ShareChartInfoQuery, err error) {
  15. obj := data_manage.ChartInfoShare{}
  16. item, err = obj.GetAllSharedChartInfoListByFromUserId(sysUserId)
  17. if err != nil {
  18. return
  19. }
  20. return
  21. }
  22. // GetAllShareChartListByReceivedUserId
  23. // @Description: 根据接收人id获取所有的指标列表
  24. // @author: Roc
  25. // @datetime 2024-12-03 10:01:49
  26. // @param sysUserId int
  27. // @return item []*data_manage.ShareChartInfoQuery
  28. // @return err error
  29. func GetAllShareChartListByReceivedUserId(sysUserId int) (item []*data_manage.ShareChartInfoQuery, err error) {
  30. obj := data_manage.ChartInfoShare{}
  31. item, err = obj.GetAllSharedChartInfoListByReceivedUserId(sysUserId)
  32. if err != nil {
  33. return
  34. }
  35. return
  36. }
  37. // GetChartClassifyItemListByShareChartInfoQueryList
  38. // @Description: 根据共享的指标来获取分类和指标的树形结构
  39. // @author: Roc
  40. // @datetime 2024-12-03 11:12:26
  41. // @param items []*data_manage.ShareChartInfoQuery
  42. // @return item data_manage.ChartClassifyItemList
  43. // @return err error
  44. func GetChartClassifyItemListByShareChartInfoQueryList(items []*data_manage.ShareChartInfoQuery) (item []*data_manage.ChartClassifyItems, err error) {
  45. // 所有分类
  46. chartClassifyItemListMap := make(map[int][]*data_manage.ChartClassifyItems)
  47. classifyIdList := make([]int, 0)
  48. for _, v := range items {
  49. chartClassifyItem := &data_manage.ChartClassifyItems{
  50. ChartClassifyId: v.ChartClassifyId,
  51. ChartInfoId: v.ChartInfoId,
  52. ChartClassifyName: v.ChartName,
  53. ChartClassifyNameEn: v.ChartNameEn,
  54. //ParentId: 0,
  55. //Level: 0,
  56. Sort: v.Sort,
  57. UniqueCode: v.UniqueCode,
  58. Source: v.Source,
  59. //SourceName: "",
  60. SysUserId: v.SysUserId,
  61. SysUserRealName: v.SysUserRealName,
  62. DateType: v.DateType,
  63. StartDate: v.StartDate,
  64. EndDate: v.EndDate,
  65. ChartType: v.ChartType,
  66. Calendar: v.Calendar,
  67. SeasonStartDate: v.SeasonStartDate,
  68. SeasonEndDate: v.SeasonEndDate,
  69. //Children: nil,
  70. Button: data_manage.ChartClassifyItemsButton{},
  71. IsJoinPermission: v.IsJoinPermission,
  72. //HaveOperaAuth: false,
  73. //ChartClassifyIdPath: "",
  74. }
  75. chartClassifyItemList, ok := chartClassifyItemListMap[v.ChartClassifyId]
  76. if !ok {
  77. chartClassifyItemList = make([]*data_manage.ChartClassifyItems, 0)
  78. }
  79. chartClassifyItemListMap[v.ChartClassifyId] = append(chartClassifyItemList, chartClassifyItem)
  80. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  81. }
  82. // 组成一个分类树形结构
  83. {
  84. // 根据分类id获取分类
  85. classifyItemsList, tmpErr := data_manage.GetChartClassifyItemsByIdList(classifyIdList)
  86. if tmpErr != nil {
  87. err = tmpErr
  88. return
  89. }
  90. allClassifyIdList := make([]int, 0)
  91. // 获取分类的完整路径id集合(子级、父级、顶级)
  92. allClassifyIdStrList := make([]string, 0)
  93. for _, v := range classifyItemsList {
  94. allClassifyIdStrList = append(allClassifyIdStrList, v.ChartClassifyIdPath)
  95. }
  96. if len(allClassifyIdStrList) > 0 {
  97. allClassifyIdStrList = strings.Split(strings.Join(allClassifyIdStrList, ","), ",")
  98. }
  99. for _, v := range allClassifyIdStrList {
  100. classifyId, tmpErr := strconv.Atoi(v)
  101. if tmpErr != nil {
  102. err = tmpErr
  103. return
  104. }
  105. allClassifyIdList = append(allClassifyIdList, classifyId)
  106. }
  107. classifyItemsList, err = data_manage.GetChartClassifyItemsByIdList(allClassifyIdList)
  108. if err != nil {
  109. return
  110. }
  111. item = GetChartClassifyTreeRecursiveAndInsert(classifyItemsList, 0, chartClassifyItemListMap)
  112. //根据sort值排序
  113. //sort.Sort(item)
  114. }
  115. return
  116. }