| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 | package modelimport (	"time"	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow")type EventCowSameTime struct {	Id            int64                       `json:"id"`	PastureId     int64                       `json:"pastureId"`	CowId         int64                       `json:"cowId"`	EarNumber     string                      `json:"earNumber"`	CowType       pasturePb.CowType_Kind      `json:"cowType"`	PenId         int32                       `json:"penId"`	PenName       string                      `json:"penName"`	Lact          int32                       `json:"lact"`	SameTimeId    int64                       `json:"sameTimeId"`	SameTimeName  string                      `json:"sameTimeName"`	SameTimeType  pasturePb.SameTimeType_Kind `json:"sameTimeType"`	PlanDay       int64                       `json:"planDay"`	EndDay        int64                       `json:"endDay"`	RealityDay    int64                       `json:"realityDay"`	Status        pasturePb.IsShow_Kind       `json:"status"`	DrugsId       int64                       `json:"drugsId"`	Unit          pasturePb.Unit_Kind         `json:"unit"`	Usage         float32                     `json:"usage"`	Remarks       string                      `json:"remarks"`	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 (s *EventCowSameTime) TableName() string {	return "event_cow_same_time"}func (s *EventCowSameTime) EventUpdate(drugs *Drugs, usage float32, realityAt int64, remarks string, currentUser, operationUser *SystemUser) {	s.Status = pasturePb.IsShow_Ok	s.DrugsId = drugs.Id	s.Unit = drugs.Unit	s.Usage = usage	s.Remarks = remarks	s.OperationId = operationUser.Id	s.OperationName = operationUser.Name	s.MessageId = currentUser.Id	s.MessageName = currentUser.Name	s.RealityDay = realityAt}func NewEventCowSameTime(pastureId int64, cow *Cow, planTime int64, sameTime *SameTime, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime {	return &EventCowSameTime{		PastureId:    pastureId,		CowId:        cow.Id,		EarNumber:    cow.EarNumber,		Lact:         cow.Lact,		CowType:      cow.CowType,		PenId:        cow.PenId,		SameTimeId:   sameTime.Id,		SameTimeName: sameTime.Name,		SameTimeType: sameTimeType,		Status:       pasturePb.IsShow_No,		PlanDay:      planTime,		EndDay:       planTime + 86399,	}}func NewEventCowSameTimeList(pastureId int64, cowList []*Cow, sameTime *SameTime, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime {	res := make([]*EventCowSameTime, len(cowList))	for i, cow := range cowList {		res[i] = NewEventCowSameTime(pastureId, cow, planTime, sameTime, sameTimeType)	}	return res}type SameTimeItemBody struct {	Id              int64                       `json:"id"`	CowId           int64                       `json:"cowId"`	EarNumber       string                      `json:"earNumber"`	BreedStatus     pasturePb.BreedStatus_Kind  `json:"breedStatus"`	BreedStatusName string                      `json:"breedStatusName"`	CowType         pasturePb.CowType_Kind      `json:"cowType"`	CowTypeName     string                      `json:"cowTypeName"`	PenId           int32                       `json:"penId"`	PenName         string                      `json:"penName"`	Lact            int32                       `json:"lact"`	CalvingAge      int32                       `json:"calvingAge"`	AbortionAge     int32                       `json:"abortionAge"`	DayAge          int32                       `json:"dayAge"`	Status          pasturePb.IsShow_Kind       `json:"status"`	SameTimeType    pasturePb.SameTimeType_Kind `json:"sameTimeType"`	LastCalvingAt   int64                       `json:"lastCalvingAt"`	LastAbortionAt  int64                       `json:"lastAbortionAt"`	MatingTimes     int32                       `json:"matingTimes"`	SameTimeName    string                      `json:"sameTimeName"`	PlanDay         int64                       `json:"planDay"`}type SameTimeBodySlice []*SameTimeItemBodyfunc (s SameTimeBodySlice) ToPB(	breedStatusMap map[pasturePb.BreedStatus_Kind]string,	sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string,) []*pasturePb.SameTimeItems {	res := make([]*pasturePb.SameTimeItems, len(s))	for i, v := range s {		calvingAtFormat, abortionAtFormat, playDayAtFormat := "", "", ""		if v.LastCalvingAt > 0 {			calvingAtFormat = time.Unix(v.LastCalvingAt, 0).Local().Format(LayoutDate2)		}		if v.LastAbortionAt > 0 {			abortionAtFormat = time.Unix(v.LastAbortionAt, 0).Local().Format(LayoutDate2)		}		if v.PlanDay > 0 {			playDayAtFormat = time.Unix(v.PlanDay, 0).Local().Format(LayoutDate2)		}		breedStatusName := ""		if bm, ok := breedStatusMap[v.BreedStatus]; ok {			breedStatusName = bm		}		sameTimeTypeName := ""		if sm, ok := sameTimeTypeMap[v.SameTimeType]; ok {			sameTimeTypeName = sm		}		res[i] = &pasturePb.SameTimeItems{			Id:               int32(v.Id),			CowId:            int32(v.CowId),			EarNumber:        v.EarNumber,			BreedStatus:      v.BreedStatus,			BreedStatusName:  breedStatusName,			PenName:          v.PenName,			PenId:            v.PenId,			Lact:             v.Lact,			CalvingAge:       v.CalvingAge,			AbortionAge:      v.AbortionAge,			DayAge:           v.DayAge,			Status:           v.Status,			SameTimeTypeName: sameTimeTypeName,			SameTimeType:     v.SameTimeType,			CalvingAtFormat:  calvingAtFormat,			AbortionAtFormat: abortionAtFormat,			MatingTimes:      v.MatingTimes,			SameTimeName:     v.SameTimeName,			PlanDay:          playDayAtFormat,		}	}	return res}type EventCowSameTimeSlice []*EventCowSameTimefunc (s EventCowSameTimeSlice) ToPB(sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string) []*pasturePb.EventSameTime {	res := make([]*pasturePb.EventSameTime, len(s))	for i, v := range s {		res[i] = &pasturePb.EventSameTime{			CowId:            int32(v.CowId),			PenId:            v.PenId,			DrugsId:          int32(v.DrugsId),			Usage:            v.Usage,			Lact:             v.Lact,			SameTimeId:       int32(v.SameTimeId),			SameTimeType:     v.SameTimeType,			SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],		}	}	return res}
 |