chart_info_share.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.UserShareChartClassifyItem, 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: true,
  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. tmpList := GetChartClassifyTreeRecursiveAndInsert(classifyItemsList, 0, chartClassifyItemListMap)
  112. // 再转一下就好了
  113. obj := data_manage.ChartClassifyItems{}
  114. item = obj.ToUserShareChartClassifyItemByList(tmpList)
  115. //根据sort值排序
  116. //sort.Sort(item)
  117. }
  118. return
  119. }
  120. // GetAllEditSharedChartInfoIdListByReceivedUserId
  121. // @Description: 获取所有我收到的共享的、可以编辑的图表id列表
  122. // @author: Roc
  123. // @datetime 2024-12-25 14:17:10
  124. // @param userId int
  125. // @return editShareChartInfoIdList []int
  126. // @return err error
  127. func GetAllEditSharedChartInfoIdListByReceivedUserId(userId int, chartInfoIdList []int) (editShareChartInfoIdList []int, err error) {
  128. shareObj := data_manage.ChartInfoShare{}
  129. editShareChartInfoIdList, err = shareObj.GetAllEditSharedChartInfoIdListByReceivedUserId(userId, chartInfoIdList)
  130. return
  131. }
  132. // GetAllEditSharedChartInfoIdMapByReceivedUserId
  133. // @Description: 获取所有我收到的共享的、可以编辑的图表id map
  134. // @author: Roc
  135. // @datetime 2024-12-25 14:19:22
  136. // @param userId int
  137. // @return editShareChartInfoIdMap map[int]bool
  138. // @return err error
  139. func GetAllEditSharedChartInfoIdMapByReceivedUserId(userId int) (editShareChartInfoIdMap map[int]bool, err error) {
  140. editShareChartInfoIdMap = make(map[int]bool)
  141. idList, err := GetAllEditSharedChartInfoIdListByReceivedUserId(userId, []int{})
  142. if err != nil {
  143. return
  144. }
  145. for _, v := range idList {
  146. editShareChartInfoIdMap[v] = true
  147. }
  148. return
  149. }
  150. // GetAllEditSharedChartInfoIdMapByReceivedUserIdAndChartInfoIdList
  151. // @Description: 获取所有我收到的共享的、可以编辑的图表id map
  152. // @author: Roc
  153. // @datetime 2024-12-25 14:19:22
  154. // @param userId int
  155. // @return editShareChartInfoIdMap map[int]bool
  156. // @return err error
  157. func GetAllEditSharedChartInfoIdMapByReceivedUserIdAndChartInfoIdList(userId int, chartInfoIdList []int) (editShareChartInfoIdMap map[int]bool, err error) {
  158. editShareChartInfoIdMap = make(map[int]bool)
  159. idList, err := GetAllEditSharedChartInfoIdListByReceivedUserId(userId, chartInfoIdList)
  160. if err != nil {
  161. return
  162. }
  163. for _, v := range idList {
  164. editShareChartInfoIdMap[v] = true
  165. }
  166. return
  167. }