| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 | package modelimport (	"math"	"time"	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow")type EventEnter struct {	Id               int64                      `json:"id"`	PastureId        int64                      `json:"pastureId"`	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(pastureId int64, cowInfo *Cow, req *pasturePb.EventEnterRequest) *EventEnter {	return &EventEnter{		PastureId:        pastureId,		EarNumber:        cowInfo.EarNumber,		CowId:            cowInfo.Id,		Sex:              cowInfo.Sex,		BirthAt:          cowInfo.BirthAt,		CowSource:        cowInfo.SourceKind,		CowType:          cowInfo.CowType,		BreedStatus:      cowInfo.BreedStatus,		Lact:             cowInfo.Lact,		DayAge:           int32(math.Floor(float64(int32(time.Now().Local().Unix())-req.BirthAt) / 86400)),		PenId:            cowInfo.PenId,		CowKind:          cowInfo.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 * 1000),		Price:            int64(req.Price * 100),		MessengerId:      int64(req.MessengerId),		MessengerName:    req.MessengerName,		OperationId:      int64(req.OperationId),		OperationName:    req.OperationName,		BatchNumber:      req.BatchNumber,	}}type EventEnterSlice []*EventEnterfunc (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) / 1000,			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}type HistoryBatchNumberResponse struct {	Code int32    `json:"code"`	Msg  string   `json:"msg"`	Data []string `json:"data"`}type GenerateBatchNumberResponse struct {	Code int32  `json:"code"`	Msg  string `json:"msg"`	Data string `json:"data"`}
 |