From 887b252754f5d312c0438c814b5d6d19deb5d522 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期三, 15 十一月 2023 16:55:13 +0800
Subject: [PATCH] 报废位置获取

---
 controllers/operation.go |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index d9b4200..d7912aa 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -23,6 +23,7 @@
 	"wms/pkg/logx"
 	"wms/pkg/structx"
 	"wms/proto/product_inventory"
+	"wms/proto/purchase_wms"
 	"wms/request"
 )
 
@@ -488,6 +489,9 @@
 					return err
 				}
 			}
+			if operation.SourceNumber != "" {
+				go UpdatePurchaseStatus(operation.SourceNumber)
+			}
 
 		}
 
@@ -530,6 +534,9 @@
 				if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil {
 					return err
 				}
+			}
+			if operation.SourceNumber != "" {
+				go UpdateSalesDetailStatus(operation.SourceNumber)
 			}
 		}
 
@@ -684,17 +691,23 @@
 		util.ResponseFormat(c, code.RequestError, err.Error())
 		return
 	}
-	if operation.SourceNumber != "" {
-		go UpdateSalesDetailStatus(operation.SourceNumber)
-	}
+
 	util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛")
 }
 
-var ProductInventoryServiceConn *grpc.ClientConn
+var (
+	ProductInventoryServiceConn *grpc.ClientConn
+	PurchaseServiceConn         *grpc.ClientConn
+)
 
 func InitProductInventoryServiceConn() {
 	var err error
 	ProductInventoryServiceConn, err = grpc.Dial(conf.GrpcServerConf.CrmAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
+	if err != nil {
+		logx.Errorf("grpc dial product service error: %v", err.Error())
+		return
+	}
+	PurchaseServiceConn, err = grpc.Dial(conf.GrpcServerConf.SrmAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
 	if err != nil {
 		logx.Errorf("grpc dial product service error: %v", err.Error())
 		return
@@ -704,6 +717,9 @@
 func CloseProductInventoryServiceConn() {
 	if ProductInventoryServiceConn != nil {
 		ProductInventoryServiceConn.Close()
+	}
+	if PurchaseServiceConn != nil {
+		PurchaseServiceConn.Close()
 	}
 }
 
@@ -715,6 +731,14 @@
 	})
 	if err != nil {
 		logx.Errorf("grpc dial UpdateSalesDetailStatus service error: %v", err)
+	}
+}
+
+func UpdatePurchaseStatus(number string) {
+	client := purchase_wms.NewPurchaseServiceClient(PurchaseServiceConn)
+	_, err := client.UpdatePurchaseStatus(context.Background(), &purchase_wms.UpdatePurchaseStatusRequest{Number: number})
+	if err != nil {
+		logx.Errorf("grpc dial UpdatePurchaseStatus service error: %v", err)
 	}
 }
 
@@ -792,7 +816,7 @@
 		return
 	}
 	operation.Status = constvar.OperationStatus_Cancel
-	if err := models.NewOperationSearch().Save(operation); err != nil {
+	if err := models.NewOperationSearch().SetID(operation.Id).Save(operation); err != nil {
 		util.ResponseFormat(c, code.SaveFail, err.Error())
 		return
 	}

--
Gitblit v1.8.0