pen.go 3.2 KB

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