Przeglądaj źródła

订单应用 api

xuzhiheng 3 lat temu
rodzic
commit
0421e30207

BIN
api/.DS_Store


BIN
api/api


+ 18 - 0
api/etc/orderapplication-api.yaml

@@ -0,0 +1,18 @@
+Name: orderApplication-api
+Host: 0.0.0.0
+Port: 9999
+OrderCenterRpc:
+  Etcd:
+    Hosts:
+    - 127.0.0.1:2379
+    Key: ordercenter.rpc
+GatewayRpcConf:
+  Etcd:
+    Hosts:
+      -  192.168.3.240:2379
+    Key: gatewayDemo.rpc
+Logx:
+  Mode: console #console|file|volume
+  Path: ./logs
+  Level: info #info|error|severe
+  KeepDays: 10

+ 14 - 0
api/internal/config/config.go

@@ -0,0 +1,14 @@
+package config
+
+import (
+	"github.com/zeromicro/go-zero/core/logx"
+	"github.com/zeromicro/go-zero/rest"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+type Config struct {
+	rest.RestConf
+	OrderCenterRpc zrpc.RpcClientConf
+	GatewayRpcConf zrpc.RpcClientConf
+	Logx           logx.LogConf
+}

+ 29 - 0
api/internal/handler/orderexaminehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func OrderExamineHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.OrderExamineReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewOrderExamineLogic(r.Context(), ctx)
+		resp, err := l.OrderExamine(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/orderinfohandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func OrderInfoHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.OrderInfoReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewOrderInfoLogic(r.Context(), ctx)
+		resp, err := l.OrderInfo(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/orderlisthandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func OrderListHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.OrderListReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewOrderListLogic(r.Context(), ctx)
+		resp, err := l.OrderList(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/orderstatusupdatehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func OrderStatusUpdateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.OrderStatusUpdateReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewOrderStatusUpdateLogic(r.Context(), ctx)
+		resp, err := l.OrderStatusUpdate(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 37 - 0
api/internal/handler/routes.go

@@ -0,0 +1,37 @@
+// Code generated by goctl. DO NOT EDIT.
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+
+	"github.com/zeromicro/go-zero/rest"
+)
+
+func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
+	engine.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/orderApplication/order/orderList",
+				Handler: OrderListHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/orderApplication/order/orderInfo",
+				Handler: OrderInfoHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/orderApplication/order/orderStatusUpdate",
+				Handler: OrderStatusUpdateHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/orderApplication/order/OrderExamine",
+				Handler: OrderExamineHandler(serverCtx),
+			},
+		},
+	)
+}

+ 30 - 0
api/internal/logic/orderexaminelogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type OrderExamineLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewOrderExamineLogic(ctx context.Context, svcCtx *svc.ServiceContext) OrderExamineLogic {
+	return OrderExamineLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *OrderExamineLogic) OrderExamine(req types.OrderExamineReq) (*types.Resp, error) {
+	// todo: add your logic here and delete this line
+
+	return &types.Resp{}, nil
+}

+ 39 - 0
api/internal/logic/orderinfologic.go

@@ -0,0 +1,39 @@
+package logic
+
+import (
+	"context"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+	. "bp.jydev.jianyu360.cn/BaseService/orderCenter/rpc/ordercenter"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type OrderInfoLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) OrderInfoLogic {
+	return OrderInfoLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *OrderInfoLogic) OrderInfo(req types.OrderInfoReq) (*types.Resp, error) {
+	// todo: add your logic here and delete this line
+	res, err := l.svcCtx.OrderCenterRpc.OrderInfo(l.ctx, &OrderInfoReq{
+		Appid:     req.Appid,
+		OrderCode: req.OrderCode,
+		DataType:  req.DataType,
+	})
+	return &types.Resp{
+		Error_code: res.ErrorCode,
+		Error_msg:  res.ErrorMsg,
+		Data:       res.Data,
+	}, err
+}

+ 37 - 0
api/internal/logic/orderlistlogic.go

