package model import ( "fmt" "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) const ShardTableNumber = 6 type EventCowLog struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` CowId int64 `json:"cowId"` DayAge int32 `json:"dayAge"` Lact int32 `json:"lact"` PenId int32 `json:"penId"` PenName string `json:"penName"` CowType pasturePb.CowType_Kind `json:"cowType"` CowTypeName string `json:"cowTypeName"` EventCategoryKind pasturePb.EventCategory_Kind `json:"eventCategoryId"` EventType pasturePb.EventType_Kind `json:"eventType"` EventTypeName string `json:"eventTypeName"` EventDescription string `json:"eventDescription"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` EventAt int64 `json:"eventAt"` Remarks string `json:"remarks"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *EventCowLog) UnShardTableName() string { return "event_cow_log" } // TableName 表名 func (e *EventCowLog) TableName() string { return fmt.Sprintf("%s_%04d", e.UnShardTableName(), e.CowId%ShardTableNumber) } type EventCowLogModel struct { Cow *Cow EventType pasturePb.EventType_Kind OperationUser *SystemUser CurrentUser *SystemUser EventAt int64 ExposeEstrusType pasturePb.ExposeEstrusType_Kind EventCategoryKind pasturePb.EventCategory_Kind PenName string Remarks string CowTypeName string EventTypeName string Description string } func NewEventCowLog(req *EventCowLogModel) *EventCowLog { operationId := int64(0) operationName := "" if req.OperationUser != nil && req.OperationUser.Id > 0 { operationId = req.OperationUser.Id operationName = req.OperationUser.Name } return &EventCowLog{ PastureId: req.Cow.PastureId, CowId: req.Cow.Id, DayAge: req.Cow.GetDayAge(), Lact: req.Cow.Lact, PenId: req.Cow.PenId, PenName: req.PenName, CowType: req.Cow.CowType, CowTypeName: req.CowTypeName, EventCategoryKind: req.EventCategoryKind, EventType: req.EventType, EventTypeName: req.EventTypeName, EventDescription: req.Description, OperationId: operationId, OperationName: operationName, EventAt: req.EventAt, Remarks: req.Remarks, } } type EventCowLogSlice []*EventCowLog func (e EventCowLogSlice) ToPB(eventCategoryMap map[pasturePb.EventCategory_Kind]string) []*pasturePb.CowEvent { res := make([]*pasturePb.CowEvent, len(e)) for i, v := range e { eventAtFormat := "" if v.EventAt > 0 { eventAtFormat = time.Unix(v.EventAt, 0).Format(LayoutDate2) } res[i] = &pasturePb.CowEvent{ Id: int32(v.Id), PastureId: int32(v.PastureId), CowId: int32(v.CowId), Lact: v.Lact, DayAge: v.DayAge, PenName: v.PenName, CowTypeName: v.CowTypeName, EventTypeName: v.EventTypeName, EventDescription: v.EventDescription, OperationName: v.OperationName, Remarks: v.Remarks, EventAtFormat: eventAtFormat, EventCategoryKind: v.EventCategoryKind, EventCategoryName: eventCategoryMap[v.EventCategoryKind], } } return res }