package bus.service.impl;

import bus.model.dto.BCoursePreDto;
import bus.model.dto.BCoursePrePageDto;
import bus.model.vo.BCoursePreVo;
import bus.model.po.BCoursePrePo;
import bus.mapper.BCoursePreMapper;

import bus.service.BCoursePreService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;
import java.util.List;

/**
 * @Program: bus
 * @Description: 描述
 * @Author: zy
 * @Date: 2025-03-17 21:07:12
 **/
@Service
public class BCoursePreServiceImpl extends ServiceImpl<BCoursePreMapper, BCoursePrePo> implements BCoursePreService {

    @Autowired
    private BCoursePreMapper bCoursePreMapper;


	/**
     * 详情
     * @param id
     * @return
     */
    @Override
    public BCoursePrePo getDetailById(String id){
        return this.bCoursePreMapper.selectById(id);
    }

	/**
     * 保存
     * @param dto
     * @return
     */
    @Override
	public void save(BCoursePreDto dto){
        BCoursePrePo po = new BCoursePrePo();
        BeanUtils.copyProperties(dto,po);
		this.bCoursePreMapper.insert(po);
    }

    /**
    * 列表
    * @param dto
    * @return
    */
    @Override
    public List<BCoursePreVo> list(BCoursePrePageDto dto){
        return this.bCoursePreMapper.list(dto);
    }

	/**
     * 修改
     * @param dto
     * @return
     */
    @Override
    public void update(BCoursePreDto dto){
        BCoursePrePo po = new BCoursePrePo();
        BeanUtils.copyProperties(dto,po);
		bCoursePreMapper.updateById(po);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public void delete(String id){
		bCoursePreMapper.deleteById(id);
    }

    @Override
    public void deleteByCourseId(String courseId) {
        QueryWrapper<BCoursePrePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id",courseId);
        bCoursePreMapper.delete(queryWrapper);
    }
}
