123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package backend
- import (
- "context"
- "kpt-pasture/model"
- "net/http"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- "gitee.com/xuyiping_admin/pkg/xerr"
- )
- func (s *StoreEntry) IndicatorsComparison(ctx context.Context, req *pasturePb.IndicatorsComparisonRequest) (*model.IndicatorsComparisonResponse, error) {
- currentUser, err := s.GetCurrentSystemUser(ctx)
- if err != nil {
- return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
- }
- indicatorsDataList := make([]*model.IndicatorsData, 0)
- pref := s.DB.Model(new(model.IndicatorsData)).
- Where("pasture_id = ?", currentUser.PastureId).
- Where("date IN (?)", req.DateList)
- if req.CategoryKind > 0 {
- pref.Where("category_type = ?", req.CategoryKind)
- }
- if len(req.KindList) > 0 {
- pref.Where("kind IN (?)", req.KindList)
- }
- if err = pref.Order("date,kind").Find(&indicatorsDataList).Error; err != nil {
- return nil, xerr.WithStack(err)
- }
- indicatorsDetails := make(map[string]*model.IndicatorsDetails)
- indicatorsDetailsList, err := s.FindIndicatorsDetailsList(ctx)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- for _, v := range indicatorsDetailsList {
- indicatorsDetails[v.Kind] = v
- }
- return &model.IndicatorsComparisonResponse{
- Code: http.StatusOK,
- Msg: "ok",
- Data: model.IndicatorsDataSlice(indicatorsDataList).ToPB(indicatorsDetails),
- }, nil
- }
|