analysis_other.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package backend
  2. import (
  3. "context"
  4. "kpt-pasture/model"
  5. "kpt-pasture/util"
  6. "net/http"
  7. "gitee.com/xuyiping_admin/pkg/xerr"
  8. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  9. )
  10. // PregnancyReport 孕检报告列表
  11. func (s *StoreEntry) PregnancyReport(ctx context.Context, req *pasturePb.PregnancyReportRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyReportResponse, error) {
  12. startDayUnix := util.TimeParseLocalUnix(req.StartDayTime)
  13. endDayUnix := util.TimeParseLocalEndUnix(req.EndDayTime)
  14. if startDayUnix > endDayUnix || startDayUnix == 0 || endDayUnix == 0 {
  15. return nil, xerr.Custom("开始时间不能大于结束时间")
  16. }
  17. eventPregnantCheckList := make([]*model.EventPregnantCheck, 0)
  18. pref := s.DB.Model(new(model.EventPregnantCheck)).Where("status = ?", pasturePb.IsShow_Ok).Where("cow_type = ?", req.CowType)
  19. if startDayUnix > 0 && endDayUnix > 0 && endDayUnix >= startDayUnix {
  20. pref = pref.Where("create_time BETWEEN ? AND ?", startDayUnix, endDayUnix)
  21. }
  22. if req.PregnantCheckResult > 0 {
  23. pref = pref.Where("pregnant_check_result = ?", req.PregnantCheckResult)
  24. }
  25. var count int64 = 0
  26. if err := pref.Count(&count).
  27. Limit(int(pagination.PageSize)).
  28. Offset(int(pagination.PageOffset)).
  29. Order("id desc").
  30. Find(&eventPregnantCheckList).Error; err != nil {
  31. return nil, xerr.WithStack(err)
  32. }
  33. pregnantCheckResultMap := s.PregnantCheckResultMap()
  34. pregnantCheckMethodMap := s.PregnantCheckMethodMap()
  35. return &pasturePb.PregnancyReportResponse{
  36. Code: http.StatusOK,
  37. Message: "ok",
  38. Data: &pasturePb.PregnancyReportData{
  39. List: model.EventPregnantCheckSlice(eventPregnantCheckList).ToPB3(pregnantCheckResultMap, pregnantCheckMethodMap),
  40. Total: int32(count),
  41. PageSize: pagination.PageSize,
  42. Page: pagination.Page,
  43. },
  44. }, nil
  45. }