This commit is contained in:
李子铭 2025-03-08 11:10:34 +08:00
parent 27743f103a
commit 549f24da52
8 changed files with 110 additions and 0 deletions

View File

@ -68,6 +68,15 @@ message CmbOrderReply {
string codeNo = 9 [json_name = "codeNo"];
}
message CmbQueryRequest {
//
//
string codeNo = 9 [json_name = "codeNo", (validate.rules).string = {min_len: 1,max_len: 32}];
}
message CmbQueryReply {
}
message CmbQueryProductRequest {
//

View File

@ -47,6 +47,20 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or
return
}
func (v *VoucherBiz) CmbQuery(ctx context.Context, orderNo string) (reps *v1.CmbQueryReply, err error) {
c := vo.CmbQueryLockKey.BuildCache([]string{orderNo})
err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
reps = &v1.CmbQueryReply{}
return nil
})
return
}
func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (reps *v1.CmbQueryProductReply, err error) {
c := vo.CmbProductQueryLockKey.BuildCache([]string{productNo})

View File

@ -9,6 +9,7 @@ import (
type CmbMixRepo interface {
VerifyResponse(ctx context.Context, req *v1.CmbReply) (string, error)
OrderVerify(ctx context.Context, req *v1.CmbRequest) (*v1.CmbOrderRequest, error)
QueryVerify(ctx context.Context, req *v1.CmbRequest) (*v1.CmbQueryRequest, error)
ProductQueryVerify(ctx context.Context, req *v1.CmbRequest) (*v1.CmbQueryProductRequest, error)
GetMockRequest(ctx context.Context, bizContent string) (*v1.CmbRequest, error)
GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (*v1.CmbRequest, error)

View File

@ -9,6 +9,7 @@ type CacheKey string
const (
CmbOrderLockKey CacheKey = "cmb_order"
CmbQueryLockKey CacheKey = "cmb_query"
CmbProductQueryLockKey CacheKey = "cmb_product_query"
WechatNotifyRegisterTagCacheKey CacheKey = "wechat_notify_register_tag"
@ -19,6 +20,7 @@ const (
var CacheKeyMap = map[CacheKey]time.Duration{
CmbOrderLockKey: 30 * time.Second,
CmbQueryLockKey: 30 * time.Second,
CmbProductQueryLockKey: 30 * time.Second,
WechatNotifyRegisterTagCacheKey: 86400 * time.Second,
WechatNotifyRegisterTagCacheLockKey: 30 * time.Second,

View File

@ -39,6 +39,20 @@ func (s *CmbMixRepoImpl) OrderVerify(ctx context.Context, req *v1.CmbRequest) (*
return resp, nil
}
func (s *CmbMixRepoImpl) QueryVerify(ctx context.Context, req *v1.CmbRequest) (*v1.CmbQueryRequest, error) {
bizStr, err := s.Verify(ctx, req)
if err != nil {
return nil, err
}
var resp *v1.CmbQueryRequest
if err = json.Unmarshal([]byte(bizStr), &resp); err != nil {
return nil, err
}
return resp, nil
}
func (s *CmbMixRepoImpl) ProductQueryVerify(ctx context.Context, req *v1.CmbRequest) (*v1.CmbQueryProductRequest, error) {
bizStr, err := s.Verify(ctx, req)
if err != nil {

View File

@ -39,6 +39,9 @@ func NewHTTPServer(
cmb.POST("/v1/orderMock", voucherService.CmbOrderMock)
cmb.POST("/v1/order", voucherService.CmbOrder)
cmb.POST("/v1/queryMock", voucherService.CmbOrderMock)
cmb.POST("/v1/query", voucherService.CmbOrder)
cmb.POST("/v1/product/QueryMock", voucherService.CmbProductQueryMock)
cmb.POST("/v1/product/query", voucherService.CmbProductQuery)

View File

@ -80,6 +80,53 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
return orderNo, nil
}
func (s *VoucherService) CmbQuery(ctx http.Context) error {
var (
reply *v1.CmbReply
bizReply *v1.CmbQueryReply
)
bizReply, err := s.cmbQuery(ctx)
if err != nil {
bizReply = &v1.CmbQueryReply{}
}
replyBizContent, _ := json.Marshal(bizReply)
xx := &bo.CmbResponseBo{
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
RespMsg: "成功",
BizContent: string(replyBizContent),
}
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
if err != nil {
log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err)
}
return ctx.JSON(200, reply)
}
func (s *VoucherService) cmbQuery(ctx http.Context) (*v1.CmbQueryReply, error) {
var req *v1.CmbRequest
if err := ctx.BindForm(&req); err != nil {
return nil, err
}
if err := req.Validate(); err != nil {
return nil, err
}
bizContent, err := s.CmbMixRepo.QueryVerify(ctx, req)
if err != nil {
return nil, err
}
return s.VoucherBiz.CmbQuery(ctx, bizContent.CodeNo)
}
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
var (

View File

@ -6,6 +6,26 @@ import (
v1 "voucher/api/v1"
)
func (s *VoucherService) CmbQueryMock(ctx http.Context) error {
var req *v1.CmbQueryRequest
if err := ctx.BindForm(&req); err != nil {
return err
}
bizJsonBytes, err := json.Marshal(req)
if err != nil {
return err
}
reply, err := s.CmbMixRepo.GetMockRequest(ctx, string(bizJsonBytes))
if err != nil {
return err
}
return ctx.JSON(200, reply)
}
func (s *VoucherService) CmbOrderMock(ctx http.Context) error {
var req *v1.CmbOrderRequest