From f0786e779666d67a50cd57d82cfe1e278b47d397 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 04 七月 2024 11:54:11 +0800
Subject: [PATCH] fix
---
controllers/reorder_rule_controller.go | 112 ++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 76 insertions(+), 36 deletions(-)
diff --git a/controllers/reorder_rule_controller.go b/controllers/reorder_rule_controller.go
index bbb446c..2a42385 100644
--- a/controllers/reorder_rule_controller.go
+++ b/controllers/reorder_rule_controller.go
@@ -3,20 +3,18 @@
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/init_client"
"wms/proto/inventory_order"
+ "wms/proto/purchase_wms"
"wms/request"
)
@@ -119,7 +117,7 @@
rule.Prediction = rule.Amount.Add(rule.Prediction)
}
//鍑哄簱灏辩华
- operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal}
+ operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal, constvar.BaseOperationTypeDisuse}
amount, err = GetProductAmount(productIds, nil, locationIds, status, operationType)
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�")
@@ -152,17 +150,17 @@
var pa []request.ProductAmount
search := models.NewOperationDetailsSearch()
search.Orm = search.Orm.Model(&models.OperationDetails{}).
- Select("wms_operation_details.product_id, wms_operation_details.amount, wms_operation.to_location_id as to_location_id, " +
- "wms_operation.from_location_id as from_location_id, wms_operation.base_operation_type").
+ Select("wms_operation_details.product_id, wms_operation_details.amount, wms_operation_details.to_location_id as to_location_id, " +
+ "wms_operation_details.from_location_id as from_location_id, wms_operation.base_operation_type").
Joins("left join wms_operation on wms_operation_details.operation_id = wms_operation.id")
if len(productIds) > 0 {
search.Orm.Where("wms_operation_details.product_id in (?)", productIds)
}
if len(toLocationIds) > 0 {
- search.Orm.Where("wms_operation.to_location_id in (?)", toLocationIds)
+ search.Orm.Where("wms_operation_details.to_location_id in (?)", toLocationIds)
}
if len(fromLocationIds) > 0 {
- search.Orm.Where("wms_operation.from_location_id in (?)", fromLocationIds)
+ search.Orm.Where("wms_operation_details.from_location_id in (?)", fromLocationIds)
}
if len(status) > 0 {
search.Orm.Where("wms_operation.status in (?)", status)
@@ -221,7 +219,7 @@
}
prediction = amount.Add(prediction)
//鍑哄簱灏辩华
- operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal}
+ operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal, constvar.BaseOperationTypeDisuse}
list, err = GetProductAmount(productIds, nil, locationIds, status, operationType)
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�")
@@ -259,22 +257,22 @@
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()
- }
-}
+//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 閲嶈璐ц鍒�
@@ -289,7 +287,17 @@
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
return
}
- client := inventory_order.NewInventoryOrderServiceClient(InventoryOrderServiceConn)
+ if params.Route == "閲囪喘" {
+ client := purchase_wms.NewPurchaseServiceClient(init_client.SrmConn)
+ resp, err := client.GetSupplierListByProductId(c, &purchase_wms.GetSupplierListByProductIdRequest{ProductId: params.ProductId})
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "grpc璋冪敤澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, resp.List)
+ return
+ }
+ client := inventory_order.NewInventoryOrderServiceClient(init_client.ApsConn)
order, err := client.CreateNewOrder(c, &inventory_order.CreateNewOrderRequest{
OrderNumber: params.OrderNumber.IntPart(),
Unit: params.Unit,
@@ -300,34 +308,42 @@
util.ResponseFormat(c, code.RequestParamError, "grpc璋冪敤澶辫触")
return
}
+ err = orderAgain(params, order.OrderId)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "閲嶈澶辫触")
+ return
+ }
+ util.ResponseFormat(c, code.Success, "閲嶈鎴愬姛")
+}
+
+func orderAgain(params models.ReorderRule, SourceNumber string) error {
location, err := models.NewLocationSearch().SetID(params.LocationId).First()
if err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆淇℃伅澶辫触")
- return
+ return err
}
houseCode := strings.Split(location.JointName, "/")[0]
var operationType models.OperationType
err = models.NewOperationTypeSearch().Orm.Model(&models.OperationType{}).Joins("left join wms_warehouse on wms_job_type.warehouse_id = wms_warehouse.id").
Where("wms_job_type.base_operation_type = 1 and wms_warehouse.code = ?", houseCode).First(&operationType).Error
if err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆淇℃伅澶辫触")
- return
+ return err
}
var operation models.Operation
var details models.OperationDetails
details.ProductId = params.ProductId
details.Amount = params.OrderNumber
+ details.FromLocationID = 1
+ details.ToLocationID = params.LocationId
operation.Details = append(operation.Details, &details)
operation.BaseOperationType = constvar.BaseOperationTypeIncoming
operation.Status = constvar.OperationStatus_Ready
operation.OperationTypeId = operationType.Id
operation.OperationTypeName = operationType.Name
operation.OperationDate = timex.TimeToString2(time.Now())
- //todo 渚涘簲鍟嗕綅缃�
- operation.FromLocationID = 1
+ operation.LocationID = params.LocationId
operation.Number = strconv.FormatInt(time.Now().Unix(), 10)
- operation.ToLocationID = params.LocationId
- operation.SourceNumber = order.OrderId
+
+ operation.SourceNumber = SourceNumber
err = models.WithTransaction(func(db *gorm.DB) error {
if err = models.NewOperationSearch().SetOrm(db).Create(&operation); err != nil {
@@ -337,9 +353,33 @@
err = models.NewReorderRuleSearch().SetOrm(db).SetID(params.Id).Update(¶ms)
return err
})
+
+ return err
+}
+
+// SubmitOrder
+// @Tags 閲嶈璐ц鍒�
+// @Summary 鍐嶈涓�娆�
+// @Produce application/json
+// @Param object body models.ReorderRule true "鍙傛暟"
+// @Success 200 {object} util.Response "鎴愬姛"
+// @Router /api-wms/v1/reorderRule/submitOrder [post]
+func (slf ReorderRuleController) SubmitOrder(c *gin.Context) {
+ var params models.ReorderRule
+ client := purchase_wms.NewPurchaseServiceClient(init_client.SrmConn)
+ resp, err := client.CreatePurchaseByWms(c, &purchase_wms.CreatePurchaseByWmsRequest{
+ SupplierId: params.SupplierId,
+ ProductId: params.ProductId,
+ Amount: params.OrderNumber.IntPart(),
+ Source: "APS",
+ })
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "grpc璋冪敤澶辫触")
+ return
+ }
+ err = orderAgain(params, resp.PurchaseNumber)
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "閲嶈澶辫触")
return
}
- util.ResponseFormat(c, code.Success, "閲嶈鎴愬姛")
}
--
Gitblit v1.8.0