zhangqian
2024-04-07 a8914a16b23e93f6bfd12bcfd5cbe8b24cf7eb84
controllers/reorder_rule_controller.go
@@ -3,19 +3,16 @@
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"
@@ -153,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)
@@ -260,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      重订货规则
@@ -291,7 +288,7 @@
      return
   }
   if params.Route == "采购" {
      client := purchase_wms.NewPurchaseServiceClient(PurchaseServiceConn)
      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调用失败")
@@ -300,7 +297,7 @@
      util.ResponseFormat(c, code.Success, resp.List)
      return
   }
   client := inventory_order.NewInventoryOrderServiceClient(InventoryOrderServiceConn)
   client := inventory_order.NewInventoryOrderServiceClient(init_client.ApsConn)
   order, err := client.CreateNewOrder(c, &inventory_order.CreateNewOrderRequest{
      OrderNumber: params.OrderNumber.IntPart(),
      Unit:        params.Unit,
@@ -335,16 +332,17 @@
   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 = SourceNumber
   err = models.WithTransaction(func(db *gorm.DB) error {
@@ -368,7 +366,7 @@
// @Router    /api-wms/v1/reorderRule/submitOrder [post]
func (slf ReorderRuleController) SubmitOrder(c *gin.Context) {
   var params models.ReorderRule
   client := purchase_wms.NewPurchaseServiceClient(PurchaseServiceConn)
   client := purchase_wms.NewPurchaseServiceClient(init_client.SrmConn)
   resp, err := client.CreatePurchaseByWms(c, &purchase_wms.CreatePurchaseByWmsRequest{
      SupplierId: params.SupplierId,
      ProductId:  params.ProductId,