package cn.iocoder.yudao.module.system.service.attendance.fixed;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.Constants;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.attendance.dto.AttendanceTimeRangeInfoDTO;
import cn.iocoder.yudao.module.system.api.attendance.vo.AttendanceGroupShiftItemVO;
import cn.iocoder.yudao.module.system.api.attendance.vo.AttendanceTimeRangeInfoVO;
import cn.iocoder.yudao.module.system.controller.admin.attendance.dto.AttendancePunchPageDTO;
import cn.iocoder.yudao.module.system.controller.admin.attendance.vo.AttendancePunchPageVO;
import cn.iocoder.yudao.module.system.controller.admin.attendance.vo.AttendanceRulesVO;
import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedRespVO;
import cn.iocoder.yudao.module.system.controller.admin.fixed.vo.AttendanceFixedSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.groupshift.vo.AttendanceGroupShiftVO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.attendancespecial.AttendanceSpecialDO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.fixed.AttendanceFixedDO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.group.AttendanceGroupDO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.groupshiftitem.AttendanceGroupShiftItemDO;
import cn.iocoder.yudao.module.system.dal.mysql.attendance.fixed.AttendanceFixedMapper;
import cn.iocoder.yudao.module.system.service.attendance.AttendanceService;
import cn.iocoder.yudao.module.system.service.attendance.attendancespecial.AttendanceSpecialService;
import cn.iocoder.yudao.module.system.service.attendance.groupshift.AttendanceGroupShiftService;
import cn.iocoder.yudao.module.system.service.attendance.groupshiftitem.AttendanceGroupShiftItemService;
import cn.iocoder.yudao.module.system.service.attendance.punch.PunchService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.FIXED_NOT_EXISTS;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.THERE_ARE_DUPLICATE_SPECIAL_DATES;

/**
 * 固定班制考勤设置 Service 实现类
 *
 * @author 艾楷
 */
