base_from_ly_classify_service.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Package data
  2. // @Author gmy 2024/8/12 16:09:00
  3. package data
  4. import "eta/eta_api/models/data_manage"
  5. // LyClassifyList 获取分类列表 包含 分类下的指标名称
  6. func LyClassifyList() ([]*data_manage.BaseFromLyClassifyAndIndexInfo, error) {
  7. // step_1 获取分类列表
  8. lyClassify, err := data_manage.GetAllLyClassify()
  9. if err != nil {
  10. return nil, err
  11. }
  12. // step_2 分类id列表
  13. classifyIds := make([]int, 0)
  14. for _, v := range lyClassify {
  15. classifyIds = append(classifyIds, v.BaseFromLyClassifyId)
  16. }
  17. // step_3 获取分类下的指标
  18. lyIndices, err := data_manage.GetLyIndexByClassifyIds(classifyIds)
  19. if err != nil {
  20. return nil, err
  21. }
  22. // step_4 封装返回
  23. lyClassifyAndIndexInfos := make([]*data_manage.BaseFromLyClassifyAndIndexInfo, 0)
  24. for _, classify := range lyClassify {
  25. lyClassifyAndIndexInfo := &data_manage.BaseFromLyClassifyAndIndexInfo{
  26. BaseFromLyClassifyId: classify.BaseFromLyClassifyId,
  27. CreateTime: classify.CreateTime,
  28. ModifyTime: classify.ModifyTime,
  29. ClassifyName: classify.ClassifyName,
  30. ParentId: classify.ParentId,
  31. Sort: classify.Sort,
  32. ClassifyNameEn: classify.ClassifyNameEn,
  33. }
  34. for _, lyIndex := range lyIndices {
  35. if classify.BaseFromLyClassifyId == lyIndex.BaseFromLyClassifyId {
  36. lyClassifyAndIndexInfo.IndexId = lyIndex.BaseFromLyIndexId
  37. lyClassifyAndIndexInfo.IndexCode = lyIndex.IndexCode
  38. lyClassifyAndIndexInfo.IndexName = lyIndex.IndexName
  39. }
  40. }
  41. lyClassifyAndIndexInfos = append(lyClassifyAndIndexInfos, lyClassifyAndIndexInfo)
  42. }
  43. return lyClassifyAndIndexInfos, nil
  44. }