@@ -0,0 +1,37 @@
+package logic
+
+import (
+	"context"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+	. "bp.jydev.jianyu360.cn/BaseService/orderCenter/rpc/ordercenter"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type OrderListLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) OrderListLogic {
+	return OrderListLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *OrderListLogic) OrderList(req types.OrderListReq) (*types.Resp, error) {
+	// todo: add your logic here and delete this line
+	res, err := l.svcCtx.OrderCenterRpc.OrderList(l.ctx, &OrderListReq{
+		Appid:      req.Appid,
+		UserId:     req.UserId,
+		NewUserId:  req.NewUserId,
+		NewUserIds: req.NewUserIds,
+		PageNum:    req.PageNum,
+		PageSize:   req.PageSize,
+	})
+	return &types.Resp{Error_code: res.ErrorCode, Error_msg: res.ErrorMsg, Data: res.Data}, err
+}

+ 40 - 0
api/internal/logic/orderstatusupdatelogic.go

@@ -0,0 +1,40 @@
+package logic
+
+import (
+	"context"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/types"
+	. "bp.jydev.jianyu360.cn/BaseService/orderCenter/rpc/ordercenter"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type OrderStatusUpdateLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewOrderStatusUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) OrderStatusUpdateLogic {
+	return OrderStatusUpdateLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *OrderStatusUpdateLogic) OrderStatusUpdate(req types.OrderStatusUpdateReq) (*types.Resp, error) {
+	// todo: add your logic here and delete this line
+	res, err := l.svcCtx.OrderCenterRpc.OrderStatusUpdate(l.ctx, &OrderStatusUpdateReq{
+		Appid:       req.Appid,
+		OrderCode:   req.OrderCode,
+		DataType:    req.DataType,
+		OrderStatus: req.OrderStatus,
+	})
+	return &types.Resp{
+		Error_code: res.ErrorCode,
+		Error_msg:  res.ErrorMsg,
+		Data:       res.Data,
+	}, err
+}

+ 20 - 0
api/internal/svc/servicecontext.go

