package com.jwipc.order.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.order.entity.AppointmentDayOff;
import com.jwipc.order.mapper.AppointmentDayOffMapper;
import com.jwipc.order.model.query.AppointmentDayOffQuery;
import com.jwipc.order.service.IAppointmentDayOffService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 预约到货法定节假日配置表 服务实现类
 * </p>
 *
 * @author WT
 * @since 2024-03-06
 */
@Service
public class AppointmentDayOffServiceImpl extends ServiceImpl<AppointmentDayOffMapper, AppointmentDayOff> implements IAppointmentDayOffService {

    @Override
    public List<AppointmentDayOff> selectListByPage(Page<AppointmentDayOff> dbPage, AppointmentDayOffQuery query) {
        if(dbPage == null){
            return baseMapper.selectListByPage(query);
        }
        return baseMapper.selectListByPage(dbPage,query);
    }

    @Override
    public void checkDay(String selectDay) throws Exception {
        List<AppointmentDayOff> day = this.list(new LambdaQueryWrapper<AppointmentDayOff>()
                .eq(AppointmentDayOff::getDay, selectDay));
        if (CollectionUtil.isNotEmpty(day)) {
            throw new Exception(selectDay + "休息，请重新选择");
        }
    }
}
