yaowanxin
10 天以前 2e67b4a6d474c584daf2ab1ff1df9d785f902b96
src/main/java/com/ruoyi/warehouse/service/impl/WarehouseGoodsShelvesServiceImpl.java
@@ -19,6 +19,7 @@
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;
@@ -46,6 +47,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean add(WarehouseGoodsShelves warehouseGoodsShelves) {
        int insert = warehouseGoodsShelvesMapper.insert(warehouseGoodsShelves);
        if (insert <= 0) {
@@ -54,8 +56,6 @@
        }
        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++) {
@@ -64,9 +64,6 @@
                rowcol.setStorey(i);
                rowcol.setArrange(j);
                rowcol.setWarehouseGoodsShelvesId(shelvesId);
                rowcol.setWarehouseId(warehouseId);
                rowcol.setCreateUser(createUser);
                rowcol.setUpdateUser(updateUser);
                rowcolList.add(rowcol);
            }
        }
@@ -74,11 +71,7 @@
        if (!rowcolList.isEmpty()) {
            try {
                // 使用批量插入方法替代循环单条插入
                boolean saveBatch = warehouseGoodsShelvesRowcolService.saveBatch(rowcolList);
                if (!saveBatch) {
                    log.warn("货架[{}]的行列记录部分添加失败", shelvesId);
                }
                warehouseGoodsShelvesRowcolService.saveBatch(rowcolList);
            } catch (Exception e) {
                log.error("货架[{}]的行列记录批量添加失败", shelvesId, e);
                // 抛出异常触发事务回滚
@@ -87,7 +80,7 @@
        }
        log.info("货架[{}]添加成功,层数:{},排数:{}",
                shelvesId,
                warehouseGoodsShelves.getGoodsShelvesName(),
                warehouseGoodsShelves.getStorey(),
                warehouseGoodsShelves.getArrange());
        return true;