123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- 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, penType int) (*pasturePb.ConfigOptionsListResponse, error) {
- penList := make([]*model.Pen, 0)
- if err := s.DB.Table(new(model.Pen).TableName()).
- Where("is_delete = ?", pasturePb.IsShow_Ok).
- Where("pen_type = ?", penType).
- Find(&penList).Error; err != nil {
- return nil, err
- }
- 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.PenSlice(penList).ToPB2(configBarnTypeList),
- }, 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
- }
- func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- switch optionsName {
- case "childNumber":
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: 1,
- Label: "单胎",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: 2,
- Label: "双胎",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: 3,
- Label: "三胎",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: 4,
- Label: "四胎",
- Disabled: true,
- })
- case "calvingLevel":
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.CalvingLevel_Natural_Childbirth),
- Label: "自然分娩",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery1),
- Label: "人工助产(1-2人)",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery2),
- Label: "人工助产(3人以上)",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.CalvingLevel_Caesarean),
- Label: "剖腹产",
- Disabled: true,
- })
- case "dystociaReason":
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DystociaReason_Malposition),
- Label: "胎位不正",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DystociaReason_Fetal_Overgrowth),
- Label: "胎儿过大",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DystociaReason_Uterine_Atony),
- Label: "子宫收缩无力",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DystociaReason_Pelvic_Stenosis),
- Label: "盆骨狭小",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DystociaReason_Sub_Health),
- Label: "母牛亚健康状态",
- Disabled: true,
- })
- }
- return &pasturePb.ConfigOptionsListResponse{
- Code: http.StatusOK,
- Message: "ok",
- Data: configOptions,
- }, nil
- }
|