123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package backend
- import (
- "context"
- "fmt"
- "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
- }
- // CalvingReport 产犊报告
- func (s *StoreEntry) CalvingReport(ctx context.Context, req *pasturePb.CalvingReportRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingReportResponse, error) {
- lastDayOfMonth, err := util.GetLastDayOfMonth(req.EndDayTime)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- endDayTimeUnix := util.TimeParseLocalEndUnix(lastDayOfMonth)
- startDayTimeUnix := util.TimeParseLocalUnix(fmt.Sprintf("%s-01", req.StartDayTime))
- if startDayTimeUnix == 0 || endDayTimeUnix == 0 || endDayTimeUnix <= startDayTimeUnix {
- return nil, xerr.Custom("开始时间不能大于结束时间")
- }
- var count int64 = 0
- eventCalvingList := make([]*model.EventCalving, 0)
- pref := s.DB.Model(new(model.EventCalving)).
- Where("reality_day BETWEEN ? AND ? ", startDayTimeUnix, endDayTimeUnix)
- fmt.Println(pref)
- return &pasturePb.CalvingReportResponse{
- Code: http.StatusOK,
- Message: "ok",
- Data: &pasturePb.CalvingReportData{
- List: model.EventCalvingSlice(eventCalvingList).ToPB(),
- Total: int32(count),
- PageSize: pagination.PageSize,
- Page: pagination.Page,
- },
- }, nil
- }
|