| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 | 
							- package model
 
- import (
 
- 	"kpt-pasture/util"
 
- 	"time"
 
- 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
- )
 
- type EventMating struct {
 
- 	Id                int64                           `json:"id"`
 
- 	PastureId         int64                           `json:"pastureId"`
 
- 	CowId             int64                           `json:"cowId"`
 
- 	EarNumber         string                          `json:"earNumber"`
 
- 	DayAge            int32                           `json:"dayAge"`
 
- 	Lact              int32                           `json:"lact"`
 
- 	PenId             int32                           `json:"penId"`
 
- 	PenName           string                          `json:"penName"`
 
- 	CowType           pasturePb.CowType_Kind          `json:"cowType"`
 
- 	CowKind           pasturePb.CowKind_Kind          `json:"cowKind"`
 
- 	CalvingAge        int32                           `json:"calvingAge"`
 
- 	PlanDay           int64                           `json:"planDay"`
 
- 	EndDay            int64                           `json:"endDay"`
 
- 	CalvingAt         int64                           `json:"calvingAt"`
 
- 	RealityDay        int64                           `json:"realityDay"`
 
- 	Status            pasturePb.IsShow_Kind           `json:"status"`
 
- 	MatingTimes       int32                           `json:"matingTimes"`
 
- 	MatingResult      pasturePb.MatingResult_Kind     `json:"matingResult"`
 
- 	MatingResultAt    int64                           `json:"matingResultAt"`
 
- 	RematingAt        int64                           `json:"rematingAt"`
 
- 	ExposeEstrusType  pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
 
- 	FrozenSemenNumber string                          `json:"frozenSemenNumber"`
 
- 	OperationId       int64                           `json:"operationId"`
 
- 	OperationName     string                          `json:"operationName"`
 
- 	MessageId         int64                           `json:"messageId"`
 
- 	MessageName       string                          `json:"messageName"`
 
- 	Remarks           string                          `json:"remarks"`
 
- 	CreatedAt         int64                           `json:"createdAt"`
 
- 	UpdatedAt         int64                           `json:"updatedAt"`
 
- }
 
- func (e *EventMating) TableName() string {
 
- 	return "event_mating"
 
- }
 
- func (e *EventMating) EventUpdate(cowInfo *Cow, matingAt int64, bullNumber string, isReMating bool, operationUser, currentUser *SystemUser) {
 
- 	e.MatingResult = pasturePb.MatingResult_Unknown
 
- 	e.Status = pasturePb.IsShow_Ok
 
- 	e.RealityDay = matingAt
 
- 	e.FrozenSemenNumber = bullNumber
 
- 	e.OperationName = operationUser.Name
 
- 	e.OperationId = operationUser.Id
 
- 	e.MessageName = currentUser.Name
 
- 	e.MessageId = currentUser.Id
 
- 	if !isReMating {
 
- 		e.MatingTimes += 1
 
- 	}
 
- 	e.DayAge = cowInfo.GetEventDayAge(matingAt)
 
- }
 
- // EventReMatingUpdate 复配更新
 
- func (e *EventMating) EventReMatingUpdate(matingAt int64) {
 
- 	e.MatingResult = pasturePb.MatingResult_ReMatch
 
- 	e.Status = pasturePb.IsShow_Ok
 
- 	e.MatingResultAt = matingAt
 
- 	e.RematingAt = matingAt
 
- }
 
- // EventMatingResultUpdate 配种结果更新
 
- func (e *EventMating) EventMatingResultUpdate(matingResult pasturePb.MatingResult_Kind, resultAt int64) {
 
- 	e.MatingResult = matingResult
 
- 	e.MatingResultAt = resultAt
 
- }
 
- // IsReMating 判断是不是复配
 
- func (e *EventMating) IsReMating(cow *Cow, matingAt int64) bool {
 
- 	lastMatingAt := time.Unix(cow.LastMatingAt, 0).Local()
 
- 	currentMatingAt := time.Unix(matingAt, 0).Local()
 
- 	daysBetween := util.DaysBetween(currentMatingAt.Unix(), lastMatingAt.Unix())
 
- 	if (daysBetween == 1 || daysBetween == 0) && e.Status == pasturePb.IsShow_Ok && e.MatingResult == pasturePb.MatingResult_Unknown {
 
- 		return true
 
- 	}
 
- 	return false
 
- }
 
- // IsMatingUpdate 判断是不是更新配种信息
 
