| | |
| | | package com.ruoyi.inventory.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.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.StockManagementDto; |
| | | import com.ruoyi.inventory.excel.StockManagementExcelDto; |
| | | import com.ruoyi.inventory.mapper.StockManagementMapper; |
| | | import com.ruoyi.inventory.mapper.StockOutMapper; |
| | | import com.ruoyi.inventory.pojo.StockManagement; |
| | | import com.ruoyi.inventory.pojo.StockOut; |
| | | import com.ruoyi.inventory.service.StockManagementService; |
| | | import com.ruoyi.purchase.mapper.ProductRecordMapper; |
| | | import com.ruoyi.purchase.pojo.ProductRecord; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | public class StockManagementServiceImpl extends ServiceImpl<StockManagementMapper,StockManagement> implements StockManagementService { |
| | | @Autowired |
| | | private StockManagementMapper stockManagementMapper; |
| | | @Autowired |
| | | private StockOutMapper stockOutMapper; |
| | | @Autowired |
| | | private ProductRecordMapper productRecordMapper; |
| | | @Autowired |
| | | private SupplierManageMapper supplierManageMapper; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public int updateStockManagement(StockManagement stockManagement) { |
| | |
| | | ExcelUtil<StockManagementExcelDto> util = new ExcelUtil<StockManagementExcelDto>(StockManagementExcelDto.class); |
| | | util.exportExcel(response, stockManageList, "库存导出"); |
| | | } |
| | | |
| | | @Override |
| | | public int stockout(StockManagement stockManagement) { |
| | | // 需要进行判断,库存数量是否足够 |
| | | StockManagement stockManagement1 = stockManagementMapper.selectById(stockManagement.getId()); |
| | | if (stockManagement1.getStockQuantity() < stockManagement.getStockQuantity()) { |
| | | throw new RuntimeException("库存数量不足"); |
| | | }else if (stockManagement1.getStockQuantity().equals(stockManagement.getStockQuantity())){ |
| | | // 减去的数量要在出库记录表中加一条数据 |
| | | StockOut stockOut = new StockOut(); |
| | | stockOut.setInboundQuantity(stockManagement.getStockQuantity()); |
| | | stockOut.setProductRecordid(stockManagement1.getProductRecordid()); |
| | | stockOut.setSupplierId(stockManagement1.getSupplierId()); |
| | | stockOut.setUserId(stockManagement.getUserId()); |
| | | stockOut.setInboundTime(stockManagement1.getBoundTime()); |
| | | stockOutMapper.insert(stockOut); |
| | | return stockManagementMapper.deleteById(stockManagement.getId()); |
| | | } |
| | | else { |
| | | stockManagement1.setStockQuantity(stockManagement1.getStockQuantity() - stockManagement.getStockQuantity()); |
| | | StockOut stockOut = new StockOut(); |
| | | stockOut.setInboundQuantity(stockManagement.getStockQuantity()); |
| | | stockOut.setProductRecordid(stockManagement1.getProductRecordid()); |
| | | stockOut.setSupplierId(stockManagement1.getSupplierId()); |
| | | stockOut.setUserId(stockManagement.getUserId()); |
| | | stockOut.setInboundTime(stockManagement1.getBoundTime()); |
| | | stockOutMapper.insert(stockOut); |
| | | return stockManagementMapper.updateById(stockManagement1); |
| | | } |
| | | } |
| | | |
| | | // 添加库存方法 |
| | | @Override |
| | | public int addStockManage(StockManagement stockManagement) { |
| | | // 需要进行判断 |
| | | LambdaQueryWrapper<ProductRecord> queryWrapper1 = new LambdaQueryWrapper<>(); |
| | | queryWrapper1.eq(ProductRecord::getProductId, stockManagement.getProductRecordid()); |
| | | ProductRecord productRecord = productRecordMapper.selectOne(queryWrapper1); |
| | | if (productRecord == null) { |
| | | throw new RuntimeException("产品不存在"); |
| | | } |
| | | LambdaQueryWrapper<SupplierManage> queryWrapper2 = new LambdaQueryWrapper<>(); |
| | | queryWrapper2.eq(SupplierManage::getId, stockManagement.getSupplierId()); |
| | | SupplierManage supplierManage = supplierManageMapper.selectOne(queryWrapper2); |
| | | System.out.println(supplierManage+"11"); |
| | | if (supplierManage == null) { |
| | | throw new RuntimeException("供应商不存在"); |
| | | } |
| | | return stockManagementMapper.insert(stockManagement); |
| | | } |
| | | } |