123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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"`
- CowId int64 `json:"cowId"`
- 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 NewEventPregnantCheck(cow *Cow, penMap map[int32]*Pen, pregnantCheckName string) *EventPregnantCheck {
- return &EventPregnantCheck{
- CowId: cow.Id,
- CowType: cow.CowType,
- PenId: cow.PenId,
- PenName: penMap[cow.PenId].Name,
- 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(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 {
- continue
- }
- res[i] = NewEventPregnantCheck(cow, penMap, pregnantCheckName)
- }
- return res
- }
- 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.PlanDay),
- 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 := PregnantCheckNameMap[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
- }
|