1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package model
- import (
- "fmt"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type Pen struct {
- Id int64 `json:"id"`
- Name string `json:"name"`
- Remarks string `json:"remarks"`
- PenType int32 `json:"pen_type"`
- Lengths int32 `json:"lengths"`
- Widths int32 `json:"widths"`
- DoctrinalCapacity int32 `json:"doctrinal_capacity"`
- ActualCapacity int32 `json:"actual_capacity"`
- BedNumber int32 `json:"bed_number"`
- NeckNumber int32 `json:"neck_number"`
- IsShow pasturePb.IsShow_Kind `json:"is_show"`
- IsDelete pasturePb.IsShow_Kind `json:"is_delete"`
- CreatedAt int64 `json:"created_at"`
- UpdatedAt int64 `json:"updated_at"`
- }
- func (p *Pen) TableName() string {
- return "pen"
- }
- type PenSlice []*Pen
- func (p PenSlice) ToPB(configBarnTypes []*ConfigPenType) []*pasturePb.SearchBarnList {
- res := make([]*pasturePb.SearchBarnList, len(p))
- for i, v := range p {
- barnTypeName := ""
- for _, c := range configBarnTypes {
- if c.Id == int64(v.PenType) {
- barnTypeName = c.Name
- break
- }
- }
- res[i] = &pasturePb.SearchBarnList{
- Id: int32(v.Id),
- Name: v.Name,
- IsShow: v.IsShow,
- Remarks: v.Remarks,
- BarnTypeId: int32(v.PenType),
- BarnTypeName: barnTypeName,
- Lengths: v.Lengths,
- Widths: v.Widths,
- DoctrinalCapacity: v.DoctrinalCapacity,
- ActualCapacity: v.ActualCapacity,
- NeckNumber: v.NeckNumber,
- BedNumber: v.BedNumber,
- CreatedAt: int32(v.CreatedAt),
- UpdatedAt: int32(v.UpdatedAt),
- }
- }
- return res
- }
- func (p PenSlice) ToPB2(req []*ConfigPenType) []*pasturePb.ConfigOptionsList {
- res := make([]*pasturePb.ConfigOptionsList, len(p))
- for i, d := range p {
- label := d.Name
- for _, r := range req {
- if r.Id != int64(d.PenType) {
- continue
- }
- label = fmt.Sprintf("%s-%s", label, r.Name)
- }
- res[i] = &pasturePb.ConfigOptionsList{
- Value: int32(d.Id),
- Label: label,
- Disabled: true,
- }
- }
- return res
- }
|