@Service("fixed")
@Validated
@Slf4j
public class AttendanceFixedServiceImpl implements AttendanceFixedService, PunchService {
    @Resource
    private AttendanceFixedMapper attendanceFixedMapper;
    @Resource
    @Lazy // 避免依赖循环
    private AttendanceService attendanceService;
    @Resource
    private AttendanceGroupShiftService attendanceGroupShiftService;
    @Resource
    private AttendanceGroupShiftItemService attendanceGroupShiftItemService;
    @Resource
    private AttendanceSpecialService attendanceSpecialService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long batchCreateOrUpdate(Long attendanceGroupId, List<AttendanceFixedSaveReqVO> vos, List<AttendanceSpecialDO> specialDOS) {
        Long groupId = null;
        // 插入
        List<AttendanceFixedDO> oldList = attendanceFixedMapper.selectList(new LambdaQueryWrapper<AttendanceFixedDO>()
                .eq(AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId));
        List<AttendanceFixedDO> fixedList = BeanUtils.toBean(vos, AttendanceFixedDO.class);
        // -- 如果旧的没数据 则直接新增
        if (oldList.isEmpty()) {
            groupId = attendanceGroupId;
            attendanceFixedMapper.insertBatch(fixedList);
        } else {
            //如果旧的有数据则区分下
            // 插入
            List<AttendanceFixedDO> saveList = fixedList.stream().filter(a -> a.getId() == null).collect(Collectors.toList());
            List<AttendanceFixedDO> editList = fixedList.stream().filter(a -> a.getId() != null).collect(Collectors.toList());
            if (!saveList.isEmpty()) {
                groupId = attendanceGroupId;
                attendanceFixedMapper.insertBatch(saveList);
            }
            LocalDateTime now = LocalDateTime.now();
            int week = now.getDayOfWeek().getValue();
            if (!editList.isEmpty()) {
                Map<Integer, AttendanceFixedDO> map = oldList.stream().collect(Collectors.toMap(AttendanceFixedDO::getWeekTime, a -> a));
                for (AttendanceFixedDO attendanceFixedDO : editList) {
                    AttendanceFixedDO item = map.get(attendanceFixedDO.getWeekTime());
                    boolean eqFlag = BeanUtil.isCommonFieldsEqual(attendanceFixedDO, item, "createTime", "updateTime", "creator", "updater", "deleted");
                    // -- 判断当天是周几是否和当前修改的时间为同一天 如果是的话则判断则提示立即生效
                    if (!eqFlag && week == attendanceFixedDO.getWeekTime()) {
                        groupId = attendanceGroupId;
                        break;
                    }
                }
                attendanceFixedMapper.updateBatch(editList);
            }
            // -- 需要删除的 -
            List<Long> oldIds = oldList.stream().map(AttendanceFixedDO::getId).collect(Collectors.toList());
            List<Long> newIds = editList.stream().map(AttendanceFixedDO::getId).collect(Collectors.toList());
            List<Long> delIds = CollectionUtil.subtractToList(oldIds, newIds);
            if (!delIds.isEmpty()) {
                groupId = attendanceGroupId;
                attendanceFixedMapper.deleteBatchIds(delIds);
            }
        }
        // - - - - - - - - -   特殊考勤日期 - - - - - - - -
        if (CollUtil.isEmpty(specialDOS)) {
            specialDOS = Collections.emptyList();
        }
        // -- 验证是否有同一天的数据 如果有则返回提醒
        Map<String, List<AttendanceSpecialDO>> map = specialDOS.stream().collect(Collectors.groupingBy(AttendanceSpecialDO::getDateTime));
        for (Map.Entry<String, List<AttendanceSpecialDO>> entry : map.entrySet()) {
            if (entry.getValue().size() > 1) {
                throw exception(THERE_ARE_DUPLICATE_SPECIAL_DATES);
            }
        }
        //查询旧的
        List<AttendanceSpecialDO> oldAttendanceSpecialDOS = attendanceSpecialService.getByGroupId(attendanceGroupId);
        List<List<AttendanceSpecialDO>> attendanceSpecialList = CollectionUtils.diffList(oldAttendanceSpecialDOS, specialDOS,
                (saveVal, newVal) -> ObjectUtil.equal(saveVal.getId(), newVal.getId()));
        attendanceSpecialService.insertUpdateDeleteBatch(attendanceGroupId, attendanceSpecialList);
        return groupId;
    }

    @Override
    public void updateFixed(AttendanceFixedSaveReqVO updateReqVO) {
        // 校验存在
        validateFixedExists(updateReqVO.getId());
        // 更新
        AttendanceFixedDO updateObj = BeanUtils.toBean(updateReqVO, AttendanceFixedDO.class);
        attendanceFixedMapper.updateById(updateObj);
    }

    @Override
    public void deleteFixed(Long id) {
        // 校验存在
        validateFixedExists(id);
        // 删除
        attendanceFixedMapper.deleteById(id);
    }

    private void validateFixedExists(Long id) {
        if (attendanceFixedMapper.selectById(id) == null) {
            throw exception(FIXED_NOT_EXISTS);
        }
    }

    @Override
    public AttendanceFixedDO getFixed(Long id) {
        return attendanceFixedMapper.selectById(id);
    }

    @Override
    public PageResult<AttendanceFixedDO> getFixedPage(AttendanceFixedPageReqVO pageReqVO) {
        return attendanceFixedMapper.selectPage(pageReqVO);
    }

