package com.ruoyi.school.course.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.school.course.domain.req.time.ReqClaTimeCount;
import com.ruoyi.school.course.mapper.ScClaTimeMapper;
import com.ruoyi.school.course.domain.ScClaTime;
import com.ruoyi.school.course.service.IScClaTimeService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 排课信息 服务实现类
 * </p>
 *
 * @author zhangby
 * @since 2020-09-16
 */
@Service
public class ScClaTimeServiceImpl extends ServiceImpl<ScClaTimeMapper, ScClaTime> implements IScClaTimeService {

    @Override
    public boolean deleteUnBeginTime(Long ruleId, String tenantId) {
        UpdateWrapper uw = new UpdateWrapper();
        uw.eq("rule_id", ruleId);
        uw.in("status", "1");
        return this.remove(uw);
    }

    @Override
    public Integer claTimeCount(ReqClaTimeCount reqClaTimeCount) {
        return baseMapper.selectClaTimeCount(reqClaTimeCount);
    }

    public Integer selectBookCount( Long ruleId,  String courseTimeId){
        return baseMapper.selectBookCount(ruleId,courseTimeId, SecurityUtils.getLoginUser().getNowTenantId());
    }

    // 检查教师冲突
    public boolean checkTeacherConflict(Long teacherId, String date, String startTime, String endTime, String excludeScheduleId) {
        // 查询该教师在同一天内，时间段重叠的排期
        int i= baseMapper.checkTeacherConflict(teacherId, date, startTime, endTime, excludeScheduleId);
        if(i>0){
            return true;
        }
        return false;
    }

    // 检查教室冲突
    public boolean checkClassroomConflict(Long classroomId, String date, String startTime, String endTime, String excludeScheduleId) {
        // 查询该教室在同一天内，时间段重叠的排期
        int i= baseMapper.checkClassroomConflict(classroomId, date, startTime, endTime, excludeScheduleId);
        if(i>0){
            return true;
        }
        return false;
    }
}
