package model import ( operationPb "kpt-tmr-group/proto/go/backend/operation" "time" ) type Forage struct { Id int64 `json:"int_64"` Name string `json:"name"` CategoryId int64 `json:"category_id"` MaterialType int64 `json:"material_type"` UniqueEncode string `json:"unique_encode"` ForageSourceId operationPb.ForageSource_Kind `json:"forage_source_id"` PlanTypeId operationPb.ForagePlanType_Kind `json:"plan_type_id"` SmallMaterialScale string `json:"small_material_scale"` AllowError int64 `json:"allow_error"` PackageWeight int64 `json:"package_weight"` Price int64 `json:"price"` JumpWeight int64 `json:"jump_weight"` JumpDelay operationPb.JumpDelaType_Kind `json:"jump_delay"` ConfirmStart operationPb.IsShow_Kind `json:"confirm_start"` RelayLocations int64 `json:"relay_locations"` Jmp operationPb.IsShow_Kind `json:"jmp"` DataSource operationPb.DataSource_Kind `json:"data_source"` Backup1 string `json:"backup1"` Backup2 string `json:"backup2"` Backup3 string `json:"backup3"` IsShow operationPb.IsShow_Kind `json:"is_show"` IsDelete operationPb.IsShow_Kind `json:"is_delete"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } func (c *Forage) TableName() string { return "forage" } func NewForage(req *operationPb.AddForageRequest) *Forage { return &Forage{ Name: req.Name, CategoryId: int64(req.CategoryId), UniqueEncode: req.UniqueEncode, ForageSourceId: req.ForageSourceId, PlanTypeId: req.PlanTypeId, SmallMaterialScale: req.SmallMaterialScale, AllowError: int64(req.AllowError), PackageWeight: int64(req.PackageWeight), Price: int64(req.Price), JumpWeight: int64(req.JumpWeight), JumpDelay: req.JumpDelay, ConfirmStart: req.ConfirmStart, RelayLocations: int64(req.RelayLocations), IsShow: operationPb.IsShow_OK, IsDelete: operationPb.IsShow_OK, DataSource: operationPb.DataSource_BACKGROUND_ADD, Jmp: req.Jmp, Backup1: req.Backup1, Backup2: req.Backup2, Backup3: req.Backup3, } } type ForageSlice []*Forage func (f ForageSlice) ToPB() []*operationPb.AddForageRequest { res := make([]*operationPb.AddForageRequest, len(f)) for i, v := range f { res[i] = &operationPb.AddForageRequest{ Id: uint32(v.Id), Name: v.Name, CategoryId: uint32(v.CategoryId), MaterialType: uint32(v.MaterialType), UniqueEncode: v.UniqueEncode, ForageSourceId: v.ForageSourceId, PlanTypeId: v.PlanTypeId, SmallMaterialScale: v.SmallMaterialScale, AllowError: uint32(v.AllowError), PackageWeight: uint32(v.PackageWeight), Price: uint32(v.Price), JumpWeight: uint32(v.JumpWeight), JumpDelay: v.JumpDelay, ConfirmStart: v.ConfirmStart, RelayLocations: uint32(v.RelayLocations), IsShow: v.IsShow, CreatedAt: uint32(v.CreatedAt), CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime), } } return res }