| | |
| | | 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.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.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 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; |
| | | 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; |
| | | @Autowired |
| | | private ProductRecordMapper productRecordMapper; |
| | | @Autowired |
| | | private SupplierManageMapper supplierManageMapper; |
| | | |
| | | |
| | | @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,要判断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("产品不存在"); |
| | | } |
| | | 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) { |
| | | int i = stockOutMapper.updateByPrimaryKeySelective(stockOut); |
| | | return i; |
| | | // 修改的时候要判断是否存在相同的产品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 |
| | | 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, "供应商导出"); |
| | | } |
| | | |
| | | } |