yaowanxin
9 天以前 7d188cc913d5ea547c5e99ae434ea3b1cf4e818a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
import com.ruoyi.warehouse.service.WarehouseGoodsShelvesService;
import com.ruoyi.warehouse.service.WarehouseService;
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
* @description 针对表【warehouse(仓库表)】的数据库操作Service实现
* @createDate 2025-08-13 11:49:02
*/
@Service
@Slf4j
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse>
    implements WarehouseService {
    @Autowired
    private WarehouseMapper warehouseMapper;
    @Autowired
    private WarehouseGoodsShelvesService warehouseGoodsShelvesService;
 
    @Override
    public List<Warehouse> listPage(Warehouse warehouse) {
        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) {
        // 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);
    }
 
}