package jnpf.attendance.service.handle.rule;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import jnpf.attendance.service.RuleProcessor;
import jnpf.constants.AttendanceConstant;
import jnpf.entity.attendance.FtbAttendanceDailyRule;
import jnpf.enums.attendance.AttendanceTypeEnum;
import jnpf.enums.attendance.LeaveUnitEnum;
import jnpf.enums.attendance.v2.WorkBoundaryCoverageEnum;
import jnpf.model.attendance.vo.DailyRuleResultVo;
import jnpf.util.DateDetail;
import jnpf.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 处理历史加班申请
 */
@Component
@Slf4j
public class WorkOvertimeRuleProcessor extends RuleProcessor {
    @Override
    public void ruleArrangementHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> currDailyRule, List<DailyRuleResultVo> resultList) {
        Map<Integer, List<FtbAttendanceDailyRule>> collect = hisDailyRules.stream().collect(Collectors.groupingBy(FtbAttendanceDailyRule::getAttendanceType));
        List<FtbAttendanceDailyRule> ftbAttendanceDailyRules = collect.getOrDefault(AttendanceTypeEnum.WORKOVERTIME.getCode(), List.of()).stream().filter(rule -> Objects.isNull(rule.getIsInsert()) || !rule.getIsInsert()).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(ftbAttendanceDailyRules)) {
            if (currDailyRule.stream().allMatch(rule -> Objects.equals(AttendanceTypeEnum.ORDINARY.getCode(), rule.getAttendanceType())
                    || Objects.equals(AttendanceTypeEnum.CLEAR.getCode(), rule.getAttendanceType()))) {
                ftbAttendanceDailyRules.forEach(oldRule -> {
                    oldRule.setOutUnbounded(0);
                    oldRule.setInUnbounded(0);
                    oldRule.setApplyViewEnable(1);
                });
            }

            Iterator<FtbAttendanceDailyRule> iterator = currDailyRule.iterator();
            Boolean isRecover = Boolean.TRUE;

            while (iterator.hasNext()) {
                FtbAttendanceDailyRule rule = iterator.next();
                //新增清除
                if (clearHandle(hisDailyRules, ftbAttendanceDailyRules, rule, resultList)) {
                    continue;
                }
                //新增排休
                if (restHandle(hisDailyRules, ftbAttendanceDailyRules, rule, resultList)) {
                    continue;
                }
                //新增上班
                if (ordinaryHandle(hisDailyRules, ftbAttendanceDailyRules, rule, resultList, isRecover)) {
                    isRecover = Boolean.FALSE;
                    continue;
                }
                //新增加班
                if (workOvertimeHandle(hisDailyRules, ftbAttendanceDailyRules, rule, resultList)) {
                    continue;
                }
                //新增请假
                if (leaveHandle(hisDailyRules, ftbAttendanceDailyRules, rule, resultList)) {
                    continue;
                }
                //新增外出、出差
                if (stepOutHandle(hisDailyRules, ftbAttendanceDailyRules, rule, resultList)) {
                    continue;
                }
            }
        }
        if (Objects.nonNull(nextRuleProcessor)) {
            nextRuleProcessor.ruleArrangementHandle(hisDailyRules, currDailyRule, resultList);
        }
    }

    /**
     * 新增清除
     *
     * @param hisDailyRules           历史规则
     * @param ftbAttendanceDailyRules 新增规则集合
     * @param rule                    当前规则
     */
    private Boolean clearHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> ftbAttendanceDailyRules, FtbAttendanceDailyRule rule, List<DailyRuleResultVo> resultList) {
        //新增清除
        if (!Objects.equals(AttendanceTypeEnum.CLEAR.getCode(), rule.getAttendanceType())) {
            return Boolean.FALSE;
        }
        recoverHandle(hisDailyRules, ftbAttendanceDailyRules);
        return Boolean.TRUE;
    }

    /**
     * 恢复原加班
     *
     * @param hisDailyRules           历史规则
     * @param ftbAttendanceDailyRules 新增规则集合
     */
    private void recoverHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> ftbAttendanceDailyRules) {
        //恢复原加班
        hisDailyRules.removeAll(hisDailyRules.stream().filter(rule -> !rule.getIsInsert() && Objects.equals(rule.getAttendanceType(), AttendanceTypeEnum.ORDINARY.getCode())).collect(Collectors.toList()));
        Map<String, List<FtbAttendanceDailyRule>> collect = ftbAttendanceDailyRules.stream().collect(Collectors.groupingBy(FtbAttendanceDailyRule::getApplyId));
        collect.forEach((k, rules) -> {
            FtbAttendanceDailyRule ftbAttendanceDailyRule = rules.stream().sorted(Comparator.comparing(FtbAttendanceDailyRule::getInPoint)).findFirst().orElse(null);
            ftbAttendanceDailyRule.setInPoint(ftbAttendanceDailyRule.getApplyStart());
            ftbAttendanceDailyRule.setOutPoint(ftbAttendanceDailyRule.getApplyEnd());
            hisDailyRules.removeAll(rules);
            hisDailyRules.add(ftbAttendanceDailyRule);
        });
    }

    /**
     * 新增外出、出差申请
     *
     * @param hisDailyRules           历史规则
     * @param ftbAttendanceDailyRules 新增规则集合
     * @param rule                    当前规则
     */
    private Boolean stepOutHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> ftbAttendanceDailyRules, FtbAttendanceDailyRule rule, List<DailyRuleResultVo> resultList) {
        //新增请假
        if (!Objects.equals(AttendanceTypeEnum.BUSINESS_TRIP.getCode(), rule.getAttendanceType()) && !Objects.equals(AttendanceTypeEnum.STEP_OUT.getCode(), rule.getAttendanceType())) {
            return Boolean.FALSE;
        }
        ftbAttendanceDailyRules.forEach(oldRule -> {
            //过滤隐藏规则
            if (Objects.equals(oldRule.getApplyViewEnable(), 0)) {
                return;
            }
            //新加入数据不做处理
            if (oldRule.getIsInsert()) {
                return;
            }
            rule.setShiftId(oldRule.getShiftId());
            rule.setPeriodId(oldRule.getPeriodId());
            rule.setApplyViewEnable(0);
            //原小时外出没命中已有班次数据，隐藏外出申请
            if (rule.getOutPoint().before(oldRule.getInPoint())
                    || rule.getInPoint().after(oldRule.getOutPoint())
                    || rule.getInPoint().after(oldRule.getInPoint()) && rule.getOutPoint().before(oldRule.getOutPoint())) {
                if (!rule.getIsInsert()) {
                    if (!hisDailyRules.contains(rule)) {
                        hisDailyRules.add(rule);
                    }
                }
                log.error("新增排班数据未命中小时外出申请或者外出数据完全被排班数据覆盖，过滤{}", JSON.toJSONString(rule));
                return;
            }
            rule.insertTrue();
            if (!hisDailyRules.contains(rule)) {
                hisDailyRules.add(rule);
            }
            rule.setApplyViewEnable(0);
            oldRule.setApplyViewEnable(rule.getAttendanceType());
            //原小时外出数据覆盖现在新增排班数据上班时间
            if (!rule.getInPoint().after(oldRule.getInPoint())) {
                oldRule.setInStepOutType(1);
                oldRule.setInStepOutApplyId(rule.getApplyId());
            }
            //原小时外出数据覆盖现在新增排班数据下班时间
            if (!rule.getOutPoint().before(oldRule.getOutPoint())) {
                oldRule.setOutStepOutType(1);
                oldRule.setOutStepOutApplyId(rule.getApplyId());
            }
            log.error("新增外出、出差申请标记原加班时段{}", JSON.toJSONString(rule));
            resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
        });
        return Boolean.TRUE;
    }

    /**
     * 新增请假
     *
     * @param hisDailyRules           历史规则
     * @param ftbAttendanceDailyRules 新增规则集合
     * @param rule                    当前规则
     */
    private Boolean leaveHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> ftbAttendanceDailyRules, FtbAttendanceDailyRule rule, List<DailyRuleResultVo> resultList) {
        //新增请假
        if (!Objects.equals(AttendanceTypeEnum.LEAVE.getCode(), rule.getAttendanceType())) {
            return Boolean.FALSE;
        }
        //全天假与加班冲突
        if (Objects.equals(rule.getApplyUnit(), LeaveUnitEnum.DAY.getCode())) {
            log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
            FtbAttendanceDailyRule oldRule = ftbAttendanceDailyRules.stream().findFirst().orElse(null);
            resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
            return Boolean.TRUE;
        }
        ftbAttendanceDailyRules.forEach(oldRule -> {
            //新加入数据不做处理
            if (oldRule.getIsInsert()) {
                return;
            }
            rule.setSelfGroup(oldRule.getSelfGroup());
            //完全覆盖
            //原来加班时段完全覆盖请假时间
            if (DateDetail.checkBetween(rule.getApplyStart(), oldRule.getInPoint(), oldRule.getOutPoint())
                    && DateDetail.checkBetween(rule.getApplyEnd(), oldRule.getInPoint(), oldRule.getOutPoint())
                    || (rule.getApplyStart().compareTo(oldRule.getInPoint()) == 0 && rule.getApplyEnd().compareTo(oldRule.getOutPoint()) == 0)) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }
            //部分覆盖
            //开始部分覆盖
            if (DateDetail.checkBetween(rule.getApplyEnd(), oldRule.getInPoint(), oldRule.getOutPoint())) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }
            //结束部分覆盖
            if (DateDetail.checkBetween(rule.getApplyStart(), oldRule.getInPoint(), oldRule.getOutPoint())) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }
            //请假完全覆盖加班
            if (DateDetail.checkTimeBetweenL(oldRule.getApplyStart(), rule.getInPoint(), rule.getOutPoint())
                    && DateDetail.checkTimeBetweenR(oldRule.getApplyEnd(), rule.getInPoint(), rule.getOutPoint())) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }
            rule.insertTrue();
            //完全没交集
            if (!hisDailyRules.contains(rule)) {
                hisDailyRules.add(rule);
            }
            log.error("请假时间完全与原来加班时段完全没交集{}", JSON.toJSONString(rule));
        });
        return Boolean.TRUE;
    }

    /**
     * 新增加班
     *
     * @param hisDailyRules           历史规则
     * @param ftbAttendanceDailyRules 新增规则集合
     * @param rule                    当前规则
     */
    private Boolean workOvertimeHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> ftbAttendanceDailyRules, FtbAttendanceDailyRule rule, List<DailyRuleResultVo> resultList) {
        //新增加班
        if (!Objects.equals(AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType())) {
            return Boolean.FALSE;
        }
        ftbAttendanceDailyRules.forEach(oldRule -> {
            //新加入数据不做处理
            if (oldRule.getIsInsert()) {
                return;
            }
            rule.setSelfGroup(oldRule.getSelfGroup());
            //新增加班时间完全覆盖原来加班时段
            if (DateDetail.checkTimeBetween(oldRule.getApplyStart(), rule.getInPoint(), rule.getOutPoint())
                    && DateDetail.checkTimeBetween(oldRule.getApplyEnd(), rule.getInPoint(), rule.getOutPoint())) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }

            //部分覆盖
            //开始部分覆盖
            if (DateDetail.checkBetween(rule.getApplyEnd(), oldRule.getInPoint(), oldRule.getOutPoint())) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }
            //结束部分覆盖
            if (DateDetail.checkBetween(rule.getApplyStart(), oldRule.getInPoint(), oldRule.getOutPoint())) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }
            //新增加班时段处于原加班时段中间
            if (DateDetail.checkTimeBetweenL(rule.getApplyStart(), oldRule.getInPoint(), oldRule.getOutPoint())
                    && DateDetail.checkTimeBetweenR(rule.getApplyEnd(), oldRule.getInPoint(), oldRule.getOutPoint())) {
                log.error(AttendanceConstant.getApplyResult(rule.getUserId(), AttendanceConstant.WORKOVERTIME));
                resultList.add(DailyRuleResultVo.failBuild(oldRule, rule, AttendanceTypeEnum.WORKOVERTIME.getCode(), rule.getAttendanceType()));
                return;
            }
            //加班与普班时间边界连接
            //加班开始时间与上班时段结束时间相同
            if (oldRule.getInPoint().compareTo(rule.getOutPoint()) == 0) {
                oldRule.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
            }
            //加班结束时间与上班时段开始时间相同
            if (oldRule.getOutPoint().compareTo(rule.getInPoint()) == 0) {
                oldRule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
            }
            //完全没交集
            rule.insertTrue();
            if (!hisDailyRules.contains(rule)) {
                hisDailyRules.add(rule);
            }
            log.error("新增加班时段与原加班时段没交集{}", JSON.toJSONString(rule));
            resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
        });
        return Boolean.TRUE;
    }

    /**
     * 新增上班
     *
     * @param hisDailyRules           历史规则
     * @param ftbAttendanceDailyRules 新增规则集合
     * @param rule                    当前规则
     */
    private Boolean ordinaryHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> ftbAttendanceDailyRules, FtbAttendanceDailyRule rule, List<DailyRuleResultVo> resultList, Boolean isRecover) {
        if (!Objects.equals(AttendanceTypeEnum.ORDINARY.getCode(), rule.getAttendanceType())) {
            return Boolean.FALSE;
        }
        if (isRecover) {
            recoverHandle(hisDailyRules, ftbAttendanceDailyRules);
        }
        //新增上班
        ftbAttendanceDailyRules = hisDailyRules.stream().filter(rule1 -> Objects.equals(rule1.getAttendanceType(), AttendanceTypeEnum.WORKOVERTIME.getCode())).collect(Collectors.toList());
        ftbAttendanceDailyRules.forEach(oldRule -> {
            //新加入数据不做处理
            if (oldRule.getIsInsert()) {
                return;
            }
            //原加班时段处于新增上班时段中间
            if (DateDetail.checkTimeBetween(oldRule.getInPoint(), rule.getInPoint(), rule.getOutPoint())
                    && DateDetail.checkTimeBetween(oldRule.getOutPoint(), rule.getInPoint(), rule.getOutPoint())) {
                oldRule.setApplyViewEnable(0);
                oldRule.setShiftId(rule.getShiftId());
                oldRule.setPeriodId(rule.getPeriodId());
                rule.insertTrue();
                if (!hisDailyRules.contains(rule)) {
                    hisDailyRules.add(rule);
                }
                log.error("新增上班时段完全覆盖原来加班时段{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            //部分覆盖
            //开始部分覆盖
            if (DateDetail.checkBetween(rule.getOutPoint(), oldRule.getInPoint(), oldRule.getOutPoint())
                    && rule.getInPoint().compareTo(oldRule.getApplyStart()) <= 0) {
                oldRule.setInPoint(rule.getOutPoint());
                oldRule.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                oldRule.setShiftId(rule.getShiftId());
                oldRule.setPeriodId(rule.getPeriodId());
                oldRule.setApplyViewEnable(1);
                rule.insertTrue();
                if (!hisDailyRules.contains(rule)) {
                    hisDailyRules.add(rule);
                }
                log.error("新增上班时段开始部分覆盖原来加班时段{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            //结束部分覆盖
            if (DateDetail.checkBetween(rule.getInPoint(), oldRule.getInPoint(), oldRule.getOutPoint())
                    && rule.getOutPoint().compareTo(oldRule.getApplyEnd()) >= 0) {
                oldRule.setOutPoint(rule.getInPoint());
                oldRule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                oldRule.setShiftId(rule.getShiftId());
                oldRule.setPeriodId(rule.getPeriodId());
                rule.insertTrue();
                if (!hisDailyRules.contains(rule)) {
                    hisDailyRules.add(rule);
                }
                log.error("新增上班时段结束部分覆盖原来加班时段{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            //原来加班时段完全覆盖新增上班时间
            if (DateDetail.checkTimeBetween(rule.getInPoint(), oldRule.getInPoint(), oldRule.getOutPoint())
                    && DateDetail.checkTimeBetween(rule.getOutPoint(), oldRule.getInPoint(), oldRule.getOutPoint())) {
                oldRule.setShiftId(rule.getShiftId());
                oldRule.setPeriodId(rule.getPeriodId());
                FtbAttendanceDailyRule oldRule1 = BeanUtil.toBean(oldRule, FtbAttendanceDailyRule.class);
                oldRule.setOutPoint(rule.getInPoint());
                oldRule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                oldRule1.setInPoint(rule.getOutPoint());
                oldRule1.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                oldRule1.setId(RandomUtil.uuId());
                oldRule1.setApplyViewEnable(1);
                rule.insertTrue();
                if (!hisDailyRules.contains(rule)) {
                    hisDailyRules.add(rule);
                }
                hisDailyRules.add(oldRule1);
                log.error("新增上班时间处于原来加班时段中间{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            //加班与普班时间边界连接
            //加班开始时间与上班时段结束时间相同
            if (oldRule.getInPoint().compareTo(rule.getOutPoint()) == 0) {
                oldRule.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
            }
            //加班结束时间与上班时段开始时间相同
            if (oldRule.getOutPoint().compareTo(rule.getInPoint()) == 0) {
                oldRule.setOutUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
                rule.setInUnbounded(WorkBoundaryCoverageEnum.OVERTIME_COVERED.getCode());
            }
            //完全没交集
            rule.insertTrue();
            if (!hisDailyRules.contains(rule)) {
                hisDailyRules.add(rule);
            }
            log.error("新增上班时段与原加班时段没交集{}", JSON.toJSONString(rule));
            resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
        });
        return Boolean.TRUE;
    }

    /**
     * 新增排休
     *
     * @param hisDailyRules           历史规则
     * @param ftbAttendanceDailyRules 新增规则集合
     * @param rule                    当前规则
     */
    private Boolean restHandle(List<FtbAttendanceDailyRule> hisDailyRules, List<FtbAttendanceDailyRule> ftbAttendanceDailyRules, FtbAttendanceDailyRule rule, List<DailyRuleResultVo> resultList) {
        //新增排休
        if (!Objects.equals(AttendanceTypeEnum.REST.getCode(), rule.getAttendanceType())
                && !Objects.equals(AttendanceTypeEnum.HOLIDAYS.getCode(), rule.getAttendanceType())
                && !Objects.equals(AttendanceTypeEnum.DEDUCTION_HOLIDAYS.getCode(), rule.getAttendanceType())
                && !Objects.equals(AttendanceTypeEnum.EXCHANGE_HOLIDAYS.getCode(), rule.getAttendanceType())) {
            return Boolean.FALSE;
        }
        recoverHandle(hisDailyRules, ftbAttendanceDailyRules);
        //休不存在打卡时间默认为当天最早、最后时间
        rule.setInPoint(Objects.isNull(rule.getInPoint()) ? DateUtil.beginOfDay(rule.getDay()) : rule.getInPoint());
        rule.setOutPoint(Objects.isNull(rule.getOutPoint()) ? DateUtil.endOfDay(rule.getDay()) : rule.getOutPoint());
        rule.insertTrue();
        if (!hisDailyRules.contains(rule)) {
            hisDailyRules.add(rule);
        }
        ftbAttendanceDailyRules.forEach(oldRule -> {
            //原加班时段处于休息时段中间
            if (DateDetail.checkTimeBetween(oldRule.getApplyStart(), rule.getInPoint(), rule.getOutPoint())
                    && DateDetail.checkTimeBetween(oldRule.getApplyEnd(), rule.getInPoint(), rule.getOutPoint())) {
                oldRule.setInPoint(oldRule.getApplyStart());
                oldRule.setOutPoint(oldRule.getApplyEnd());
                log.error("新增休完全覆盖原来加班时段{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            //部分覆盖
            //开始部分覆盖
            if (DateDetail.checkTimeBetween(rule.getOutPoint(), oldRule.getApplyStart(), oldRule.getApplyEnd())
                    && rule.getInPoint().compareTo(oldRule.getApplyStart()) <= 0) {
                oldRule.setInPoint(oldRule.getApplyStart());
                oldRule.setApplyViewEnable(1);
                log.error("新增休开始部分覆盖原来加班时段{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            //结束部分覆盖
            if (DateDetail.checkTimeBetween(rule.getInPoint(), oldRule.getApplyStart(), oldRule.getApplyEnd())
                    && rule.getOutPoint().compareTo(oldRule.getApplyEnd()) >= 0) {
                oldRule.setOutPoint(oldRule.getApplyEnd());
                log.error("新增休结束部分覆盖原来加班时段{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            //原来加班时段完全覆盖休时间
            if (DateDetail.checkTimeBetween(rule.getInPoint(), oldRule.getApplyStart(), oldRule.getApplyEnd())
                    && DateDetail.checkTimeBetween(rule.getOutPoint(), oldRule.getApplyStart(), oldRule.getApplyEnd())) {
                log.error("原来加班时段完全覆盖新增休时间{}", JSON.toJSONString(rule));
                resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
                return;
            }
            oldRule.setShiftId(rule.getShiftId());
            oldRule.setPeriodId(rule.getPeriodId());
            //完全没交集
            log.error("新增休与原加班时段没交集{}", JSON.toJSONString(rule));
            resultList.add(DailyRuleResultVo.successBuild(oldRule, rule));
        });
        log.error("新增排休与原加班时段,过滤新增排休{}", JSON.toJSONString(rule));
        return Boolean.TRUE;
    }


}
