range_analysis_classify.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package range_analysis
  2. import (
  3. "eta/eta_api/models/data_manage"
  4. "eta/eta_api/services/data"
  5. )
  6. func GetClassifyListByIsShowMe(adminId, parentId, source int, classifyList []*data_manage.ChartClassifyItems) (items []*data_manage.ChartClassifyItems, err error) {
  7. chartItems, err := data_manage.GetChartInfoBySourceAndAdminId(source, adminId)
  8. if err != nil {
  9. return
  10. }
  11. classifyIdList := make([]int, 0)
  12. for _, chart := range chartItems {
  13. if chart.ChartClassifyId > 0 {
  14. classifyIdList = append(classifyIdList, chart.ChartClassifyId)
  15. }
  16. }
  17. if parentId > 0 {
  18. for _, v := range classifyList {
  19. if v.ChartClassifyId > 0 && v.ChartInfoId == 0 {
  20. classifyItems, er, _ := data.GetChildChartClassifyByClassifyId(v.ChartClassifyId)
  21. if er != nil {
  22. err = er
  23. return
  24. }
  25. existClassifyMap := make(map[int]struct{})
  26. for _, classify := range classifyItems {
  27. existClassifyMap[classify.ChartClassifyId] = struct{}{}
  28. }
  29. for _, edb := range chartItems {
  30. if _, ok := existClassifyMap[edb.ChartClassifyId]; ok {
  31. items = append(items, v)
  32. break
  33. }
  34. }
  35. } else {
  36. items = append(items, v)
  37. }
  38. }
  39. } else {
  40. tmpClassify, er := data_manage.GetChartClassifyByIdList(classifyIdList)
  41. if er != nil {
  42. err = er
  43. return
  44. }
  45. existClassifyIdMap := make(map[int]struct{})
  46. for _, classify := range tmpClassify {
  47. existClassifyIdMap[classify.RootId] = struct{}{}
  48. }
  49. for _, classify := range classifyList {
  50. if _, ok := existClassifyIdMap[classify.ChartClassifyId]; ok {
  51. items = append(items, classify)
  52. }
  53. }
  54. }
  55. return
  56. }