| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 | package modelimport (	"kpt-pasture/util"	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow")type EventCalving struct {	Id                   int64                         `json:"id"`	PastureId            int64                         `json:"pastureId"`	CowId                int64                         `json:"cowId"`	CowType              pasturePb.CowType_Kind        `json:"cowType"`	CowKind              pasturePb.CowKind_Kind        `json:"cowKind"`	EarNumber            string                        `json:"earNumber"`	Lact                 int32                         `json:"lact"`	DayAge               int32                         `json:"dayAge"`	PlanDay              int64                         `json:"planDay"`	RealityDay           int64                         `json:"realityDay"`	EndDay               int64                         `json:"endDay"`	Status               pasturePb.IsShow_Kind         `json:"status"`	PenId                int32                         `json:"penId"`	ChildNumber          int32                         `json:"childNumber"`	BullNumber           string                        `json:"bullNumber"`	PregnancyAge         int32                         `json:"pregnancyAge"`	CalvingLevel         pasturePb.CalvingLevel_Kind   `json:"calvingLevel"`	OperationId          int64                         `json:"operationId"`	OperationName        string                        `json:"operationName"`	MessageId            int64                         `json:"messageId"`	MessageName          string                        `json:"messageName"`	DystociaReason       pasturePb.DystociaReason_Kind `json:"dystociaReason"`	IsInducingChildbirth pasturePb.IsShow_Kind         `json:"isInducingChildbirth"`	Remarks              string                        `json:"remarks"`	CreatedAt            int64                         `json:"created_at"`	UpdatedAt            int64                         `json:"updated_at"`}func (e *EventCalving) TableName() string {	return "event_calving"}func (e *EventCalving) EventUpdate(operationUser, currentUser *SystemUser, req *pasturePb.EventCalving, cow *Cow) {	if operationUser != nil {		e.OperationId = operationUser.Id		e.OperationName = operationUser.Name	}	e.RealityDay = int64(req.CalvingAt)	e.DayAge = cow.GetEventDayAge(int64(req.CalvingAt))	e.PregnancyAge = cow.GetDaysPregnant()	e.CalvingLevel = req.CalvingLevel	e.BullNumber = cow.LastBullNumber	e.ChildNumber = req.ChildNumber	e.Status = pasturePb.IsShow_Ok	e.PenId = cow.PenId	e.IsInducingChildbirth = req.IsInducingChildbirth	e.Remarks = req.Remarks	e.DystociaReason = req.DystociaReason	e.MessageId = currentUser.Id	e.MessageName = currentUser.Name}func NewEventCalving(pastureId int64, cow *Cow, startDay, endDay string) *EventCalving {	return &EventCalving{		PastureId:  pastureId,		CowId:      cow.Id,		Lact:       cow.Lact,		CowKind:    cow.CowKind,		CowType:    cow.CowType,		EarNumber:  cow.EarNumber,		PenId:      cow.PenId,		BullNumber: cow.LastBullNumber,		Status:     pasturePb.IsShow_No,		PlanDay:    util.TimeParseLocalUnix(startDay),		EndDay:     util.TimeParseLocalEndUnix(endDay),	}}func NewEventCalvingList(pastureId int64, cowList []*Cow, startDay, endDay string) []*EventCalving {	eventCalvingList := make([]*EventCalving, 0)	for _, cow := range cowList {		eventCalvingList = append(eventCalvingList, NewEventCalving(pastureId, cow, startDay, endDay))	}	return eventCalvingList}type EventCalvingList struct {	EventCalving	PenName         string `json:"pen_name"`	StaffMemberName string `json:"staff_member_name"`}type EventCalvingListSlice []*EventCalvingListfunc (e EventCalvingListSlice) ToPB(req []*CalvingCalf) []*pasturePb.LavingList {	var list []*pasturePb.LavingList	for _, item := range e {		CalfItemList := make([]*pasturePb.CalfItem, 0)		for _, v := range req {			if v.CalvingId != item.Id {				continue			}			CalfItemList = append(CalfItemList, &pasturePb.CalfItem{				EarNumber:  v.EarNumber,				Sex:        v.Sex,				Weight:     float32(v.BirthWeight) / 1000,				IsAdoption: v.IsAdoption,				IsLive:     v.IsLive,				CreatedAt:  int32(v.CreatedAt),				UpdatedAt:  int32(v.UpdatedAt),				PenId:      v.PenId,				Remarks:    v.Remarks,				MotherId:   int32(v.MotherId),				Id:         int32(v.Id),			})		}		list = append(list, &pasturePb.LavingList{			Id:             int32(item.Id),			CowId:          int32(item.CowId),			Lact:           item.Lact,			PenId:          item.PenId,			PenName:        item.PenName,			CalvingAt:      int32(item.PlanDay),			ChildNumber:    int32(item.ChildNumber),			DaysPregnant:   int32(item.PregnancyAge),			OperationId:    int32(item.OperationId),			OperationName:  item.OperationName,			CalvingLevel:   item.CalvingLevel,			Remarks:        item.Remarks,			CreatedAt:      int32(item.CreatedAt),			UpdatedAt:      int32(item.UpdatedAt),			DystociaReason: item.DystociaReason,			CalfItemList:   CalfItemList,		})	}	return list}type EventCalvingSlice []*EventCalvingfunc (e EventCalvingSlice) ToPB() []*pasturePb.CalvingReportTable {	res := make([]*pasturePb.CalvingReportTable, len(e))	for i, v := range e {		res[i] = &pasturePb.CalvingReportTable{			StatisticMethod:     v.Remarks,			Twins:               0,			TwinsRate:           0,			Bulls:               0,			BullsRate:           0,			Cows:                0,			CowsRate:            0,			SurviveCount:        0,			SurviveRate:         0,			DieCount:            0,			DieRate:             0,			BullsDieCount:       0,			BullsDieRate:        0,			CowsDieCount:        0,			CowsDieRate:         0,			AdoptCount:          0,			AdoptRate:           0,			PrematureLaborCount: 0,			PrematureLaborRate:  0,			LateLaborCount:      0,			LateLaborRate:       0,			NormalLaborCount:    0,		}	}	return res}
 |