From 44bba3c3479d8b9cd04ef4087762f9f960c5bb55 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期四, 23 十一月 2023 20:17:10 +0800
Subject: [PATCH] 获取客户列表grpc客户端

---
 proto/client.proto       |   20 ++++++++++
 controllers/operation.go |   19 +++++++++
 main.go                  |    3 +
 proto/client/client.go   |   27 +++++++++++++
 conf/config.yaml         |    2 
 router/router.go         |    1 
 6 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/conf/config.yaml b/conf/config.yaml
index 63a0e2b..1d5cc35 100644
--- a/conf/config.yaml
+++ b/conf/config.yaml
@@ -25,5 +25,5 @@
   storePath: uploads/file
 grpcServer:
   apsAddr: 192.168.20.119:9091
-  crmAddr: 192.168.20.118:9092
+  crmAddr: :9092
   srmAddr: 192.168.20.118:9093
diff --git a/controllers/operation.go b/controllers/operation.go
index 136a9c3..143c959 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -24,6 +24,7 @@
 	"wms/opa"
 	"wms/pkg/logx"
 	"wms/pkg/structx"
+	"wms/proto/client"
 	"wms/proto/product_inventory"
 	"wms/proto/purchase_wms"
 	"wms/proto/supplier"
@@ -1084,3 +1085,21 @@
 	}
 	util.ResponseFormat(c, code.Success, resp.List)
 }
+
+// GetClientList
+// @Tags      鍏ュ簱/鍑哄簱
+// @Summary   鑾峰彇鐗╂祦鍏徃鍒楄〃
+// @Produce   application/json
+//
+//	@Success	200	{object}	util.Response	"鎴愬姛"
+//
+// @Router    /api-wms/v1/operation/getClientList [get]
+func (slf OperationController) GetClientList(c *gin.Context) {
+	cli := client.NewClientServiceClient(client.ClientConn)
+	resp, err := cli.GetClientList(c, &client.ClientListRequest{})
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "grpc璋冪敤澶辫触:"+err.Error())
+		return
+	}
+	util.ResponseFormat(c, code.Success, resp.List)
+}
diff --git a/main.go b/main.go
index d4a15c9..91c2eeb 100644
--- a/main.go
+++ b/main.go
@@ -14,6 +14,7 @@
 	"wms/controllers"
 	"wms/models"
 	"wms/pkg/logx"
+	"wms/proto/client"
 	"wms/proto/product_inventory"
 	"wms/proto/purchase_wms"
 	"wms/proto/supplier"
@@ -51,6 +52,7 @@
 	go controllers.InitProductInventoryServiceConn()
 	go controllers.InitCodeServiceConn()
 	go supplier.InitConn()
+	go client.InitConn()
 	//鍚姩grpc鏈嶅姟
 	go func() {
 		ln, err := net.Listen("tcp", ":"+conf.WebConf.GrpcPort)
@@ -90,6 +92,7 @@
 	controllers.CloseProductInventoryServiceConn()
 	controllers.CloseCodeServiceConn()
 	supplier.CloseConn()
+	client.CloseConn()
 	// 鍏抽棴HTTP鏈嶅姟鍣�
 	if err := server.Shutdown(ctx); err != nil {
 		logx.Infof("鏈嶅姟浼橀泤閫�鍑哄け璐�: %v", err)
diff --git a/proto/client.proto b/proto/client.proto
new file mode 100644
index 0000000..c374a41
--- /dev/null
+++ b/proto/client.proto
@@ -0,0 +1,20 @@
+syntax = "proto3";
+
+option go_package = "./client";
+
+service ClientService {
+  rpc GetClientList(ClientListRequest) returns (ClientListResponse);
+}
+
+message ClientListRequest {
+
+}
+
+message ClientInfo {
+  int32 ClientId =1;
+  string ClientName =2;
+}
+
+message ClientListResponse {
+  repeated ClientInfo List =1;
+}
\ No newline at end of file
diff --git a/proto/client/client.go b/proto/client/client.go
new file mode 100644
index 0000000..14289b3
--- /dev/null
+++ b/proto/client/client.go
@@ -0,0 +1,27 @@
+package client
+
+import (
+	"google.golang.org/grpc"
+	"google.golang.org/grpc/credentials/insecure"
+	"wms/conf"
+	"wms/pkg/logx"
+)
+
+var (
+	ClientConn *grpc.ClientConn
+)
+
+func InitConn() {
+	var err error
+	ClientConn, err = grpc.Dial(conf.GrpcServerConf.CrmAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
+	if err != nil {
+		logx.Errorf("grpc dial product service error: %v", err.Error())
+		return
+	}
+}
+
+func CloseConn() {
+	if ClientConn != nil {
+		ClientConn.Close()
+	}
+}
diff --git a/router/router.go b/router/router.go
index 6ca5d1b..bef5f29 100644
--- a/router/router.go
+++ b/router/router.go
@@ -90,6 +90,7 @@
 		operationAPI.PUT("cancel/:id", operationController.Cancel)
 		operationAPI.PUT("outputOperation/:id", operationController.OutputOperation)
 		operationAPI.GET("getSupplierList", operationController.GetSupplierList)
+		operationAPI.GET("getClientList", operationController.GetClientList)
 
 	}
 

--
Gitblit v1.8.0