package backend import ( "context" "kpt-pasture/model" "net/http" "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" "gitee.com/xuyiping_admin/pkg/xerr" ) func (s *StoreEntry) CalendarList(ctx context.Context, req *pasturePb.CalendarRequest) (*pasturePb.CalendarResponse, error) { calendarList := make([]*model.Calendar, 0) if err := s.DB.Model(&model.Calendar{}). Where("show_day >= ?", req.ShowStartDay). Where("show_day <= ?", req.ShowEndDay). Where("is_show = ?", pasturePb.IsShow_Ok). Find(&calendarList).Error; err != nil { return nil, xerr.WithStack(err) } return &pasturePb.CalendarResponse{ Code: http.StatusOK, Message: "ok", Data: model.CalendarSlice(calendarList).ToPB(), }, nil } func (s *StoreEntry) CalendarTableDetail( ctx context.Context, req *pasturePb.CalendarTableRequest, pagination *pasturePb.PaginationModel, ) (interface{}, error) { if req.Start != time.Now().Format(model.LayoutDate2) { return nil, xerr.New("参数错误") } newCalendar := &model.Calendar{} if err := s.DB.Model(&model.Calendar{}). Where("calendar_type = ?", req.CalendarType). Where("show_day = ?", req.Start). Where("is_show = ?", pasturePb.IsShow_Ok). First(newCalendar).Error; err != nil { return nil, xerr.WithStack(err) } if newCalendar.Id == 0 { return nil, xerr.New("不存在该日历数据") } return s.getCalendarCowList(ctx, req.CalendarType, req.Start, pagination), nil } func (s *StoreEntry) getCalendarCowList( ctx context.Context, calendarType pasturePb.CalendarType_Kind, startDate string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { switch calendarType { case pasturePb.CalendarType_Immunisation: // 免疫 return s.ImmunisationCowList(ctx, startDate, pagination) case pasturePb.CalendarType_PG: // 同期PG return s.PGCowList(ctx, startDate, pagination) case pasturePb.CalendarType_RnGH: // 同期RnGH return s.RnGHCowList(ctx, startDate, pagination) case pasturePb.CalendarType_Pregnancy_Check: // 孕检 return s.PregnancyCheckCowList(ctx, startDate, pagination) case pasturePb.CalendarType_WorkOrder: // 工作单 return s.WorkOrderCowList(ctx, startDate, pagination) case pasturePb.CalendarType_Weaning: // 断奶 return s.WeaningCowList(ctx, startDate, pagination) case pasturePb.CalendarType_Treatment: // 治疗 return s.TreatmentCowList(ctx, startDate, pagination) case pasturePb.CalendarType_Mating: // 配种 return s.MatingCowList(ctx, startDate, pagination) default: return nil, xerr.New("不支持的日历类型") } } func (s *StoreEntry) ImmunisationCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { immunizationPlanCowList := make([]*model.ImmunizationPlanCow, 0) count := int64(0) if err := s.DB.Model(&model.ImmunizationPlanCow{}). Where("plan_start_time <= ?", dateTime). Where("status = ?", pasturePb.IsShow_No). Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)). Find(&immunizationPlanCowList).Error; err != nil { return nil, xerr.WithStack(err) } return &model.CalendarResponse{ Code: http.StatusOK, Message: "ok", Data: &model.CalendarData{ Total: int32(count), Page: pagination.Page, PageSize: pagination.PageSize, Header: model.ImmunizationCalendarHeader{ Id: "id", CowId: "cowId", PlanStartTime: "planStartTime", ImmunizationPlanId: "immunizationPlanId", ImmunizationPlanName: "immunizationPlanName", Status: "status", }, List: model.ImmunizationPlanCowSlice(immunizationPlanCowList).ToPB(), }, }, nil } func (s *StoreEntry) PGCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { return nil, nil } func (s *StoreEntry) RnGHCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { return nil, nil } func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { return nil, nil } func (s *StoreEntry) WorkOrderCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { return nil, nil } func (s *StoreEntry) WeaningCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { return nil, nil } func (s *StoreEntry) TreatmentCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { return nil, nil } func (s *StoreEntry) MatingCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) { return nil, nil }