- func (e *EventMating) IsMatingUpdate() bool {
 
- 	if e.Status == pasturePb.IsShow_No && e.MatingResult == pasturePb.MatingResult_Unknown {
 
- 		return true
 
- 	}
 
- 	return false
 
- }
 
- // IsEmptyMating 判断上次配种结果是不是空怀
 
- func (e *EventMating) IsEmptyMating(cow *Cow, matingAt int64) bool {
 
- 	lastMatingAt := time.Unix(cow.LastMatingAt, 0).Local()
 
- 	currentMatingAt := time.Unix(matingAt, 0).Local()
 
- 	daysBetween := util.DaysBetween(currentMatingAt.Unix(), lastMatingAt.Unix())
 
- 	if (e.MatingResult == pasturePb.MatingResult_Unknown || e.MatingResult == pasturePb.MatingResult_ReMatch) && daysBetween >= 2 {
 
- 		return true
 
- 	}
 
- 	return false
 
- }
 
- func NewEventMating(pastureId int64, cow *Cow, planDay int64, exposeEstrusType pasturePb.ExposeEstrusType_Kind) *EventMating {
 
- 	return &EventMating{
 
- 		PastureId:        pastureId,
 
- 		CowId:            cow.Id,
 
- 		EarNumber:        cow.EarNumber,
 
- 		Lact:             cow.Lact,
 
- 		PenId:            cow.PenId,
 
- 		PenName:          cow.PenName,
 
- 		CowType:          cow.CowType,
 
- 		CowKind:          cow.CowKind,
 
- 		DayAge:           cow.DayAge,
 
- 		CalvingAt:        cow.LastMatingAt,
 
- 		PlanDay:          planDay,
 
- 		EndDay:           planDay + 86399,
 
- 		MatingResult:     pasturePb.MatingResult_Unknown,
 
- 		ExposeEstrusType: exposeEstrusType,
 
- 		Status:           pasturePb.IsShow_No,
 
- 	}
 
- }
 
- // NewEventMatingNaturalEstrus 自然发情的牛只
 
- func NewEventMatingNaturalEstrus(pastureId int64, item *EventMatingCheckBatchModel, currentUser *SystemUser) *EventMating {
 
- 	return &EventMating{
 
- 		PastureId:         pastureId,
 
- 		CowId:             item.Cow.Id,
 
- 		EarNumber:         item.Cow.EarNumber,
 
- 		Lact:              item.Cow.Lact,
 
- 		DayAge:            item.Cow.GetDayAge(),
 
- 		CowType:           item.Cow.CowType,
 
- 		CowKind:           item.Cow.CowKind,
 
- 		CalvingAt:         item.Cow.LastMatingAt,
 
- 		PlanDay:           item.MatingAt,
 
- 		RealityDay:        item.MatingAt,
 
- 		EndDay:            item.MatingAt,
 
- 		MatingResult:      pasturePb.MatingResult_Unknown,
 
- 		ExposeEstrusType:  pasturePb.ExposeEstrusType_Natural_Estrus,
 
- 		Status:            pasturePb.IsShow_Ok,
 
- 		OperationId:       item.OperationUser.Id,
 
- 		OperationName:     item.OperationUser.Name,
 
- 		MessageId:         currentUser.Id,
 
- 		MessageName:       currentUser.Name,
 
- 		FrozenSemenNumber: item.FrozenSemen.BullId,
 
- 		Remarks:           item.Remarks,
 
- 		MatingTimes:       item.Cow.MatingTimes + 1,
 
- 	}
 
- }
 
- // NewEventMatingList 同期配种
 
- func NewEventMatingList(pastureId int64, cowList []*Cow, planDay int64, exposeEstrusType pasturePb.ExposeEstrusType_Kind) []*EventMating {
 
- 	var matingList []*EventMating
 
- 	for _, cow := range cowList {
 
- 		matingList = append(matingList, NewEventMating(pastureId, cow, planDay, exposeEstrusType))
 
- 	}
 
- 	return matingList
 
- }
 
- type EventMatingSlice []*EventMating
 
