refactor: localize protobuf definitions

This commit is contained in:
2026-08-09 20:14:57 +08:00
parent 9f6f318bbb
commit 5ea45a76fe
429 changed files with 54058 additions and 61623 deletions

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/ec/mall/internal/logic/ads"
pb "bsm/full/module/ec/mall/pb"
"context"
)
type AdsServer struct {
@@ -21,21 +21,21 @@ func (s *AdsServer) ByPos(ctx context.Context, in *pb.ByPosRequest) (*pb.AdsList
}
// 广告列表
func (s *AdsServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.AdsListReply, error) {
func (s *AdsServer) Fetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.AdsListReply, error) {
return ads.Fetch(ctx, in)
}
// 新建广告
func (s *AdsServer) Create(ctx context.Context, in *pb.AdsItem) (*pb.StatusReply, error) {
func (s *AdsServer) Create(ctx context.Context, in *pb.AdsItem) (*pb.IdentityStatusReply, error) {
return ads.Create(ctx, in)
}
// 修改广告
func (s *AdsServer) Modify(ctx context.Context, in *pb.AdsItem) (*pb.StatusReply, error) {
func (s *AdsServer) Modify(ctx context.Context, in *pb.AdsItem) (*pb.IdentityStatusReply, error) {
return ads.Modify(ctx, in)
}
// 删除广告
func (s *AdsServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *AdsServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return ads.Delete(ctx, in)
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/ec/mall/internal/logic/category"
pb "bsm/full/module/ec/mall/pb"
"context"
)
type CategoryServer struct {
@@ -21,16 +21,16 @@ func (s *CategoryServer) Fetch(ctx context.Context, in *pb.CategoryFetchRequest)
}
// 添加分类
func (s *CategoryServer) Create(ctx context.Context, in *pb.CategoryItem) (*pb.StatusReply, error) {
func (s *CategoryServer) Create(ctx context.Context, in *pb.CategoryItem) (*pb.IdentityStatusReply, error) {
return category.Create(ctx, in)
}
// 删除分类
func (s *CategoryServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *CategoryServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return category.Delete(ctx, in)
}
// 修改分类
func (s *CategoryServer) Modify(ctx context.Context, in *pb.CategoryItem) (*pb.StatusReply, error) {
func (s *CategoryServer) Modify(ctx context.Context, in *pb.CategoryItem) (*pb.IdentityStatusReply, error) {
return category.Modify(ctx, in)
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/ec/mall/internal/logic/freight"
pb "bsm/full/module/ec/mall/pb"
"context"
)
type FreightServer struct {
@@ -16,22 +16,22 @@ func NewFreightServer() *FreightServer {
}
// 运费模板列表
func (s *FreightServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.FreightReply, error) {
func (s *FreightServer) Fetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.FreightReply, error) {
return freight.Fetch(ctx, in)
}
// 运费模板修改
func (s *FreightServer) Modify(ctx context.Context, in *pb.FreightItem) (*pb.StatusReply, error) {
func (s *FreightServer) Modify(ctx context.Context, in *pb.FreightItem) (*pb.IdentityStatusReply, error) {
return freight.Modify(ctx, in)
}
// 运费模板删除
func (s *FreightServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FreightServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return freight.Delete(ctx, in)
}
// 运费模板创建
func (s *FreightServer) Create(ctx context.Context, in *pb.FreightItem) (*pb.StatusReply, error) {
func (s *FreightServer) Create(ctx context.Context, in *pb.FreightItem) (*pb.IdentityStatusReply, error) {
return freight.Create(ctx, in)
}
@@ -41,21 +41,21 @@ func (s *FreightServer) Detail(ctx context.Context, in *pb.IdentRequest) (*pb.Fr
}
// 限制区域列表
func (s *FreightServer) DenyRegionFetch(ctx context.Context, in *pb.FetchRequest) (*pb.DenyRegionReply, error) {
func (s *FreightServer) DenyRegionFetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.DenyRegionReply, error) {
return freight.DenyRegionFetch(ctx, in)
}
// 新建限制区域
func (s *FreightServer) DenyRegionCreate(ctx context.Context, in *pb.DenyRegionItem) (*pb.StatusReply, error) {
func (s *FreightServer) DenyRegionCreate(ctx context.Context, in *pb.DenyRegionItem) (*pb.IdentityStatusReply, error) {
return freight.DenyRegionCreate(ctx, in)
}
// 移除限制区域
func (s *FreightServer) DenyRegionDelete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *FreightServer) DenyRegionDelete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return freight.DenyRegionDelete(ctx, in)
}
// 编辑限制区域
func (s *FreightServer) DenyRegionModify(ctx context.Context, in *pb.DenyRegionItem) (*pb.StatusReply, error) {
func (s *FreightServer) DenyRegionModify(ctx context.Context, in *pb.DenyRegionItem) (*pb.IdentityStatusReply, error) {
return freight.DenyRegionModify(ctx, in)
}

View File

@@ -2,28 +2,27 @@
package server
import (
"context"
pb "bsm/full/module/ec/mall/pb"
"git.apinb.com/bsm-sdk/core/vars"
"context"
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/proto"
"net/http"
"os"
"strings"
)
type Server struct {
Grpc *grpc.Server
Ctx context.Context
Mux *gwRuntime.ServeMux
Grpc *grpc.Server
Ctx context.Context
Mux *gwRuntime.ServeMux
grpcConns map[string]*grpc.ClientConn // 连接池
}
func New(addr string) *Server {
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
)}
srv := &Server{
Ctx: context.Background(),
Grpc: grpc.NewServer(),
grpcConns: make(map[string]*grpc.ClientConn),
}
// register service to grpc.Server
pb.RegisterAdsServer(srv.Grpc, NewAdsServer())
@@ -36,48 +35,5 @@ func New(addr string) *Server {
reflection.Register(srv.Grpc)
// 将服务注册到Gateway
opts := []grpc.DialOption{grpc.WithInsecure()}
pb.RegisterAdsHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterCategoryHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterFreightHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterNoticeHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterProductHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterStaffHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterStoreHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
// Register services swagger
srv.RegisterSwagger()
return srv
}
// RegisterSwagger 注册swagger
func (s *Server) RegisterSwagger() {
srvKey := strings.ToLower(vars.ServiceKey)
s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
w.Header().Set("Content-Type", "application/json")
bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json")
if err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(err.Error()))
return
}
w.Write(bytes)
return
})
}
// response envelope
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
name := string(response.ProtoReflect().Descriptor().Name())
if name == "Status" || name == "Error" || name == "StatusReply" {
return response, nil
}
return map[string]any{
"code": 0,
"message": "OK",
"result": response,
}, nil
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/ec/mall/internal/logic/notice"
pb "bsm/full/module/ec/mall/pb"
"context"
)
type NoticeServer struct {
@@ -16,21 +16,21 @@ func NewNoticeServer() *NoticeServer {
}
// 公告列表
func (s *NoticeServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.NoticeListReply, error) {
func (s *NoticeServer) Fetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.NoticeListReply, error) {
return notice.Fetch(ctx, in)
}
// 新建公告
func (s *NoticeServer) Create(ctx context.Context, in *pb.NoticeItem) (*pb.StatusReply, error) {
func (s *NoticeServer) Create(ctx context.Context, in *pb.NoticeItem) (*pb.IdentityStatusReply, error) {
return notice.Create(ctx, in)
}
// 修改公告
func (s *NoticeServer) Modify(ctx context.Context, in *pb.NoticeItem) (*pb.StatusReply, error) {
func (s *NoticeServer) Modify(ctx context.Context, in *pb.NoticeItem) (*pb.IdentityStatusReply, error) {
return notice.Modify(ctx, in)
}
// 删除公告
func (s *NoticeServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *NoticeServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return notice.Delete(ctx, in)
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/ec/mall/internal/logic/product"
pb "bsm/full/module/ec/mall/pb"
"context"
)
type ProductServer struct {
@@ -16,7 +16,7 @@ func NewProductServer() *ProductServer {
}
// 获取产品列表
func (s *ProductServer) ItemFetch(ctx context.Context, in *pb.FetchRequest) (*pb.ListReply, error) {
func (s *ProductServer) ItemFetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.ListReply, error) {
return product.ItemFetch(ctx, in)
}
@@ -36,42 +36,42 @@ func (s *ProductServer) ItemDetailBySpec(ctx context.Context, in *pb.DetailBySpe
}
// 添加产品
func (s *ProductServer) ItemCreate(ctx context.Context, in *pb.ProductItem) (*pb.StatusReply, error) {
func (s *ProductServer) ItemCreate(ctx context.Context, in *pb.ProductItem) (*pb.IdentityStatusReply, error) {
return product.ItemCreate(ctx, in)
}
// 删除产品
func (s *ProductServer) ItemDelete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *ProductServer) ItemDelete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return product.ItemDelete(ctx, in)
}
// 发布/取消发布 产品
func (s *ProductServer) ItemModify(ctx context.Context, in *pb.ModifyRequest) (*pb.StatusReply, error) {
func (s *ProductServer) ItemModify(ctx context.Context, in *pb.ModifyRequest) (*pb.IdentityStatusReply, error) {
return product.ItemModify(ctx, in)
}
// 批量操作
func (s *ProductServer) ItemBatchOp(ctx context.Context, in *pb.OpRequest) (*pb.StatusReply, error) {
func (s *ProductServer) ItemBatchOp(ctx context.Context, in *pb.OpRequest) (*pb.IdentityStatusReply, error) {
return product.ItemBatchOp(ctx, in)
}
// 产品规格列表
func (s *ProductServer) SpecFetch(ctx context.Context, in *pb.FetchRequest) (*pb.SpecReply, error) {
func (s *ProductServer) SpecFetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.SpecReply, error) {
return product.SpecFetch(ctx, in)
}
// 添加产品规格
func (s *ProductServer) SpecCreate(ctx context.Context, in *pb.SpecItem) (*pb.StatusReply, error) {
func (s *ProductServer) SpecCreate(ctx context.Context, in *pb.SpecItem) (*pb.IdentityStatusReply, error) {
return product.SpecCreate(ctx, in)
}
// 修改产品规格
func (s *ProductServer) SpecModify(ctx context.Context, in *pb.SpecItem) (*pb.StatusReply, error) {
func (s *ProductServer) SpecModify(ctx context.Context, in *pb.SpecItem) (*pb.IdentityStatusReply, error) {
return product.SpecModify(ctx, in)
}
// 删除产品规格
func (s *ProductServer) SpecDelete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *ProductServer) SpecDelete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return product.SpecDelete(ctx, in)
}
@@ -81,12 +81,12 @@ func (s *ProductServer) SpecDetail(ctx context.Context, in *pb.IdentRequest) (*p
}
// 添加产品图片
func (s *ProductServer) PhotoCreate(ctx context.Context, in *pb.PhotoItem) (*pb.StatusReply, error) {
func (s *ProductServer) PhotoCreate(ctx context.Context, in *pb.PhotoItem) (*pb.IdentityStatusReply, error) {
return product.PhotoCreate(ctx, in)
}
// 删除产品图片
func (s *ProductServer) PhotoDelete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *ProductServer) PhotoDelete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return product.PhotoDelete(ctx, in)
}
@@ -96,26 +96,26 @@ func (s *ProductServer) PhotoList(ctx context.Context, in *pb.PhotoItem) (*pb.Ph
}
// 产品的评论列表
func (s *ProductServer) CommentFetch(ctx context.Context, in *pb.FetchRequest) (*pb.CommentListReply, error) {
func (s *ProductServer) CommentFetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.CommentListReply, error) {
return product.CommentFetch(ctx, in)
}
// 评论
func (s *ProductServer) CommentCreate(ctx context.Context, in *pb.CommentItem) (*pb.StatusReply, error) {
func (s *ProductServer) CommentCreate(ctx context.Context, in *pb.CommentItem) (*pb.IdentityStatusReply, error) {
return product.CommentCreate(ctx, in)
}
// 回复评论
func (s *ProductServer) CommentRe(ctx context.Context, in *pb.CommentItem) (*pb.StatusReply, error) {
func (s *ProductServer) CommentRe(ctx context.Context, in *pb.CommentItem) (*pb.IdentityStatusReply, error) {
return product.CommentRe(ctx, in)
}
// 删除评论
func (s *ProductServer) CommentDelete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *ProductServer) CommentDelete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return product.CommentDelete(ctx, in)
}
// 修改评论
func (s *ProductServer) CommentModify(ctx context.Context, in *pb.CommentItem) (*pb.StatusReply, error) {
func (s *ProductServer) CommentModify(ctx context.Context, in *pb.CommentItem) (*pb.IdentityStatusReply, error) {
return product.CommentModify(ctx, in)
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/ec/mall/internal/logic/staff"
pb "bsm/full/module/ec/mall/pb"
"context"
)
type StaffServer struct {
@@ -21,17 +21,17 @@ func (s *StaffServer) Login(ctx context.Context, in *pb.LoginRequest) (*pb.Login
}
// 获取工作人员列表
func (s *StaffServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.StaffListReply, error) {
func (s *StaffServer) Fetch(ctx context.Context, in *pb.MallFetchRequest) (*pb.StaffListReply, error) {
return staff.Fetch(ctx, in)
}
// 创建工作人员
func (s *StaffServer) Create(ctx context.Context, in *pb.StaffItem) (*pb.StatusReply, error) {
func (s *StaffServer) Create(ctx context.Context, in *pb.StaffItem) (*pb.IdentityStatusReply, error) {
return staff.Create(ctx, in)
}
// 删除工作人员
func (s *StaffServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
func (s *StaffServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.IdentityStatusReply, error) {
return staff.Delete(ctx, in)
}
@@ -41,11 +41,11 @@ func (s *StaffServer) GetProfile(ctx context.Context, in *pb.IdentRequest) (*pb.
}
// 设置个人信息
func (s *StaffServer) SetProfile(ctx context.Context, in *pb.StaffItem) (*pb.StatusReply, error) {
func (s *StaffServer) SetProfile(ctx context.Context, in *pb.StaffItem) (*pb.IdentityStatusReply, error) {
return staff.SetProfile(ctx, in)
}
// 设置账号密码
func (s *StaffServer) SetPassword(ctx context.Context, in *pb.SetAccountRequest) (*pb.StatusReply, error) {
func (s *StaffServer) SetPassword(ctx context.Context, in *pb.SetAccountRequest) (*pb.IdentityStatusReply, error) {
return staff.SetPassword(ctx, in)
}

View File

@@ -2,9 +2,9 @@
package server
import (
"context"
"bsm/full/module/ec/mall/internal/logic/store"
pb "bsm/full/module/ec/mall/pb"
"context"
)
type StoreServer struct {
@@ -16,12 +16,12 @@ func NewStoreServer() *StoreServer {
}
// 申请加入店铺
func (s *StoreServer) ApplyJoin(ctx context.Context, in *pb.ApplyJoinRequest) (*pb.StatusReply, error) {
func (s *StoreServer) ApplyJoin(ctx context.Context, in *pb.ApplyJoinRequest) (*pb.IdentityStatusReply, error) {
return store.ApplyJoin(ctx, in)
}
// 店铺许可授权
func (s *StoreServer) Licensing(ctx context.Context, in *pb.LicensingRequest) (*pb.StatusReply, error) {
func (s *StoreServer) Licensing(ctx context.Context, in *pb.LicensingRequest) (*pb.IdentityStatusReply, error) {
return store.Licensing(ctx, in)
}
@@ -31,17 +31,17 @@ func (s *StoreServer) GetSetting(ctx context.Context, in *pb.IdentRequest) (*pb.
}
// 设置店铺基础配置
func (s *StoreServer) SetSetting(ctx context.Context, in *pb.StoreBasic) (*pb.StatusReply, error) {
func (s *StoreServer) SetSetting(ctx context.Context, in *pb.StoreBasic) (*pb.IdentityStatusReply, error) {
return store.SetSetting(ctx, in)
}
// 设置支付方式配置
func (s *StoreServer) SetPayment(ctx context.Context, in *pb.SettingRequest) (*pb.StatusReply, error) {
func (s *StoreServer) SetPayment(ctx context.Context, in *pb.SettingRequest) (*pb.IdentityStatusReply, error) {
return store.SetPayment(ctx, in)
}
// 设置邮件服务器配置
func (s *StoreServer) SetEmail(ctx context.Context, in *pb.SettingRequest) (*pb.StatusReply, error) {
func (s *StoreServer) SetEmail(ctx context.Context, in *pb.SettingRequest) (*pb.IdentityStatusReply, error) {
return store.SetEmail(ctx, in)
}