    @Override
    public AttendanceFixedDO getByGroupIdAndWeek(Long attendanceGroupId, Integer week) {
        List<AttendanceFixedDO> list = attendanceFixedMapper.selectList(new LambdaQueryWrapper<AttendanceFixedDO>()
                .eq(attendanceGroupId != null, AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId)
                .eq(week != null, AttendanceFixedDO::getWeekTime, week));
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<AttendanceFixedDO> getByGroupIdAndWeeks(Long attendanceGroupId, List<Integer> weeks) {
        return attendanceFixedMapper.selectList(new LambdaQueryWrapper<AttendanceFixedDO>()
                .eq(attendanceGroupId != null, AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId)
                .in(CollUtil.isNotEmpty(weeks), AttendanceFixedDO::getWeekTime, weeks));
    }

    @Override
    public List<AttendanceFixedDO> getByGroupId(Long attendanceGroupId) {
        return attendanceFixedMapper.selectList(new LambdaQueryWrapper<AttendanceFixedDO>()
                .eq(attendanceGroupId != null, AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId));
    }

    @Override
    public List<AttendanceFixedDO> getByGroupIdAndWeek(List<Long> attendanceGroupIds, Integer week) {
        return attendanceFixedMapper.selectList(new LambdaQueryWrapper<AttendanceFixedDO>()
                .in(CollectionUtil.isNotEmpty(attendanceGroupIds), AttendanceFixedDO::getAttendanceGroupId, attendanceGroupIds)
                .eq(week != null, AttendanceFixedDO::getWeekTime, week));
    }

    @Override
    public Map<Long, Long> getGroupToShiftIdMap(List<AttendanceGroupDO> fixedList, LocalDateTime localDateTime) {
        Map<Long, Long> map = new HashMap<>();
        //获取到当天是周几
        int week = localDateTime.getDayOfWeek().getValue();
        List<Long> groupIds = fixedList.stream().map(AttendanceGroupDO::getId).collect(Collectors.toList());
        List<AttendanceFixedDO> attendanceFixedDOS = this.getByGroupIdAndWeek(groupIds, week);
        // - 获取到补班的列表 - 节假日补班班次
        List<AttendanceFixedDO> makeUpClassList = this.getByGroupIdAndWeek(groupIds, 8);
        Map<Long, List<AttendanceFixedDO>> makeUpClassListMap = makeUpClassList.stream().collect(Collectors.groupingBy(AttendanceFixedDO::getAttendanceGroupId));
        Map<Long, List<AttendanceFixedDO>> attendanceFixedMap = attendanceFixedDOS.stream().collect(Collectors.groupingBy(AttendanceFixedDO::getAttendanceGroupId));
        // -- 这里是考勤预设 - 不需要把加班的考勤规则考虑在内 - 需要考虑 必须打卡时间 - 和非必须打卡时间即可
        List<AttendanceSpecialDO> specialDOS = attendanceSpecialService.getByGroupIdsAndTime(groupIds, localDateTime.format(Constants.REPO_DATE_FORMAT));
        Map<String, AttendanceSpecialDO> specialMap = specialDOS.stream().collect(Collectors.toMap(a -> a.getAttendanceGroupId() + "_" + a.getType(), a -> a));
        for (AttendanceGroupDO activationGroup : fixedList) {
            AttendanceSpecialDO mustClockInTime = specialMap.get(activationGroup.getId() + "_" + 1);
            // -- 判断是否有必须打卡时间 - 如果有的话直接摄入进去即可
            if (mustClockInTime != null && mustClockInTime.getAttendanceGroupShiftId() != null) {
                map.put(activationGroup.getId(), mustClockInTime.getAttendanceGroupShiftId());
                continue;
            }

            // -- 判断是否有无需打卡时间 - 如果有的话直接返回 --- 无需打卡 直接返回结果
            AttendanceSpecialDO noNeedToClockIn = specialMap.get(activationGroup.getId() + "_" + 0);
            if (noNeedToClockIn != null) {
                continue;
            }

            // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来
            Boolean isHolidayFlag = Constants.TRUE.equals(activationGroup.getAutoHolidaysFlag()) ?
                    attendanceService.isHoliday(localDateTime) : null;
            // -- 当前是节假日 并且是放假
            if (isHolidayFlag != null && isHolidayFlag) {
                continue;
            }
            AttendanceFixedDO attendanceFixedDO = null;
            List<AttendanceFixedDO> list;
            if (isHolidayFlag != null) {
                list = makeUpClassListMap.get(activationGroup.getId());
            } else {
                list = attendanceFixedMap.get(activationGroup.getId());
            }
            if (CollectionUtil.isNotEmpty(list)) {
                attendanceFixedDO = list.get(0);
            }
            // -- 当前没有班次 - 不需要考勤
            if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) {
                continue;
            }
            map.put(activationGroup.getId(), attendanceFixedDO.getAttendanceGroupShiftId());
        }
        return map;
    }