- func (e EventMatingSlice) ToPB(exposeEstrusTypeMap map[pasturePb.ExposeEstrusType_Kind]string) []*pasturePb.SearchMatingList {
 
- 	res := make([]*pasturePb.SearchMatingList, len(e))
 
- 	for i, v := range e {
 
- 		res[i] = &pasturePb.SearchMatingList{
 
- 			Id:                   int32(v.Id),
 
- 			CowId:                int32(v.CowId),
 
- 			EarNumber:            v.EarNumber,
 
- 			DayAge:               v.DayAge,
 
- 			Lact:                 v.Lact,
 
- 			CalvingAge:           v.CalvingAge,
 
- 			PlanDay:              time.Unix(v.PlanDay, 0).Local().Format(LayoutDate2),
 
- 			RealityDay:           time.Unix(v.RealityDay, 0).Local().Format(LayoutDate2),
 
- 			ExposeEstrusType:     v.ExposeEstrusType,
 
- 			ExposeEstrusTypeName: exposeEstrusTypeMap[v.ExposeEstrusType],
 
- 			FrozenSemenNumber:    v.FrozenSemenNumber,
 
- 			Remarks:              v.Remarks,
 
- 			OperationId:          int32(v.OperationId),
 
- 			OperationName:        v.OperationName,
 
- 			CreatedAt:            int32(v.CreatedAt),
 
- 			UpdatedAt:            int32(v.UpdatedAt),
 
- 		}
 
- 	}
 
- 	return res
 
- }
 
- func (e EventMatingSlice) ToPB2() []*pasturePb.CowList {
 
- 	res := make([]*pasturePb.CowList, len(e))
 
- 	for i, v := range e {
 
- 		calvingAt, matingAtFormat := "", ""
 
- 		if v.CalvingAt > 0 {
 
- 			calvingAt = time.Unix(v.CalvingAt, 0).Local().Format(LayoutDate2)
 
- 		}
 
- 		if v.RealityDay > 0 {
 
- 			matingAtFormat = time.Unix(v.RealityDay, 0).Local().Format(LayoutDate2)
 
- 		}
 
- 		res[i] = &pasturePb.CowList{
 
- 			CowId:           int32(v.CowId),
 
- 			DayAge:          int32(v.DayAge),
 
- 			CalvingAge:      v.CalvingAge,
 
- 			MatingAtFormat:  matingAtFormat,
 
- 			CalvingAtFormat: calvingAt,
 
- 			Lact:            int32(v.Lact),
 
- 		}
 
- 	}
 
- 	return res
 
- }
 
- func (e EventMatingSlice) ToPB3(isMating bool, cowTypeMap map[pasturePb.CowType_Kind]string) []*pasturePb.TwentyOnePregnantItems {
 
- 	res := make([]*pasturePb.TwentyOnePregnantItems, 0)
 
- 	for _, v := range e {
 
- 		if !isMating {
 
- 			continue
 
- 		}
 
- 		res = append(res, &pasturePb.TwentyOnePregnantItems{
 
- 			CowId:       int32(v.CowId),
 
- 			EarNumber:   v.EarNumber,
 
- 			CowTypeName: cowTypeMap[v.CowType],
 
- 			Lact:        v.Lact,
 
- 		})
 
- 	}
 
- 	return res
 
- }
 
- func (e EventMatingSlice) ToPB4(cowTypeMap map[pasturePb.CowType_Kind]string) []*pasturePb.TwentyOnePregnantItems {
 
- 	res := make([]*pasturePb.TwentyOnePregnantItems, 0)
 
- 	for _, v := range e {
 
- 		if v.MatingResult != pasturePb.MatingResult_Abort {
 
- 			continue
 
- 		}
 
- 		res = append(res, &pasturePb.TwentyOnePregnantItems{
 
- 			CowId:       int32(v.CowId),
 
- 			EarNumber:   v.EarNumber,
 
- 			CowTypeName: cowTypeMap[v.CowType],
 
- 			Lact:        v.Lact,
 
- 		})
 
- 	}
 
- 	return res
 
- }
 
- type CowMatingBody struct {
 
- 	Id              int64                      `json:"id"`
 
- 	CowId           int64                      `json:"cowId"`
 
- 	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"`
 
- }
 
- type CowMatingBodySlice []*CowMatingBody
 
- func (s CowMatingBodySlice) ToPB(
 
- 	cowTypeMap map[pasturePb.CowType_Kind]string,
 
- 	breedStatusMap map[pasturePb.BreedStatus_Kind]string,
 
- 	penMap map[int32]*Pen,
 
- ) []*CowMatingBody {
 
- 	res := make([]*CowMatingBody, len(s))
 
- 	for i, v := range s {
 
- 		res[i] = &CowMatingBody{
 
- 			Id:              v.Id,
 
- 			CowId:           v.CowId,
 
- 			CowType:         v.CowType,
 
- 			CowTypeName:     cowTypeMap[v.CowType],
 
- 			BreedStatus:     v.BreedStatus,
 
- 			BreedStatusName: breedStatusMap[v.BreedStatus],
 
- 			PenName:         penMap[v.PenId].Name,
 
- 			PenId:           v.PenId,
 
- 			Lact:            v.Lact,
 
- 			CalvingAge:      v.CalvingAge,
 
- 			AbortionAge:     v.AbortionAge,
 
- 			DayAge:          v.DayAge,
 
- 			Status:          v.Status,
 
- 		}
 
- 	}
 
- 	return res
 
- }
 
