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.MainStudentExperience;
import org.dromara.main.domain.bo.MainStudentExperienceBo;
import org.dromara.main.domain.vo.MainStudentExperienceVo;
import org.dromara.main.mapper.MainStudentExperienceMapper;
import org.dromara.main.service.IMainStudentExperienceService;
import org.springframework.stereotype.Service;

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

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