    @Override
    public List<AttendanceFixedRespVO> getListByGroupId(Long attendanceGroupId) {
        List<AttendanceFixedRespVO> respVOS = new ArrayList<>();
        List<AttendanceFixedDO> fixedDOList = attendanceFixedMapper.selectList(new LambdaQueryWrapper<AttendanceFixedDO>()
                .eq(attendanceGroupId != null, AttendanceFixedDO::getAttendanceGroupId, attendanceGroupId));
        if (!fixedDOList.isEmpty()) {
            respVOS = BeanUtils.toBean(fixedDOList, AttendanceFixedRespVO.class);
            List<Long> attendanceGroupShiftIds = fixedDOList.stream().map(AttendanceFixedDO::getAttendanceGroupShiftId).filter(Objects::nonNull).collect(Collectors.toList());
            if (CollUtil.isEmpty(attendanceGroupShiftIds)) {
                return respVOS;
            }
            List<AttendanceGroupShiftVO> vos = attendanceGroupShiftService.listByShiftIds(attendanceGroupShiftIds);
            Map<Long, AttendanceGroupShiftVO> map = vos.stream().collect(Collectors.toMap(AttendanceGroupShiftVO::getId, a -> a));
            for (AttendanceFixedRespVO respVO : respVOS) {
                respVO.setShiftVO(map.get(respVO.getAttendanceGroupShiftId()));
            }
        }
        return respVOS;
    }

    @Override
    public List<Long> getUseGroupIds(Long shiftId) {
        return attendanceFixedMapper.getUseGroupIds(shiftId);
    }

