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

This commit is contained in:
zzw
2026-08-26 16:53:50 +08:00
parent 0ca3f6d84f
commit 72d55d396d
39 changed files with 1284 additions and 363 deletions
+7
View File
@@ -16,9 +16,11 @@ import (
type (
PolicyReq = chore.PolicyReq
Response = chore.Response
TestReq = chore.TestReq
Chore interface {
Policy(ctx context.Context, in *PolicyReq, opts ...grpc.CallOption) (*Response, error)
Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*Response, error)
}
defaultChore struct {
@@ -36,3 +38,8 @@ func (m *defaultChore) Policy(ctx context.Context, in *PolicyReq, opts ...grpc.C
client := chore.NewChoreClient(m.cli.Conn())
return client.Policy(ctx, in, opts...)
}
func (m *defaultChore) Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*Response, error) {
client := chore.NewChoreClient(m.cli.Conn())
return client.Test(ctx, in, opts...)
}
@@ -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)
}
+12 -2
View File
@@ -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,
}
}
+14 -13
View File
@@ -16,18 +16,16 @@
compress = false
[oss]
accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu"
accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk"
roleArn = "acs:ram::1663896742753915:role/oss-upload"
roleSessionName = "oss-upload"
region = "oss-cn-hangzhou"
bucketName = "lone-images"
# SDK 会拼成 {bucket}.{endpoint},这里不要再带 bucket 名
# 错误示例: lone-images.oss-accelerate... → 实际请求 lone-images.lone-images.oss-accelerate...
endpoint = "https://oss-accelerate.aliyuncs.com"
host = "https://images.ailuowan.com"
dir = "upload/"
expireSeconds = 3600
accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu"
accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk"
roleArn = "acs:ram::1663896742753915:role/oss-upload"
roleSessionName = "oss-upload"
region = "oss-cn-hangzhou"
bucketName = "lone-images"
endpoint = "https://lone-images.oss-accelerate.aliyuncs.com"
host = "https://images.ailuowan.com"
dir = "upload/"
expireSeconds = 3600
[redis]
host = '39.106.171.204'
@@ -36,4 +34,7 @@
db = 0
[encrypt]
data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a"
data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a"
[services]
product = "product-service"