| | |
| | | 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.ruoyi.basic.excel.SupplierManageExcelDto; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.inventory.dto.StockoutDto; |
| | | import com.ruoyi.inventory.excel.StockOutExcelDto; |
| | | 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.StockOutService; |
| | | import inventory.domain.StockOut; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class StockOutServiceImpl implements StockOutService { |
| | | @Autowired |
| | | private StockOutMapper stockOutMapper; |
| | | @Autowired |
| | | private StockManagementMapper stockManagementMapper; |
| | | |
| | | |
| | | @Override |
| | | public List<StockOut> getStockOuts() { |
| | | List<StockOut> stockOuts = stockOutMapper.selectAll(); |
| | | return stockOuts; |
| | | public int delStockOut(List<Integer> ids) { |
| | | return stockOutMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public StockOut getStockOutById(Long id) { |
| | | StockOut stockOut = stockOutMapper.selectByPrimaryKey(id); |
| | | StockOut stockOut = stockOutMapper.selectById(id); |
| | | return stockOut; |
| | | } |
| | | |
| | | @Override |
| | | public int addStockOut(StockOut stockOut) { |
| | | int i = stockOutMapper.insertSelective(stockOut); |
| | | return i; |
| | | @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); |
| | | } |
| | | else { |
| | | throw new RuntimeException("库存不存在"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int updateStockOut(StockOut stockOut) { |
| | | int i = stockOutMapper.updateByPrimaryKeySelective(stockOut); |
| | | return i; |
| | | // 需要进行判断在库存中是否存在该产品,如果存在,就进行修改,否则就抛出异常 |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | public int deleteStockOut(Long id) { |
| | | int i = stockOutMapper.deleteByPrimaryKey(id); |
| | | return i; |
| | | public IPage<StockoutDto> selectStockOutPage(Page page, StockoutDto stockoutDto) { |
| | | return stockOutMapper.selectStockOutBypage(page, stockoutDto); |
| | | } |
| | | |
| | | @Override |
| | | public void stockoutExport(HttpServletResponse response, StockoutDto stockoutDto) { |
| | | List<StockOutExcelDto> stockoutList = stockOutMapper.stockoutExportList(stockoutDto); |
| | | ExcelUtil<StockOutExcelDto> util = new ExcelUtil<StockOutExcelDto>(StockOutExcelDto.class); |
| | | util.exportExcel(response, stockoutList, "供应商导出"); |
| | | } |
| | | } |