12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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"
- )
- // AdultCowsPregnancyRate 成牛受胎率
- func (e *Entry) AdultCowsPregnancyRate(pastureList []*model.AppPastureList, startTime, endTime int64) map[int64]string {
- res := make(map[int64]string)
- for _, pasture := range pastureList {
- var (
- pregnantCount int64 // 确认怀孕的
- realityBreedCount int64 // 参与配种的
- )
- if err := e.DB.Model(new(model.EventMating)).
- Where("pasture_id = ?", pasture.Id).
- Where("status = ?", pasturePb.IsShow_Ok).
- Where("mating_result = ?", pasturePb.MatingResult_Pregnant).
- Where("mating_result_at BETWEEN ? AND ?", startTime, endTime).
- Count(&pregnantCount).Error; err != nil {
- zaplog.Error("pregnantCount", zap.Any("err", err))
- }
- if err := e.DB.Model(new(model.EventMating)).
- Where("pasture_id = ?", pasture.Id).
- Where("status = ?", pasturePb.IsShow_Ok).
- Where("reality_day BETWEEN ? AND ?", startTime, endTime).
- Count(&realityBreedCount).Error; err != nil {
- zaplog.Error("realityBreedCount", zap.Any("err", err))
- }
- if realityBreedCount > 0 && pregnantCount > 0 {
- res[pasture.Id] = fmt.Sprintf("%.2f", float64(pregnantCount)/float64(realityBreedCount))
- } else {
- res[pasture.Id] = "0"
- }
- }
- return res
- }
- // LactPregnancyRate 母牛不同胎次受胎率
- func (e *Entry) LactPregnancyRate(pastureList []*model.AppPastureList, condition string, startTime, endTime int64) map[int64]string {
- res := make(map[int64]string)
- for _, pasture := range pastureList {
- var (
- pregnantCount int64 // 确认怀孕的
- realityBreedCount int64 // 参与配种的
- )
- if err := e.DB.Model(new(model.EventMating)).
- Where("pasture_id = ?", pasture.Id).
- Where("status = ?", pasturePb.IsShow_Ok).
- Where(condition).
- Where("mating_result = ?", pasturePb.MatingResult_Pregnant).
- Where("mating_result_at BETWEEN ? AND ?", startTime, endTime).
- Count(&pregnantCount).Error; err != nil {
- zaplog.Error("pregnantCount", zap.Any("err", err))
- }
- if err := e.DB.Model(new(model.EventMating)).
- Where("pasture_id = ?", pasture.Id).
- Where("status = ?", pasturePb.IsShow_Ok).
- Where(condition).
- Where("reality_day BETWEEN ? AND ?", startTime, endTime).
- Count(&realityBreedCount).Error; err != nil {
- zaplog.Error("realityBreedCount", zap.Any("err", err))
- }
- if realityBreedCount > 0 && pregnantCount > 0 {
- res[pasture.Id] = fmt.Sprintf("%.2f", float64(pregnantCount)/float64(realityBreedCount))
- } else {
- res[pasture.Id] = "0"
- }
- }
- return res
- }
|