From 0a79405533aeb7dfe6bfcae1279f670b89b194fa Mon Sep 17 00:00:00 2001 From: ziming Date: Wed, 2 Jul 2025 15:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=AD=A638?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/register_tag.go | 5 ++--- internal/biz/repo/product.go | 1 + internal/data/repoimpl/product.go | 17 +++++++++++++++++ internal/server/http.go | 2 +- internal/service/cmb.go | 16 +++++++++++----- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/internal/biz/register_tag.go b/internal/biz/register_tag.go index 5688370..c6ed64d 100644 --- a/internal/biz/register_tag.go +++ b/internal/biz/register_tag.go @@ -9,10 +9,9 @@ import ( "voucher/internal/pkg/lock" ) -// RegisterTag 注册通知标签 stock.MchId 批次创建商户, stock.BatchNo 商品批次号 -func (this *VoucherBiz) RegisterTag(ctx context.Context, batchNo string) error { +func (this *VoucherBiz) RegisterTag(ctx context.Context, id int32) error { - stock, err := this.ProductRepo.GetByBatchNo(ctx, batchNo) + stock, err := this.ProductRepo.GetById(ctx, id) if err != nil { return err } diff --git a/internal/biz/repo/product.go b/internal/biz/repo/product.go index 3333ea9..1194a81 100644 --- a/internal/biz/repo/product.go +++ b/internal/biz/repo/product.go @@ -7,6 +7,7 @@ import ( ) type ProductRepo interface { + GetById(ctx context.Context, id int32) (*bo.ProductBo, error) FindWarningBudget(ctx context.Context, fun func(ctx context.Context, rows []*bo.ProductBo) error) error GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error) GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error) diff --git a/internal/data/repoimpl/product.go b/internal/data/repoimpl/product.go index a2fb78e..b70abb1 100644 --- a/internal/data/repoimpl/product.go +++ b/internal/data/repoimpl/product.go @@ -83,6 +83,23 @@ func (r *ProductRepoImpl) UpdateByWxResp(ctx context.Context, id int32, req *do. return nil } +func (r *ProductRepoImpl) GetById(ctx context.Context, id int32) (*bo.ProductBo, error) { + + var item *model.Product + + tx := r.db.DB(ctx).Model(model.Product{}).Where(model.Product{ID: id}).First(&item) + + if tx.Error != nil { + return nil, tx.Error + } + + if tx.RowsAffected == 0 { + return nil, gorm.ErrRecordNotFound + } + + return r.ToBo(item), nil +} + func (r *ProductRepoImpl) GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error) { var item *model.Product diff --git a/internal/server/http.go b/internal/server/http.go index 7fd0ef5..63de995 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -39,7 +39,7 @@ func NewHTTPServer( srv.Route("/voucher/").POST("notifyRetry/{id}", cmb.NotifyRetry) srv.Route("/voucher/").POST("queryOrder/{order_no}", cmb.QueryOrder) srv.Route("/voucher/").POST("queryStock/{product_no}", cmb.QueryStock) - srv.Route("/voucher/").POST("registerTag/{batch_no}", cmb.RegisterTag) + srv.Route("/voucher/").POST("registerTag/{id}", cmb.RegisterTag) srv.Route("/voucher/").POST("pushWechatQuery", cmb.PushWechatQuery) srv.Route("/voucher/").POST("timeSliceQueryPush", cmb.TimeSliceQueryPush) srv.Route("/voucher/").POST("pushWechatRetry/{batch_no}", cmb.PushWechatRetry) diff --git a/internal/service/cmb.go b/internal/service/cmb.go index a1cf2a6..2ba2db1 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -7,6 +7,7 @@ import ( "github.com/go-kratos/kratos/v2/transport/http" "github.com/robfig/cron" http2 "net/http" + "strconv" v1 "voucher/api/v1" "voucher/internal/biz" "voucher/internal/biz/bo" @@ -70,16 +71,21 @@ func (c *CmbService) OrderRetry(ctx context.Context, request *v1.OrderRetryReque func (this *CmbService) RegisterTag(ctx http.Context) error { - batchNo := ctx.Vars().Get("batch_no") - if batchNo == "" { - return fmt.Errorf("batch_no is empty") + id := ctx.Vars().Get("id") + if id == "" { + return fmt.Errorf("id is empty") } - if err := this.VoucherBiz.RegisterTag(ctx, batchNo); err != nil { + int64Id, err := strconv.ParseInt(id, 10, 32) + if err != nil { + return err + } + + if err = this.VoucherBiz.RegisterTag(ctx, int32(int64Id)); err != nil { return err } return ctx.JSON(http2.StatusOK, map[string]interface{}{ - "data": batchNo, + "data": id, }) }