package model import ( operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation" "time" ) type Forage struct { Id int64 `json:"id"` PastureId int64 `json:"pasture_id"` PastureName string `json:"pasture_name"` PastureDataId int64 `json:"pasture_data_id"` Name string `json:"name"` CategoryId int64 `json:"category_id"` CategoryName string `json:"category_name"` MaterialTypeKey operationPb.FormulaType_Kind `json:"material_type_key"` MaterialTypeName string `json:"material_type_name"` UniqueEncode string `json:"unique_encode"` ForageSourceId operationPb.ForageSource_Kind `json:"forage_source_id"` ForageSourceName string `json:"forage_source_name"` PlanTypeId operationPb.ForagePlanType_Kind `json:"plan_type_id"` PlanTypeName string `json:"plan_type_name"` 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"` Sort int64 `json:"sort"` 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, PastureName: "集团", CategoryId: int64(req.CategoryId), CategoryName: req.CategoryName, UniqueEncode: req.UniqueEncode, ForageSourceId: req.ForageSourceId, ForageSourceName: req.ForageSourceName, PlanTypeId: req.PlanTypeId, PlanTypeName: req.PlanTypeName, MaterialTypeKey: req.MaterialTypeKey, MaterialTypeName: req.MaterialTypeName, 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: int32(v.Id), Name: v.Name, CategoryId: int32(v.CategoryId), CategoryName: v.CategoryName, MaterialTypeKey: v.MaterialTypeKey, MaterialTypeName: v.MaterialTypeName, UniqueEncode: v.UniqueEncode, ForageSourceId: v.ForageSourceId, ForageSourceName: v.ForageSourceName, PlanTypeId: v.PlanTypeId, PlanTypeName: v.PlanTypeName, SmallMaterialScale: v.SmallMaterialScale, AllowError: int32(v.AllowError), PackageWeight: int32(v.PackageWeight), Price: int32(v.Price), JumpWeight: int32(v.JumpWeight), JumpDelay: v.JumpDelay, ConfirmStart: v.ConfirmStart, RelayLocations: int32(v.RelayLocations), Jmp: v.Jmp, IsShow: v.IsShow, Backup1: v.Backup1, Backup2: v.Backup2, Backup3: v.Backup3, DataSource: v.PastureName, CreatedAt: int32(v.CreatedAt), CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime), } } return res } func NewForageByPastureFeed(groupPasture *GroupPasture, data *Feed) *Forage { forageSourceName := data.Source forageSourceId := operationPb.ForageSource_SYSTEM_BUILT_IN if forageSourceName == "用户自定义" { forageSourceId = operationPb.ForageSource_USER_DEFINED } confirmStart := operationPb.IsShow_INVALID if data.ConfirmStart == 0 { confirmStart = operationPb.IsShow_NO } if data.ConfirmStart == 1 { confirmStart = operationPb.IsShow_OK } return &Forage{ Name: data.FName, CategoryId: data.FClassId, CategoryName: data.FClass, MaterialTypeKey: 0, // 部分牧场有该字段 MaterialTypeName: "", // UniqueEncode: data.FeedCode, ForageSourceId: forageSourceId, ForageSourceName: forageSourceName, PlanTypeId: operationPb.ForagePlanType_Kind(data.PrintGroupId), PlanTypeName: data.PrintGroup, SmallMaterialScale: data.SmtMrName, AllowError: data.AllowRatio, PackageWeight: data.UnitWeight, Price: int64(data.UPrice * 100), JumpWeight: data.AutoZone, JumpDelay: operationPb.JumpDelaType_Kind(data.AutoSecond), ConfirmStart: confirmStart, RelayLocations: int64(data.TrgAddress), Jmp: operationPb.IsShow_Kind(data.Jmp), DataSource: operationPb.DataSource_FROM_PASTURE, Sort: int64(data.Sort), PastureId: groupPasture.PastureId, PastureName: groupPasture.Name, PastureDataId: data.Id, IsShow: operationPb.IsShow_Kind(data.Enable), IsDelete: operationPb.IsShow_OK, } }