package bus.service.impl;

import bus.model.dto.BCourseStationDto;
import bus.model.dto.page.BCourseStationPageDto;
import bus.model.vo.BCourseStationVo;
import bus.model.po.BCourseStationPo;
import bus.mapper.BCourseStationMapper;

import bus.service.BCourseStationService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
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 javax.management.Query;
import java.util.List;

/**
 * @Program: bus
 * @Description: 描述
 * @Author: zy
 * @Date: 2025-03-02 19:54:59
 **/
@Service
public class BCourseStationServiceImpl extends ServiceImpl<BCourseStationMapper, BCourseStationPo> implements BCourseStationService {

    @Autowired
    private BCourseStationMapper bCourseStationMapper;


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

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

    /**
    * 列表
    * @param dto
    * @return
    */
    @Override
    public List<BCourseStationVo> list(BCourseStationPageDto dto){
        return this.bCourseStationMapper.list(dto);
    }

	/**
     * 修改
     * @param dto
     * @return
     */
    @Override
    public void update(BCourseStationDto dto){
        BCourseStationPo po = new BCourseStationPo();
        BeanUtils.copyProperties(dto,po);
		bCourseStationMapper.updateById(po);
    }
    @Override
    public List<BCourseStationPo> getListByCourse(String courseId) {

        QueryWrapper<BCourseStationPo> query = new QueryWrapper();
            query.eq("course_id", courseId);
            query.orderByAsc("sort");
        List<BCourseStationPo> list = this.bCourseStationMapper.selectList(query);
        return list;
    }

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

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