72d55d396d
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
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
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
|
|
}
|