123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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
- }
|