lishenao
23 小时以前 fbc53e77f994f15c3ebcd4fa07dfd23671c0ce26
src/main/java/com/ruoyi/inventory/service/impl/StockManagementServiceImpl.java
@@ -14,12 +14,14 @@
import com.ruoyi.inventory.pojo.StockManagement;
import com.ruoyi.inventory.pojo.StockOut;
import com.ruoyi.inventory.service.StockManagementService;
import com.ruoyi.purchase.dto.ProductRecordDto;
import com.ruoyi.purchase.mapper.ProductRecordMapper;
import com.ruoyi.purchase.pojo.ProductRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
@Service
@@ -60,51 +62,55 @@
    @Override
    public int stockout(StockManagement stockManagement) {
//        需要进行判断,库存数量是否足够
        StockManagement stockManagement1 = stockManagementMapper.selectById(stockManagement.getId());
//        在前端其实就穿了3个数,数量,出库人,时间,只需要进行判断,库存数量是否足够即可,有三种情况
        StockOut stockOut = new StockOut();
        LambdaQueryWrapper<StockManagement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StockManagement::getId, stockManagement.getId());
        StockManagement stockManagement1 = stockManagementMapper.selectOne(queryWrapper);
        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 if (stockManagement1.getStockQuantity() > stockManagement.getStockQuantity()) {
            stockManagement1.setStockQuantity(stockManagement1.getStockQuantity() - stockManagement.getStockQuantity());
            stockManagementMapper.updateById(stockManagement1);
        }
        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);
            stockManagementMapper.deleteById(stockManagement.getId());
        }
        stockOut.setProductrecordId(stockManagement1.getProductrecordId());
        stockOut.setInboundTime(stockManagement.getBoundTime());
//            出库批次自动生成
        String batchCode = "CK" + System.currentTimeMillis();
        stockOut.setInboundBatch(batchCode);
        stockOut.setSupplierId(stockManagement1.getSupplierId());
        stockOut.setInboundQuantity(stockManagement.getStockQuantity());
        stockOut.setUserId(stockManagement.getUserId());
        return stockOutMapper.insert(stockOut);
    }
//    添加库存方法
    @Override
    public int addStockManage(StockManagement stockManagement) {
//        需要进行判断
//        需要先判断采购记录表中是否有该产品的采购记录
        LambdaQueryWrapper<ProductRecord> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(ProductRecord::getProductId, stockManagement.getProductRecordid());
        queryWrapper1.eq(ProductRecord::getId, 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("供应商不存在");
        }
        ProductRecordDto productRecordDto = productRecordMapper.selectProductRecordById(productRecord.getId());
        if (productRecordDto!= null) {
            stockManagement.setProductrecordId(productRecordDto.getId());
            stockManagement.setBoundTime(stockManagement.getBoundTime());
            stockManagement.setSupplierId(productRecordDto.getSupplierId());
            stockManagement.setStockQuantity(stockManagement.getStockQuantity());
            stockManagement.setUserId(stockManagement.getUserId());
        return stockManagementMapper.insert(stockManagement);
        }else {
            throw new RuntimeException("采购记录表中没有该产品的采购记录");
    }
}
    @Override
    public StockManagement getStockManageById(Long id) {
        return stockManagementMapper.selectById(id);
    }
}