package model import ( pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventSemeTime struct { Id int64 `json:"id"` Name string `json:"name"` WeekType pasturePb.Week_Kind `json:"week_type"` CowType pasturePb.CowType_Kind `json:"cow_type"` IsShow pasturePb.IsShow_Kind `json:"is_show"` IsDelete pasturePb.IsShow_Kind `json:"is_delete"` PostpartumDays int32 `json:"postpartum_days"` Remarks string `json:"remarks"` OperationId int64 `json:"operation_id"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func (e *EventSemeTime) TableName() string { return "event_seme_time" } func NewEventSemeTime(currentUser *SystemUser, req *pasturePb.SemeTimeRequest) *EventSemeTime { return &EventSemeTime{ Name: req.Form.Name, WeekType: req.Form.WeekType, CowType: req.Form.CowType, IsShow: pasturePb.IsShow_Ok, IsDelete: pasturePb.IsShow_Ok, PostpartumDays: req.Form.PostpartumDays, Remarks: req.Form.Remarks, OperationId: currentUser.Id, } } type EventSemeTimeSlice []*EventSemeTime func (e EventSemeTimeSlice) ToPB( weekMap map[pasturePb.Week_Kind]string, cowTypeMap map[pasturePb.CowType_Kind]string, systemUserList []*SystemUser, ) []*pasturePb.SearchSemeTimeList { res := make([]*pasturePb.SearchSemeTimeList, len(e)) for i, v := range e { operationName := "" for _, u := range systemUserList { if u.Id != v.OperationId { continue } operationName = u.Name } res[i] = &pasturePb.SearchSemeTimeList{ Id: int32(v.Id), Name: v.Name, WeekType: v.WeekType, WeekName: weekMap[v.WeekType], CowType: v.CowType, CowTypeName: cowTypeMap[v.CowType], IsShow: v.IsShow, PostpartumDays: v.PostpartumDays, Remarks: v.Remarks, OperationId: int32(v.OperationId), OperationName: operationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return res }