12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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 int32 `json:"type_id"`
- BreedStatusId int32 `json:"breed_status_id"`
- KindId int32 `json:"kind_id"`
- BirthWeight int64 `json:"birth_weight"`
- CurrentWeight int64 `json:"current_weight"`
- SourceId int32 `json:"source_id"`
- FatherId int32 `json:"father_id"`
- MotherId int32 `json:"mother_id"`
- IsRemove pasturePb.IsShow_Kind `json:"is_remove"`
- IsPregnant pasturePb.IsShow_Kind `json:"is_pregnant"`
- Status int32 `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"`
- 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 int32 = 1
- isPregnant pasturePb.IsShow_Kind = pasturePb.IsShow_No
- )
- if req.BreedStatusId == 4 || req.BreedStatusId == 5 {
- isPregnant = pasturePb.IsShow_Ok
- status = 4
- }
- 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: req.FatherId,
- MotherId: 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 (c *Cow) GetDayAge() int32 {
- return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
- }
- func (c *Cow) GetDaysPregnant() int32 {
- return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
- }
|