This commit is contained in:
李子铭 2025-03-20 19:46:15 +08:00
parent a8dae49f45
commit a1750d6959
4 changed files with 10 additions and 10 deletions

View File

@ -36,7 +36,7 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or
return nil return nil
} }
product, err := v.ProductRepo.GetByPNO(ctx, req.ProductNo) product, err := v.ProductRepo.GetByProductNo(ctx, req.ProductNo)
if err != nil { if err != nil {
return err return err
} }
@ -98,7 +98,7 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error { err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
product, err := v.ProductRepo.GetByPNO(ctx, productNo) product, err := v.ProductRepo.GetByProductNo(ctx, productNo)
if err != nil { if err != nil {
return err return err
} }

View File

@ -130,7 +130,7 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo) error {
Type: order.Type, Type: order.Type,
} }
if err := v.cmbNotice(ctx, order, orderNotify); err != nil { if err = v.cmbNotice(ctx, order, orderNotify); err != nil {
return err return err
} }

View File

@ -6,5 +6,5 @@ import (
) )
type ProductRepo interface { type ProductRepo interface {
GetByPNO(ctx context.Context, PNO string) (*bo.ProductBo, error) GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error)
} }

View File

@ -32,11 +32,11 @@ func (p *ProductRepoImpl) DB(ctx context.Context) *gorm.DB {
return p.db.DB(ctx).WithContext(ctx).Model(model.Product{}) return p.db.DB(ctx).WithContext(ctx).Model(model.Product{})
} }
func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.ProductBo, error) { func (r *ProductRepoImpl) GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error) {
var item *model.Product var item *model.Product
c := vo.ProductQueryKey.BuildCache([]string{PNO}) c := vo.ProductQueryKey.BuildCache([]string{productNo})
cacheValue, err := r.rdb.Rdb.Get(ctx, c.Key).Result() cacheValue, err := r.rdb.Rdb.Get(ctx, c.Key).Result()
@ -51,7 +51,7 @@ func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.Product
return r.ToBo(item), nil return r.ToBo(item), nil
} }
cl := vo.ProductQueryLockKey.BuildCache([]string{PNO}) cl := vo.ProductQueryLockKey.BuildCache([]string{productNo})
err = lock.NewMutex(r.rdb.Rdb, cl.TTL).Lock(ctx, cl.Key, func(ctx context.Context) error { err = lock.NewMutex(r.rdb.Rdb, cl.TTL).Lock(ctx, cl.Key, func(ctx context.Context) error {
@ -65,7 +65,7 @@ func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.Product
return json.Unmarshal([]byte(cacheValue), &item) return json.Unmarshal([]byte(cacheValue), &item)
} }
item, err = r.getByPNO(ctx, item, PNO) item, err = r.getByProductNo(ctx, item, productNo)
b, err := json.Marshal(item) b, err := json.Marshal(item)
if err != nil { if err != nil {
@ -82,10 +82,10 @@ func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.Product
return r.ToBo(item), err return r.ToBo(item), err
} }
func (r *ProductRepoImpl) getByPNO(ctx context.Context, item *model.Product, PNO string) (*model.Product, error) { func (r *ProductRepoImpl) getByProductNo(ctx context.Context, item *model.Product, productNo string) (*model.Product, error) {
db := r.DB(ctx) db := r.DB(ctx)
tx := db.Where(model.Product{ProductNo: PNO}).First(&item) tx := db.Where(model.Product{ProductNo: productNo}).First(&item)
if tx.Error != nil { if tx.Error != nil {
sqlDB, _ := db.DB() sqlDB, _ := db.DB()