From 4508dfe00e4a3f0ec338735cacfbf7b76c2191ad Mon Sep 17 00:00:00 2001 From: ziming Date: Wed, 17 Dec 2025 14:59:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=AC=94=E7=AB=8B=E5=87=8F=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/multi.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/internal/biz/multi.go b/internal/biz/multi.go index eddf098..64f8b03 100644 --- a/internal/biz/multi.go +++ b/internal/biz/multi.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/go-kratos/kratos/v2/log" "gorm.io/gorm" + "sync" err2 "voucher/api/err" v1 "voucher/api/v1" "voucher/internal/biz/bo" @@ -28,6 +29,9 @@ type MultiBiz struct { MultiNotifyDataRepo repo.MultiNotifyDataRepo MultiNotifyLogRepo repo.MultiNotifyLogRepo CmbMixRepo mixrepos.CmbMixRepo + + mu sync.RWMutex + NonExistentBatchData map[string]bool } func NewMultiBiz( @@ -52,8 +56,29 @@ func NewMultiBiz( } } +func (this *MultiBiz) Get(uid string) bool { + + if _, ok := this.NonExistentBatchData[uid]; ok { + return ok + } + + return false +} + +func (this *MultiBiz) Add(uid string) { + + this.mu.Lock() + defer this.mu.Unlock() + + this.NonExistentBatchData[uid] = true +} + func (biz *MultiBiz) Notify(ctx context.Context, ip, source string, req *bo.WechatVoucherNotifyBo) error { + if !biz.Get(req.PlainText.StockID) { + return nil + } + cl := vo.MultiNotifyLockKey.BuildCache([]string{ source, req.PlainText.StockID, @@ -65,9 +90,11 @@ func (biz *MultiBiz) Notify(ctx context.Context, ip, source string, req *bo.Wech _, err := biz.ProductRepo.GetByBatchNo(ctx, req.PlainText.StockID) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { + biz.Add(req.PlainText.StockID) return nil } if err2.IsDbNotFound(err) { + biz.Add(req.PlainText.StockID) return nil } return err