123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package model
- import (
- "time"
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
- )
- type FeedFormula struct {
- Id int64 `json:"id"`
- Name string `json:"name"`
- Colour string `json:"colour"`
- EncodeNumber string `json:"encode_number"`
- CattleCategoryId operationPb.CattleCategoryParent_Kind `json:"cattle_category_id"`
- CattleCategoryName string `json:"cattle_category_name"`
- FormulaTypeId operationPb.FormulaType_Kind `json:"formula_type_id"`
- FormulaTypeName string `json:"formula_type_name"`
- DataSourceId operationPb.DataSource_Kind `json:"data_source_id"`
- DataSourceName string `json:"data_source_name"`
- Remarks string `json:"remarks"`
- Version int64 `json:"version"`
- PastureId int64 `json:"pasture_id"`
- PastureName string `json:"pasture_name"`
- PastureDataId int64 `json:"pasture_data_id"`
- IsShow operationPb.IsShow_Kind `json:"is_show"`
- IsModify operationPb.IsShow_Kind `json:"is_modify"`
- IsDelete operationPb.IsShow_Kind `json:"is_delete"`
- CreatedAt int64 `json:"created_at"`
- UpdatedAt int64 `json:"updated_at"`
- }
- func (f *FeedFormula) TableName() string {
- return "feed_formula"
- }
- func NewFeedFormula(req *operationPb.AddFeedFormulaRequest) *FeedFormula {
- return &FeedFormula{
- Name: req.Name,
- Colour: req.Colour,
- EncodeNumber: req.EncodeNumber,
- CattleCategoryId: req.CattleCategoryId,
- CattleCategoryName: req.CattleCategoryName,
- FormulaTypeId: req.FormulaTypeId,
- FormulaTypeName: req.FormulaTypeName,
- DataSourceId: req.DataSourceId,
- DataSourceName: req.DataSourceName,
- Remarks: req.Remarks,
- Version: 1,
- PastureId: 0,
- PastureName: "集团",
- IsShow: req.IsShow,
- IsDelete: operationPb.IsShow_OK,
- IsModify: operationPb.IsShow_OK,
- }
- }
- type FeedFormulaSlice []*FeedFormula
- func (f FeedFormulaSlice) ToPB() []*operationPb.AddFeedFormulaRequest {
- res := make([]*operationPb.AddFeedFormulaRequest, len(f))
- for i, v := range f {
- res[i] = &operationPb.AddFeedFormulaRequest{
- Id: int32(v.Id),
- Name: v.Name,
- Colour: v.Colour,
- EncodeNumber: v.EncodeNumber,
- CattleCategoryId: v.CattleCategoryId,
- CattleCategoryName: v.CattleCategoryName,
- FormulaTypeId: v.FormulaTypeId,
- FormulaTypeName: v.FormulaTypeName,
- DataSourceName: v.DataSourceName,
- DataSourceId: v.DataSourceId,
- Remarks: v.Remarks,
- Version: int32(v.Version),
- PastureName: v.PastureName,
- IsShow: v.IsShow,
- IsModify: v.IsModify,
- CreatedAt: int32(v.CreatedAt),
- CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
- }
- }
- return res
- }
- func (f FeedFormulaSlice) ToDistributePB() []*operationPb.DistributeFeedRequest {
- res := make([]*operationPb.DistributeFeedRequest, len(f))
- for i, v := range f {
- res[i] = &operationPb.DistributeFeedRequest{
- Id: int32(v.Id),
- Name: v.Name,
- Colour: v.Colour,
- EncodeNumber: v.EncodeNumber,
- CattleCategoryId: v.CattleCategoryId,
- CattleCategoryName: v.CattleCategoryName,
- FormulaTypeId: v.FormulaTypeId,
- FormulaTypeName: v.FormulaTypeName,
- DataSourceName: v.DataSourceName,
- DataSourceId: v.DataSourceId,
- Remarks: v.Remarks,
- Version: int32(v.Version),
- PastureName: v.PastureName,
- IsShow: v.IsShow,
- IsModify: v.IsModify,
- CreatedAt: int32(v.CreatedAt),
- CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
- }
- }
- return res
- }
- func NewNewFeedFormulaByMixed(req *operationPb.MixedFeedFormulaRequest) *FeedFormula {
- return &FeedFormula{
- Name: req.Name,
- Colour: req.Colour,
- CattleCategoryId: operationPb.CattleCategoryParent_Kind(req.CattleCategoryId),
- CattleCategoryName: req.CattleCategoryName,
- FormulaTypeId: req.FormulaTypeId,
- FormulaTypeName: req.FormulaTypeName,
- DataSourceId: operationPb.DataSource_Kind(req.DataSourceId),
- DataSourceName: operationPb.DataSource_Kind_name[req.DataSourceId],
- Remarks: req.Remarks,
- PastureName: "集团",
- IsShow: operationPb.IsShow_OK,
- IsModify: operationPb.IsShow_OK,
- IsDelete: operationPb.IsShow_OK,
- }
- }
|