| | |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean add(WarehouseGoodsShelves warehouseGoodsShelves) { |
| | | int insert = warehouseGoodsShelvesMapper.insert(warehouseGoodsShelves); |
| | | if (insert <= 0) { |
| | |
| | | } |
| | | Long shelvesId = warehouseGoodsShelves.getId(); |
| | | Long warehouseId = warehouseGoodsShelves.getWarehouseId(); |
| | | Long createUser = warehouseGoodsShelves.getCreateUser(); |
| | | Long updateUser = warehouseGoodsShelves.getUpdateUser(); |
| | | // 3. 批量创建行列记录 |
| | | List<WarehouseGoodsShelvesRowcol> rowcolList = new ArrayList<>(); |
| | | for (long i = 1; i <= warehouseGoodsShelves.getStorey(); i++) { |
| | |
| | | rowcol.setStorey(i); |
| | | rowcol.setArrange(j); |
| | | rowcol.setWarehouseGoodsShelvesId(shelvesId); |
| | | rowcol.setWarehouseId(warehouseId); |
| | | rowcol.setCreateUser(createUser); |
| | | rowcol.setUpdateUser(updateUser); |
| | | rowcolList.add(rowcol); |
| | | } |
| | | } |
| | |
| | | if (!rowcolList.isEmpty()) { |
| | | try { |
| | | // 使用批量插入方法替代循环单条插入 |
| | | boolean saveBatch = warehouseGoodsShelvesRowcolService.saveBatch(rowcolList); |
| | | |
| | | if (!saveBatch) { |
| | | log.warn("货架[{}]的行列记录部分添加失败", shelvesId); |
| | | } |
| | | warehouseGoodsShelvesRowcolService.saveBatch(rowcolList); |
| | | } catch (Exception e) { |
| | | log.error("货架[{}]的行列记录批量添加失败", shelvesId, e); |
| | | // 抛出异常触发事务回滚 |
| | |
| | | } |
| | | |
| | | log.info("货架[{}]添加成功,层数:{},排数:{}", |
| | | shelvesId, |
| | | warehouseGoodsShelves.getGoodsShelvesName(), |
| | | warehouseGoodsShelves.getStorey(), |
| | | warehouseGoodsShelves.getArrange()); |
| | | return true; |