| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.basic.excel.SupplierManageExcelDto; |
| | | import com.ruoyi.basic.mapper.SupplierManageMapper; |
| | | import com.ruoyi.basic.pojo.SupplierManage; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.inventory.dto.StockoutDto; |
| | | import com.ruoyi.inventory.excel.StockOutExcelDto; |
| | |
| | | import com.ruoyi.inventory.pojo.StockOut; |
| | | import com.ruoyi.inventory.service.StockOutService; |
| | | |
| | | import com.ruoyi.purchase.mapper.ProductRecordMapper; |
| | | import com.ruoyi.purchase.pojo.ProductRecord; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private StockOutMapper stockOutMapper; |
| | | @Autowired |
| | | private StockManagementMapper stockManagementMapper; |
| | | @Autowired |
| | | private ProductRecordMapper productRecordMapper; |
| | | @Autowired |
| | | private SupplierManageMapper supplierManageMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveStockout(StockOut stockOut) { |
| | | // 进行判断是否存在相同的产品id和供应商id |
| | | LambdaQueryWrapper<StockManagement> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(StockManagement::getProductId, stockOut.getProductId()); |
| | | queryWrapper.eq(StockManagement::getSupplierId, stockOut.getSupplierId()); |
| | | StockManagement stockManagement1 = stockManagementMapper.selectOne(queryWrapper); |
| | | if (stockManagement1!= null) { |
| | | // 判断库存数量是否大于出库数量 |
| | | if (stockManagement1.getStockQuantity() < stockOut.getInboundQuantity()) { |
| | | throw new RuntimeException("库存数量不足"); |
| | | } |
| | | stockOutMapper.insert(stockOut); |
| | | stockManagement1.setStockQuantity(stockManagement1.getStockQuantity() - stockOut.getInboundQuantity()); |
| | | stockManagement1.setInboundTime(new Date()); |
| | | stockManagementMapper.updateById(stockManagement1); |
| | | // 进行判断是否存在相同的产品id和供应商id,要判断product_id在表product_record中是否存在,因为stock_out表中的product_id是product_record表中的product_id关联的 |
| | | LambdaQueryWrapper<ProductRecord> queryWrapper1 = new LambdaQueryWrapper<>(); |
| | | queryWrapper1.eq(ProductRecord::getProductId, stockOut.getProductRecordid()); |
| | | ProductRecord productRecord = productRecordMapper.selectOne(queryWrapper1); |
| | | if (productRecord == null) { |
| | | throw new RuntimeException("产品不存在"); |
| | | } |
| | | else { |
| | | throw new RuntimeException("库存不存在"); |
| | | LambdaQueryWrapper<SupplierManage> queryWrapper2 = new LambdaQueryWrapper<>(); |
| | | queryWrapper2.eq(SupplierManage::getId, stockOut.getSupplierId()); |
| | | SupplierManage supplierManage = supplierManageMapper.selectOne(queryWrapper2); |
| | | if (supplierManage == null) { |
| | | throw new RuntimeException("供应商不存在"); |
| | | } |
| | | LambdaQueryWrapper<StockManagement> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(StockManagement::getProductRecordid, stockOut.getProductRecordid()); |
| | | queryWrapper.eq(StockManagement::getSupplierId, stockOut.getSupplierId()); |
| | | StockManagement stockManagement = stockManagementMapper.selectOne(queryWrapper); |
| | | if (stockManagement != null) { |
| | | stockOut.setStockmanageId(stockManagement.getId()); |
| | | stockOutMapper.insert(stockOut); |
| | | }else { |
| | | throw new RuntimeException("库存中不存在该产品和供应商"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int updateStockOut(StockOut stockOut) { |
| | | // 需要进行判断在库存中是否存在该产品,如果存在,就进行修改,否则就抛出异常 |
| | | StockOut stockOut1 = stockOutMapper.selectById(stockOut.getId()); |
| | | LambdaQueryWrapper<StockManagement> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(StockManagement::getProductId, stockOut.getProductId()); |
| | | StockManagement stockManagement1 = stockManagementMapper.selectOne(queryWrapper); |
| | | if (stockManagement1!= null) { |
| | | // 判断库存数量是否大于出库数量 |
| | | if (stockManagement1.getStockQuantity()+stockOut1.getInboundQuantity() < stockOut.getInboundQuantity()) { |
| | | throw new RuntimeException("库存数量不足"); |
| | | } |
| | | stockManagement1.setStockQuantity(stockManagement1.getStockQuantity() + stockOut1.getInboundQuantity() - stockOut.getInboundQuantity()); |
| | | stockManagement1.setInboundTime(stockOut.getInboundTime()); |
| | | stockManagement1.setBoundTime(new Date()); |
| | | System.out.println(stockManagement1 + "22"); |
| | | stockManagementMapper.updateById(stockManagement1); |
| | | } else { |
| | | throw new RuntimeException("库存不存在"); |
| | | } |
| | | return stockOutMapper.updateById(stockOut); |
| | | // 修改的时候要判断是否存在相同的产品id和供应商id |
| | | LambdaQueryWrapper<ProductRecord> queryWrapper1 = new LambdaQueryWrapper<>(); |
| | | queryWrapper1.eq(ProductRecord::getProductId, stockOut.getProductRecordid()); |
| | | ProductRecord productRecord = productRecordMapper.selectOne(queryWrapper1); |
| | | if (productRecord == null) { |
| | | throw new RuntimeException("产品不存在"); |
| | | } |
| | | LambdaQueryWrapper<SupplierManage> queryWrapper2 = new LambdaQueryWrapper<>(); |
| | | queryWrapper2.eq(SupplierManage::getId, stockOut.getSupplierId()); |
| | | SupplierManage supplierManage = supplierManageMapper.selectOne(queryWrapper2); |
| | | if (supplierManage == null) { |
| | | throw new RuntimeException("供应商不存在"); |
| | | } |
| | | LambdaQueryWrapper<StockManagement> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(StockManagement::getProductRecordid, stockOut.getProductRecordid()); |
| | | queryWrapper.eq(StockManagement::getSupplierId, stockOut.getSupplierId()); |
| | | StockManagement stockManagement = stockManagementMapper.selectOne(queryWrapper); |
| | | if (stockManagement != null) { |
| | | stockOut.setStockmanageId(stockManagement.getId()); |
| | | return stockOutMapper.updateById(stockOut); |
| | | }else { |
| | | throw new RuntimeException("库存中不存在该产品和供应商"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | ExcelUtil<StockOutExcelDto> util = new ExcelUtil<StockOutExcelDto>(StockOutExcelDto.class); |
| | | util.exportExcel(response, stockoutList, "供应商导出"); |
| | | } |
| | | |
| | | } |