| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | 
							- 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"`
 
- 	PastureId         int64                  `json:"pastureId"`
 
- 	Name              string                 `json:"name"`
 
- 	Remarks           string                 `json:"remarks"`
 
- 	PenType           pasturePb.PenType_Kind `json:"penType"`
 
- 	Lengths           int32                  `json:"lengths"`
 
- 	Widths            int32                  `json:"widths"`
 
- 	DoctrinalCapacity int32                  `json:"doctrinalCapacity"`
 
- 	ActualCapacity    int32                  `json:"actualCapacity"`
 
- 	BedNumber         int32                  `json:"bedNumber"`
 
- 	NeckNumber        int32                  `json:"neckNumber"`
 
- 	IsShow            pasturePb.IsShow_Kind  `json:"isShow"`
 
- 	IsDelete          pasturePb.IsShow_Kind  `json:"isDelete"`
 
- 	CreatedAt         int64                  `json:"createdAt"`
 
- 	UpdatedAt         int64                  `json:"updatedAt"`
 
- }
 
- func (p *Pen) TableName() string {
 
- 	return "pen"
 
- }
 
- type PenSlice []*Pen
 
- func (p PenSlice) ToPB(barnTypeMap map[pasturePb.PenType_Kind]string) []*pasturePb.SearchBarnList {
 
- 	res := make([]*pasturePb.SearchBarnList, len(p))
 
- 	for i, v := range p {
 
- 		res[i] = &pasturePb.SearchBarnList{
 
- 			Id:                v.Id,
 
- 			Name:              v.Name,
 
- 			IsShow:            v.IsShow,
 
- 			Remarks:           v.Remarks,
 
- 			BarnTypeId:        int32(v.PenType),
 
- 			BarnTypeName:      barnTypeMap[v.PenType],
 
- 			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 != int32(d.PenType) {
 
- 				continue
 
- 			}
 
- 			label = fmt.Sprintf("%s-%s", label, r.Label)
 
- 		}
 
- 		res = append(res, &pasturePb.ConfigOptionsList{
 
- 			Value:    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
 
- }
 
 
  |