db fail
This commit is contained in:
parent
f469b36833
commit
e511aae2d4
|
|
@ -36,6 +36,7 @@ type OrderCreateReqBo struct {
|
||||||
AppID string
|
AppID string
|
||||||
Type vo.OrderType
|
Type vo.OrderType
|
||||||
AccountType vo.OrderAccountType
|
AccountType vo.OrderAccountType
|
||||||
|
NotifyUrl string
|
||||||
Attach string
|
Attach string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@ import "context"
|
||||||
|
|
||||||
// GenerateMixRepo interface
|
// GenerateMixRepo interface
|
||||||
type GenerateMixRepo interface {
|
type GenerateMixRepo interface {
|
||||||
GeneratorString(ctx context.Context) string
|
GeneratorString(ctx context.Context, uid string) string
|
||||||
GeneratorNumber(ctx context.Context) int64
|
GeneratorNumber(ctx context.Context, uid string) int64
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ 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) {
|
||||||
|
|
||||||
return v.OrderRepo.Create(ctx, &bo.OrderBo{
|
return v.OrderRepo.Create(ctx, &bo.OrderBo{
|
||||||
OrderNo: v.GenerateMixRepo.GeneratorString(ctx),
|
OrderNo: v.GenerateMixRepo.GeneratorString(ctx, fmt.Sprintf("%d%s", req.Type, req.OutBizNo)),
|
||||||
OutBizNo: req.OutBizNo,
|
OutBizNo: req.OutBizNo,
|
||||||
ProductNo: req.ProductNo,
|
ProductNo: req.ProductNo,
|
||||||
Account: req.Account,
|
Account: req.Account,
|
||||||
|
|
@ -72,9 +72,9 @@ func (v *VoucherBiz) create(ctx context.Context, req *bo.OrderCreateReqBo, produ
|
||||||
MerchantNo: product.MchId,
|
MerchantNo: product.MchId,
|
||||||
Channel: product.Channel,
|
Channel: product.Channel,
|
||||||
BatchNo: product.BatchNo,
|
BatchNo: product.BatchNo,
|
||||||
NotifyUrl: v.bc.Cmb.NotifyUrl,
|
NotifyUrl: req.NotifyUrl,
|
||||||
AccountType: vo.OrderAccountTypeOpenId,
|
AccountType: vo.OrderAccountTypeOpenId,
|
||||||
Type: vo.OrderTypeCmb,
|
Type: req.Type,
|
||||||
Status: vo.OrderStatusIng, // 同步发放,状态至为发放中
|
Status: vo.OrderStatusIng, // 同步发放,状态至为发放中
|
||||||
Attach: req.Attach,
|
Attach: req.Attach,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ package mixrepoimpl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/bwmarrin/snowflake"
|
"github.com/bwmarrin/snowflake"
|
||||||
"hash/fnv"
|
|
||||||
"math"
|
|
||||||
"os"
|
"os"
|
||||||
"voucher/internal/biz/mixrepos"
|
"voucher/internal/biz/mixrepos"
|
||||||
"voucher/internal/data"
|
"voucher/internal/data"
|
||||||
|
"voucher/internal/pkg/helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenerateRepoImpl struct {
|
type GenerateRepoImpl struct {
|
||||||
|
|
@ -25,7 +25,7 @@ func NewGenerateMixRepoImpl(rdb *data.Rdb) (mixrepos.GenerateMixRepo, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
serverId := g.hashMod(name)
|
serverId := helper.HashMod(name)
|
||||||
|
|
||||||
node, err := snowflake.NewNode(int64(serverId))
|
node, err := snowflake.NewNode(int64(serverId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -37,21 +37,14 @@ func NewGenerateMixRepoImpl(rdb *data.Rdb) (mixrepos.GenerateMixRepo, error) {
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashMod hash mod
|
|
||||||
func (s *GenerateRepoImpl) hashMod(hashStr string) int {
|
|
||||||
hash := fnv.New32a()
|
|
||||||
_, _ = hash.Write([]byte(hashStr))
|
|
||||||
|
|
||||||
hashValue := hash.Sum32()
|
|
||||||
return int(math.Mod(float64(hashValue), 32))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GeneratorString 生成字符串
|
// GeneratorString 生成字符串
|
||||||
func (s *GenerateRepoImpl) GeneratorString(_ context.Context) string {
|
func (s *GenerateRepoImpl) GeneratorString(_ context.Context, uid string) string {
|
||||||
return s.node.Generate().String()
|
id := helper.HashMod(uid)
|
||||||
|
return fmt.Sprintf("%s%d", s.node.Generate().String(), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeneratorNumber 生成 int64
|
// GeneratorNumber 生成 int64
|
||||||
func (s *GenerateRepoImpl) GeneratorNumber(_ context.Context) int64 {
|
func (s *GenerateRepoImpl) GeneratorNumber(_ context.Context, uid string) int64 {
|
||||||
return s.node.Generate().Int64()
|
id := helper.HashMod(uid)
|
||||||
|
return s.node.Generate().Int64() + int64(id)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"hash/fnv"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func FileExists(filePath string) bool {
|
func FileExists(filePath string) bool {
|
||||||
|
|
@ -10,46 +11,10 @@ func FileExists(filePath string) bool {
|
||||||
return err == nil || os.IsExist(err)
|
return err == nil || os.IsExist(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy 深拷贝函数
|
func HashMod(hashStr string) int {
|
||||||
func DeepCopy(src interface{}) interface{} {
|
hash := fnv.New32a()
|
||||||
if src == nil {
|
_, _ = hash.Write([]byte(hashStr))
|
||||||
return nil
|
|
||||||
}
|
hashValue := hash.Sum32()
|
||||||
t := reflect.TypeOf(src)
|
return int(math.Mod(float64(hashValue), 32))
|
||||||
v := reflect.ValueOf(src)
|
|
||||||
// 创建新的对象
|
|
||||||
dst := reflect.New(t.Elem()).Elem()
|
|
||||||
// 遍历结构体的所有字段
|
|
||||||
for i := 0; i < t.Elem().NumField(); i++ {
|
|
||||||
field := t.Elem().Field(i)
|
|
||||||
srcField := v.Elem().Field(i)
|
|
||||||
dstField := dst.Field(i)
|
|
||||||
// 处理不同类型的字段
|
|
||||||
switch field.Type.Kind() {
|
|
||||||
case reflect.Map:
|
|
||||||
// 处理映射类型
|
|
||||||
newMap := reflect.MakeMap(field.Type)
|
|
||||||
for _, key := range srcField.MapKeys() {
|
|
||||||
value := srcField.MapIndex(key)
|
|
||||||
newMap.SetMapIndex(key, value)
|
|
||||||
}
|
|
||||||
dstField.Set(newMap)
|
|
||||||
case reflect.Slice:
|
|
||||||
// 处理切片类型
|
|
||||||
newSlice := reflect.MakeSlice(field.Type, srcField.Len(), srcField.Cap())
|
|
||||||
reflect.Copy(newSlice, srcField)
|
|
||||||
dstField.Set(newSlice)
|
|
||||||
case reflect.Ptr:
|
|
||||||
// 处理指针类型
|
|
||||||
if !srcField.IsNil() {
|
|
||||||
newPtr := reflect.New(field.Type.Elem())
|
|
||||||
newPtr.Elem().Set(DeepCopy(srcField.Elem()).(reflect.Value))
|
|
||||||
dstField.Set(newPtr)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// 处理其他类型
|
|
||||||
dstField.Set(srcField)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dst.Interface()
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHashMod(t *testing.T) {
|
||||||
|
serverId := HashMod("1dfsfdsfsddf12dddd5451212iodewnsanf2")
|
||||||
|
fmt.Println(serverId)
|
||||||
|
}
|
||||||
|
|
@ -101,6 +101,7 @@ func (v *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
||||||
Attach: bizContent.Attach,
|
Attach: bizContent.Attach,
|
||||||
AccountType: vo.OrderAccountTypeOpenId,
|
AccountType: vo.OrderAccountTypeOpenId,
|
||||||
Type: vo.OrderTypeCmb,
|
Type: vo.OrderTypeCmb,
|
||||||
|
NotifyUrl: v.bc.Cmb.NotifyUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
orderNo, err := v.VoucherBiz.CmbOrder(ctx, boReq)
|
orderNo, err := v.VoucherBiz.CmbOrder(ctx, boReq)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue