analysis_other.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/model"
  6. "kpt-pasture/util"
  7. "net/http"
  8. "gitee.com/xuyiping_admin/pkg/xerr"
  9. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  10. )
  11. // PregnancyReport 孕检报告
  12. func (s *StoreEntry) PregnancyReport(ctx context.Context, req *pasturePb.PregnancyReportRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyReportResponse, error) {
  13. startDayUnix := util.TimeParseLocalUnix(req.StartDayTime)
  14. endDayUnix := util.TimeParseLocalEndUnix(req.EndDayTime)
  15. if startDayUnix > endDayUnix || startDayUnix == 0 || endDayUnix == 0 {
  16. return nil, xerr.Custom("开始时间不能大于结束时间")
  17. }
  18. eventPregnantCheckList := make([]*model.EventPregnantCheck, 0)
  19. pref := s.DB.Model(new(model.EventPregnantCheck)).Where("status = ?", pasturePb.IsShow_Ok).Where("cow_type = ?", req.CowType)
  20. if startDayUnix > 0 && endDayUnix > 0 && endDayUnix >= startDayUnix {
  21. pref = pref.Where("create_time BETWEEN ? AND ?", startDayUnix, endDayUnix)
  22. }
  23. if req.PregnantCheckResult > 0 {
  24. pref = pref.Where("pregnant_check_result = ?", req.PregnantCheckResult)
  25. }
  26. var count int64 = 0
  27. if err := pref.Count(&count).
  28. Limit(int(pagination.PageSize)).
  29. Offset(int(pagination.PageOffset)).
  30. Order("id desc").
  31. Find(&eventPregnantCheckList).Error; err != nil {
  32. return nil, xerr.WithStack(err)
  33. }
  34. pregnantCheckResultMap := s.PregnantCheckResultMap()
  35. pregnantCheckMethodMap := s.PregnantCheckMethodMap()
  36. return &pasturePb.PregnancyReportResponse{
  37. Code: http.StatusOK,
  38. Message: "ok",
  39. Data: &pasturePb.PregnancyReportData{
  40. List: model.EventPregnantCheckSlice(eventPregnantCheckList).ToPB3(pregnantCheckResultMap, pregnantCheckMethodMap),
  41. Total: int32(count),
  42. PageSize: pagination.PageSize,
  43. Page: pagination.Page,
  44. },
  45. }, nil
  46. }
  47. // CalvingReport 产犊报告
  48. func (s *StoreEntry) CalvingReport(ctx context.Context, req *pasturePb.CalvingReportRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingReportResponse, error) {
  49. lastDayOfMonth, err := util.GetLastDayOfMonth(req.EndDayTime)
  50. if err != nil {
  51. return nil, xerr.WithStack(err)
  52. }
  53. endDayTimeUnix := util.TimeParseLocalEndUnix(lastDayOfMonth)
  54. startDayTimeUnix := util.TimeParseLocalUnix(fmt.Sprintf("%s-01", req.StartDayTime))
  55. if startDayTimeUnix == 0 || endDayTimeUnix == 0 || endDayTimeUnix <= startDayTimeUnix {
  56. return nil, xerr.Custom("开始时间不能大于结束时间")
  57. }
  58. var count int64 = 0
  59. eventCalvingList := make([]*model.EventCalving, 0)
  60. pref := s.DB.Model(new(model.EventCalving)).
  61. Where("reality_day BETWEEN ? AND ? ", startDayTimeUnix, endDayTimeUnix)
  62. fmt.Println(pref)
  63. return &pasturePb.CalvingReportResponse{
  64. Code: http.StatusOK,
  65. Message: "ok",
  66. Data: &pasturePb.CalvingReportData{
  67. List: model.EventCalvingSlice(eventCalvingList).ToPB(),
  68. Total: int32(count),
  69. PageSize: pagination.PageSize,
  70. Page: pagination.Page,
  71. },
  72. }, nil
  73. }