cow_indicators_breed.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package crontab
  2. import (
  3. "fmt"
  4. "kpt-pasture/model"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. "gitee.com/xuyiping_admin/pkg/logger/zaplog"
  7. "go.uber.org/zap"
  8. )
  9. func (e *Entry) FindCalvingNumber(pastureList []*model.AppPastureList, startTime, endTime int64) map[int64]string {
  10. res := make(map[int64]string)
  11. for _, pasture := range pastureList {
  12. var count int64
  13. if err := e.DB.Model(new(model.EventSale)).
  14. Where("pasture_id = ?", pasture.Id).
  15. Where("status = ?", pasturePb.IsShow_Ok).
  16. Where("reality_day BETWEEN ? AND ?", startTime, endTime).
  17. Count(&count).Error; err != nil {
  18. zaplog.Error("FindCalvingNumber", zap.Any("pasture_id", pasture.Id), zap.Any("err", err))
  19. }
  20. res[pasture.Id] = fmt.Sprintf("%d", count)
  21. }
  22. return res
  23. }
  24. func (e *Entry) LactationCow(pastureList []*model.AppPastureList, milkKind pasturePb.CowMilk_Kind) map[int64]string {
  25. res := make(map[int64]string)
  26. for _, pasture := range pastureList {
  27. var count int64
  28. if err := e.DB.Model(new(model.Cow)).
  29. Where("pasture_id = ?", pasture.Id).
  30. Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
  31. Where("milk_kind = ?", milkKind).
  32. Count(&count).Error; err != nil {
  33. zaplog.Error("LactationCow", zap.Any("pasture_id", pasture.Id), zap.Any("err", err))
  34. }
  35. res[pasture.Id] = fmt.Sprintf("%d", count)
  36. }
  37. return res
  38. }