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, Msg: "ok", Data: s.BarnTypeEnumList(), }, nil } func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int, isAll string) (*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, Msg: "ok", Data: model.PenSlice(penList).ToPB2(s.BarnTypeEnumList(), isAll), }, nil } func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context, isChildren string) (*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) } diseaseList := make([]*model.Disease, 0) if isChildren == model.IsAllYes { if err := s.DB.Table(new(model.Disease).TableName()). Where("is_show =? ", pasturePb.IsShow_Ok).Find(&diseaseList).Error; err != nil { return nil, xerr.WithStack(err) } } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: model.ConfigDiseaseTypeSlice(diseaseTypeList).ToPB2(diseaseList), }, 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, Msg: "ok", Data: model.DiseaseSlice(diseaseList).ToPB2(), }, nil } func (s *StoreEntry) PrescriptionOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { prescriptionList := make([]*model.Prescription, 0) pref := s.DB.Table(new(model.Prescription).TableName()). Where("is_show =? ", pasturePb.IsShow_Ok) if err := pref.Find(&prescriptionList).Error; err != nil { return nil, xerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: model.PrescriptionSlice(prescriptionList).ToPB2(), }, nil } func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: s.BreedStatusEnumList(), }, nil } func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: s.CowKindEnumList(), }, nil } func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: s.CowSourceEnumList(), }, nil } func (s *StoreEntry) CowTypeOptions(ctx context.Context, optionName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: s.CowTypeEnumList(optionName, isAll), }, nil } func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: s.TransferPenEnumList(""), }, nil } func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) { _, err := s.GetUserModel(ctx) if err != nil { return nil, xerr.WithStack(err) } 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, Msg: "ok", Data: model.SystemUserSlice(systemUserList).ToPB2(), }, nil } func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) { userModel, err := s.GetUserModel(ctx) if err != nil { return nil, xerr.WithStack(err) } return &pasturePb.BullOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: s.BullNumberEnumList("", userModel.AppPasture.Id), }, nil } func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName, isAll string) (*pasturePb.ConfigOptionsListResponse, error) { if optionsName == "" { return nil, xerr.New("optionsName is empty") } getConfigFuncMap := map[string]func(isAll string) []*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.SameTimeCowTypeEnumList, "sameTimeType": s.SameTimeTypeEnumList, "immunizationCowType": s.ImmunizationCowTypeEnumList, "workOrderFrequency": s.WorkOrderFrequencyEnumList, "workOrderSubUnit": s.WorkOrderSubUnitEnumList, "workOrderPriority": s.WorkOrderPriorityEnumList, "workOrderCategory": s.WorkOrderCategoryEnumList, "immunizationConditions": s.ImmunizationConditionsEnumList, "abortionReasons": s.AbortionReasonsEnumList, "healthStatus": s.HealthStatusEnumList, "calendarType": CalendarTypeEnumList, "calvingAnalysisMethod": s.CalvingAnalysisMethodEnumList, "lact": s.LactEnumList, "diseaseAnalysisMethod": s.DiseaseAnalysisMethodEnumList, "singleFactorAnalysisMethod": s.SingleFactorAnalysisMethodEnumList, "lactIntervalSymbol": s.LactIntervalSymbolEnumList, "multiFactorAnalysisMethod": s.MultiFactorAnalysisMethodEnumList, "saleCowAnalysisMethod": s.SaleCowAnalysisMethodEnumList, "neckRingStatus": s.NeckRingStatusEnumList, "outType": s.OutTypeEnumList, "auditStatus": s.AuditStatusEnumList, "pregnantCheckName": s.PregnantCheckNameEnumList, "unMatingReasons": s.UnMatingReasonsEnumList, "evenType": s.EventTypeEnumList, "departureType": s.DepartureTypeEnumList, "outReason": s.OutReasonEnumList, "deadReason": s.DeadReasonEnumList, "categoryKind": s.EventCategoryEnumList, "indicatorsDetails": s.IndicatorsDetailsList, } getConfigFunc, ok := getConfigFuncMap[optionsName] if !ok { return nil, fmt.Errorf("invalid optionsName: %s", optionsName) } configOptions := getConfigFunc(isAll) if configOptions == nil { return nil, fmt.Errorf("failed to retrieve configOptions for %s", optionsName) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Msg: "ok", Data: configOptions, }, nil }