123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package model
- import (
- "math"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type EventEnter struct {
- Id int64 `json:"id"`
- BatchNumber string `json:"batchNumber"`
- EarNumber string `json:"earNumber"`
- CowId int64 `json:"cowId"`
- Sex pasturePb.Genders_Kind `json:"sex"`
- BirthAt int64 `json:"birthAt"`
- CowSource pasturePb.CowSource_Kind `json:"cowSource"`
- OldEarNumber string `json:"oldEarNumber"`
- CowType pasturePb.CowType_Kind `json:"cowType"`
- BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
- Lact int32 `json:"lact"`
- DayAge int32 `json:"dayAge"`
- PenId int32 `json:"penId"`
- CowKind pasturePb.CowKind_Kind `json:"cowKind"`
- FatherNumber string `json:"fatherNumber"`
- MotherNumber string `json:"motherNumber"`
- MatingAt int64 `json:"matingAt"`
- PregnancyCheckAt int64 `json:"pregnancyCheckAt"`
- DryMilkAt int64 `json:"dryMilkAt"`
- WeaningAt int64 `json:"weaningAt"`
- EstrusAt int64 `json:"estrusAt"`
- EnterAt int64 `json:"enterAt"`
- Remarks string `json:"remarks"`
- Weight int64 `json:"weight"`
- Price int64 `json:"price"`
- OperationId int64 `json:"operationId"`
- OperationName string `json:"operationName"`
- MessengerId int64 `json:"messengerId"`
- MessengerName string `json:"messengerName"`
- CreatedAt int64 `json:"created_at"`
- UpdatedAt int64 `json:"updated_at"`
- }
- func (e *EventEnter) TableName() string {
- return "event_enter"
- }
- func NewEventEnter(cowId int64, req *pasturePb.EventEnterRequest) *EventEnter {
- return &EventEnter{
- EarNumber: req.EarNumber,
- CowId: cowId,
- Sex: req.Sex,
- BirthAt: int64(req.BirthAt),
- CowSource: req.CowSource,
- CowType: req.CowType,
- BreedStatus: req.BreedStatus,
- Lact: req.Lact,
- DayAge: int32(math.Floor(float64(int32(time.Now().Unix())-req.BirthAt) / 86400)),
- PenId: req.PenId,
- CowKind: req.CowKind,
- FatherNumber: req.FatherNumber,
- MotherNumber: req.MotherNumber,
- MatingAt: int64(req.MatingAt),
- PregnancyCheckAt: int64(req.PregnancyCheckAt),
- DryMilkAt: int64(req.DryMilkAt),
- WeaningAt: int64(req.WeaningAt),
- EstrusAt: int64(req.EstrusAt),
- EnterAt: int64(req.EnterAt),
- Remarks: req.Remarks,
- Weight: int64(req.Weight * 100),
- Price: int64(req.Price * 100),
- MessengerId: int64(req.MessengerId),
- MessengerName: req.MessengerName,
- OperationId: int64(req.OperationId),
- OperationName: req.OperationName,
- }
- }
- type EventEnterSlice []*EventEnter
- func (e EventEnterSlice) ToPB(
- penMap map[int32]*Pen,
- breedStatusMap map[pasturePb.BreedStatus_Kind]string,
- cowSourceMap map[pasturePb.CowSource_Kind]string,
- cowTypeMap map[pasturePb.CowType_Kind]string,
- cowKindMap map[pasturePb.CowKind_Kind]string,
- ) []*pasturePb.EventEnterRequest {
- res := make([]*pasturePb.EventEnterRequest, len(e))
- for i, d := range e {
- penName := ""
- if pen, ok := penMap[d.PenId]; ok {
- penName = pen.Name
- }
- res[i] = &pasturePb.EventEnterRequest{
- Id: int32(d.Id),
- EarNumber: d.EarNumber,
- CowId: int32(d.CowId),
- Sex: d.Sex,
- BirthAt: int32(d.BirthAt),
- CowSource: d.CowSource,
- CowSourceName: cowSourceMap[d.CowSource],
- CowType: d.CowType,
- CowTypeName: cowTypeMap[d.CowType],
- BreedStatus: d.BreedStatus,
- BreedStatusName: breedStatusMap[d.BreedStatus],
- Lact: d.Lact,
- PenId: d.PenId,
- PenName: penName,
- CowKind: d.CowKind,
- CowKindName: cowKindMap[d.CowKind],
- FatherNumber: d.FatherNumber,
- MotherNumber: d.MotherNumber,
- MatingAt: int32(d.MatingAt),
- PregnancyCheckAt: int32(d.PregnancyCheckAt),
- DryMilkAt: int32(d.DryMilkAt),
- WeaningAt: int32(d.WeaningAt),
- EstrusAt: int32(d.EstrusAt),
- EnterAt: int32(d.EnterAt),
- Weight: float32(d.Weight) / 100,
- Price: float32(d.Price) / 100,
- Remarks: d.Remarks,
- MessengerId: int32(d.MessengerId),
- MessengerName: d.MessengerName,
- OperationId: int32(d.OperationId),
- OperationName: d.OperationName,
- CreatedAt: int32(d.CreatedAt),
- UpdatedAt: int32(d.UpdatedAt),
- }
- }
- return res
- }
|