package org.dromara.main.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.main.domain.MainBackCategory;
import org.dromara.main.domain.bo.MainBackCategoryBo;
import org.dromara.main.domain.vo.MainBackCategoryVo;
import org.dromara.main.mapper.MainBackCategoryMapper;
import org.dromara.main.service.IMainBackCategoryService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@RequiredArgsConstructor
@Service
public class MainBackCategoryServiceImpl implements IMainBackCategoryService {

    private final MainBackCategoryMapper baseMapper;

    @Override
    public List<MainBackCategoryVo> queryList(MainBackCategoryBo bo) {
        LambdaQueryWrapper<MainBackCategory> lqw = Wrappers.lambdaQuery();
        lqw.like(ObjectUtil.isNotNull(bo.getName()), MainBackCategory::getName, bo.getName());
        lqw.eq(ObjectUtil.isNotNull(bo.getStatus()), MainBackCategory::getStatus, bo.getStatus());
        return baseMapper.selectVoList(lqw);
    }

    @Override
    public Boolean insertByBo(MainBackCategoryBo bo) {
        MainBackCategory add = MapstructUtils.convert(bo, MainBackCategory.class);
        return baseMapper.insert(add) > 0;
    }

    @Override
    public Boolean updateByBo(MainBackCategoryBo bo) {
        MainBackCategory update = MapstructUtils.convert(bo, MainBackCategory.class);
        return baseMapper.updateById(update) > 0;
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        return baseMapper.deleteByIds(ids) > 0;
    }
}
