barn.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. }