package bus.service.impl;

import bus.model.dto.BCourseTimeDto;
import bus.model.dto.page.BCourseTimePageDto;
import bus.model.vo.BCourseTimeVo;
import bus.model.po.BCourseTimePo;
import bus.mapper.BCourseTimeMapper;

import bus.service.BCourseTimeService;
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-02 19:55:46
 **/
@Service
public class BCourseTimeServiceImpl extends ServiceImpl<BCourseTimeMapper, BCourseTimePo> implements BCourseTimeService {

    @Autowired
    private BCourseTimeMapper bCourseTimeMapper;


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

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

    /**
    * 列表
    * @param dto
    * @return
    */
    @Override
    public List<BCourseTimeVo> list(BCourseTimePageDto dto){
        return this.bCourseTimeMapper.list(dto);
    }

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

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

    /**
     * 根据线路id删除
     *
     * @param courseId
     */
    @Override
    public void deleteByCourseId(String courseId) {
        QueryWrapper<BCourseTimePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id", courseId);
        bCourseTimeMapper.delete(queryWrapper);
    }
}
