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 | 72 +++++++++++++++++++++++++++++++++--- 1 files changed, 66 insertions(+), 6 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index a541b4d..d7912aa 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -1,6 +1,7 @@ package controllers import ( + "context" "encoding/json" "errors" "fmt" @@ -22,6 +23,7 @@ "wms/pkg/logx" "wms/pkg/structx" "wms/proto/product_inventory" + "wms/proto/purchase_wms" "wms/request" ) @@ -487,6 +489,9 @@ return err } } + if operation.SourceNumber != "" { + go UpdatePurchaseStatus(operation.SourceNumber) + } } @@ -529,6 +534,9 @@ if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil { return err } + } + if operation.SourceNumber != "" { + go UpdateSalesDetailStatus(operation.SourceNumber) } } @@ -683,17 +691,23 @@ util.ResponseFormat(c, code.RequestError, err.Error()) return } - if operation.SourceNumber != "" { - go UpdateSalesDetailStatus(c, 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,16 +718,27 @@ if ProductInventoryServiceConn != nil { ProductInventoryServiceConn.Close() } + if PurchaseServiceConn != nil { + PurchaseServiceConn.Close() + } } -func UpdateSalesDetailStatus(ctx *gin.Context, number string) { +func UpdateSalesDetailStatus(number string) { client := product_inventory.NewProductInventoryServiceClient(ProductInventoryServiceConn) - _, err := client.UpdateSalesDetailStatus(ctx, &product_inventory.UpdateSalesDetailStatusRequest{ + _, err := client.UpdateSalesDetailStatus(context.Background(), &product_inventory.UpdateSalesDetailStatusRequest{ Number: number, SalesDetailStatus: "宸插嚭搴�", }) 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) } } @@ -762,3 +787,38 @@ } util.ResponseFormat(c, code.Success, companies) } + +// Cancel +// +// @Tags 鍏ュ簱/鍑哄簱 +// @Summary 鍙栨秷 +// @Produce application/json +// @Param id path int true "id" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/operation/cancel/{id} [put] +func (slf OperationController) Cancel(c *gin.Context) { + id, err := strconv.Atoi(c.Param("id")) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "閿欒鐨刬d鍊�") + return + } + if id == 0 { + util.ResponseFormat(c, code.RequestParamError, "id涓�0") + return + } + operation, err := models.NewOperationSearch().SetPreload(true).SetID(id).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏈壘鍒扮浉鍏冲嚭鍏ュ簱淇℃伅:"+err.Error()) + return + } + if operation.Status != constvar.OperationStatus_Ready { + util.ResponseFormat(c, code.RequestError, "璇ュ嚭鍏ュ簱淇℃伅鏃犳硶鍙栨秷") + return + } + operation.Status = constvar.OperationStatus_Cancel + if err := models.NewOperationSearch().SetID(operation.Id).Save(operation); err != nil { + util.ResponseFormat(c, code.SaveFail, err.Error()) + return + } + util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛") +} -- Gitblit v1.8.0