package com.kxs.store.biz.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kxs.store.biz.mapper.KxsWarehouseStockMapper;
import com.kxs.store.api.model.KxsWarehouseStock;
import com.kxs.store.biz.service.KxsWarehouseStockService;
import org.springframework.stereotype.Service;

/**
 * 客小爽仓库库存统计表(KxsWarehouseStock)表服务实现类
 *
 * @author 系统
 * @since 2024-01-08 09:46:02
 */
@Service("kxsWarehouseStockService")
public class KxsWarehouseStockServiceImpl extends ServiceImpl<KxsWarehouseStockMapper, KxsWarehouseStock> implements KxsWarehouseStockService {

    @Override
    public KxsWarehouseStock updateDeliveryStock(Integer warehouseId, int count) {

        KxsWarehouseStock warehouseStock = baseMapper.selectOne(Wrappers.<KxsWarehouseStock>lambdaQuery().eq(KxsWarehouseStock::getWarehouseId, warehouseId));
        warehouseStock.setDeliveryNum(warehouseStock.getDeliveryNum() + count);
        warehouseStock.setStockNum(warehouseStock.getStockNum() - count);
        baseMapper.updateById(warehouseStock);
        return warehouseStock;
    }

    @Override
    public KxsWarehouseStock updateAddStock(Integer warehouseId, int count) {

        KxsWarehouseStock warehouseStock = baseMapper.selectOne(Wrappers.<KxsWarehouseStock>lambdaQuery().eq(KxsWarehouseStock::getWarehouseId, warehouseId));
        warehouseStock.setStockTotal(warehouseStock.getStockTotal() + count);
        warehouseStock.setStockNum(warehouseStock.getStockNum() + count);
        baseMapper.updateById(warehouseStock);
        return warehouseStock;
    }
}

