refactor: reorganize modules and add Linux build tooling
This commit is contained in:
36
module/ec/order/internal/server/cart_server.go
Normal file
36
module/ec/order/internal/server/cart_server.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/ec/order/internal/logic/cart"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
)
|
||||
|
||||
type CartServer struct {
|
||||
pb.UnimplementedCartServer
|
||||
}
|
||||
|
||||
func NewCartServer() *CartServer {
|
||||
return &CartServer{}
|
||||
}
|
||||
|
||||
// 获取购物车的商品数据
|
||||
func (s *CartServer) Fetch(ctx context.Context, in *pb.CartGetRequest) (*pb.CartGetReply, error) {
|
||||
return cart.Fetch(ctx, in)
|
||||
}
|
||||
|
||||
// 将商品增加至购物车
|
||||
func (s *CartServer) Create(ctx context.Context, in *pb.CartAddRequest) (*pb.StatusReply, error) {
|
||||
return cart.Create(ctx, in)
|
||||
}
|
||||
|
||||
// 修改购物车中的商品数量
|
||||
func (s *CartServer) Modify(ctx context.Context, in *pb.CartSetRequest) (*pb.StatusReply, error) {
|
||||
return cart.Modify(ctx, in)
|
||||
}
|
||||
|
||||
// 删除购物车中的商品
|
||||
func (s *CartServer) Delete(ctx context.Context, in *pb.CartDelRequest) (*pb.StatusReply, error) {
|
||||
return cart.Delete(ctx, in)
|
||||
}
|
||||
21
module/ec/order/internal/server/coupon_server.go
Normal file
21
module/ec/order/internal/server/coupon_server.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/ec/order/internal/logic/coupon"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
)
|
||||
|
||||
type CouponServer struct {
|
||||
pb.UnimplementedCouponServer
|
||||
}
|
||||
|
||||
func NewCouponServer() *CouponServer {
|
||||
return &CouponServer{}
|
||||
}
|
||||
|
||||
// 按状态获取优惠卷
|
||||
func (s *CouponServer) ByStatus(ctx context.Context, in *pb.Status) (*pb.CouponListReply, error) {
|
||||
return coupon.ByStatus(ctx, in)
|
||||
}
|
||||
51
module/ec/order/internal/server/mgt_server.go
Normal file
51
module/ec/order/internal/server/mgt_server.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/ec/order/internal/logic/mgt"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
)
|
||||
|
||||
type MgtServer struct {
|
||||
pb.UnimplementedMgtServer
|
||||
}
|
||||
|
||||
func NewMgtServer() *MgtServer {
|
||||
return &MgtServer{}
|
||||
}
|
||||
|
||||
// 创建订单
|
||||
func (s *MgtServer) OrderCreate(ctx context.Context, in *pb.CreateOrderRequest) (*pb.StatusReply, error) {
|
||||
return mgt.OrderCreate(ctx, in)
|
||||
}
|
||||
|
||||
// 修改订单
|
||||
func (s *MgtServer) OrderModify(ctx context.Context, in *pb.OrderSummaryItem) (*pb.StatusReply, error) {
|
||||
return mgt.OrderModify(ctx, in)
|
||||
}
|
||||
|
||||
// 获取一个订单的详情数据
|
||||
func (s *MgtServer) OrderGet(ctx context.Context, in *pb.IdentRequest) (*pb.OrderGetReply, error) {
|
||||
return mgt.OrderGet(ctx, in)
|
||||
}
|
||||
|
||||
// 根据不同的类型获取店铺的订单列表
|
||||
func (s *MgtServer) OrderListByStore(ctx context.Context, in *pb.OrderListByStoreRequest) (*pb.OrderListByStoreReply, error) {
|
||||
return mgt.OrderListByStore(ctx, in)
|
||||
}
|
||||
|
||||
// 取消订单
|
||||
func (s *MgtServer) OrderCancel(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return mgt.OrderCancel(ctx, in)
|
||||
}
|
||||
|
||||
// 退货
|
||||
func (s *MgtServer) OrderReturnable(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return mgt.OrderReturnable(ctx, in)
|
||||
}
|
||||
|
||||
// 订单审批
|
||||
func (s *MgtServer) OrderApprove(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return mgt.OrderApprove(ctx, in)
|
||||
}
|
||||
77
module/ec/order/internal/server/new.go
Normal file
77
module/ec/order/internal/server/new.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
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
|
||||
}
|
||||
|
||||
func New(addr string) *Server {
|
||||
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
|
||||
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
|
||||
)}
|
||||
|
||||
// register service to grpc.Server
|
||||
pb.RegisterCartServer(srv.Grpc, NewCartServer())
|
||||
pb.RegisterCouponServer(srv.Grpc, NewCouponServer())
|
||||
pb.RegisterMgtServer(srv.Grpc, NewMgtServer())
|
||||
pb.RegisterSummaryServer(srv.Grpc, NewSummaryServer())
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
|
||||
// 将服务注册到Gateway
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
pb.RegisterCartHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterCouponHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterMgtHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterSummaryHandlerFromEndpoint(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
|
||||
}
|
||||
66
module/ec/order/internal/server/summary_server.go
Normal file
66
module/ec/order/internal/server/summary_server.go
Normal file
@@ -0,0 +1,66 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/ec/order/internal/logic/summary"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
)
|
||||
|
||||
type SummaryServer struct {
|
||||
pb.UnimplementedSummaryServer
|
||||
}
|
||||
|
||||
func NewSummaryServer() *SummaryServer {
|
||||
return &SummaryServer{}
|
||||
}
|
||||
|
||||
// 快速创建一个店铺订单
|
||||
func (s *SummaryServer) QuickCreateByProduct(ctx context.Context, in *pb.QuickCreateByProductRequest) (*pb.StatusReply, error) {
|
||||
return summary.QuickCreateByProduct(ctx, in)
|
||||
}
|
||||
|
||||
// 将购物车的数据提交生成订单
|
||||
func (s *SummaryServer) Submit(ctx context.Context, in *pb.SubmitRequest) (*pb.StatusReply, error) {
|
||||
return summary.Submit(ctx, in)
|
||||
}
|
||||
|
||||
// 检测是否有未确认及付款的订单
|
||||
func (s *SummaryServer) Check(ctx context.Context, in *pb.Empty) (*pb.StatusReply, error) {
|
||||
return summary.Check(ctx, in)
|
||||
}
|
||||
|
||||
// 获取一个订单的详情数据
|
||||
func (s *SummaryServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.SummaryGetReply, error) {
|
||||
return summary.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 根据不同的类型获取我的订单列表
|
||||
func (s *SummaryServer) List(ctx context.Context, in *pb.SummaryListRequest) (*pb.SummaryListReply, error) {
|
||||
return summary.List(ctx, in)
|
||||
}
|
||||
|
||||
// 确认订单,物流,优惠卷等其它信息
|
||||
func (s *SummaryServer) Confirm(ctx context.Context, in *pb.ConfirmRequest) (*pb.ConfirmReply, error) {
|
||||
return summary.Confirm(ctx, in)
|
||||
}
|
||||
|
||||
// 取消订单
|
||||
func (s *SummaryServer) Cancel(ctx context.Context, in *pb.CancelRequest) (*pb.StatusReply, error) {
|
||||
return summary.Cancel(ctx, in)
|
||||
}
|
||||
|
||||
// 模拟支付
|
||||
func (s *SummaryServer) SimulatePay(ctx context.Context, in *pb.SimulatePayRequest) (*pb.StatusReply, error) {
|
||||
return summary.SimulatePay(ctx, in)
|
||||
}
|
||||
|
||||
// 模拟发货
|
||||
func (s *SummaryServer) SimulateShipments(ctx context.Context, in *pb.SimulateShipmentsRequest) (*pb.StatusReply, error) {
|
||||
return summary.SimulateShipments(ctx, in)
|
||||
}
|
||||
|
||||
// 模拟收货
|
||||
func (s *SummaryServer) SimulateReceiving(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return summary.SimulateReceiving(ctx, in)
|
||||
}
|
||||
Reference in New Issue
Block a user