package model import ( "encoding/json" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type SameTime struct { Id int64 `json:"id"` Name string `json:"name"` WeekType pasturePb.Week_Kind `json:"weekType"` CowType pasturePb.CowType_Kind `json:"cowType"` IsShow pasturePb.IsShow_Kind `json:"isShow"` IsDelete pasturePb.IsShow_Kind `json:"isDelete"` PostpartumDaysStart int32 `json:"postpartumDaysStart"` PostpartumDaysEnd int32 `json:"postpartumDaysEnd"` SameTimeDetails string `json:"sameTimeDetails"` Remarks string `json:"remarks"` OperationId int64 `json:"operationId"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *SameTime) TableName() string { return "same_time" } func NewSameTime(currentUser *SystemUser, req *pasturePb.SearchSameTimeList) *SameTime { sameTimeDetails, _ := json.Marshal(req.CollateNodes) return &SameTime{ Name: req.Name, WeekType: req.WeekType, CowType: req.CowType, IsShow: pasturePb.IsShow_Ok, IsDelete: pasturePb.IsShow_Ok, PostpartumDaysStart: req.PostpartumDaysStart, PostpartumDaysEnd: req.PostpartumDaysEnd, SameTimeDetails: string(sameTimeDetails), Remarks: req.Remarks, OperationId: currentUser.Id, } } type SameTimeSlice []*SameTime func (e SameTimeSlice) ToPB( weekMap map[pasturePb.Week_Kind]string, cowTypeMap map[pasturePb.CowType_Kind]string, systemUserList []*SystemUser, ) []*pasturePb.SearchSameTimeList { res := make([]*pasturePb.SearchSameTimeList, len(e)) for i, v := range e { operationName := "" for _, u := range systemUserList { if u.Id != v.OperationId { continue } operationName = u.Name } res[i] = &pasturePb.SearchSameTimeList{ Id: int32(v.Id), Name: v.Name, WeekType: v.WeekType, WeekName: weekMap[v.WeekType], CowType: v.CowType, CowTypeName: cowTypeMap[v.CowType], IsShow: v.IsShow, PostpartumDaysStart: v.PostpartumDaysStart, PostpartumDaysEnd: v.PostpartumDaysEnd, Remarks: v.Remarks, OperationId: int32(v.OperationId), OperationName: operationName, CreatedAt: int32(v.CreatedAt), UpdatedAt: int32(v.UpdatedAt), } } return res }