pen.go 3.2 KB

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