123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package model
- import (
- "math"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type Cow struct {
- Id int64 `json:"id"`
- Sex pasturePb.Genders_Kind `json:"sex"`
- NeckRingNumber string `json:"neck_ring_number"`
- EarNumber string `json:"ear_number"`
- EarOldNumber string `json:"ear_old_number"`
- PenId int64 `json:"pen_id"`
- Lact int32 `json:"lact"`
- TypeId pasturePb.CowType_Kind `json:"type_id"`
- BreedStatusId pasturePb.BreedStatus_Kind `json:"breed_status_id"`
- KindId pasturePb.CowKind_Kind `json:"kind_id"`
- BirthWeight int64 `json:"birth_weight"`
- CurrentWeight int64 `json:"current_weight"`
- SourceId pasturePb.CowSource_Kind `json:"source_id"`
- FatherId int64 `json:"father_id"`
- MotherId int64 `json:"mother_id"`
- IsRemove pasturePb.IsShow_Kind `json:"is_remove"`
- IsPregnant pasturePb.IsShow_Kind `json:"is_pregnant"`
- Status pasturePb.CowStatus_Kind `json:"status"`
- WeaningAt int64 `json:"weaning_at"`
- BirthAt int64 `json:"birth_at"`
- FirstMatingAt int64 `json:"first_mating_at"`
- LastEstrusAt int64 `json:"last_estrus_at"`
- LastCalvingAt int64 `json:"last_calving_at"`
- LastMatingAt int64 `json:"last_mating_at"`
- LastBullId int64 `json:"last_bull_id"`
- LastPregnantCheckAt int64 `json:"last_pregnant_check_at"`
- LastDryMilkAt int64 `json:"last_dry_milk_at"`
- LastSecondWeight int64 `json:"last_second_weight"`
- LastSecondWeightAt int64 `json:"last_second_weight_at"`
- LastWeightAt int64 `json:"last_weight_at"`
- CreatedAt int64 `json:"created_at"`
- UpdatedAt int64 `json:"updated_at"`
- }
- func (c *Cow) TableName() string {
- return "cow"
- }
- func NewCow(req *pasturePb.SearchEnterData) *Cow {
- var (
- status = pasturePb.CowStatus_Calving
- isPregnant = pasturePb.IsShow_No
- )
- if req.BreedStatusId == pasturePb.BreedStatus_InCheck_Pregnant ||
- req.BreedStatusId == pasturePb.BreedStatus_Recheck_Pregnant {
- isPregnant = pasturePb.IsShow_Ok
- status = pasturePb.CowStatus_Pregnant
- }
- return &Cow{
- Sex: req.Sex,
- EarNumber: req.EarNumber,
- PenId: int64(req.PenId),
- Lact: req.Lact,
- TypeId: req.CowTypeId,
- BreedStatusId: req.BreedStatusId,
- KindId: req.CowKindId,
- SourceId: req.CowSourceId,
- FatherId: int64(req.FatherId),
- MotherId: int64(req.MotherId),
- IsRemove: pasturePb.IsShow_Ok,
- IsPregnant: isPregnant,
- Status: status,
- WeaningAt: int64(req.WeaningAt),
- BirthAt: int64(req.BirthAt),
- FirstMatingAt: int64(req.MatingAt),
- LastMatingAt: int64(req.MatingAt),
- LastPregnantCheckAt: int64(req.PregnancyCheckAt),
- }
- }
- func NewCalfCow(motherId, fatherId int64, calf *EventCalvingCalf) *Cow {
- return &Cow{
- Sex: calf.Sex,
- EarNumber: calf.EarNumber,
- PenId: int64(calf.PenId),
- TypeId: pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
- BreedStatusId: pasturePb.BreedStatus_Unmarried, // 未配
- KindId: pasturePb.CowKind_HST, // 荷斯坦
- BirthWeight: calf.Weight,
- SourceId: pasturePb.CowSource_Calving, // 产犊方式
- FatherId: fatherId,
- MotherId: motherId,
- IsRemove: pasturePb.IsShow_Ok,
- IsPregnant: pasturePb.IsShow_No,
- Status: pasturePb.CowStatus_Calving, // 哺乳犊牛
- }
- }
- // GetDayAge 日龄
- func (c *Cow) GetDayAge() int32 {
- return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
- }
- // GetDaysPregnant 在胎天数
- func (c *Cow) GetDaysPregnant() int32 {
- if c.Status == pasturePb.CowStatus_Breeding || c.Status == pasturePb.CowStatus_Pregnant {
- return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
- }
- return 0
- }
- // GetLactationDays 泌乳天数
- func (c *Cow) GetLactationDays() int32 {
- if c.Status == pasturePb.CowStatus_Calving {
- return int32(math.Floor(float64(time.Now().Unix()-c.LastCalvingAt) / 86400))
- }
- return 0
- }
- // GetDayWeight 日增重
- func (c *Cow) GetDayWeight() float64 {
- if c.CurrentWeight-c.LastSecondWeight > 0 && c.LastWeightAt > c.LastSecondWeightAt {
- days := int32(math.Floor(float64(c.LastWeightAt-c.LastSecondWeightAt) / 86400))
- if days <= 0 {
- return 0
- }
- return math.Round(1.0 * float64(c.CurrentWeight-c.LastSecondWeight) / float64(days))
- }
- return 0
- }
- // GetAverageDailyWeight 平均日增重
- func (c *Cow) GetAverageDailyWeight() float64 {
- if c.CurrentWeight-c.BirthWeight > 0 && c.LastWeightAt > c.BirthAt {
- days := int32(math.Floor(float64(c.LastWeightAt-c.BirthAt) / 86400))
- if days <= 0 {
- return 0
- }
- dailyWeight := math.Round(1.0 * float64(c.CurrentWeight-c.BirthWeight) / float64(days))
- return dailyWeight
- }
- return 0
- }
|