zhangqian
2024-07-03 a2cfbd59045d7426088e9ec9e93794dc895849a9
controllers/warehouse.go
@@ -12,7 +12,6 @@
   "wms/extend/code"
   "wms/extend/util"
   "wms/models"
   "wms/pkg/logx"
   "wms/pkg/structx"
   "wms/request"
)
@@ -53,25 +52,33 @@
      util.ResponseFormat(c, code.SaveFail, "视图创建失败")
      return
   }
   //创建默认位置
   location := &models.Location{
      Name:              params.Name,
      JointName:         params.Name,
      Type:              constvar.LocationTypeInternal,
      ReplenishLocation: true,
      ParentId:          id,
   }
   locationId, err := models.NewLocationSearch().CreateReturnId(location)
   if err != nil {
      util.ResponseFormat(c, code.SaveFail, "位置创建失败")
      return
   }
   params.LocationId = locationId
   err = models.WithTransaction(func(tx *gorm.DB) error {
      err := models.NewWarehouseSearch().SetOrm(tx).Create(&params)
      if err != nil {
         return err
      }
      //创建默认位置
      location := &models.Location{
         Name:              params.Name,
         JointName:         params.Name,
         Type:              constvar.LocationTypeInternal,
         ReplenishLocation: true,
         ParentId:          id,
         WarehouseId:       params.Id,
      }
      locationId, err := models.NewLocationSearch().SetOrm(tx).CreateReturnId(location)
      if err != nil {
         return err
      }
      //更改仓库记录里的位置id
      params.LocationId = locationId
      err = models.NewWarehouseSearch().SetOrm(tx).SetID(params.Id).UpdateByMap(map[string]interface{}{"location_id": locationId})
      if err != nil {
         return err
      }
      //创建三个默认操作类型
      var types []*models.OperationType
      inType := &models.OperationType{
@@ -95,9 +102,8 @@
      err = models.NewOperationTypeSearch().SetOrm(tx).CreateBatch(types)
      return err
   })
   if err != nil {
      _ = models.NewLocationSearch().SetID(locationId).Delete()
      logx.Errorf("warehouse create err: %v", err)
      util.ResponseFormat(c, code.SaveFail, "插入失败")
      return
   }
@@ -238,7 +244,7 @@
   for _, warehouse := range list {
      for _, location := range locations {
         if warehouse.LocationId == location.Id {
            warehouse.WarehouseLocation = warehouse.Code + "/" + location.Name
            warehouse.WarehouseLocation = location.Name
            break
         }
      }