package com.fjhx.service.stock.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.entity.stock.StockJournal;
import com.fjhx.mapper.stock.StockJournalMapper;
import com.fjhx.params.stock.StockJournalVo;
import com.fjhx.service.stock.StockJournalService;
import com.fjhx.utils.WrapperUtil;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <p>
 * 出入库流水记录 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-11-24
 */
@Service
public class StockJournalServiceImpl extends ServiceImpl<StockJournalMapper, StockJournal> implements StockJournalService {

    @Override
    public Page<StockJournal> getPage(Map<String, String> condition) {

        QueryWrapper<StockJournal> wrapper = Wrappers.query();

        WrapperUtil.init(condition, wrapper)
                .createTimeDesc();

        Page<StockJournal> page = page(condition, wrapper);
        return page;
    }

    @Override
    public void add(StockJournalVo stockJournalVo) {
        save(stockJournalVo);
    }

    @Override
    public void edit(StockJournalVo stockJournalVo) {
        updateById(stockJournalVo);
    }

    @Override
    public void delete(StockJournalVo stockJournalVo) {
        removeById(stockJournalVo.getId());
    }

    @Override
    public void add(Integer type, Integer detailsType, Long goodsId, Long warehouseId, BigDecimal changeQuantity, String remarks) {
        StockJournal stockJournal = new StockJournal();
        stockJournal.setType(type);
        stockJournal.setDetailsType(detailsType);
        stockJournal.setGoodsId(goodsId);
        stockJournal.setWarehouseId(warehouseId);
        stockJournal.setChangeQuantity(changeQuantity);
        stockJournal.setRemarks(remarks);
        save(stockJournal);
    }

}
