package bus.service.impl;

import bus.model.dto.BCourseBusDto;
import bus.model.dto.page.BCourseBusPageDto;
import bus.model.vo.BCourseBusVo;
import bus.model.po.BCourseBusPo;
import bus.mapper.BCourseBusMapper;

import bus.service.BCourseBusService;
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:56:32
 **/
@Service
public class BCourseBusServiceImpl extends ServiceImpl<BCourseBusMapper, BCourseBusPo> implements BCourseBusService {

    @Autowired
    private BCourseBusMapper bCourseBusMapper;


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

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

    /**
    * 列表
    * @param dto
    * @return
    */
    @Override
    public List<BCourseBusVo> list(BCourseBusPageDto dto){
        return this.bCourseBusMapper.list(dto);
    }

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

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

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