package backend import ( "context" "kpt-pasture/model" "net/http" "gitee.com/xuyiping_admin/pkg/logger/zaplog" "go.uber.org/zap" "gitee.com/xuyiping_admin/pkg/xerr" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) func (s *StoreEntry) Bar(ctx context.Context) (*pasturePb.BarCowStructResponse, error) { barCowStructList := make([]*model.BarCowStruct, 0) var count int32 = 0 if err := s.DB.Model(new(model.Cow)). Select("COUNT(*) AS number ,cow_type"). Where("admission_status = ?", pasturePb.AdmissionStatus_Admission). Group("cow_type"). Find(&barCowStructList).Error; err != nil { return nil, xerr.WithStack(err) } cowTypeMap := s.CowTypeMap() for _, v := range barCowStructList { count += v.Number } return &pasturePb.BarCowStructResponse{ Code: http.StatusOK, Msg: "ok", Data: &pasturePb.BarCowStructData{ List: model.BarCowStructSlice(barCowStructList).ToPB(cowTypeMap, count), Total: 38563, }, }, nil } func (s *StoreEntry) NeckRingWarning(ctx context.Context) (*pasturePb.IndexNeckRingResponse, error) { userModel, err := s.GetUserModel(ctx) if err != nil { return nil, xerr.WithStack(err) } estrusWarningCowList := make([]*model.EventEstrus, 0) estrusWarningLevelItems := make(map[int32]int32) if err = s.DB.Model(new(model.EventEstrus)). Where("pasture_id = ?", userModel.AppPasture.Id). Where("is_show = ?", pasturePb.IsShow_Ok). Group("cow_id").Find(&estrusWarningCowList).Error; err != nil { zaplog.Error("NeckRingWarning", zap.Any("estrusWarningNumber", err)) } for _, v := range estrusWarningCowList { estrusWarningLevelItems[int32(v.Level)] += estrusWarningLevelItems[int32(v.Level)] } healthWarningNumber := int64(0) if err = s.DB.Model(new(model.NeckRingHealthWarning)). Where("pasture_id = ?", userModel.AppPasture.Id). Where("is_show = ?", pasturePb.IsShow_Ok). Group("cow_id"). Count(&healthWarningNumber).Error; err != nil { zaplog.Error("NeckRingWarning", zap.Any("estrusWarningNumber", err)) } return &pasturePb.IndexNeckRingResponse{ Code: http.StatusOK, Msg: "ok", Data: &pasturePb.NeckRingData{ EstrusWarningNumber: int32(len(estrusWarningCowList)), HealthWarningNumber: int32(healthWarningNumber), AbortionWarningNumber: 0, StressWarningNumber: 0, EstrusWarningLevelItems: estrusWarningLevelItems, }, }, nil }