    @Override
    public AttendancePunchPageVO getPunchPage(AttendancePunchPageDTO dto) {
        AttendancePunchPageVO vo = new AttendancePunchPageVO();
        vo.setActivationGroup(dto.getActivationGroup());
        AttendanceGroupDO activationGroup = dto.getActivationGroup();
        Long attendanceGroupShiftId = null;
        // todo aiKai 获取特殊打卡日期 - 判断是否有存在 - 如果有的话 - 则按照必打卡日期所设置的班次返回 - 如果没有的话再 去 判断其他
        List<AttendanceSpecialDO> specialDOS = attendanceSpecialService.getByGroupIdAndTime(activationGroup.getId(), dto.getLocalDateTime().format(Constants.REPO_DATE_FORMAT));
        Map<Integer, AttendanceSpecialDO> map = specialDOS.stream().collect(Collectors.toMap(AttendanceSpecialDO::getType, a -> a));
        if (map.get(1) != null && map.get(1).getAttendanceGroupShiftId() != null) {
            attendanceGroupShiftId = map.get(1).getAttendanceGroupShiftId();
        } else if (map.get(0) != null) {
            // 当前为 不需要打卡时间 - 判断是否有加班班次 - 如果没有的话 直接跳过
            AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), -1);
            if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) {
                return vo.setTodayNeedAttendance(Constants.FALSE);
            } else {
                vo.setWorkOvertimeFlag(Constants.ONE);
                attendanceGroupShiftId = attendanceFixedDO.getAttendanceGroupShiftId();
            }
        } else {
            // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来
            Boolean isHolidayFlag = Constants.TRUE.equals(activationGroup.getAutoHolidaysFlag()) ?
                    attendanceService.isHoliday(dto.getLocalDateTime()) : null;
            // -- 先判断当前是否是节假日放假的日子 - 如果是的话 设为 -1 查询加班加班班次 如果不是的话 判断当前是否是补班 如果是的话设为8 为补班日 - 最后获取当前是周几（后续判断这个周几是否是有班次 - 没有的话再查询下 -1 是否有加班班次）
            int week = isHolidayFlag != null && isHolidayFlag ? -1 : (isHolidayFlag != null ? 8 : dto.getLocalDateTime().getDayOfWeek().getValue());
            AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), week);
            // -- 当前没有班次 - 不需要考勤
            if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) {
                // -- 再获取一次加班班次 - 判断下是否有加班日 没有的话直接返回
                if (week != -1) {
                    attendanceFixedDO = this.getByGroupIdAndWeek(activationGroup.getId(), -1);
                    if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) {
                        return vo.setTodayNeedAttendance(Constants.FALSE);
                    } else {
                        vo.setWorkOvertimeFlag(Constants.ONE);
                    }
                } else {
                    return vo.setTodayNeedAttendance(Constants.FALSE);
                }
            } else if (week == -1) {
                vo.setWorkOvertimeFlag(Constants.ONE);
            }
            attendanceGroupShiftId = attendanceFixedDO.getAttendanceGroupShiftId();
        }
        vo.setAttendanceGroupShiftId(attendanceGroupShiftId);
        attendanceService.calculatePunch(dto, vo);
        vo.setAttendanceGroupId(activationGroup.getId());
        vo.setUser(dto.getUser());
        return vo;
    }

    @Override
    public List<AttendanceRulesVO.WorkRules> getRule(Long attendanceGroupId) {
        List<AttendanceRulesVO.WorkRules> rules = new ArrayList<>();
        List<AttendanceFixedDO> list = this.getByGroupId(attendanceGroupId);
        List<Long> attendanceGroupShiftIds = list.stream().map(AttendanceFixedDO::getAttendanceGroupShiftId).filter(Objects::nonNull).collect(Collectors.toList());
        if (CollUtil.isEmpty(attendanceGroupShiftIds)) {
            return rules;
        }
        List<AttendanceGroupShiftVO> vos = attendanceGroupShiftService.listByShiftIds(attendanceGroupShiftIds);
        Map<Long, AttendanceGroupShiftVO> map = vos.stream().collect(Collectors.toMap(AttendanceGroupShiftVO::getId, a -> a));
        LocalDateTime now = LocalDateTime.now();
        for (AttendanceFixedDO attendanceFixedDO : list) {
            AttendanceRulesVO.WorkRules workRules = new AttendanceRulesVO.WorkRules();
            String weekday = DateUtils.convertToChineseWeekday(attendanceFixedDO.getWeekTime());
            workRules.setIndexStr(weekday);
            workRules.setFlag(false);
            if (now.getDayOfWeek().getValue() == attendanceFixedDO.getWeekTime()) {
                workRules.setFlag(true);
            }
            if (attendanceFixedDO.getAttendanceGroupShiftId() == null) {
                workRules.setRule("休息");
            } else {
                AttendanceGroupShiftVO attendanceGroupShiftVOS = map.get(attendanceFixedDO.getAttendanceGroupShiftId());
                List<String> itemRule = new ArrayList<>();
                for (AttendanceGroupShiftItemDO attendanceGroupShiftItemDO : attendanceGroupShiftVOS.getAttendanceGroupShiftItemDOList()) {
                    itemRule.add(attendanceGroupShiftItemDO.getBeginTime() + "-" + attendanceGroupShiftItemDO.getEndTime());
                }
                String rule = String.join(",", itemRule);
                workRules.setRule(rule);
            }
            rules.add(workRules);
        }
        return rules;
    }

    @Override
    public Map<String, AttendanceTimeRangeInfoVO> getAttendanceInfoByTimeRange(AttendanceTimeRangeInfoDTO dto) {
        Map<String, AttendanceTimeRangeInfoVO> map = new HashMap<>();
        List<AttendanceSpecialDO> attendanceSpecials = attendanceSpecialService.getByGroupIdAndTimes(dto.getGroupId(), dto.getTimes());
        Map<String, AttendanceSpecialDO> specialDOMap = attendanceSpecials.stream().collect(Collectors.toMap(a -> a.getDateTime() + "_" + a.getType(), a -> a));
        //不在考勤组
        for (String time : dto.getTimes()) {
            AttendanceTimeRangeInfoVO attendanceTimeRangeInfoVO = new AttendanceTimeRangeInfoVO();
            Long attendanceGroupShiftId = null;
            // -- 判断是否有必须打卡时间 - 如果有的话直接摄入进去即可
            AttendanceSpecialDO mustClockInTime = specialDOMap.get(time + "_" + 1);
            // -- 判断是否有无需打卡时间 - 如果有的话直接返回 --- 无需打卡 直接返回结果
            AttendanceSpecialDO noNeedToClockIn = specialDOMap.get(time + "_" + 0);
            if (mustClockInTime != null && mustClockInTime.getAttendanceGroupShiftId() != null) {
                attendanceGroupShiftId = mustClockInTime.getAttendanceGroupShiftId();
                map.put(time, attendanceTimeRangeInfoVO.setDatType(Constants.ONE));
            } else if (noNeedToClockIn != null) {
                map.put(time, attendanceTimeRangeInfoVO.setDatType(Constants.TWO));
                continue;
            } else {
                // -- 判断是否根据节假日自动排班 - 如果是的话 - 根据排班的来
                LocalDateTime localDateTime = LocalDateTimeUtil.parseDate(time, Constants.REPO_DATE_FORMAT).atStartOfDay();
                Boolean holiday = attendanceService.isHoliday(localDateTime);
                // -- 如果是节假日的话先插入下是节假日 - 不管上不上班
                Boolean isHolidayFlag = Constants.TRUE.equals(dto.getAutoHolidaysFlag()) ?
                        holiday : null;
                attendanceTimeRangeInfoVO.setDatType(isHolidayFlag != null && isHolidayFlag ? Constants.THREE : Constants.ONE);
                // -- 当前是节假日 并且是放假
                if (isHolidayFlag != null && isHolidayFlag) {
                    map.put(time, attendanceTimeRangeInfoVO);
                    continue;
                }
                //获取到当天是周几 - 如果是节假日补班的话 - 班次日期就是8
                int week = isHolidayFlag != null ? 8 : localDateTime.getDayOfWeek().getValue();
                AttendanceFixedDO attendanceFixedDO = this.getByGroupIdAndWeek(dto.getGroupId(), week);
                // -- 当前没有班次 - 不需要考勤
                if (attendanceFixedDO == null || attendanceFixedDO.getAttendanceGroupShiftId() == null) {
                    map.put(time, attendanceTimeRangeInfoVO.setDatType(Constants.TWO));
                    continue;
                }
                attendanceGroupShiftId = attendanceFixedDO.getAttendanceGroupShiftId();
            }
            // - 如果当前有班次 - 但是又不是需要打卡的时间 - 那么看有没有加班班次 - 有的话按照加班班次来 - 没有的话设为不需要打卡 - 解决单双休场景
            List<AttendanceGroupShiftItemDO> attendanceGroupShiftItemDOList = attendanceGroupShiftItemService.getGroupShiftItemListByShiftId(attendanceGroupShiftId);
            if (CollectionUtil.isNotEmpty(attendanceGroupShiftItemDOList)) {
                List<AttendanceGroupShiftItemVO> items = BeanUtil.copyToList(attendanceGroupShiftItemDOList, AttendanceGroupShiftItemVO.class);
                map.put(time, attendanceTimeRangeInfoVO.setNeedAttendance(1).setItems(items));
            }
        }
        return map;
    }
}
