cmb
This commit is contained in:
parent
803a8706b1
commit
27743f103a
|
|
@ -116,6 +116,10 @@ func loadConfig() *conf.Bootstrap {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bc := loadConfig()
|
bc := loadConfig()
|
||||||
|
if bc == nil {
|
||||||
|
panic("配置文件加载失败")
|
||||||
|
}
|
||||||
|
|
||||||
businessLogger := log2.NewBusinessLogger(bc.Logs.Business, Name, Name, Version)
|
businessLogger := log2.NewBusinessLogger(bc.Logs.Business, Name, Name, Version)
|
||||||
accessLogger := log2.NewAccessLogger(bc.Logs.Business, id, Name, Version)
|
accessLogger := log2.NewAccessLogger(bc.Logs.Business, id, Name, Version)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
|
||||||
v1 "voucher/api/v1"
|
v1 "voucher/api/v1"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
|
|
@ -14,7 +13,9 @@ import (
|
||||||
|
|
||||||
func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) {
|
func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) {
|
||||||
|
|
||||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error {
|
c := vo.CmbOrderLockKey.BuildCache([]string{req.OutBizNo})
|
||||||
|
|
||||||
|
err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
|
||||||
|
|
||||||
order, err := v.OrderRepo.GetByOutBizNo(ctx, req.OutBizNo)
|
order, err := v.OrderRepo.GetByOutBizNo(ctx, req.OutBizNo)
|
||||||
|
|
||||||
|
|
@ -48,7 +49,9 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or
|
||||||
|
|
||||||
func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (reps *v1.CmbQueryProductReply, err error) {
|
func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (reps *v1.CmbQueryProductReply, err error) {
|
||||||
|
|
||||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_product_query_%s", productNo), func(ctx context.Context) error {
|
c := vo.CmbProductQueryLockKey.BuildCache([]string{productNo})
|
||||||
|
|
||||||
|
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.GetByPNO(ctx, productNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,21 @@ import (
|
||||||
type CacheKey string
|
type CacheKey string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
CmbOrderLockKey CacheKey = "cmb_order"
|
||||||
|
CmbProductQueryLockKey CacheKey = "cmb_product_query"
|
||||||
|
|
||||||
WechatNotifyRegisterTagCacheKey CacheKey = "wechat_notify_register_tag"
|
WechatNotifyRegisterTagCacheKey CacheKey = "wechat_notify_register_tag"
|
||||||
WechatNotifyRegisterTagCacheLockKey CacheKey = "wechat_notify_register_tag_lock"
|
WechatNotifyRegisterTagCacheLockKey CacheKey = "wechat_notify_register_tag_lock"
|
||||||
|
|
||||||
WechatNotifyConsumeKey CacheKey = "wechat_notify_consume"
|
WechatNotifyConsumeLockKey CacheKey = "wechat_notify_consume"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CacheKeyMap = map[CacheKey]time.Duration{
|
var CacheKeyMap = map[CacheKey]time.Duration{
|
||||||
|
CmbOrderLockKey: 30 * time.Second,
|
||||||
|
CmbProductQueryLockKey: 30 * time.Second,
|
||||||
WechatNotifyRegisterTagCacheKey: 86400 * time.Second,
|
WechatNotifyRegisterTagCacheKey: 86400 * time.Second,
|
||||||
WechatNotifyRegisterTagCacheLockKey: 30 * time.Second,
|
WechatNotifyRegisterTagCacheLockKey: 30 * time.Second,
|
||||||
|
WechatNotifyConsumeLockKey: 30 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (j *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *bo.WechatVoucherNotifyBo) error {
|
func (j *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *bo.WechatVoucherNotifyBo) error {
|
||||||
c := vo.WechatNotifyConsumeKey.BuildCache([]string{tag, req.PlainText.StockID, req.PlainText.CouponID})
|
c := vo.WechatNotifyConsumeLockKey.BuildCache([]string{tag, req.PlainText.StockID, req.PlainText.CouponID})
|
||||||
|
|
||||||
return lock.NewMutex(j.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
|
return lock.NewMutex(j.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue