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