From 99ffda4126a4217ecaf57f4eab2a5615ae353aff Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 07 十一月 2023 14:30:51 +0800 Subject: [PATCH] crm获取库存信息 --- controllers/reorder_rule_controller.go | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/controllers/reorder_rule_controller.go b/controllers/reorder_rule_controller.go index 0c04e43..69d8590 100644 --- a/controllers/reorder_rule_controller.go +++ b/controllers/reorder_rule_controller.go @@ -3,15 +3,20 @@ import ( "github.com/gin-gonic/gin" "github.com/shopspring/decimal" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" "gorm.io/gorm" "strconv" "strings" "time" + "wms/conf" "wms/constvar" "wms/extend/code" "wms/extend/util" "wms/models" + "wms/pkg/logx" "wms/pkg/timex" + "wms/proto/inventory_order" "wms/request" ) @@ -254,6 +259,23 @@ util.ResponseFormat(c, code.Success, "鏇存柊鎴愬姛") } +var InventoryOrderServiceConn *grpc.ClientConn + +func InitInventoryOrderServiceConn() { + var err error + InventoryOrderServiceConn, err = grpc.Dial(conf.GrpcServerConf.ApsAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + logx.Errorf("grpc dial product service error: %v", err.Error()) + return + } +} + +func CloseInventoryOrderServiceConn() { + if InventoryOrderServiceConn != nil { + InventoryOrderServiceConn.Close() + } +} + // OrderAgain // @Tags 閲嶈璐ц鍒� // @Summary 鍐嶈涓�娆� @@ -265,6 +287,17 @@ var params models.ReorderRule if err := c.BindJSON(¶ms); err != nil { util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + client := inventory_order.NewInventoryOrderServiceClient(InventoryOrderServiceConn) + order, err := client.CreateNewOrder(c, &inventory_order.CreateNewOrderRequest{ + OrderNumber: params.OrderNumber.IntPart(), + Unit: params.Unit, + ProductId: params.ProductId, + Customer: "WMS鎺ㄩ��", + }) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "grpc璋冪敤澶辫触") return } location, err := models.NewLocationSearch().SetID(params.LocationId).First() @@ -294,6 +327,7 @@ operation.FromLocationID = 1 operation.Number = strconv.FormatInt(time.Now().Unix(), 10) operation.ToLocationID = params.LocationId + operation.SourceNumber = order.OrderId err = models.WithTransaction(func(db *gorm.DB) error { if err = models.NewOperationSearch().SetOrm(db).Create(&operation); err != nil { -- Gitblit v1.8.0