package com.ruoyi.liandao.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.query.LambdaQueryWrapperX;
import com.ruoyi.liandao.domain.TourGuideAppointment;
import com.ruoyi.liandao.domain.TourGuideInfo;
import com.ruoyi.liandao.dto.tourGuide.TourGuideAppointmentAddReqDto;
import com.ruoyi.liandao.dto.tourGuide.TourGuidePageReqDto;
import com.ruoyi.liandao.mapper.TourGuideAppointmentMapper;
import com.ruoyi.liandao.service.TourGuideAppointmentService;
import com.ruoyi.liandao.service.TourGuideInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author admin
 * @description 针对表【ld_tour_guide_appointment(导游预约)】的数据库操作Service实现
 * @createDate 2024-03-14 10:51:09
 */
@Service
@DataSource(DataSourceType.MASTER)
public class TourGuideAppointmentServiceImpl extends ServiceImpl<TourGuideAppointmentMapper, TourGuideAppointment>
        implements TourGuideAppointmentService {

    @Autowired
    private TourGuideInfoService infoService;

    @Override
    public IPage<TourGuideAppointment> getPage(TourGuidePageReqDto dto) {
        return page((IPage<TourGuideAppointment>) dto.getPage(), new LambdaQueryWrapperX<TourGuideAppointment>()
                .likeIfPresent(TourGuideAppointment::getTourGuideName, dto.getName())
                .orderByDesc(TourGuideAppointment::getUpdateTime));
    }

    @Override
    public void add(TourGuideAppointmentAddReqDto dto) {
        TourGuideAppointment tourGuideAppointment = Convert.convert(TourGuideAppointment.class, dto);
        TourGuideInfo tourGuideInfo = infoService.getById(dto.getTourGuideId());
        tourGuideAppointment.setTourGuideName(tourGuideInfo.getName());
        save(tourGuideAppointment);
    }
}




