package backend import ( "context" "kpt-pasture/model" "net/http" xxerr "gitee.com/xuyiping_admin/pkg/xerr" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { configBarnTypeList := make([]*model.ConfigPenType, 0) if err := s.DB.Table(new(model.ConfigPenType).TableName()).Find(&configBarnTypeList).Error; err != nil { return nil, err } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigBarnTypeSlice(configBarnTypeList).ToPB2(), }, nil } func (s *StoreEntry) BarnListOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { penList := make([]*model.Pen, 0) if err := s.DB.Table(new(model.Pen).TableName()). Where("is_delete = ?", pasturePb.IsShow_Ok). Find(&penList).Error; err != nil { return nil, err } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.PenSlice(penList).ToPB2(), }, nil } func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { configBreedStatusList := make([]*model.ConfigBreedStatus, 0) if err := s.DB.Table(new(model.ConfigBreedStatus).TableName()).Find(&configBreedStatusList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigBreedStatusSlice(configBreedStatusList).ToPB2(), }, nil } func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { configCowKindList := make([]*model.ConfigCowKind, 0) if err := s.DB.Table(new(model.ConfigCowKind).TableName()).Find(&configCowKindList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigCowKindSlice(configCowKindList).ToPB2(), }, nil } func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { configCowSourceList := make([]*model.ConfigCowSource, 0) if err := s.DB.Table(new(model.ConfigCowSource).TableName()).Find(&configCowSourceList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigCowSourceSlice(configCowSourceList).ToPB2(), }, nil } func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { configCowStatusList := make([]*model.ConfigCowStatus, 0) if err := s.DB.Table(new(model.ConfigCowStatus).TableName()).Find(&configCowStatusList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigCowStatusSlice(configCowStatusList).ToPB2(), }, nil } func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { configCowTypeList := make([]*model.ConfigCowType, 0) if err := s.DB.Table(new(model.ConfigCowType).TableName()).Find(&configCowTypeList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigCowTypeSlice(configCowTypeList).ToPB2(), }, nil } func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { configTransferPenReasonList := make([]*model.ConfigTransferPenReason, 0) if err := s.DB.Table(new(model.ConfigTransferPenReason).TableName()).Find(&configTransferPenReasonList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigTransferPenReasonSlice(configTransferPenReasonList).ToPB2(), }, nil } func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) { systemUserList := make([]*model.SystemUser, 0) pref := s.DB.Table(new(model.SystemUser).TableName()) if depId != -1 && depId > 0 { pref = pref.Where("dep_id = ?", depId) } if err := pref.Find(&systemUserList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.SystemUserSlice(systemUserList).ToPB2(), }, nil }