多笔立减金

This commit is contained in:
ziming 2025-12-17 14:59:09 +08:00
parent d1fb805dff
commit 4508dfe00e
1 changed files with 27 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/log"
"gorm.io/gorm" "gorm.io/gorm"
"sync"
err2 "voucher/api/err" err2 "voucher/api/err"
v1 "voucher/api/v1" v1 "voucher/api/v1"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
@ -28,6 +29,9 @@ type MultiBiz struct {
MultiNotifyDataRepo repo.MultiNotifyDataRepo MultiNotifyDataRepo repo.MultiNotifyDataRepo
MultiNotifyLogRepo repo.MultiNotifyLogRepo MultiNotifyLogRepo repo.MultiNotifyLogRepo
CmbMixRepo mixrepos.CmbMixRepo CmbMixRepo mixrepos.CmbMixRepo
mu sync.RWMutex
NonExistentBatchData map[string]bool
} }
func NewMultiBiz( 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 { 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{ cl := vo.MultiNotifyLockKey.BuildCache([]string{
source, source,
req.PlainText.StockID, 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) _, err := biz.ProductRepo.GetByBatchNo(ctx, req.PlainText.StockID)
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
biz.Add(req.PlainText.StockID)
return nil return nil
} }
if err2.IsDbNotFound(err) { if err2.IsDbNotFound(err) {
biz.Add(req.PlainText.StockID)
return nil return nil
} }
return err return err