123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package model
- import (
- "fmt"
- "kpt-pasture/store/kptstore"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type EventEstrus struct {
- Id int64 `json:"id"`
- PastureId int64 `json:"pastureId"`
- CowId int64 `json:"cowId"`
- NeckRingNumber string `json:"neckRingNumber"`
- EarNumber string `json:"earNumber"`
- Lact int32 `json:"lact"`
- DayAge int32 `json:"dayAge"`
- CalvingAge int32 `json:"calvingAge"`
- ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
- LastEstrusDay int64 `json:"lastEstrusDay"`
- PlanDay int64 `json:"planDay"`
- RealityDay int64 `json:"realityDay"`
- EndDay int64 `json:"endDay"`
- IsMating pasturePb.IsShow_Kind `json:"isMating"`
- UnMatingReasonsKind pasturePb.UnMatingReasons_Kind `json:"unMatingReasonsKind"`
- UnMatingReasonsName string `json:"unMatingReasonsName"`
- Remarks string `json:"remarks"`
- IsShow pasturePb.IsShow_Kind `json:"isShow"`
- OperationId int64 `json:"operationId"`
- OperationName string `json:"operationName"`
- MessageId int64 `json:"messageId"`
- MessageName string `json:"messageName"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- }
- func (e *EventEstrus) TableName() string {
- return "event_estrus"
- }
- func NewEventEstrus(
- pastureId int64,
- cow *Cow,
- exposeEstrusType pasturePb.ExposeEstrusType_Kind,
- isShow pasturePb.IsShow_Kind,
- isMating pasturePb.IsShow_Kind,
- PlanDay int32,
- operationUser, currentUser *SystemUser,
- ) *EventEstrus {
- return &EventEstrus{
- PastureId: pastureId,
- CowId: cow.Id,
- Lact: cow.Lact,
- DayAge: cow.DayAge,
- CalvingAge: cow.CalvingAge,
- NeckRingNumber: cow.NeckRingNumber,
- EarNumber: cow.EarNumber,
- ExposeEstrusType: exposeEstrusType,
- PlanDay: int64(PlanDay),
- RealityDay: int64(PlanDay),
- IsMating: isMating,
- IsShow: isShow,
- OperationId: operationUser.Id,
- OperationName: operationUser.Name,
- MessageId: currentUser.Id,
- MessageName: currentUser.Name,
- }
- }
- type EventEstrusSlice []*EventEstrus
- func (e EventEstrusSlice) ToPB(
- dB *kptstore.DB,
- getCowInfo func(dB *kptstore.DB, cowId int64) *Cow,
- getCowLastEvent func(DB *kptstore.DB, cowId int64, eventCategoryId pasturePb.EventCategory_Kind) *EventCowLog,
- ) []*pasturePb.EstrusItems {
- res := make([]*pasturePb.EstrusItems, len(e))
- for i, v := range e {
- cowInfo := getCowInfo(dB, v.CowId)
- lastEventLog := getCowLastEvent(dB, v.CowId, pasturePb.EventCategory_Breed)
- planDay, optimumMatingTime := "", ""
- lastBreedEventDetails := ""
- if lastEventLog != nil {
- lastBreedEventDetails = fmt.Sprintf("%s %s", lastEventLog.EventTypeName, lastEventLog.EventDescription)
- }
- res[i] = &pasturePb.EstrusItems{
- Id: int32(v.Id),
- CowId: int32(v.CowId),
- EarNumber: v.EarNumber,
- DayAge: cowInfo.DayAge,
- Lact: v.Lact,
- PenName: cowInfo.PenName,
- Status: v.IsShow,
- CalvingAge: cowInfo.CalvingAge,
- PlanDay: planDay,
- MatingTimes: cowInfo.MatingTimes,
- OptimumMatingStartTime: optimumMatingTime,
- OptimumMatingEndTime: optimumMatingTime,
- LastBreedEventDetails: lastBreedEventDetails,
- }
- }
- return res
- }
|