123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- package model
- import (
- "fmt"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- const IsAllYes = "Yes"
- type Pen struct {
- Id int32 `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: v.Id,
- Name: v.Name,
- IsShow: v.IsShow,
- Remarks: v.Remarks,
- BarnTypeId: 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 []*pasturePb.ConfigOptionsList, isAll string) []*pasturePb.ConfigOptionsList {
- res := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == IsAllYes {
- res = append(res, &pasturePb.ConfigOptionsList{
- Value: int32(0),
- Label: "全部",
- Disabled: true,
- })
- }
- for _, d := range p {
- label := d.Name
- for _, r := range req {
- if r.Value != d.PenType {
- continue
- }
- label = fmt.Sprintf("%s-%s", label, r.Label)
- }
- res = append(res, &pasturePb.ConfigOptionsList{
- Value: int32(d.Id),
- Label: label,
- Disabled: true,
- })
- }
- return res
- }
- type PenWeight struct {
- PenId int32 `json:"penId"`
- CowCount int32 `json:"cowCount"`
- AllWeight int32 `json:"allWeight"`
- AvgWeight int32 `json:"avgWeight"`
- }
- type PenWeightSlice []*PenWeight
- func (p PenWeightSlice) ToPB(penMap map[int32]*Pen) *pasturePb.PenWeightChart {
- res := &pasturePb.PenWeightChart{}
- for _, v := range p {
- penName := ""
- if pen, ok := penMap[v.PenId]; ok {
- penName = pen.Name
- }
- res.Header = append(res.Header, penName)
- res.AllWeight = append(res.AllWeight, v.AllWeight)
- res.AvgWeight = append(res.AvgWeight, v.AvgWeight)
- res.CowCount = append(res.CowCount, v.CowCount)
- }
- return res
- }
- func (p PenWeightSlice) GetPenWeight(penId int32) *PenWeight {
- for _, v := range p {
- if v.PenId == penId {
- return v
- }
- }
- return nil
- }
|