订单生成调整
This commit is contained in:
parent
5494d7079e
commit
fbe1d8712e
|
|
@ -4,6 +4,6 @@ import "context"
|
||||||
|
|
||||||
// GenerateMixRepo interface
|
// GenerateMixRepo interface
|
||||||
type GenerateMixRepo interface {
|
type GenerateMixRepo interface {
|
||||||
GeneratorString(ctx context.Context, workId int) (string, error)
|
GeneratorString(ctx context.Context) string
|
||||||
GeneratorNumber(ctx context.Context, workId int) (uint64, error)
|
GeneratorNumber(ctx context.Context) int64
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
"voucher/internal/pkg/lock"
|
"voucher/internal/pkg/lock"
|
||||||
"voucher/internal/pkg/uid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *VoucherBiz) order(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.ProductBo) (*bo.OrderBo, error) {
|
func (v *VoucherBiz) order(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.ProductBo) (*bo.OrderBo, error) {
|
||||||
|
|
@ -64,13 +63,8 @@ func (v *VoucherBiz) orderRetry(ctx context.Context, order *bo.OrderBo) error {
|
||||||
|
|
||||||
func (v *VoucherBiz) create(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.ProductBo) (*bo.OrderBo, error) {
|
func (v *VoucherBiz) create(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.ProductBo) (*bo.OrderBo, error) {
|
||||||
|
|
||||||
orderNo, err := v.GenerateMixRepo.GeneratorString(ctx, uid.Order)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return v.OrderRepo.Create(ctx, &bo.OrderBo{
|
return v.OrderRepo.Create(ctx, &bo.OrderBo{
|
||||||
OrderNo: orderNo,
|
OrderNo: v.GenerateMixRepo.GeneratorString(ctx),
|
||||||
OutBizNo: req.OutBizNo,
|
OutBizNo: req.OutBizNo,
|
||||||
ProductNo: req.ProductNo,
|
ProductNo: req.ProductNo,
|
||||||
Account: req.Account,
|
Account: req.Account,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"voucher/internal/biz/mixrepos"
|
"voucher/internal/biz/mixrepos"
|
||||||
"voucher/internal/data"
|
"voucher/internal/data"
|
||||||
"voucher/internal/pkg/uid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenerateRepoImpl struct {
|
type GenerateRepoImpl struct {
|
||||||
|
|
@ -25,6 +24,7 @@ func NewGenerateMixRepoImpl(rdb *data.Rdb) (mixrepos.GenerateMixRepo, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
serverId := g.hashMod(name)
|
serverId := g.hashMod(name)
|
||||||
|
|
||||||
node, err := snowflake.NewNode(int64(serverId))
|
node, err := snowflake.NewNode(int64(serverId))
|
||||||
|
|
@ -37,35 +37,6 @@ func NewGenerateMixRepoImpl(rdb *data.Rdb) (mixrepos.GenerateMixRepo, error) {
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeneratorString 生成字符串
|
|
||||||
func (s *GenerateRepoImpl) GeneratorString(_ context.Context, workId int) (string, error) {
|
|
||||||
|
|
||||||
return s.node.Generate().String(), nil
|
|
||||||
|
|
||||||
//serverIdStr := uid.GetAppId(ctx)
|
|
||||||
//serverId := s.hashMod(serverIdStr)
|
|
||||||
//
|
|
||||||
//number, err := uid.NewSignGenerator(s.rdb.Rdb).SetWorkerID(workId).SetServerID(serverId).GetNumber()
|
|
||||||
//if err != nil {
|
|
||||||
// return "", err
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//return strconv.FormatUint(number, 10), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GeneratorNumber 生成unit64
|
|
||||||
func (s *GenerateRepoImpl) GeneratorNumber(ctx context.Context, workId int) (uint64, error) {
|
|
||||||
serverIdStr := uid.GetAppId(ctx)
|
|
||||||
serverId := s.hashMod(serverIdStr)
|
|
||||||
|
|
||||||
number, err := uid.NewSignGenerator(s.rdb.Rdb).SetWorkerID(workId).SetServerID(serverId).GetNumber()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return number, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// hashMod hash mod
|
// hashMod hash mod
|
||||||
func (s *GenerateRepoImpl) hashMod(hashStr string) int {
|
func (s *GenerateRepoImpl) hashMod(hashStr string) int {
|
||||||
hash := fnv.New32a()
|
hash := fnv.New32a()
|
||||||
|
|
@ -74,3 +45,13 @@ func (s *GenerateRepoImpl) hashMod(hashStr string) int {
|
||||||
hashValue := hash.Sum32()
|
hashValue := hash.Sum32()
|
||||||
return int(math.Mod(float64(hashValue), 32))
|
return int(math.Mod(float64(hashValue), 32))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GeneratorString 生成字符串
|
||||||
|
func (s *GenerateRepoImpl) GeneratorString(_ context.Context) string {
|
||||||
|
return s.node.Generate().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GeneratorNumber 生成 int64
|
||||||
|
func (s *GenerateRepoImpl) GeneratorNumber(_ context.Context) int64 {
|
||||||
|
return s.node.Generate().Int64()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue