indicators.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package backend
  2. import (
  3. "context"
  4. "kpt-pasture/model"
  5. "net/http"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. "gitee.com/xuyiping_admin/pkg/xerr"
  8. )
  9. func (s *StoreEntry) IndicatorsComparison(ctx context.Context, req *pasturePb.IndicatorsComparisonRequest) (*model.IndicatorsComparisonResponse, error) {
  10. currentUser, err := s.GetCurrentSystemUser(ctx)
  11. if err != nil {
  12. return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
  13. }
  14. indicatorsDataList := make([]*model.IndicatorsData, 0)
  15. pref := s.DB.Model(new(model.IndicatorsData)).
  16. Where("pasture_id = ?", currentUser.PastureId).
  17. Where("date IN (?)", req.DateList)
  18. if req.CategoryKind > 0 {
  19. pref.Where("category_type = ?", req.CategoryKind)
  20. }
  21. if len(req.KindList) > 0 {
  22. pref.Where("kind IN (?)", req.KindList)
  23. }
  24. if err = pref.Order("date,kind").Find(&indicatorsDataList).Error; err != nil {
  25. return nil, xerr.WithStack(err)
  26. }
  27. indicatorsDetails := make(map[string]*model.IndicatorsDetails)
  28. indicatorsDetailsList, err := s.FindIndicatorsDetailsList(ctx)
  29. if err != nil {
  30. return nil, xerr.WithStack(err)
  31. }
  32. for _, v := range indicatorsDetailsList {
  33. indicatorsDetails[v.Kind] = v
  34. }
  35. return &model.IndicatorsComparisonResponse{
  36. Code: http.StatusOK,
  37. Msg: "ok",
  38. Data: model.IndicatorsDataSlice(indicatorsDataList).ToPB(indicatorsDetails),
  39. }, nil
  40. }