@@ -0,0 +1,20 @@
+package svc
+
+import (
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/config"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderCenter/rpc/ordercenter"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+type ServiceContext struct {
+	Config         config.Config
+	OrderCenterRpc ordercenter.OrderCenter
+}
+
+func NewServiceContext(c config.Config) *ServiceContext {
+	return &ServiceContext{
+		Config:         c,
+		OrderCenterRpc: ordercenter.NewOrderCenter(zrpc.MustNewClient(c.OrderCenterRpc)),
+	}
+}

+ 38 - 0
api/internal/types/types.go

@@ -0,0 +1,38 @@
+// Code generated by goctl. DO NOT EDIT.
+package types
+
+type Resp struct {
+	Error_code int64       `json:"error_code"` //响应代码
+	Error_msg  string      `json:"error_msg"`  //响应消息
+	Data       interface{} `json:"data"`
+}
+
+type OrderListReq struct {
+	Appid      string `header:"appid"`              //应用标识
+	UserId     string `header:"userId,optional"`    //老库用户id
+	NewUserId  int64  `header:"newUserId,optional"` //新库用户id
+	NewUserIds string `json:"user_id,optional"`     //社交中心使用
+	PageNum    int64  `json:"page_num"`             //当前页码
+	PageSize   int64  `json:"page_size"`            //每页数量
+}
+
+type OrderInfoReq struct {
+	Appid     string `header:"appid"`    //应用标识
+	OrderCode string `json:"order_code"` //订单编号
+	DataType  int64  `json:"data_type"`  //1新库 2老库
+}
+
+type OrderStatusUpdateReq struct {
+	Appid       string `header:"appid"`      //应用标识
+	OrderCode   string `json:"order_code"`   //订单编号
+	DataType    int64  `json:"data_type"`    //1新库 2老库
+	OrderStatus int64  `json:"order_status"` //订单状态
+}
+
+type OrderExamineReq struct {
+	Appid       string `header:"appid"`      //应用标识
+	OrderCode   string `json:"order_code"`   //订单编号
+	AuditStatus int64  `json:"audit_status"` //审核状态;0:待提交  1:待审核  2:审核中 3:审核通过(默认值,前台应用) 4:审核不通过
+	AuditPerson int64  `json:"audit_person"` //审核人
+	Remark      string `json:"remark"`       //备注
+}

+ 50 - 0
api/orderApplication.api

@@ -0,0 +1,50 @@
+syntax = "v1"
+
+type (
+	resp {
+		Error_code int64       `json:"error_code"` //响应代码
+		Error_msg  string      `json:"error_msg"`  //响应消息
+		Data       interface{} `json:"data"`
+	}
+
+	orderListReq {
+		Appid      string `header:"appid"`              //应用标识
+		UserId     string `header:"userId,optional"`    //老库用户id
+		NewUserId  int64  `header:"newUserId,optional"` //新库用户id
+		NewUserIds string `json:"user_id,optional"`     //社交中心使用
+		PageNum    int64  `json:"page_num"`             //当前页码
+		PageSize   int64  `json:"page_size"`            //每页数量
+	}
+
+	orderInfoReq {
+		Appid     string `header:"appid"`    //应用标识
+		OrderCode string `json:"order_code"` //订单编号
+		DataType  int64  `json:"data_type"`  //1新库 2老库
+	}
+
+	orderStatusUpdateReq {
+		Appid       string `header:"appid"`      //应用标识
+		OrderCode   string `json:"order_code"`   //订单编号
+		DataType    int64  `json:"data_type"`    //1新库 2老库
+		OrderStatus int64  `json:"order_status"` //订单状态
+	}
+
+	OrderExamineReq {
+		Appid       string `header:"appid"`      //应用标识
+		OrderCode   string `json:"order_code"`   //订单编号
+		AuditStatus int64  `json:"audit_status"` //审核状态;0:待提交  1:待审核  2:审核中 3:审核通过(默认值,前台应用) 4:审核不通过
+		AuditPerson int64  `json:"audit_person"` //审核人
+		Remark      string `json:"remark"`       //备注
+	}
+)
+
+service orderApplication-api {
+	@handler OrderList
+	post /orderApplication/order/orderList (orderListReq) returns (resp)
+	@handler OrderInfo
+	post /orderApplication/order/orderInfo (orderInfoReq) returns (resp)
+	@handler OrderStatusUpdate
+	post /orderApplication/order/orderStatusUpdate (orderStatusUpdateReq) returns (resp)
+	@handler OrderExamine
+	post /orderApplication/order/OrderExamine (OrderExamineReq) returns (resp)
+}

+ 52 - 0
api/orderapplication.go

@@ -0,0 +1,52 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+	"os"
+	"os/signal"
+	"syscall"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/config"
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/handler"
+
+	"bp.jydev.jianyu360.cn/BaseService/orderApplication/api/internal/svc"
+
+	"bp.jydev.jianyu360.cn/BaseService/gateway/core/node"
+	"github.com/zeromicro/go-zero/core/conf"
+	"github.com/zeromicro/go-zero/core/logx"
+	"github.com/zeromicro/go-zero/rest"
+)
+
+var configFile = flag.String("f", "etc/orderApplication-api.yaml", "the config file")
+
+func main() {
+	flag.Parse()
+
+	var c config.Config
+	conf.MustLoad(*configFile, &c)
+
+	// logx 根据配置初始化
+	logx.MustSetup(c.Logx)
+	//前置代理相关
+	var serverCode string = "orderapplication"
+	var serverPort int = c.Port
+	closeNotify, err := node.NewNode(c.GatewayRpcConf.Etcd.Hosts[0]).Register(serverCode, fmt.Sprintf("%d", serverPort))
+	if err != nil {
+		panic(err)
+	}
+
+	ctx := svc.NewServiceContext(c)
+	server := rest.MustNewServer(c.RestConf)
+	defer server.Stop()
+
+	handler.RegisterHandlers(server, ctx)
+
+	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
+	server.Start()
+
+	quit := make(chan os.Signal, 1)
+	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
+	<-quit
+	closeNotify()
+}