12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package crontab
- import (
- "fmt"
- "kpt-pasture/model"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
- "go.uber.org/zap"
- )
- func (e *Entry) FindCalvingNumber(pastureList []*model.AppPastureList, startTime, endTime int64) map[int64]string {
- res := make(map[int64]string)
- for _, pasture := range pastureList {
- var count int64
- if err := e.DB.Model(new(model.EventSale)).
- Where("pasture_id = ?", pasture.Id).
- Where("status = ?", pasturePb.IsShow_Ok).
- Where("reality_day BETWEEN ? AND ?", startTime, endTime).
- Count(&count).Error; err != nil {
- zaplog.Error("FindCalvingNumber", zap.Any("pasture_id", pasture.Id), zap.Any("err", err))
- }
- res[pasture.Id] = fmt.Sprintf("%d", count)
- }
- return res
- }
- func (e *Entry) LactationCow(pastureList []*model.AppPastureList, milkKind pasturePb.CowMilk_Kind) map[int64]string {
- res := make(map[int64]string)
- for _, pasture := range pastureList {
- var count int64
- if err := e.DB.Model(new(model.Cow)).
- Where("pasture_id = ?", pasture.Id).
- Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
- Where("milk_kind = ?", milkKind).
- Count(&count).Error; err != nil {
- zaplog.Error("LactationCow", zap.Any("pasture_id", pasture.Id), zap.Any("err", err))
- }
- res[pasture.Id] = fmt.Sprintf("%d", count)
- }
- return res
- }
|