controllers/operation.go
@@ -14,6 +14,7 @@
   "os"
   "sort"
   "strconv"
   "strings"
   "time"
   "wms/conf"
   "wms/constvar"
@@ -337,7 +338,10 @@
   }
   if err := models.WithTransaction(func(tx *gorm.DB) error {
      if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Update(&models.Operation{Status: constvar.OperationStatus_Finish}); err != nil {
      if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Update(&models.Operation{Status: constvar.OperationStatus_Finish, AuditDate: time.Now().Format("2006-01-02 15:04:05")}); err != nil {
         return err
      }
      if err := AddMoveHistory([]*models.Operation{operation}, tx); err != nil {
         return err
      }
@@ -404,7 +408,6 @@
               //   return err
               //}
               //TODO:出入库的finish和报废的finish都要增加对location_product_amount表数量的更新,因为此表有ProductCategory字段,所以operation_details表中要增加ProductCategoryId字段
               locAmount, err := models.NewLocationProductAmountSearch().
                  SetProductId(v.ID).
                  SetLocationId(locationRule.LocationId).
@@ -454,7 +457,6 @@
                  //   return err
                  //}
                  //TODO:出入库的finish和报废的finish都要增加对location_product_amount表数量的更新,因为此表有ProductCategory字段,所以operation_details表中要增加ProductCategoryId字段
                  locAmount, err := models.NewLocationProductAmountSearch().
                     SetProductId(v.ID).
                     SetLocationId(locationRule.LocationId).
@@ -471,7 +473,6 @@
                     return res.Error
                  }
               } else {
                  //TODO:出入库的finish和报废的finish都要增加对location_product_amount表数量的更新,因为此表有ProductCategory字段,所以operation_details表中要增加ProductCategoryId字段
                  locAmount, err := models.NewLocationProductAmountSearch().
                     SetProductId(v.ID).
                     SetLocationId(operation.ToLocationID).
@@ -703,6 +704,34 @@
   util.ResponseFormat(c, code.Success, "操作成功")
}
func AddMoveHistory(operationList []*models.Operation, db *gorm.DB) error {
   var histories []*models.MoveHistory
   for _, operation := range operationList {
      for _, v := range operation.Details {
         history := &models.MoveHistory{
            Number:            operation.Number,
            BaseOperationType: operation.BaseOperationType,
            OperationTypeId:   operation.OperationTypeId,
            OperationTypeName: operation.OperationTypeName,
            OperationId:       operation.Id,
            ProductName:       v.Product.Name,
            Amount:            v.Amount,
            Unit:              v.Product.Unit,
            Weight:            operation.Weight,
            FromLocationId:    operation.FromLocationID,
            FromLocation:      operation.FromLocation.Name,
            ToLocationId:      operation.ToLocationID,
            ToLocation:        operation.ToLocation.Name,
         }
         histories = append(histories, history)
      }
   }
   if err := db.Model(&models.MoveHistory{}).Create(&histories).Error; err != nil {
      return err
   }
   return nil
}
var (
   ProductInventoryServiceConn *grpc.ClientConn
   PurchaseServiceConn         *grpc.ClientConn
@@ -824,6 +853,7 @@
      return
   }
   operation.Status = constvar.OperationStatus_Cancel
   operation.AuditDate = time.Now().Format("2006-01-02 15:04:05")
   if err := models.NewOperationSearch().SetID(operation.Id).Save(operation); err != nil {
      util.ResponseFormat(c, code.SaveFail, err.Error())
      return
@@ -960,6 +990,7 @@
}
func ExportOutputOperation(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
   repositoryLevels := strings.Split(operation.FromLocation.JointName, "/")
   template, err := models.NewFileTemplateAttachmentSearch().SetPreload(true).SetCategory(category).First()
   if err != nil {
      return "", errors.New("获取模版记录失败:" + err.Error())
@@ -988,11 +1019,15 @@
      },
   })
   f.SetCellValue("Sheet1", "C2", operation.FromLocation.Name)
   f.SetCellValue("Sheet1", "C2", repositoryLevels[0])
   f.SetCellValue("Sheet1", "H2", operation.WaybillNumber)
   f.SetCellValue("Sheet1", "K2", operation.AuditDate)
   f.SetCellValue("Sheet1", "H3", operation.SourceNumber)
   f.SetCellValue("Sheet1", "K3", operation.Number)
   f.SetCellValue("Sheet1", "C4", operation.CompanyName)
   f.SetCellValue("Sheet1", "I4", operation.ReceiverAddr)
   f.SetCellValue("Sheet1", "C5", operation.ReceiverName)
   f.SetCellValue("Sheet1", "H5", operation.ReceiverPhone)
   rowIndex := 8
   totalAmount := decimal.NewFromInt(0)