config_disease_type.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 ConfigDiseaseType struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. Kind int32 `json:"kind"`
  10. Zh string `json:"Zh"`
  11. En string `json:"En"`
  12. Remarks string `json:"remarks"`
  13. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  14. CreatedAt int64 `json:"created_at"`
  15. UpdatedAt int64 `json:"updated_at"`
  16. }
  17. func (c *ConfigDiseaseType) TableName() string {
  18. return "config_disease_type"
  19. }
  20. type ConfigDiseaseTypeSlice []*ConfigDiseaseType
  21. func (c ConfigDiseaseTypeSlice) 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 ConfigDiseaseTypeSlice) ToPB2(lang string, diseaseList []*Disease) []*pasturePb.ConfigOptionsList {
  40. res := make([]*pasturePb.ConfigOptionsList, len(c))
  41. for i, d := range c {
  42. children := make([]*pasturePb.ConfigOptionsList, 0)
  43. if len(diseaseList) > 0 {
  44. for _, v := range diseaseList {
  45. if int64(v.DiseaseType) != d.Id {
  46. continue
  47. }
  48. children = append(children, &pasturePb.ConfigOptionsList{
  49. Value: int32(v.Id),
  50. Label: v.Name,
  51. Disabled: true,
  52. })
  53. }
  54. }
  55. label := d.Zh
  56. if lang == language.English.String() {
  57. label = d.En
  58. }
  59. res[i] = &pasturePb.ConfigOptionsList{
  60. Value: int32(d.Id),
  61. Label: label,
  62. Disabled: true,
  63. Children: children,
  64. }
  65. }
  66. return res
  67. }
  68. func (c ConfigDiseaseTypeSlice) ToPB3(lang string) []*pasturePb.ConfigOptionsList {
  69. res := make([]*pasturePb.ConfigOptionsList, 0)
  70. for _, v := range c {
  71. label := v.Zh
  72. if lang == "en" {
  73. label = v.En
  74. }
  75. res = append(res, &pasturePb.ConfigOptionsList{
  76. Value: int32(v.Kind),
  77. Label: label,
  78. Disabled: true,
  79. })
  80. }
  81. return res
  82. }