| | |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | | "wms/pkg/logx" |
| | | "wms/pkg/structx" |
| | | "wms/request" |
| | | ) |
| | |
| | | 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(¶ms) |
| | | 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{ |
| | |
| | | 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 |
| | | } |
| | |
| | | for _, warehouse := range list { |
| | | for _, location := range locations { |
| | | if warehouse.LocationId == location.Id { |
| | | warehouse.WarehouseLocation = warehouse.Code + "/" + location.Name |
| | | warehouse.WarehouseLocation = location.Name |
| | | break |
| | | } |
| | | } |