1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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"`
- LastEstrusDate string `json:"lastEstrusDate"`
- 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,
- 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,
- IsShow: isShow,
- OperationId: operationUser.Id,
- OperationName: operationUser.Name,
- MessageId: currentUser.Id,
- MessageName: currentUser.Name,
- }
- }
- type EstrusSlice []*EventEstrus
- func (e EstrusSlice) 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: v.DayAge,
- Lact: v.Lact,
- PenName: cowInfo.PenName,
- Status: v.IsShow,
- CalvingAge: int32(cowInfo.CalvingAge),
- PlanDay: planDay,
- MatingTimes: cowInfo.MatingTimes,
- OptimumMatingStartTime: optimumMatingTime,
- OptimumMatingEndTime: optimumMatingTime,
- LastBreedEventDetails: lastBreedEventDetails,
- }
- }
- return res
- }
|