config_cow_type.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 ConfigCowType struct {
  7. Id int64 `json:"id"`
  8. Kind pasturePb.CowType_Kind `json:"kind"`
  9. I18nFieldTag string `json:"i18nFieldTag"`
  10. Remarks string `json:"remarks"`
  11. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  12. CreatedAt int64 `json:"createdAt"`
  13. UpdatedAt int64 `json:"updatedAt"`
  14. }
  15. func (c *ConfigCowType) TableName() string {
  16. return "config_cow_type"
  17. }
  18. type ConfigCowTypeSlice []*ConfigCowType
  19. func (c ConfigCowTypeSlice) ToPB(userModel *UserModel) []*pasturePb.SearchBaseConfigList {
  20. res := make([]*pasturePb.SearchBaseConfigList, len(c))
  21. for i, d := range c {
  22. name, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
  23. MessageID: d.I18nFieldTag,
  24. })
  25. res[i] = &pasturePb.SearchBaseConfigList{
  26. Id: int32(d.Id),
  27. Name: name,
  28. Remarks: d.Remarks,
  29. IsShow: d.IsShow,
  30. CreatedAt: int32(d.CreatedAt),
  31. UpdatedAt: int32(d.UpdatedAt),
  32. }
  33. }
  34. return res
  35. }
  36. func (c ConfigCowTypeSlice) ToPB2(userModel *UserModel, optionName string) []*pasturePb.ConfigOptionsList {
  37. res := make([]*pasturePb.ConfigOptionsList, 0)
  38. for _, v := range c {
  39. label, _ := userModel.LanguageContent.Localize(&i18n.LocalizeConfig{
  40. MessageID: v.I18nFieldTag,
  41. })
  42. if optionName == "breed" && !isBreedingOrReserveCalf(v.Kind) {
  43. continue
  44. }
  45. res = append(res, &pasturePb.ConfigOptionsList{
  46. Value: int32(v.Kind),
  47. Label: label,
  48. Disabled: true,
  49. })
  50. }
  51. return res
  52. }
  53. // 辅助函数:判断是否为 Breeding_Calf 或 Reserve_Calf
  54. func isBreedingOrReserveCalf(kind pasturePb.CowType_Kind) bool {
  55. return kind == pasturePb.CowType_Breeding_Calf || kind == pasturePb.CowType_Reserve_Calf
  56. }