package com.fjhx.service.stock.impl;

import cn.hutool.core.util.ObjectUtil;
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.base.StorageBaseEntity;
import com.fjhx.entity.stock.StockHouse;
import com.fjhx.mapper.stock.StockHouseMapper;
import com.fjhx.params.stock.StockHouseVo;
import com.fjhx.service.stock.StockHouseService;
import com.fjhx.utils.WrapperUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 仓库 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-08-05
 */
@Service
public class StockHouseServiceImpl extends ServiceImpl<StockHouseMapper, StockHouse> implements StockHouseService {

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

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

        WrapperUtil.init(condition, wrapper)
                .like("name", "keyword");

        return page(condition, wrapper);
    }

    @Override
    public void add(StockHouseVo stockHouseVo) {
        save(stockHouseVo);
    }

    @Override
    public void edit(StockHouseVo stockHouseVo) {
        updateById(stockHouseVo);
    }

    @Override
    public void delete(StockHouseVo stockHouseVo) {
        removeById(stockHouseVo.getId());
    }

    @Override
    public List<StockHouse> getList(StockHouse stockHouse) {
        return lambdaQuery()
                .select(StorageBaseEntity::getId, StockHouse::getName)
                .like(ObjectUtil.isNotEmpty(stockHouse.getName()), StockHouse::getName, stockHouse.getName())
                .list();
    }

}
