package model import ( pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" "golang.org/x/text/language" ) type ConfigCowSource struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` Kind pasturePb.CowSource_Kind `json:"kind"` Zh string `json:"zh"` En string `json:"en"` Remarks string `json:"remarks"` IsShow pasturePb.IsShow_Kind `json:"isShow"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (c *ConfigCowSource) TableName() string { return "config_cow_source" } type ConfigCowSourceSlice []*ConfigCowSource func (c ConfigCowSourceSlice) ToPB(lang string) []*pasturePb.SearchBaseConfigList { res := make([]*pasturePb.SearchBaseConfigList, len(c)) for i, d := range c { name := d.Zh if lang == language.English.String() { name = d.En } res[i] = &pasturePb.SearchBaseConfigList{ Id: int32(d.Id), Name: name, Remarks: d.Remarks, IsShow: d.IsShow, CreatedAt: int32(d.CreatedAt), UpdatedAt: int32(d.UpdatedAt), } } return res } func (c ConfigCowSourceSlice) ToPB2(lang string) []*pasturePb.ConfigOptionsList { res := make([]*pasturePb.ConfigOptionsList, 0) for _, v := range c { label := v.Zh if lang == "en" { label = v.En } res = append(res, &pasturePb.ConfigOptionsList{ Value: int32(v.Kind), Label: label, Disabled: true, }) } return res }