feat: product number
CI / changes (push) Successful in 36s
CI / docker-bff (push) Successful in 3m8s
CI / docker-product (push) Successful in 3m36s
CI / docker-admin (push) Successful in 3m35s
CI / docker-user (push) Successful in 9s
CI / docker-ad (push) Successful in 29s
CI / docker-chore (push) Failing after 4s
CI / changes (push) Successful in 36s
CI / docker-bff (push) Successful in 3m8s
CI / docker-product (push) Successful in 3m36s
CI / docker-admin (push) Successful in 3m35s
CI / docker-user (push) Successful in 9s
CI / docker-ad (push) Successful in 29s
CI / docker-chore (push) Failing after 4s
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"lone-services/pkg/rpcclient"
|
||||
"lone-services/pkg/utils"
|
||||
chore "lone-services/rpc/chore/pb"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"lone-services/services/chore/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// product 库存变更:1 增加 2 减少
|
||||
const productNumberTypeIncr uint32 = 1
|
||||
const productNumberTypeDecr uint32 = 2
|
||||
|
||||
type TestLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestLogic {
|
||||
return &TestLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *TestLogic) Test(in *chore.TestReq) (*chore.Response, error) {
|
||||
cli, err := rpcclient.Get(l.svcCtx.ProductSvcName)
|
||||
if err != nil {
|
||||
l.Errorf("get product rpc: %v", err)
|
||||
return failResponse(utils.ErrorInternalServer), nil
|
||||
}
|
||||
|
||||
// 产品库存更变
|
||||
// _, err = product.NewProductClient(cli.Conn()).Number(l.ctx, &product.NumberReq{
|
||||
// Id: in.GetId(),
|
||||
// Type: productNumberTypeDecr,
|
||||
// Number: in.GetNumber(),
|
||||
// })
|
||||
|
||||
// 获取单个产品详情
|
||||
// res, err := product.NewProductClient(cli.Conn()).InfoById(l.ctx, &product.InfoByIdReq{
|
||||
// Id: int64(in.GetId()),
|
||||
// })
|
||||
|
||||
// fmt.Println(res.GetName())
|
||||
|
||||
// 获取多个产品详情
|
||||
res, err := product.NewProductClient(cli.Conn()).ItemsByIds(l.ctx, &product.ItemsByIdsReq{
|
||||
Ids: in.GetIds(),
|
||||
})
|
||||
for _, item := range res.GetItems() {
|
||||
fmt.Println(item.GetName())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
l.Errorf("错误信息: %v", err)
|
||||
return failResponse(utils.ErrorInternalServer), nil
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
l.Errorf("res为空")
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
return okResponse(res), nil
|
||||
}
|
||||
@@ -27,3 +27,8 @@ func (s *ChoreServer) Policy(ctx context.Context, in *chore.PolicyReq) (*chore.R
|
||||
l := logic.NewPolicyLogic(ctx, s.svcCtx)
|
||||
return l.Policy(in)
|
||||
}
|
||||
|
||||
func (s *ChoreServer) Test(ctx context.Context, in *chore.TestReq) (*chore.Response, error) {
|
||||
l := logic.NewTestLogic(ctx, s.svcCtx)
|
||||
return l.Test(in)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/chore/internal/config"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Config config.Config
|
||||
ProductSvcName string
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
productSvc := utils.GetConfigString("services.product")
|
||||
if productSvc == utils.StringEmpty {
|
||||
logx.Error("config services.product empty")
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Config: c,
|
||||
ProductSvcName: productSvc,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user