- type MatingTimelyChart struct {
 
- 	CalvingAge int32  `json:"calvingAge"`
 
- 	RealityDay string `json:"realityDay"`
 
- 	LactGroup  string `json:"lactGroup"`
 
- }
 
- type MatingTimelyResponse struct {
 
- 	Code int32             `json:"code"`
 
- 	Msg  string            `json:"msg"`
 
- 	Data *MatingTimelyData `json:"data"`
 
- }
 
- type MatingTimelyData struct {
 
- 	CowList []*pasturePb.CowList `json:"cowList"`
 
- 	Chart   *CowMatingChart      `json:"chart"`
 
- }
 
- type CowMatingChart struct {
 
- 	Lact0 [][]string `json:"lact0"`
 
- 	Lact1 [][]string `json:"lact1"`
 
- 	Lact2 [][]string `json:"lact2"`
 
- 	Lact3 [][]string `json:"lact3"`
 
- }
 
- // MultiFactorPregnancyRateResponse 多维度受胎率
 
- type MultiFactorPregnancyRateResponse struct {
 
- 	Code int32                         `json:"code"`
 
- 	Msg  string                        `json:"msg"`
 
- 	Data *MultiFactorPregnancyRateData `json:"data"`
 
- }
 
- // MultiFactorPregnancyRateList 多维度受胎率分析
 
- type MultiFactorPregnancyRateList struct {
 
- 	StatisticMethod1   string  `json:"statisticMethod1"`   // 统计方式名称1 (月度、品种)
 
- 	StatisticMethod2   string  `json:"statisticMethod2"`   // 统计方式名称2 (月度、品种)
 
- 	PregnantRate       float32 `json:"pregnantRate"`       // 受胎率%(怀孕数 / 怀孕数 + 空怀数)
 
- 	PregnantCount      int32   `json:"pregnantCount"`      // 怀孕总数
 
- 	EmptyPregnantCount int32   `json:"emptyPregnantCount"` // 空怀数
 
- 	OtherCount         int32   `json:"otherCount"`         // 其他数 (配种后结果未知的个数,小于等于三次配种后,尚未孕检已经淘汰的个数)
 
- 	AbortionCount      int32   `json:"abortionCount"`      // 流产数 (已经怀孕后流产的个数)
 
- 	TotalCount         int32   `json:"totalCount"`         // 合计( 怀孕总数+空怀数+其他数)
 
- 	SpcRate            float32 `json:"spcRate"`            // spc(1 / 受胎率)
 
- 	Months             string  `json:"months"`             // 月份
 
- 	OperationName      string  `json:"operationName"`      // 配种员名称
 
- 	Bull               string  `json:"bull"`               // 公牛
 
- 	Lact               string  `json:"lact"`               // 胎次
 
- 	MatingTimes        string  `json:"matingTimes"`        // 配次
 
- 	ExposeEstrusType   string  `json:"exposeEstrusType"`   // 发情揭发方式
 
- 	Week               string  `json:"week"`               // 周
 
- }
 
- type MultiFactorPregnancyRateData struct {
 
- 	Total    int32                           `json:"total"`
 
- 	PageSize int32                           `json:"pageSize"`
 
- 	Page     int32                           `json:"page"`
 
- 	List     []*MultiFactorPregnancyRateList `json:"list"`
 
- 	Chart    *MultiFactorPregnancyRateChart  `json:"chart"`
 
- }
 
- type MultiFactorPregnancyRateChart struct {
 
- 	Header          []string                     `json:"header"` // 标题头
 
- 	PregnantRateMap map[string]map[string]string `json:"pregnantRateMap"`
 
- 	KepMap          []string                     `json:"kepMap"`
 
- }
 
- // EventMatingCheckBatchModel 批量配种
 
- type EventMatingCheckBatchModel struct {
 
- 	Cow              *Cow
 
- 	FrozenSemen      *FrozenSemen
 
- 	OperationUser    *SystemUser
 
- 	MatingAt         int64
 
- 	FrozenSemenCount int32
 
- 	Remarks          string
 
- 	ExposeEstrusType pasturePb.ExposeEstrusType_Kind
 
- }
 
 
  |