package backend import ( "context" "kpt-pasture/model" "kpt-pasture/util" "net/http" "gitee.com/xuyiping_admin/pkg/xerr" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) // PregnancyReport 孕检报告列表 func (s *StoreEntry) PregnancyReport(ctx context.Context, req *pasturePb.PregnancyReportRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyReportResponse, error) { startDayUnix := util.TimeParseLocalUnix(req.StartDayTime) endDayUnix := util.TimeParseLocalEndUnix(req.EndDayTime) if startDayUnix > endDayUnix || startDayUnix == 0 || endDayUnix == 0 { return nil, xerr.Custom("开始时间不能大于结束时间") } eventPregnantCheckList := make([]*model.EventPregnantCheck, 0) pref := s.DB.Model(new(model.EventPregnantCheck)).Where("status = ?", pasturePb.IsShow_Ok).Where("cow_type = ?", req.CowType) if startDayUnix > 0 && endDayUnix > 0 && endDayUnix >= startDayUnix { pref = pref.Where("create_time BETWEEN ? AND ?", startDayUnix, endDayUnix) } if req.PregnantCheckResult > 0 { pref = pref.Where("pregnant_check_result = ?", req.PregnantCheckResult) } var count int64 = 0 if err := pref.Count(&count). Limit(int(pagination.PageSize)). Offset(int(pagination.PageOffset)). Order("id desc"). Find(&eventPregnantCheckList).Error; err != nil { return nil, xerr.WithStack(err) } pregnantCheckResultMap := s.PregnantCheckResultMap() pregnantCheckMethodMap := s.PregnantCheckMethodMap() return &pasturePb.PregnancyReportResponse{ Code: http.StatusOK, Message: "ok", Data: &pasturePb.PregnancyReportData{ List: model.EventPregnantCheckSlice(eventPregnantCheckList).ToPB3(pregnantCheckResultMap, pregnantCheckMethodMap), Total: int32(count), PageSize: pagination.PageSize, Page: pagination.Page, }, }, nil }