pen.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package model
  2. import (
  3. "fmt"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type Pen struct {
  7. Id int64 `json:"id"`
  8. Name string `json:"name"`
  9. Remarks string `json:"remarks"`
  10. PenType int32 `json:"pen_type"`
  11. Lengths int32 `json:"lengths"`
  12. Widths int32 `json:"widths"`
  13. DoctrinalCapacity int32 `json:"doctrinal_capacity"`
  14. ActualCapacity int32 `json:"actual_capacity"`
  15. BedNumber int32 `json:"bed_number"`
  16. NeckNumber int32 `json:"neck_number"`
  17. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  18. IsDelete pasturePb.IsShow_Kind `json:"is_delete"`
  19. CreatedAt int64 `json:"created_at"`
  20. UpdatedAt int64 `json:"updated_at"`
  21. }
  22. func (p *Pen) TableName() string {
  23. return "pen"
  24. }
  25. type PenSlice []*Pen
  26. func (p PenSlice) ToPB(configBarnTypes []*ConfigPenType) []*pasturePb.SearchBarnList {
  27. res := make([]*pasturePb.SearchBarnList, len(p))
  28. for i, v := range p {
  29. barnTypeName := ""
  30. for _, c := range configBarnTypes {
  31. if c.Id == int64(v.PenType) {
  32. barnTypeName = c.Name
  33. break
  34. }
  35. }
  36. res[i] = &pasturePb.SearchBarnList{
  37. Id: int32(v.Id),
  38. Name: v.Name,
  39. IsShow: v.IsShow,
  40. Remarks: v.Remarks,
  41. BarnTypeId: v.PenType,
  42. BarnTypeName: barnTypeName,
  43. Lengths: v.Lengths,
  44. Widths: v.Widths,
  45. DoctrinalCapacity: v.DoctrinalCapacity,
  46. ActualCapacity: v.ActualCapacity,
  47. NeckNumber: v.NeckNumber,
  48. BedNumber: v.BedNumber,
  49. CreatedAt: int32(v.CreatedAt),
  50. UpdatedAt: int32(v.UpdatedAt),
  51. }
  52. }
  53. return res
  54. }
  55. func (p PenSlice) ToPB2(req []*pasturePb.ConfigOptionsList) []*pasturePb.ConfigOptionsList {
  56. res := make([]*pasturePb.ConfigOptionsList, len(p))
  57. for i, d := range p {
  58. label := d.Name
  59. for _, r := range req {
  60. if r.Value != d.PenType {
  61. continue
  62. }
  63. label = fmt.Sprintf("%s-%s", label, r.Label)
  64. }
  65. res[i] = &pasturePb.ConfigOptionsList{
  66. Value: int32(d.Id),
  67. Label: label,
  68. Disabled: true,
  69. }
  70. }
  71. return res
  72. }
  73. type PenWeight struct {
  74. PenId int32 `json:"penId"`
  75. CowCount int32 `json:"cowCount"`
  76. AllWeight int32 `json:"allWeight"`
  77. AvgWeight int32 `json:"avgWeight"`
  78. }
  79. type PenWeightSlice []*PenWeight
  80. func (p PenWeightSlice) ToPB(penMap map[int32]*Pen) *pasturePb.PenWeightChart {
  81. res := &pasturePb.PenWeightChart{}
  82. for _, v := range p {
  83. penName := ""
  84. if pen, ok := penMap[v.PenId]; ok {
  85. penName = pen.Name
  86. }
  87. res.Header = append(res.Header, penName)
  88. res.AllWeight = append(res.AllWeight, v.AllWeight)
  89. res.AvgWeight = append(res.AvgWeight, v.AvgWeight)
  90. res.CowCount = append(res.CowCount, v.CowCount)
  91. }
  92. return res
  93. }
  94. func (p PenWeightSlice) GetPenWeight(penId int32) *PenWeight {
  95. for _, v := range p {
  96. if v.PenId == penId {
  97. return v
  98. }
  99. }
  100. return nil
  101. }