| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.basic.dto.ProductDto; |
| | | import com.ruoyi.basic.dto.ProductTreeDto; |
| | |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.service.IProductService; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import lombok.AllArgsConstructor; |
| | | import com.ruoyi.consumables.mapper.ConsumablesInventoryMapper; |
| | | import com.ruoyi.consumables.pojo.ConsumablesInventory; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import com.ruoyi.stock.pojo.StockInventory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService { |
| | | |
| | | @Autowired |
| | | private ProductMapper productMapper; |
| | | |
| | | @Autowired |
| | | private ProductModelMapper productModelMapper; |
| | | @Autowired |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | @Autowired |
| | | private ConsumablesInventoryMapper consumablesInventoryMapper; |
| | | |
| | | @Override |
| | | public List<ProductTreeDto> selectProductList(ProductDto productDto) { |
| | |
| | | } |
| | | return tree; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<ProductModel> listPageProductModel(Page<ProductModel> page, ProductModel productModel) { |
| | | return productModelMapper.listPageProductModel(page, productModel); |
| | | } |
| | | |
| | | |
| | | // 递归构建子节点 |
| | | private List<ProductTreeDto> buildChildrenNodes(Long parentId) { |
| | |
| | | |
| | | @Override |
| | | public int delProductByIds(Long[] ids) { |
| | | |
| | | List<StockInventory> stockInventoryList = stockInventoryMapper.selectList(new LambdaQueryWrapper<StockInventory>().in(StockInventory::getProductId, Arrays.asList(ids))); |
| | | List<ConsumablesInventory> consumablesInventoryList = consumablesInventoryMapper.selectList(new LambdaQueryWrapper<ConsumablesInventory>().in(ConsumablesInventory::getProductId, Arrays.asList(ids))); |
| | | if (!stockInventoryList.isEmpty() || !consumablesInventoryList.isEmpty()) { |
| | | throw new RuntimeException("该产品存在库存关联!"); |
| | | } |
| | | |
| | | // 1. 删除子表 product_model 中关联的数据 |
| | | LambdaQueryWrapper<ProductModel> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(ProductModel::getProductId, ids); |
| | | productModelMapper.delete(queryWrapper); |
| | | |
| | | // 2. 删除主表 product 数据 |
| | | int deleteCount = productMapper.deleteBatchIds(Arrays.asList(ids)); |
| | | |
| | | return deleteCount; |
| | | return productMapper.deleteBatchIds(Arrays.asList(ids)); |
| | | } |
| | | |
| | | } |