package model import ( "fmt" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) const ShardTableNumber = 6 type EventCowLog struct { Id int64 `json:"id"` 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"` EventType int64 `json:"eventType"` EventTypeName string `json:"eventTypeName"` EventDescription string `json:"eventDescription"` OperationId int64 `json:"operationId"` OperationName string `json:"operationName"` EventAt string `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) } func NewCowEventLog(cow *Cow, penMap map[int32]*Pen, cowType map[pasturePb.CowType_Kind]string, operation *SystemUser) *EventCowLog { penName := "" if pen, ok := penMap[cow.PenId]; ok { penName = pen.Name } return &EventCowLog{ CowId: cow.Id, DayAge: cow.GetDayAge(), Lact: cow.Lact, PenId: cow.PenId, PenName: penName, CowType: cow.CowType, CowTypeName: cowType[cow.CowType], EventType: 0, EventTypeName: "", EventDescription: "", OperationId: operation.Id, OperationName: operation.Name, EventAt: "", Remarks: "", } }