1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package model
- import (
- operationPb "kpt-tmr-group/proto/go/backend/operation"
- "time"
- )
- type CattleCategory struct {
- Id int64 `json:"id"`
- ParentId operationPb.CattleCategoryParent_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 (c *CattleCategory) TableName() string {
- return "cattle_category"
- }
- func NewCattleCategory(req *operationPb.AddCattleCategoryRequest) *CattleCategory {
- return &CattleCategory{
- 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 CattleCategorySlice []*CattleCategory
- func (c CattleCategorySlice) ToPB() []*operationPb.AddCattleCategoryRequest {
- res := make([]*operationPb.AddCattleCategoryRequest, len(c))
- for i, v := range c {
- res[i] = &operationPb.AddCattleCategoryRequest{
- 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 (c *CattleCategory) ToPb() *operationPb.AddCattleCategoryRequest {
- return &operationPb.AddCattleCategoryRequest{
- Id: uint32(c.Id),
- Name: c.Name,
- Number: c.Number,
- ParentId: c.ParentId,
- ParentName: c.ParentName,
- IsShow: c.IsShow,
- CreatedAt: uint32(c.CreatedAt),
- }
- }
- func NewPastureCattleCategory(req *operationPb.CategorySyncRequest, pastureDetail *GroupPasture) *CattleCategory {
- return &CattleCategory{
- ParentId: operationPb.CattleCategoryParent_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: "牧场端数据同步",
- }
- }
|