package com.ruoyi.zhushi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.zhushi.entity.Category;
import com.ruoyi.zhushi.entity.InventoryBase;
import com.ruoyi.zhushi.mapper.InventoryBaseMapper;
import com.ruoyi.zhushi.service.InventoryBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class InventoryBaseServiceImpl implements InventoryBaseService {

    @Autowired
    private InventoryBaseMapper inventoryBaseMapper;

    @Transactional
    @Override
    public boolean saveInventoryBase(InventoryBase inventoryBase) {
        //先删除当天的   前段是 按照 website  和 category  分批上传的
     //   int i =  inventoryBaseMapper.delete(delWrapper);
        inventoryBaseMapper.insert(inventoryBase);
        return  true;
    }

    @Override
    public boolean deleteInventoryBaseById(String id) {
        return inventoryBaseMapper.deleteById(id) > 0;
    }

    @Override
    public boolean updateInventoryBase(InventoryBase inventoryBase) {
        inventoryBaseMapper.updateById(inventoryBase);
        return true;
    }

    @Override
    public InventoryBase getInventoryBaseById(String id) {
        return inventoryBaseMapper.selectById(id);
    }

    @Override
    public TableDataInfo<InventoryBase> getAllInventoryBases( String type, PageQuery pageQuery) {
        QueryWrapper<InventoryBase> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", type);
        return TableDataInfo.build(inventoryBaseMapper.selectPage(pageQuery.build(),queryWrapper));
    }
}
