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.MainStudent;
import org.dromara.main.domain.MainStudentEducation;
import org.dromara.main.domain.bo.MainStudentEducationBo;
import org.dromara.main.domain.vo.MainStudentEducationVo;
import org.dromara.main.mapper.MainStudentEducationMapper;
import org.dromara.main.service.IMainStudentEducationService;
import org.springframework.stereotype.Service;

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

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