config_cow_source.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package model
  2. import (
  3. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  4. "golang.org/x/text/language"
  5. )
  6. type ConfigCowSource struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. Kind pasturePb.CowSource_Kind `json:"kind"`
  10. Zh string `json:"zh"`
  11. En string `json:"en"`
  12. Remarks string `json:"remarks"`
  13. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  14. CreatedAt int64 `json:"createdAt"`
  15. UpdatedAt int64 `json:"updatedAt"`
  16. }
  17. func (c *ConfigCowSource) TableName() string {
  18. return "config_cow_source"
  19. }
  20. type ConfigCowSourceSlice []*ConfigCowSource
  21. func (c ConfigCowSourceSlice) ToPB(lang string) []*pasturePb.SearchBaseConfigList {
  22. res := make([]*pasturePb.SearchBaseConfigList, len(c))
  23. for i, d := range c {
  24. name := d.Zh
  25. if lang == language.English.String() {
  26. name = d.En
  27. }
  28. res[i] = &pasturePb.SearchBaseConfigList{
  29. Id: int32(d.Id),
  30. Name: name,
  31. Remarks: d.Remarks,
  32. IsShow: d.IsShow,
  33. CreatedAt: int32(d.CreatedAt),
  34. UpdatedAt: int32(d.UpdatedAt),
  35. }
  36. }
  37. return res
  38. }
  39. func (c ConfigCowSourceSlice) ToPB2(lang string) []*pasturePb.ConfigOptionsList {
  40. res := make([]*pasturePb.ConfigOptionsList, 0)
  41. for _, v := range c {
  42. label := v.Zh
  43. if lang == "en" {
  44. label = v.En
  45. }
  46. res = append(res, &pasturePb.ConfigOptionsList{
  47. Value: int32(v.Kind),
  48. Label: label,
  49. Disabled: true,
  50. })
  51. }
  52. return res
  53. }