异步通知

This commit is contained in:
李子铭 2025-03-15 14:26:17 +08:00
parent 091e0ef0ce
commit 3b672e7e05
6 changed files with 33 additions and 20 deletions

View File

@ -49,6 +49,8 @@ wechatNotifyMQ:
- voucher_notify_dev
isOpenConsumer: false #是否启动消费 true/false
registerTagUrl: "https://wpcallbacks.api.1688sup.com/wechatPay/register_tag"
noticeStartDays: 7
noticeEndDays: 1
wechat:
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置

View File

@ -49,6 +49,8 @@ wechatNotifyMQ:
- voucher_notify_dev
isOpenConsumer: false #是否启动消费 true/false
registerTagUrl: "https://wpcallbacks.api.1688sup.com/wechatPay/register_tag"
noticeStartDays: 7
noticeEndDays: 1
wechat:
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置

View File

@ -2,6 +2,7 @@ package biz
import (
"context"
"errors"
"fmt"
"github.com/go-kratos/kratos/v2/log"
"github.com/redis/go-redis/v9"
@ -17,6 +18,11 @@ func (v *VoucherBiz) OrderNotice(ctx context.Context) error {
return err
}
return v.ExecuteNotice(ctx)
}
func (v *VoucherBiz) ExecuteNotice(ctx context.Context) error {
now := time.Now()
// 获取七天前的日期
@ -41,8 +47,7 @@ func (v *VoucherBiz) OrderNotice(ctx context.Context) error {
if order.Type.IsCmb() {
if err := v.cmbOrderNotice(ctx, order); err != nil {
log.Errorf("cmbOrderNotice err:%v", err)
return err
log.Errorf("招行查询券订单状态发生错误,orderNo:%s,err:%v", order.OrderNo, err)
}
}
@ -57,13 +62,11 @@ func (v *VoucherBiz) OrderNotice(ctx context.Context) error {
func (v *VoucherBiz) isCanNotice(ctx context.Context) error {
if v.bc.Cmb.NoticeStartDays == 0 {
log.Warnf("noticeStartDays eq 0")
return nil
return errors.New("noticeStartDays eq 0")
}
if v.bc.Cmb.NoticeEndDays == 0 {
log.Warnf("noticeEndDays eq 0")
return nil
return errors.New("noticeEndDays eq 0")
}
cache := vo.CmbBatchNoticeCacheKey.BuildCache([]string{""})

View File

@ -32,15 +32,11 @@ func (p *OrderRepoImpl) FindInBatches(ctx context.Context, w *bo.FindInBatchesUs
var results = make([]*model.Order, 0)
db := p.db.DB(ctx)
db.Where("type = ?", w.Type)
db.Where("status = ?", vo.OrderStatusUse)
db.Where("last_use_time >= ?", w.StartTime)
db.Where("last_use_time <= ?", w.EndTime)
// 处理记录批处理大小为100
result := db.FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
result := p.db.DB(ctx).
Where("last_use_time BETWEEN ? AND ?", w.StartTime, w.EndTime).
Where("type = ?", w.Type).
Where("status = ?", vo.OrderStatusUse).
FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
// tx.RowsAffected 提供当前批处理中记录的计数the count of records in the current batch
// 'batch' 变量表示当前批号the current batch number
// 返回 error 将阻止更多的批处理

View File

@ -50,6 +50,7 @@ func NewHTTPServer(
v1.POST("/decryptBody", voucherService.DecryptBody)
v1.POST("/queryWechatVoucherNotifyUrl", voucherService.QueryWechatVoucherNotifyUrl)
v1.POST("/setWechatVoucherNotifyUrl", voucherService.SetWechatVoucherNotifyUrl)
v1.POST("/test", voucherService.Test)
return srv
}

View File

@ -151,3 +151,12 @@ func (s *VoucherService) SetWechatVoucherNotifyUrl(ctx http.Context) error {
//})
return nil
}
func (s *VoucherService) Test(ctx http.Context) error {
if err := s.VoucherBiz.ExecuteNotice(ctx); err != nil {
return err
}
return nil
}