jiangshuai
2023-11-16 a0125ef3d6ce35be7b6dc4919c4192dba4a7329a
controllers/operation.go
@@ -23,6 +23,7 @@
   "wms/pkg/logx"
   "wms/pkg/structx"
   "wms/proto/product_inventory"
   "wms/proto/purchase_wms"
   "wms/request"
)
@@ -412,6 +413,7 @@
               locAmount.ProductId = v.ID
               locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
               locAmount.Amount = locAmount.Amount.Add(value)
               locAmount.ProductCategoryID = v.CategoryId
               if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
                  return res.Error
               }
@@ -461,6 +463,7 @@
                  locAmount.ProductId = v.ID
                  locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
                  locAmount.Amount = locAmount.Amount.Add(value)
                  locAmount.ProductCategoryID = v.CategoryId
                  if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
                     return res.Error
                  }
@@ -477,6 +480,7 @@
                  locAmount.ProductId = v.ID
                  locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
                  locAmount.Amount = locAmount.Amount.Add(value)
                  locAmount.ProductCategoryID = v.CategoryId
                  if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
                     return res.Error
                  }
@@ -487,6 +491,9 @@
            if err := tx.Create(&operationInputs).Error; err != nil {
               return err
            }
         }
         if operation.SourceNumber != "" {
            go UpdatePurchaseStatus(operation.SourceNumber)
         }
      }
@@ -530,6 +537,9 @@
            if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil {
               return err
            }
         }
         if operation.SourceNumber != "" {
            go UpdateSalesDetailStatus(operation.SourceNumber)
         }
      }
@@ -604,6 +614,7 @@
               locAmount.ProductId = v.ID
               locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
               locAmount.Amount = locAmount.Amount.Add(value)
               locAmount.ProductCategoryID = v.CategoryId
               if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
                  return res.Error
               }
@@ -652,6 +663,7 @@
                  locAmount.ProductId = v.ID
                  locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
                  locAmount.Amount = locAmount.Amount.Add(value)
                  locAmount.ProductCategoryID = v.CategoryId
                  if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
                     return res.Error
                  }
@@ -684,17 +696,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 +722,9 @@
func CloseProductInventoryServiceConn() {
   if ProductInventoryServiceConn != nil {
      ProductInventoryServiceConn.Close()
   }
   if PurchaseServiceConn != nil {
      PurchaseServiceConn.Close()
   }
}
@@ -715,6 +736,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 +821,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
   }