123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package backend
- import (
- "context"
- "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) {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- switch optionsName {
- case "childNumber":
- configOptions = s.ChildNumberEnumList()
- case "calvingLevel":
- configOptions = s.CalvingLevelEnumList()
- case "dystociaReason":
- configOptions = s.DystociaReasonEnumList()
- case "drugCategory":
- configOptions = s.DrugCategoryEnumList()
- case "drugUsage":
- configOptions = s.DrugUsageEnumList()
- case "unit":
- configOptions = s.UnitEnumList()
- case "pregnantCheckResult":
- configOptions = s.PregnantCheckResultEnumList()
- case "pregnantCheckMethod":
- configOptions = s.PregnantCheckMethodEnumList()
- case "exposeEstrusType":
- configOptions = s.ExposeEstrusTypeEnumList()
- case "frozenSemenType":
- configOptions = s.FrozenSemenTypeEnumList()
- case "week":
- configOptions = s.WeekEnumList()
- case "month":
- configOptions = s.monthEnumList()
- case "sameTimeCowType":
- configOptions = s.SemeTimeCowTypeEnumList()
- case "immunizationCowType":
- configOptions = s.ImmunizationCowTypeEnumList()
- case "workOrderFrequency":
- configOptions = s.WorkOrderFrequencyEnumList()
- case "workOrderSubUnit":
- configOptions = s.WorkOrderSubUnitEnumList()
- case "workOrderPriority":
- configOptions = s.WorkOrderPriorityEnumList()
- case "workOrderCategory":
- configOptions = s.WorkOrderCategoryEnumList()
- case "immunizationConditions":
- configOptions = s.ImmunizationConditionsEnumList()
- }
- return &pasturePb.ConfigOptionsListResponse{
- Code: http.StatusOK,
- Message: "ok",
- Data: configOptions,
- }, nil
- }
|