From 5ff8c8a0e6fd7dd1c21a51c77dce61317ececaf7 Mon Sep 17 00:00:00 2001 From: ziming Date: Tue, 10 Jun 2025 09:50:20 +0800 Subject: [PATCH] query --- internal/biz/cron_notice.go | 12 +++++------- internal/biz/wechat_query.go | 16 ++++++++++------ internal/data/repoimpl/order.go | 1 - internal/pkg/helper/utils_test.go | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/internal/biz/cron_notice.go b/internal/biz/cron_notice.go index 276eb7a..605cb34 100644 --- a/internal/biz/cron_notice.go +++ b/internal/biz/cron_notice.go @@ -18,11 +18,6 @@ func (v *VoucherBiz) Notice(ctx context.Context) error { return err } - return v.ExecuteNotice(ctx) -} - -func (v *VoucherBiz) ExecuteNotice(ctx context.Context) error { - now := time.Now() // 获取七天前的日期 @@ -40,6 +35,11 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context) error { EndTime: &endTime, } + return v.ExecuteNotice(ctx, req) +} + +func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUseBo) error { + return v.OrderRepo.FindInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error { for _, order := range rows { @@ -50,8 +50,6 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context) error { } - time.Sleep(1 * time.Second) - return nil }) diff --git a/internal/biz/wechat_query.go b/internal/biz/wechat_query.go index d9c7534..4bc1781 100644 --- a/internal/biz/wechat_query.go +++ b/internal/biz/wechat_query.go @@ -14,7 +14,7 @@ import ( func (v *VoucherBiz) PushWechatQuery(ctx http.Context, req *do.WechatQuery) error { if v.Get("CMB_WECHAT_QUERY") { - return fmt.Errorf("此台服务队列正在处理中,ip:", ctx.Header().Get("X-Forwarded-For")) + return fmt.Errorf("此台服务队列正在处理中,ip:%s", ctx.Header().Get("X-Forwarded-For")) } if req.ProductNo != "" { @@ -56,12 +56,16 @@ func (v *VoucherBiz) WechatQuery(ctx context.Context, msg string) error { } start := time.Now() - log.Warnf("微信券查询处理开始:%s,msg:%s", start.String(), msg) - fmt.Printf("微信券查询处理开始:%s,msg:%s", start.String(), msg) + startStr := time.Now().String() + log.Warnf("微信券查询处理开始:%s,msg:%s", startStr, msg) + fmt.Printf("微信券查询处理开始:%s,msg:%s", startStr, msg) + + n := 0 num := 0 err := v.OrderRepo.FinSucByStockIdInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error { + n += 1 for _, order := range rows { num += 1 @@ -72,13 +76,13 @@ func (v *VoucherBiz) WechatQuery(ctx context.Context, msg string) error { } - time.Sleep(1 * time.Second) + log.Warnf("微信券查询处理第 %d 批次,执行开始时间:%s,当前执行耗时:%s", n, startStr, time.Now().Sub(start).String()) return nil }) - log.Warnf("微信券查询处理耗时:%s,msg:%s,处理%d单", time.Now().Sub(start).String(), msg, num) - fmt.Printf("微信券查询处理耗时:%s,msg:%s,处理%d单", time.Now().Sub(start).String(), msg, num) + log.Warnf("微信券查询处理耗时:%s,处理%d单,msg:%s", time.Now().Sub(start).String(), num, msg) + fmt.Printf("微信券查询处理耗时:%s,处理%d单,msg:%s", time.Now().Sub(start).String(), num, msg) return err } diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index 3ff09e3..6c803bc 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -101,7 +101,6 @@ func (p *OrderRepoImpl) FindInBatches(ctx context.Context, w *bo.FindInBatchesUs var results = make([]*model.Order, 0) result := p.DB(ctx). - Where("type = ?", w.Type). Where("status IN (?)", []uint8{vo.OrderStatusSuccess.GetValue(), vo.OrderStatusUse.GetValue()}). Where("receive_success_time BETWEEN ? AND ?", w.StartTime, w.EndTime). FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { diff --git a/internal/pkg/helper/utils_test.go b/internal/pkg/helper/utils_test.go index 64996c6..8f14839 100644 --- a/internal/pkg/helper/utils_test.go +++ b/internal/pkg/helper/utils_test.go @@ -15,11 +15,11 @@ func TestNoticeTime(t *testing.T) { now := time.Now() // 获取七天前的日期 - noticeStartDay := now.AddDate(0, 0, -29) + noticeStartDay := now.AddDate(0, 0, -15) // 获取七天前 00:00:00 的时间 startTime := time.Date(noticeStartDay.Year(), noticeStartDay.Month(), noticeStartDay.Day(), 0, 0, 0, 0, noticeStartDay.Location()) - noticeEndDay := now.AddDate(0, 0, -28) + noticeEndDay := now.AddDate(0, 0, -1) // 获取昨天 23:59:59 的时间 endTime := time.Date(noticeEndDay.Year(), noticeEndDay.Month(), noticeEndDay.Day(), 23, 59, 59, 0, noticeEndDay.Location())