package model import ( operationPb "kpt-tmr-group/proto/go/backend/operation" "time" ) type ForageCategory struct { Id int64 `json:"id"` ParentId operationPb.ForageCategoryParent_Kind `json:"parent_id"` ParentName string `json:"parent_name"` PastureId int64 `json:"pasture_id"` PastureName string `json:"pasture_name"` DataId int64 `json:"data_id"` Name string `json:"name"` Number string `json:"number"` IsShow operationPb.IsShow_Kind `json:"is_show"` IsDelete operationPb.IsShow_Kind `json:"is_delete"` DataSource operationPb.DataSource_Kind `json:"data_source"` Remarks string `json:"remarks"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func (s *ForageCategory) TableName() string { return "forage_category" } func NewForageCategory(req *operationPb.AddForageCategoryRequest) *ForageCategory { return &ForageCategory{ ParentId: req.ParentId, ParentName: req.ParentName, Name: req.Name, Number: req.Number, IsShow: operationPb.IsShow_OK, IsDelete: operationPb.IsShow_OK, DataSource: operationPb.DataSource_BACKGROUND_ADD, Remarks: "集团新增数据", } } type ForageCategorySlice []*ForageCategory func (f ForageCategorySlice) ToPB() []*operationPb.AddForageCategoryRequest { res := make([]*operationPb.AddForageCategoryRequest, len(f)) for i, v := range f { res[i] = &operationPb.AddForageCategoryRequest{ Id: uint32(v.Id), Name: v.Name, ParentId: v.ParentId, ParentName: v.ParentName, Number: v.Number, IsShow: v.IsShow, CreatedAt: uint32(v.CreatedAt), CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime), } } return res } func (f *ForageCategory) ToPb() *operationPb.AddForageCategoryRequest { return &operationPb.AddForageCategoryRequest{ Id: uint32(f.Id), Name: f.Name, Number: f.Number, ParentId: f.ParentId, ParentName: f.ParentName, IsShow: f.IsShow, CreatedAt: uint32(f.CreatedAt), } } func NewPastureForageCategory(req *operationPb.CategorySyncRequest, pastureDetail *GroupPasture) *ForageCategory { return &ForageCategory{ ParentId: operationPb.ForageCategoryParent_Kind(req.ParentId), ParentName: req.ParentName, PastureId: int64(req.PastureId), PastureName: pastureDetail.Name, Name: req.Name, Number: req.Number, IsShow: req.IsShow, IsDelete: operationPb.IsShow_NO, DataSource: operationPb.DataSource_FROM_PASTURE, Remarks: "牧场端数据同步", } }