config_disease_type.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package model
  2. import (
  3. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  4. "github.com/nicksnyder/go-i18n/v2/i18n"
  5. )
  6. type ConfigDiseaseType struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. Kind int32 `json:"kind"`
  10. I18nFieldTag string `json:"i18nFieldTag"`
  11. Remarks string `json:"remarks"`
  12. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  13. CreatedAt int64 `json:"created_at"`
  14. UpdatedAt int64 `json:"updated_at"`
  15. }
  16. func (c *ConfigDiseaseType) TableName() string {
  17. return "config_disease_type"
  18. }
  19. type ConfigDiseaseTypeSlice []*ConfigDiseaseType
  20. func (c ConfigDiseaseTypeSlice) ToPB(userModel *UserModel) []*pasturePb.SearchBaseConfigList {
  21. res := make([]*pasturePb.SearchBaseConfigList, len(c))
  22. for i, d := range c {
  23. name, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
  24. MessageID: d.I18nFieldTag,
  25. })
  26. res[i] = &pasturePb.SearchBaseConfigList{
  27. Id: int32(d.Id),
  28. Name: name,
  29. Remarks: d.Remarks,
  30. IsShow: d.IsShow,
  31. CreatedAt: int32(d.CreatedAt),
  32. UpdatedAt: int32(d.UpdatedAt),
  33. }
  34. }
  35. return res
  36. }
  37. func (c ConfigDiseaseTypeSlice) ToPB2(userModel *UserModel, diseaseList []*Disease) []*pasturePb.ConfigOptionsList {
  38. res := make([]*pasturePb.ConfigOptionsList, len(c))
  39. for i, d := range c {
  40. children := make([]*pasturePb.ConfigOptionsList, 0)
  41. if len(diseaseList) > 0 {
  42. for _, v := range diseaseList {
  43. if int64(v.DiseaseType) != d.Id {
  44. continue
  45. }
  46. children = append(children, &pasturePb.ConfigOptionsList{
  47. Value: int32(v.Id),
  48. Label: v.Name,
  49. Disabled: true,
  50. })
  51. }
  52. }
  53. label, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
  54. MessageID: d.I18nFieldTag,
  55. })
  56. res[i] = &pasturePb.ConfigOptionsList{
  57. Value: int32(d.Id),
  58. Label: label,
  59. Disabled: true,
  60. Children: children,
  61. }
  62. }
  63. return res
  64. }
  65. func (c ConfigDiseaseTypeSlice) ToPB3(userModel *UserModel) []*pasturePb.ConfigOptionsList {
  66. res := make([]*pasturePb.ConfigOptionsList, 0)
  67. for _, v := range c {
  68. label, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
  69. MessageID: v.I18nFieldTag,
  70. })
  71. res = append(res, &pasturePb.ConfigOptionsList{
  72. Value: int32(v.Kind),
  73. Label: label,
  74. Disabled: true,
  75. })
  76. }
  77. return res
  78. }