package backend import ( "kpt-pasture/model" "gitee.com/xuyiping_admin/pkg/logger/zaplog" "go.uber.org/zap" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) func (s *StoreEntry) DeathReasonEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { dataList := make([]*model.ConfigDeathReason, 0) pref := s.DB.Model(new(model.ConfigDeathReason)). Where("is_show =? ", pasturePb.IsShow_Ok). Where("pasture_id =? ", userModel.AppPasture.Id) if isAll == model.IsAllYes { pref = pref.Where("kind >= ?", pasturePb.DeathReason_Invalid) } else { pref = pref.Where("kind > ?", pasturePb.DeathReason_Invalid) } if err := pref.Order("kind ASC"). Find(&dataList).Error; err != nil { zaplog.Error("DeathReasonEnumList", zap.Any("err", err)) return make([]*pasturePb.ConfigOptionsList, 0) } return model.ConfigDeathReasonSlice(dataList).ToPB(userModel) } func (s *StoreEntry) MatingResultEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { dataList := make([]*model.ConfigMatingResult, 0) pref := s.DB.Model(new(model.ConfigMatingResult)). Where("is_show =? ", pasturePb.IsShow_Ok). Where("pasture_id =? ", userModel.AppPasture.Id) if isAll == model.IsAllYes { pref = pref.Where("kind >= ?", pasturePb.MatingResult_Invalid) } else { pref = pref.Where("kind > ?", pasturePb.MatingResult_Invalid) } if err := pref.Order("kind ASC"). Find(&dataList).Error; err != nil { zaplog.Error("MatingResultEnumList", zap.Any("err", err)) return make([]*pasturePb.ConfigOptionsList, 0) } return model.ConfigMatingResultSlice(dataList).ToPB(userModel) } func (s *StoreEntry) EventCategoryEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { dataList := make([]*model.ConfigEventCategory, 0) pref := s.DB.Model(new(model.ConfigEventCategory)). Where("is_show =? ", pasturePb.IsShow_Ok). Where("pasture_id =? ", userModel.AppPasture.Id) if isAll == model.IsAllYes { pref = pref.Where("kind >= ?", pasturePb.EventCategory_Invalid) } else { pref = pref.Where("kind > ?", pasturePb.EventCategory_Invalid) } if err := pref.Order("kind ASC"). Find(&dataList).Error; err != nil { zaplog.Error("EventCategoryEnumList", zap.Any("err", err)) return make([]*pasturePb.ConfigOptionsList, 0) } return model.ConfigEventCategorySlice(dataList).ToPB(userModel) } func (s *StoreEntry) IndicatorsCategoryEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { dataList := make([]*model.ConfigIndicatorsCategory, 0) pref := s.DB.Model(new(model.ConfigIndicatorsCategory)). Where("is_show =? ", pasturePb.IsShow_Ok). Where("pasture_id =? ", userModel.AppPasture.Id) if isAll == model.IsAllYes { pref = pref.Where("kind >= ?", pasturePb.IndicatorType_Invalid) } else { pref = pref.Where("kind > ?", pasturePb.IndicatorType_Invalid) } if err := pref.Order("kind ASC"). Find(&dataList).Error; err != nil { zaplog.Error("IndicatorsCategoryEnumList", zap.Any("err", err)) return make([]*pasturePb.ConfigOptionsList, 0) } return model.ConfigIndicatorsCategorySlice(dataList).ToPB(userModel) } func (s *StoreEntry) IndicatorsDetailsList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) if isAll == model.IsAllYes { configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(0), Label: "全部", Disabled: true, }) } indicatorsDetailsList, _ := s.FindIndicatorsDetailsList() if len(indicatorsDetailsList) <= 0 { return configOptions } for _, v := range indicatorsDetailsList { configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Label: v.Name, Disabled: true, Props: v.Kind, }) } return configOptions } func (s *StoreEntry) CowPurposeList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { dataList := make([]*model.ConfigCowPurpose, 0) pref := s.DB.Model(new(model.ConfigCowPurpose)). Where("is_show =? ", pasturePb.IsShow_Ok). Where("pasture_id =? ", userModel.AppPasture.Id) if isAll == model.IsAllYes { pref = pref.Where("kind >= ?", pasturePb.Purpose_Invalid) } else { pref = pref.Where("kind > ?", pasturePb.Purpose_Invalid) } if err := pref.Order("kind ASC"). Find(&dataList).Error; err != nil { zaplog.Error("CowPurposeList", zap.Any("err", err)) return make([]*pasturePb.ConfigOptionsList, 0) } return model.ConfigCowPurposeSlice(dataList).ToPB(userModel) } func (s *StoreEntry) CowOutReasonEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { dataList := make([]*model.ConfigCowOutReason, 0) pref := s.DB.Model(new(model.ConfigCowOutReason)). Where("is_show =? ", pasturePb.IsShow_Ok). Where("pasture_id =? ", userModel.AppPasture.Id) if isAll == model.IsAllYes { pref = pref.Where("kind >= ?", pasturePb.OutReasons_Invalid) } else { pref = pref.Where("kind > ?", pasturePb.OutReasons_Invalid) } if err := pref.Order("kind ASC"). Find(&dataList).Error; err != nil { zaplog.Error("CowOutReasonList", zap.Any("err", err)) return make([]*pasturePb.ConfigOptionsList, 0) } return model.ConfigCowOutReasonSlice(dataList).ToPB(userModel) } func (s *StoreEntry) CowDeathDestinationList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList { dataList := make([]*model.ConfigCowDeathDestination, 0) pref := s.DB.Model(new(model.ConfigCowDeathDestination)). Where("is_show =? ", pasturePb.IsShow_Ok). Where("pasture_id =? ", userModel.AppPasture.Id) if isAll == model.IsAllYes { pref = pref.Where("kind >= ?", pasturePb.DeathDestination_Invalid) } else { pref = pref.Where("kind > ?", pasturePb.DeathDestination_Invalid) } if err := pref.Order("kind ASC"). Find(&dataList).Error; err != nil { zaplog.Error("CowDeathDestinationList", zap.Any("err", err)) return make([]*pasturePb.ConfigOptionsList, 0) } return model.ConfigCowDeathDestinationSlice(dataList).ToPB(userModel) }