liujiandao
2023-11-07 99ffda4126a4217ecaf57f4eab2a5615ae353aff
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(&params); err != nil {
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
      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 {