yaowanxin
9 天以前 7d188cc913d5ea547c5e99ae434ea3b1cf4e818a
src/main/java/com/ruoyi/warehouse/service/impl/WarehouseServiceImpl.java
@@ -1,10 +1,13 @@
package com.ruoyi.warehouse.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.warehouse.mapper.WarehouseMapper;
import com.ruoyi.warehouse.pojo.Warehouse;
import com.ruoyi.warehouse.pojo.WarehouseGoodsShelves;
@@ -13,9 +16,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Array;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author 86151
@@ -36,18 +41,35 @@
        return warehouseMapper.listPage( warehouse);
    }
//    @Override
//    public boolean deleteByIds(List<Long> ids) {
//
//        for (Long id : ids) {
//            List<WarehouseGoodsShelves> list = warehouseGoodsShelvesService.list(new QueryWrapper<WarehouseGoodsShelves>().lambda()
//                    .eq(WarehouseGoodsShelves::getWarehouseId, id));
//            if(list.size()>0){
//                log.error("仓库下有货架,不能删除 重新选择");
//                return false;
//            }
//        }
//        return removeByIds(ids);
//    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIds(List<Long> ids) {
        for (Long id : ids) {
            List<WarehouseGoodsShelves> list = warehouseGoodsShelvesService.list(new QueryWrapper<WarehouseGoodsShelves>().lambda()
                    .eq(WarehouseGoodsShelves::getWarehouseId, id));
            if(list.size()>0){
                log.error("仓库下有货架,不能删除 重新选择");
                return false;
            }
        // 1. 检查是否有货架
        Wrapper<WarehouseGoodsShelves> queryWrapper = new LambdaQueryWrapper<WarehouseGoodsShelves>()
                .in(WarehouseGoodsShelves::getWarehouseId, ids);
        List<WarehouseGoodsShelves> shelvesList = warehouseGoodsShelvesService.list(queryWrapper);
        //获得shelvesList中所有的Id
        List<Long> shelvesIds = shelvesList.stream().map(WarehouseGoodsShelves::getId).collect(Collectors.toList());
        // 2. 删除货架
        if (!shelvesIds.isEmpty()) {
            warehouseGoodsShelvesService.deleteByIds(shelvesIds);
        }
        return removeByIds(ids);
    }
}