package model import ( "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type NeckRingLog struct { Id int64 `json:"id"` Number string `json:"number"` CowId int64 `json:"cowId"` WearAt int64 `json:"wearAt"` UnbindAt int64 `json:"unbindAt"` Status pasturePb.NeckRingStatus_Kind `json:"status"` ErrorReason string `json:"errorReason"` OperationId int32 `json:"operationId"` OperationName string `json:"operationName"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (n *NeckRingLog) TableName() string { return "neck_ring_log" } func NewNeckRingLog(number string, cowId int64, currentUser *SystemUser) *NeckRingLog { return &NeckRingLog{ Number: number, CowId: cowId, WearAt: time.Now().Unix(), Status: pasturePb.NeckRingStatus_Bind, OperationId: int32(currentUser.Id), OperationName: currentUser.Name, } } func NewNeckRingLogList(req []*pasturePb.NeckRingCreateItem, currentUser *SystemUser) []*NeckRingLog { res := make([]*NeckRingLog, len(req)) for i, v := range req { res[i] = NewNeckRingLog(v.Number, int64(v.CowId), currentUser) } return res } type NeckRingLogSlice []*NeckRingLog func (n NeckRingLogSlice) ToPB(neckRingStatus map[pasturePb.NeckRingStatus_Kind]string) []*pasturePb.SearchNeckRingList { res := make([]*pasturePb.SearchNeckRingList, len(n)) for i, v := range n { res[i] = &pasturePb.SearchNeckRingList{ Id: int32(v.Id), Number: v.Number, CowId: int32(v.CowId), WearAtFormat: time.Unix(v.WearAt, 0).Format(LayoutDate2), WearDays: int32(time.Now().Sub(time.Unix(v.WearAt, 0)).Hours() / 24), Status: v.Status, StatusName: neckRingStatus[v.Status], ErrorReason: v.ErrorReason, } } return res }