package org.dromara.main.service.impl;

import cn.hutool.core.bean.BeanUtil;
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.main.domain.MainStudentProject;
import org.dromara.main.domain.bo.MainStudentProjectBo;
import org.dromara.main.domain.vo.MainStudentProjectVo;
import org.dromara.main.mapper.MainStudentProjectMapper;
import org.dromara.main.service.IMainStudentProjectService;
import org.springframework.stereotype.Service;

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

@RequiredArgsConstructor
@Service
public class MainStudentProjectServiceImpl implements IMainStudentProjectService {
    private final MainStudentProjectMapper baseMapper;
    @Override
    public MainStudentProjectVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }
    @Override
    public List<MainStudentProjectVo> queryList(MainStudentProjectBo bo) {
        LambdaQueryWrapper<MainStudentProject> lqw = Wrappers.lambdaQuery();
        if (bo != null && ObjectUtil.isNotNull(bo.getStudentId())) {
            lqw.eq(MainStudentProject::getStudentId, bo.getStudentId());
        }
        return baseMapper.selectVoList(lqw);
    }
    @Override
    public Boolean insertByBo(MainStudentProjectBo bo) {
        MainStudentProject add = BeanUtil.toBean(bo, MainStudentProject.class);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) { bo.setId(add.getId()); }
        return flag;
    }
    @Override
    public Boolean updateByBo(MainStudentProjectBo bo) {
        MainStudentProject update = BeanUtil.toBean(bo, MainStudentProject.class);
        return baseMapper.updateById(update) > 0;
    }
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
