package backend import ( "context" "fmt" "kpt-pasture/model" "net/http" "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) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.BarnTypeEnumList(), }, nil } func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error) { penList := make([]*model.Pen, 0) pref := s.DB.Table(new(model.Pen).TableName()). Where("is_delete = ?", pasturePb.IsShow_Ok) if penType != -1 { pref.Where("pen_type = ?", penType) } if err := pref.Find(&penList).Error; err != nil { return nil, err } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.PenSlice(penList).ToPB2(s.BarnTypeEnumList()), }, nil } func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { diseaseTypeList := make([]*model.ConfigDiseaseType, 0) pref := s.DB.Table(new(model.ConfigDiseaseType).TableName()). Where("is_show =? ", pasturePb.IsShow_Ok) if err := pref.Find(&diseaseTypeList).Error; err != nil { return nil, xerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigDiseaseTypeSlice(diseaseTypeList).ToPB2(), }, nil } func (s *StoreEntry) DiseaseOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { diseaseList := make([]*model.Disease, 0) pref := s.DB.Table(new(model.Disease).TableName()). Where("is_show =? ", pasturePb.IsShow_Ok) if err := pref.Find(&diseaseList).Error; err != nil { return nil, xerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.DiseaseSlice(diseaseList).ToPB2(), }, nil } func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.BreedStatusEnumList(), }, nil } func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.CowKindEnumList(), }, nil } func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.CowSourceEnumList(), }, nil } func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.CowTypeEnumList(), }, nil } func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.TransferPenEnumList(), }, 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()). Where("is_delete = ?", pasturePb.IsShow_Ok). Where("is_show =? ", pasturePb.IsShow_Ok) if depId != -1 && depId > 0 { pref = pref.Where("dept_id = ?", depId) } if err := pref.Find(&systemUserList).Error; err != nil { return nil, xerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.SystemUserSlice(systemUserList).ToPB2(), }, nil } func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) { return &pasturePb.BullOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.BullNumberEnumList(), }, nil } func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) { if optionsName == "" { return nil, xerr.New("optionsName is empty") } getConfigFuncMap := map[string]func() []*pasturePb.ConfigOptionsList{ "childNumber": s.ChildNumberEnumList, "calvingLevel": s.CalvingLevelEnumList, "dystociaReason": s.DystociaReasonEnumList, "drugCategory": s.DrugCategoryEnumList, "drugUsage": s.DrugUsageEnumList, "unit": s.UnitEnumList, "pregnantCheckResult": s.PregnantCheckResultEnumList, "pregnantCheckMethod": s.PregnantCheckMethodEnumList, "exposeEstrusType": s.ExposeEstrusTypeEnumList, "frozenSemenType": s.FrozenSemenTypeEnumList, "week": s.WeekEnumList, "month": s.MonthEnumList, "sameTimeCowType": s.SemeTimeCowTypeEnumList, "sameTimeType": s.SameTimeTypeEnumList, "immunizationCowType": s.ImmunizationCowTypeEnumList, "workOrderFrequency": s.WorkOrderFrequencyEnumList, "workOrderSubUnit": s.WorkOrderSubUnitEnumList, "workOrderPriority": s.WorkOrderPriorityEnumList, "workOrderCategory": s.WorkOrderCategoryEnumList, "immunizationConditions": s.ImmunizationConditionsEnumList, } getConfigFunc, ok := getConfigFuncMap[optionsName] if !ok { return nil, fmt.Errorf("invalid optionsName: %s", optionsName) } configOptions := getConfigFunc() if configOptions == nil { return nil, fmt.Errorf("failed to retrieve configOptions for %s", optionsName) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: configOptions, }, nil }