123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package model
- import (
- "kpt-pasture/util"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type EventPregnantCheck 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"`
- DayAge int32 `json:"dayAge"`
- Lact int8 `json:"lact"`
- MatingAge int32 `json:"matingAge"`
- PlanDay int64 `json:"planDay"`
- RealityDay int64 `json:"realityDay"`
- EndDay int64 `json:"endDay"`
- PregnantCheckName string `json:"pregnantCheckName"`
- PregnantCheckResult pasturePb.PregnantCheckResult_Kind `json:"pregnantCheckResult"`
- PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind `json:"pregnantCheckMethod"`
- BullId string `json:"bullId"`
- Status pasturePb.IsShow_Kind `json:"status"`
- 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 *EventPregnantCheck) TableName() string {
- return "event_pregnant_check"
- }
- func (e *EventPregnantCheck) EventUpdate(
- pregnantCheckAt int64,
- pregnantCheckResult pasturePb.PregnantCheckResult_Kind,
- pregnantCheckMethod pasturePb.PregnantCheckMethod_Kind,
- operationUser, currentUser *SystemUser,
- remarks string,
- ) {
- e.RealityDay = pregnantCheckAt
- e.PregnantCheckResult = pregnantCheckResult
- e.PregnantCheckMethod = pregnantCheckMethod
- e.OperationId = operationUser.Id
- e.OperationName = operationUser.Name
- e.MessageId = currentUser.Id
- e.MessageName = currentUser.Name
- e.Remarks = remarks
- e.Status = pasturePb.IsShow_Ok
- }
- func NewEventPregnantCheck(pastureId int64, cow *Cow, penMap map[int32]*Pen, pregnantCheckName string) *EventPregnantCheck {
- penName := ""
- if pen, ok := penMap[cow.PenId]; ok {
- penName = pen.Name
- }
- return &EventPregnantCheck{
- PastureId: pastureId,
- CowId: cow.Id,
- EarNumber: cow.EarNumber,
- CowType: cow.CowType,
- PenId: cow.PenId,
- PenName: penName,
- DayAge: cow.GetDayAge(),
- Lact: int8(cow.Lact),
- PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutDate2)),
- EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutDate2)),
- PregnantCheckName: pregnantCheckName,
- BullId: cow.LastBullNumber,
- Status: pasturePb.IsShow_No,
- }
- }
- func NewEventPregnantCheckList(pastureId int64, cowList []*Cow, penMap map[int32]*Pen, pregnantCheckName string) []*EventPregnantCheck {
- res := make([]*EventPregnantCheck, len(cowList))
- for i, cow := range cowList {
- if cow.BreedStatus != pasturePb.BreedStatus_Breeding && cow.BreedStatus != pasturePb.BreedStatus_Pregnant {
- continue
- }
- res[i] = NewEventPregnantCheck(pastureId, cow, penMap, pregnantCheckName)
- }
- return res
- }
- type EventPregnantCheck2 struct {
- Cow *Cow
- OperationUser *SystemUser
- CurrentUser *SystemUser
- PregnantCheckAt int64
- PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind
- PregnantCheckResult pasturePb.PregnantCheckResult_Kind
- Remarks string
- }
- func NewEventPregnantCheck2(req *EventPregnantCheck2, penMap map[int32]*Pen) *EventPregnantCheck {
- penName := ""
- if pen, ok := penMap[req.Cow.PenId]; ok {
- penName = pen.Name
- }
- return &EventPregnantCheck{
- CowId: req.Cow.Id,
- CowType: req.Cow.CowType,
- PenId: req.Cow.PenId,
- PenName: penName,
- DayAge: req.Cow.GetDayAge(),
- Lact: int8(req.Cow.Lact),
- PlanDay: req.PregnantCheckAt,
- RealityDay: req.PregnantCheckAt,
- EndDay: req.PregnantCheckAt,
- PregnantCheckResult: req.PregnantCheckResult,
- PregnantCheckMethod: req.PregnantCheckMethod,
- PregnantCheckName: PregnantCheckForFirst,
- BullId: req.Cow.LastBullNumber,
- Status: pasturePb.IsShow_Ok,
- OperationId: req.OperationUser.Id,
- OperationName: req.OperationUser.Name,
- Remarks: req.Remarks,
- MessageId: req.CurrentUser.Id,
- MessageName: req.CurrentUser.Name,
- }
- }
- type EventPregnantCheckSlice []*EventPregnantCheck
- func (e EventPregnantCheckSlice) ToPB(
- pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
- pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
- ) []*pasturePb.SearchPregnantCheckList {
- result := make([]*pasturePb.SearchPregnantCheckList, len(e))
- for i, v := range e {
- result[i] = &pasturePb.SearchPregnantCheckList{
- Id: int32(v.Id),
- CowId: int32(v.CowId),
- DayAge: v.DayAge,
- Lact: int32(v.Lact),
- PregnantCheckAt: int32(v.RealityDay),
- PregnantCheckResult: v.PregnantCheckResult,
- PregnantCheckResultName: pregnantCheckResultMap[v.PregnantCheckResult],
- PregnantCheckMethod: v.PregnantCheckMethod,
- PregnantCheckMethodName: pregnantCheckMethodMap[v.PregnantCheckMethod],
- Remarks: v.Remarks,
- OperationId: int32(v.OperationId),
- OperationName: v.OperationName,
- CreatedAt: int32(v.CreatedAt),
- UpdatedAt: int32(v.UpdatedAt),
- }
- }
- return result
- }
- func (e EventPregnantCheckSlice) ToPB3(
- pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
- pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
- ) []*pasturePb.PregnancyReportTable {
- res := make([]*pasturePb.PregnancyReportTable, len(e))
- for i, v := range e {
- pregnancyCheckName := ""
- if checkName, ok := PregnantCheckNameKeyMap[v.PregnantCheckName]; ok {
- pregnancyCheckName = checkName
- }
- pregnantCheckMethodName := ""
- if checkMethodName, ok := pregnantCheckMethodMap[v.PregnantCheckMethod]; ok {
- pregnantCheckMethodName = checkMethodName
- }
- pregnantCheckResultName := ""
- if checkResultName, ok := pregnantCheckResultMap[v.PregnantCheckResult]; ok {
- pregnantCheckResultName = checkResultName
- }
- res[i] = &pasturePb.PregnancyReportTable{
- Id: int32(v.Id),
- CowId: int32(v.CowId),
- Lact: int32(v.Lact),
- PregnancyCheckName: pregnancyCheckName,
- PregnancyCheckAtFormat: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
- MatingAge: v.MatingAge,
- PregnantCheckMethod: v.PregnantCheckMethod,
- PregnantCheckMethodName: pregnantCheckMethodName,
- PregnantCheckResult: v.PregnantCheckResult,
- PregnantCheckResultName: pregnantCheckResultName,
- OperationName: v.OperationName,
- }
- }
- return res
- }
|