package com.engine.attendance.attendanceanalysis.cmd;

import com.engine.attendance.enums.AccountingUnitEnum;
import com.engine.attendance.enums.CheckBoxEnum;
import com.engine.attendance.enums.ClassSegmentTypeEnum;
import com.engine.attendance.enums.ClockPointEnum;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.common.util.DateUtil;
import com.engine.common.util.Utils;
import com.engine.core.interceptor.CommandContext;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;

import java.time.ZoneOffset;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 获取打卡卡点
 */
@Slf4j
public class GetClockInPointCmd extends AbstractCommonCommand<Map<String, Object>> {
    public GetClockInPointCmd(Map<String, Object> params) {
        this.params = params;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> resultMap = Maps.newHashMap();
        String analysisDate = Util.null2String(params.get("analysisDate"));
        List<Map<String, Object>> scheduleResult = (List<Map<String, Object>>) params.get("scheduleResult");
        List<Map<String, Object>> clockInTimeList = (List<Map<String, Object>>) params.get("clockInTimeList");
        List<Map<String, Object>> askForLeaveAndEvctionScheduleList = (List<Map<String, Object>>) params.get("askForLeaveAndEvctionSchedule");
        List<Map<String, Object>> needClockInList = scheduleResult.stream().filter(e -> !ClassSegmentTypeEnum.REST_AND_DINE.getKey().equals(e.get("bdlx")) && !ClassSegmentTypeEnum.REST_PERIOD.getKey().equals(e.get("bdlx")) &&
                !ClassSegmentTypeEnum.DINING_PERIOD.getKey().equals(e.get("bdlx")) ).collect(Collectors.toList());

        /**
         * 当请假或外出开始时间和外出时间在上班之外时，不需要打卡
         */
        log.info("未重新计算卡点时 老的scheduleResult : [{}],askForLeaveAndEvctionScheduleList:[{}]",scheduleResult,askForLeaveAndEvctionScheduleList);
        boolean ifStartNeedClock=false;
        boolean ifEndNeedClock=false;

        if (needClockInList.size() > 0 && askForLeaveAndEvctionScheduleList.size() > 0) {
            String startTime = analysisDate + " " + needClockInList.get(0).get("dtkssj").toString();
            String endStartTime  = analysisDate + " " + needClockInList.get(needClockInList.size()-1).get("dtkssj").toString();
            String endTime  = analysisDate + " " + needClockInList.get(needClockInList.size()-1).get("dtjssj").toString();
            if (DateUtil.getTime(endStartTime).compareTo(DateUtil.getTime(endTime)) > 0) {
                endTime = DateUtil.AfterDay(analysisDate, 1) + " " + needClockInList.get(needClockInList.size()-1).get("dtjssj");
            }
            for (Map<String, Object> askForLeaveAndEvctionSchedule :askForLeaveAndEvctionScheduleList){
                String dtkssj = analysisDate + " " + askForLeaveAndEvctionSchedule.get("dtkssj");
                String dtjssj = analysisDate + " " + askForLeaveAndEvctionSchedule.get("dtjssj");
                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(dtjssj)) > 0) {
                    dtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + askForLeaveAndEvctionSchedule.get("dtjssj");
                }
                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(startTime))<=0 || DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(endTime)) >= 0){
                    askForLeaveAndEvctionSchedule.put("ksdk",CheckBoxEnum.UNCHECKED.getKey());
                }
                if (DateUtil.getTime(dtjssj).compareTo(DateUtil.getTime(endTime))>=0 || DateUtil.getTime(dtjssj).compareTo(DateUtil.getTime(startTime))<=0){
                    askForLeaveAndEvctionSchedule.put("jsdk",CheckBoxEnum.UNCHECKED.getKey());
                }

                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(startTime))<=0 && DateUtil.getTime(dtjssj).compareTo(DateUtil.getTime(endTime))<0 && DateUtil.getTime(dtjssj).compareTo(DateUtil.getTime(startTime)) >0){
                    //骑在开始上班时间
                    for (Map<String,Object> needClockMap:needClockInList){
                        String kssj = analysisDate + " " + needClockMap.get("dtkssj");
                        String jssj  = analysisDate + " " + needClockMap.get("dtjssj");
                        if (DateUtil.getTime(kssj).compareTo(DateUtil.getTime(jssj)) > 0) {
                            jssj = DateUtil.AfterDay(analysisDate, 1) + " " + needClockMap.get("dtjssj");
                        }

                        if (CheckBoxEnum.CHECKED.getKey().equals(needClockMap.get("ksdk")) && DateUtil.getTime(dtjssj).compareTo(DateUtil.getTime(jssj)) >=0){
                            ifStartNeedClock=true;
                        }
                    }
                }

                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(startTime)) > 0 && DateUtil.getTime(dtjssj).compareTo(DateUtil.getTime(endTime))>=0 && DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(endTime)) < 0){
                    //骑在下班时间
                    for (Map<String,Object> needClockMap:needClockInList){
                        String kssj = analysisDate + " " + needClockMap.get("dtkssj");

                        if (CheckBoxEnum.CHECKED.getKey().equals(needClockMap.get("jsdk")) && DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(kssj)) <=0){
                            ifEndNeedClock=true;
                        }
                    }
                }

            }
        }

        /**
         * 当请假或外出包含打卡卡点时，判断该卡点是否需要打卡
         */
        for (Map<String, Object> askForLeaveAndEvctionMap :askForLeaveAndEvctionScheduleList){
            String evctiondtkssj = analysisDate + " " +Util.null2String(askForLeaveAndEvctionMap.get("dtkssj"));
            String evctionksdk = Util.null2String(askForLeaveAndEvctionMap.get("ksdk"));
            String evctiondtjssj = analysisDate + " " +Util.null2String(askForLeaveAndEvctionMap.get("dtjssj"));
            String evctionjsdk = Util.null2String(askForLeaveAndEvctionMap.get("jsdk"));
            if (DateUtil.getTime(evctiondtkssj).compareTo(DateUtil.getTime(evctiondtjssj)) > 0) {
                evctiondtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + Util.null2String(askForLeaveAndEvctionMap.get("dtjssj"));
            }
            List<String> lists = Lists.newArrayList();
            for (int i=0;i<scheduleResult.size();i++){
                String dtkssj = analysisDate + " " +Util.null2String(scheduleResult.get(i).get("dtkssj"));
                String dtjssj = analysisDate + " " +Util.null2String(scheduleResult.get(i).get("dtjssj"));
                String bdlx = Util.null2String(scheduleResult.get(i).get("bdlx"));
                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(dtjssj)) > 0) {
                    dtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + Util.null2String(scheduleResult.get(i).get("dtjssj"));
                }
                if (DateUtil.getTime(evctiondtkssj).compareTo(DateUtil.getTime(dtkssj)) <= 0 && DateUtil.getTime(evctiondtjssj).compareTo(DateUtil.getTime(dtkssj)) >=0
                  && !ClassSegmentTypeEnum.REST_AND_DINE.getKey().equals(bdlx) && !ClassSegmentTypeEnum.REST_PERIOD.getKey().equals(bdlx) && !ClassSegmentTypeEnum.DINING_PERIOD.getKey().equals(bdlx)){
                    lists.add(scheduleResult.get(i).get("dtkssj")+"-"+ClockPointEnum.START.getKey()+"-"+Util.null2String(scheduleResult.get(i).get("ksdk")));
                }
                if (DateUtil.getTime(evctiondtkssj).compareTo(DateUtil.getTime(dtjssj)) <= 0 && DateUtil.getTime(evctiondtjssj).compareTo(DateUtil.getTime(dtjssj)) >=0
                        && !ClassSegmentTypeEnum.REST_AND_DINE.getKey().equals(bdlx) && !ClassSegmentTypeEnum.REST_PERIOD.getKey().equals(bdlx) && !ClassSegmentTypeEnum.DINING_PERIOD.getKey().equals(bdlx)){
                    lists.add(scheduleResult.get(i).get("dtjssj")+"-"+ClockPointEnum.END.getKey()+"-"+Util.null2String(scheduleResult.get(i).get("jsdk")));
                }
            }
            //新打卡
            List<String> newNeedClockLists = Lists.newArrayList();
            //时间-结束卡\开始卡-是否打卡
            if (lists.size() == 1){
                String str = lists.get(0);
                if (ClockPointEnum.START.getKey().equals(str.split("-")[1]) && CheckBoxEnum.CHECKED.getKey().equals(evctionjsdk)){
                    newNeedClockLists.add(str.split("-")[0]+"-"+str.split("-")[1]+"-0");
                }else if (ClockPointEnum.END.getKey().equals(str.split("-")[1]) && CheckBoxEnum.CHECKED.getKey().equals(evctionksdk)){
                    newNeedClockLists.add(str.split("-")[0]+"-"+str.split("-")[1]+"-0");
                }
            }else if (lists.size() > 1){
                for(int i=0;i<lists.size();i++){
                    String str = lists.get(i);
                    if (i ==0){
                        if (CheckBoxEnum.CHECKED.getKey().equals(evctionksdk) || ClockPointEnum.START.getKey().equals(str.split("-")[1])){
                            newNeedClockLists.add(str.split("-")[0]+"-"+str.split("-")[1]+"-0");
                        }
                    }else if (i == lists.size()-1){
                        if (CheckBoxEnum.CHECKED.getKey().equals(evctionjsdk) || ClockPointEnum.END.getKey().equals(str.split("-")[1])){
                            newNeedClockLists.add(str.split("-")[0]+"-"+str.split("-")[1]+"-0");
                        }
                    }else {
                        newNeedClockLists.add(str.split("-")[0]+"-"+str.split("-")[1]+"-0");
                    }

                }
            }

            for (int i=0;i<scheduleResult.size();i++){
                String dtkssj = Util.null2String(scheduleResult.get(i).get("dtkssj"));
                String dtjssj = Util.null2String(scheduleResult.get(i).get("dtjssj"));
                for (String newNeedClock : newNeedClockLists){
                    if (ClockPointEnum.START.getKey().equals(newNeedClock.split("-")[1])){
                        if (newNeedClock.split("-")[0].equals(dtkssj)){
                            scheduleResult.get(i).put("ksdk",newNeedClock.split("-")[2]);
                        }
                    }else if (ClockPointEnum.END.getKey().equals(newNeedClock.split("-")[1])){
                        if (newNeedClock.split("-")[0].equals(dtjssj)){
                            scheduleResult.get(i).put("jsdk",newNeedClock.split("-")[2]);
                        }
                    }
                }

            }
        }
        if (askForLeaveAndEvctionScheduleList.size() > 0){


            scheduleResult.addAll(askForLeaveAndEvctionScheduleList);
            scheduleResult = scheduleResult.stream().sorted(Comparator.comparing(e->DateUtil.getTime(analysisDate+" "+e.get("dtkssj")).toInstant(ZoneOffset.of("+8")).toEpochMilli())).collect(Collectors.toList());
        }

        List<String> needClockDateList = Lists.newArrayList();
        for (int i=0;i<scheduleResult.size();i++){
            String dtkssj = analysisDate + " " + scheduleResult.get(i).get("dtkssj");
            String dtjssj = analysisDate + " " + scheduleResult.get(i).get("dtjssj");
            if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(dtjssj)) > 0) {
                dtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + scheduleResult.get(i).get("dtjssj");
            }
            if (CheckBoxEnum.CHECKED.getKey().equals(scheduleResult.get(i).get("ksdk"))) {
                needClockDateList.add(dtkssj);
            }
            if (CheckBoxEnum.CHECKED.getKey().equals(scheduleResult.get(i).get("jsdk"))){
                needClockDateList.add(dtjssj);
            }
        }

        /**
         * 当请假时间或出差时间包含最早上班时间和最晚下班时间时,补偿机制
         */
        if (needClockDateList.size() == 1){
            for (int i=0;i<scheduleResult.size();i++){
                String dtkssj = Util.null2String(scheduleResult.get(i).get("dtkssj"));
                String dtjssj = Util.null2String(scheduleResult.get(i).get("dtjssj"));
                String bdlx = Util.null2String(scheduleResult.get(i).get("bdlx"));
                if (ifStartNeedClock && needClockInList.get(0).get("dtkssj").equals(dtkssj) &&
                        !ClassSegmentTypeEnum.EVECTION.getKey().equals(bdlx) &&
                        !ClassSegmentTypeEnum.ASK_FOR_LEAVE.getKey().equals(bdlx)){
                    scheduleResult.get(i).put("ksdk",CheckBoxEnum.CHECKED.getKey());
                    needClockDateList.add(0,analysisDate + " "+dtkssj);
                    break;
                }
                if (ifEndNeedClock && needClockInList.get(needClockInList.size()-1).get("dtjssj").equals(dtjssj) &&
                        !ClassSegmentTypeEnum.EVECTION.getKey().equals(bdlx) &&
                        !ClassSegmentTypeEnum.ASK_FOR_LEAVE.getKey().equals(bdlx)){
                    scheduleResult.get(i).put("jsdk",CheckBoxEnum.CHECKED.getKey());
                    dtkssj = analysisDate + " " + scheduleResult.get(i).get("dtkssj");
                    dtjssj = analysisDate + " " + scheduleResult.get(i).get("dtjssj");
                    if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(dtjssj)) > 0) {
                        dtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + scheduleResult.get(i).get("dtjssj");
                    }
                    needClockDateList.add(dtjssj);
                    break;
                }
            }
        }





        log.info("经过重新计算卡点时 新的scheduleResult : [{}]",scheduleResult);


        List<Map<String, Map<String, Object>>> clcokInTimeData = getClockInPoint(analysisDate, scheduleResult, clockInTimeList,needClockDateList);
        log.info("clcokInTimeData :[{}]",clcokInTimeData);
        resultMap.put("clcokInTimeData", clcokInTimeData);
        return resultMap;
    }

    /**
     * 获取打卡卡点
     *
     * @param analysisDate        分析日期
     * @param scheduleResult 需要打卡的班次
     * @param clockInTimeList     打卡集合
     * @param needClockDateList     需要打卡的时间点
     * @return {2023-11-12 09:00|0|3|2023-11-12 09:15 ={signtime=09:11:00, id=48, userid=53, signdate=2023-11-12}}
     * 班次时间|打卡类型（上班卡或下班卡）|打卡时间处所在位置|timeType|弹性时间 = 打卡时间map集合
     */
    public  List<Map<String, Map<String, Object>>> getClockInPoint(String analysisDate, List<Map<String, Object>> scheduleResult, List<Map<String, Object>> clockInTimeList, List<String> needClockDateList) {


        List<Map<String, Map<String, Object>>> clcokInTimeData = Lists.newArrayList();
        for (Map<String, Object> needClockIn : scheduleResult) {

            /**非请假外出开始打卡逻辑处理*/
            if (CheckBoxEnum.CHECKED.getKey().equals(needClockIn.get("ksdk")) && !ClassSegmentTypeEnum.EVECTION.getKey().equals(needClockIn.get("bdlx")) &&
                    !ClassSegmentTypeEnum.ASK_FOR_LEAVE.getKey().equals(needClockIn.get("bdlx"))) {
                String dtkssj = analysisDate + " " + needClockIn.get("dtkssj");
                String dtjssj = analysisDate + " " + needClockIn.get("dtjssj");
                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(dtjssj)) > 0) {
                    dtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + needClockIn.get("dtjssj");
                }
                int tqdkfzs = 60;
                if (Util.null2String(needClockIn.get("tqdkfzs")).equals("") && !"".equals(getBeforeClockTime(needClockDateList,dtkssj))){
                    tqdkfzs = DateUtil.getBetWeenMinutes(getBeforeClockTime(needClockDateList,dtkssj),dtkssj);
                }else {

                    tqdkfzs = Util.null2String(needClockIn.get("tqdkfzs")).equals("")?0:Integer.valueOf(needClockIn.get("tqdkfzs").toString());
                }

                Map<String, Map<String, Object>> ksdkNearestClcokInTime = Utils.getNearestClcokInTimeCmd(dtkssj, clockInTimeList);
                String timeType = ClockPointEnum.EMPTY.getKey();
                Map<String, Map<String, Object>> clcokInTimeMap = Maps.newHashMap();
                if (ksdkNearestClcokInTime.get(ClockPointEnum.EQUAL.getKey()) != null) {
                    timeType = ClockPointEnum.EQUAL.getKey();
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && ksdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()) != null) {
                    String clockInTime = ksdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signdate") + " " + ksdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signtime");
                    if (DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(DateUtil.beforeMinutes(dtkssj, tqdkfzs))) >= 0 &&
                            (getBeforeClockTime(needClockDateList,dtkssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getBeforeClockTime(needClockDateList,dtkssj))) > 0)) {
                        //打卡时间大于等于最早打卡时间
                        timeType = ClockPointEnum.BEFORE.getKey();
                    }
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && ksdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()) != null) {
                    String clockInTime = ksdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signdate") + " " + ksdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signtime");

                    if (getNextClockTime(needClockDateList,dtkssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getNextClockTime(needClockDateList,dtkssj))) < 0) {
                        //打卡时间小于结束时间
                        timeType = ClockPointEnum.AFTER.getKey();
                    }
                }
                clcokInTimeMap.put(dtkssj + "|" + ClockPointEnum.START.getKey() + "|" + timeType, ksdkNearestClcokInTime.get(timeType));
                clcokInTimeData.add(clcokInTimeMap);
            }
            /**非请假外出结束打卡逻辑处理*/
            if (CheckBoxEnum.CHECKED.getKey().equals(needClockIn.get("jsdk")) && !ClassSegmentTypeEnum.EVECTION.getKey().equals(needClockIn.get("bdlx")) &&
                    !ClassSegmentTypeEnum.ASK_FOR_LEAVE.getKey().equals(needClockIn.get("bdlx"))) {
                String dtkssj = analysisDate + " " + needClockIn.get("dtkssj");
                String dtjssj = analysisDate + " " + needClockIn.get("dtjssj");
                int thdkfzs = 60;
                if (Util.null2String(needClockIn.get("thdkfzs")).equals("") && !"".equals(getNextClockTime(needClockDateList,dtjssj))){
                    thdkfzs = DateUtil.getBetWeenMinutes(dtjssj,getNextClockTime(needClockDateList,dtjssj));
                }else {
                    thdkfzs = Util.null2String(needClockIn.get("thdkfzs")).equals("")?0:Integer.valueOf(needClockIn.get("thdkfzs").toString());
                }

                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(dtjssj)) > 0) {
                    dtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + needClockIn.get("dtjssj");
                }
                Map<String, Map<String, Object>> jsdkNearestClcokInTime = Utils.getNearestClcokInTimeCmd(dtjssj, clockInTimeList);

                String timeType = ClockPointEnum.EMPTY.getKey();
                Map<String, Map<String, Object>> clcokInTimeMap = Maps.newHashMap();
                if (jsdkNearestClcokInTime.get(ClockPointEnum.EQUAL.getKey()) != null) {
                    timeType = ClockPointEnum.EQUAL.getKey();
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()) != null) {
                    String clockInTime = jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signdate") + " " + jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signtime");
                    if (DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(DateUtil.AfterMinutes(dtjssj, thdkfzs))) <= 0 &&
                            (getNextClockTime(needClockDateList,dtjssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getNextClockTime(needClockDateList,dtjssj))) < 0)) {
                        timeType = ClockPointEnum.AFTER.getKey();
                    }
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()) != null) {
                    String clockInTime = jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signdate") + " " + jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signtime");
                    if (getBeforeClockTime(needClockDateList,dtjssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getBeforeClockTime(needClockDateList,dtjssj))) > 0) {
                        timeType = ClockPointEnum.BEFORE.getKey();
                    }
                }
                clcokInTimeMap.put(dtjssj + "|" + ClockPointEnum.END.getKey() + "|" + timeType, jsdkNearestClcokInTime.get(timeType));
                clcokInTimeData.add(clcokInTimeMap);
            }

            /**
             * 请假外出的开始打卡处理
             */
            if (CheckBoxEnum.CHECKED.getKey().equals(needClockIn.get("ksdk")) && (ClassSegmentTypeEnum.EVECTION.getKey().equals(needClockIn.get("bdlx")) ||
                    ClassSegmentTypeEnum.ASK_FOR_LEAVE.getKey().equals(needClockIn.get("bdlx")))){
                String dtkssj = analysisDate + " " + needClockIn.get("dtkssj");
                int thdkfzs = Integer.valueOf(Util.null2String(needClockIn.get("thdkfzs")));
                if (!"".equals(getNextClockTime(needClockDateList,dtkssj))){
                    DateUtil.getBetWeenMinutes(dtkssj,getNextClockTime(needClockDateList,dtkssj));
                }

                Map<String, Map<String, Object>> jsdkNearestClcokInTime = Utils.getNearestClcokInTimeCmd(dtkssj, clockInTimeList);

                String timeType = ClockPointEnum.EMPTY.getKey();
                Map<String, Map<String, Object>> clcokInTimeMap = Maps.newHashMap();
                if (jsdkNearestClcokInTime.get(ClockPointEnum.EQUAL.getKey()) != null) {
                    timeType = ClockPointEnum.EQUAL.getKey();
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()) != null) {
                    String clockInTime = jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signdate") + " " + jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signtime");
                    if (DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(DateUtil.AfterMinutes(dtkssj, thdkfzs))) <= 0 &&
                            (getNextClockTime(needClockDateList,dtkssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getNextClockTime(needClockDateList,dtkssj))) < 0)) {
                        timeType = ClockPointEnum.AFTER.getKey();
                    }
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()) != null) {
                    String clockInTime = jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signdate") + " " + jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signtime");
                    if (getBeforeClockTime(needClockDateList,dtkssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getBeforeClockTime(needClockDateList,dtkssj))) > 0) {
                        timeType = ClockPointEnum.BEFORE.getKey();
                    }
                }
                clcokInTimeMap.put(dtkssj + "|" + ClockPointEnum.END.getKey() + "|" + timeType+"|0", jsdkNearestClcokInTime.get(timeType));
                clcokInTimeData.add(clcokInTimeMap);

            }
            /**
             * 请假外出的结束打卡处理
             */
            if (CheckBoxEnum.CHECKED.getKey().equals(needClockIn.get("jsdk")) && (ClassSegmentTypeEnum.EVECTION.getKey().equals(needClockIn.get("bdlx")) ||
                    ClassSegmentTypeEnum.ASK_FOR_LEAVE.getKey().equals(needClockIn.get("bdlx")))){

                String dtkssj = analysisDate + " " + needClockIn.get("dtkssj");
                String dtjssj = analysisDate + " " + needClockIn.get("dtjssj");
                if (DateUtil.getTime(dtkssj).compareTo(DateUtil.getTime(dtjssj)) > 0) {
                    dtjssj = DateUtil.AfterDay(analysisDate, 1) + " " + needClockIn.get("dtjssj");
                }
                int tqdkfzs = Integer.valueOf(Util.null2String(needClockIn.get("tqdkfzs")));

                if (!"".equals(getBeforeClockTime(needClockDateList,dtjssj))){
                    tqdkfzs = DateUtil.getBetWeenMinutes(getBeforeClockTime(needClockDateList,dtjssj),dtjssj);
                }


                Map<String, Map<String, Object>> ksdkNearestClcokInTime = Utils.getNearestClcokInTimeCmd(dtjssj, clockInTimeList);
                String timeType = ClockPointEnum.EMPTY.getKey();
                Map<String, Map<String, Object>> clcokInTimeMap = Maps.newHashMap();
                if (ksdkNearestClcokInTime.get(ClockPointEnum.EQUAL.getKey()) != null) {
                    timeType = ClockPointEnum.EQUAL.getKey();
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && ksdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()) != null) {
                    String clockInTime = ksdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signdate") + " " + ksdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signtime");
                    if (DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(DateUtil.beforeMinutes(dtjssj, tqdkfzs))) >= 0 &&
                            (getBeforeClockTime(needClockDateList,dtjssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getBeforeClockTime(needClockDateList,dtjssj))) > 0)) {
                        //打卡时间大于等于最早打卡时间
                        timeType = ClockPointEnum.BEFORE.getKey();
                    }
                }
                if (ClockPointEnum.EMPTY.getKey().equals(timeType) && ksdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()) != null) {
                    String clockInTime = ksdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signdate") + " " + ksdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signtime");

                    if (getNextClockTime(needClockDateList,dtjssj).equals("") || DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getNextClockTime(needClockDateList,dtjssj))) < 0) {
                        //打卡时间小于结束时间
                        timeType = ClockPointEnum.AFTER.getKey();
                    }
                }
                clcokInTimeMap.put(dtjssj + "|" + ClockPointEnum.START.getKey() + "|" + timeType+"|0", ksdkNearestClcokInTime.get(timeType));
                clcokInTimeData.add(clcokInTimeMap);

            }

        }



        clcokInTimeData = clcokInTimeData.stream().sorted(Comparator.comparing(e->{
            //卡点
            String point = "";
            //当天打卡数据
            for (Map.Entry<String,Map<String,Object>> entry :e.entrySet()){
                point = entry.getKey();
            }
           return DateUtil.getTime(point.split("\\|")[0]).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        })).collect(Collectors.toList());
        /**
         * 计算弹性上下班
         */  //上下班弹性，
        List<Map<String, Object>> workScheduleList = scheduleResult.stream().filter(e -> ClassSegmentTypeEnum.WORK_TIME.getKey().equals(e.get("bdlx")) || ClassSegmentTypeEnum.EARLY_OVERTIME.getKey().equals(e.get("bdlx"))).collect(Collectors.toList());
        if (scheduleResult.size() > 0 && workScheduleList.size()>0) {

            //请假和外出集合
            List<Map<String, Object>> leaveAndEvctionList = scheduleResult.stream().filter(e -> ClassSegmentTypeEnum.ASK_FOR_LEAVE.getKey().equals(e.get("bdlx")) ||
                    ClassSegmentTypeEnum.EVECTION.getKey().equals(e.get("bdlx"))).collect(Collectors.toList());
            //是否弹性
            String sfdx = Util.null2String(workScheduleList.get(0).get("sfdx"));
            //上班是否需要打卡
            String ifToWorkClock = Util.null2String(workScheduleList.get(0).get("ksdk"));
            //下班是否需要打卡
            String ifToCloseClock = Util.null2String(workScheduleList.get(workScheduleList.size()-1).get("jsdk"));

            //第一条工作时段、早上加班
            if (workScheduleList.size() > 0 && CheckBoxEnum.CHECKED.getKey().equals(sfdx)) {
                //最大弹性分钟
                int zddxfz = Integer.valueOf(Util.null2String(workScheduleList.get(0).get("zddxfz")));
                //弹性核算
                int dxhs = Integer.valueOf(Util.null2String(workScheduleList.get(0).get("dxhs")));
                Map<String, Object> ksdkMap = workScheduleList.get(0);
                String kssjStart = analysisDate + " " + Util.null2String(ksdkMap.get("dtkssj"));
                String jssjStart = analysisDate + " " + Util.null2String(ksdkMap.get("dtjssj"));


                Map<String, Object> jsdkMap = workScheduleList.get(workScheduleList.size() - 1);
                int thdkfzs = Integer.valueOf(Util.null2String(jsdkMap.get("thdkfzs")));
                String kssjEnd = analysisDate + " " + Util.null2String(jsdkMap.get("dtkssj"));
                String jssjEnd = analysisDate + " " + Util.null2String(jsdkMap.get("dtjssj"));

                if (ksdkMap != jsdkMap) {
                    if (DateUtil.getTime(kssjStart).compareTo(DateUtil.getTime(jssjStart)) > 0) {
                        kssjStart = DateUtil.beforeDay(analysisDate, 1) + " " + Util.null2String(ksdkMap.get("dtkssj"));
                    }
                    if (DateUtil.getTime(kssjEnd).compareTo(DateUtil.getTime(jssjEnd)) > 0) {
                        jssjEnd = DateUtil.AfterDay(analysisDate, 1) + " " + Util.null2String(jsdkMap.get("dtjssj"));
                    }
                } else {
                    jssjEnd = DateUtil.AfterDay(analysisDate, 1) + " " + Util.null2String(jsdkMap.get("dtjssj"));
                }

                //弹性上班时间
                String flexibleWorkTime = "";
                //弹性下班时间
                String flexibleOffWorkTime="";
                if (leaveAndEvctionList.size() >0){
                    //第一笔请假、外出时间
                    Map<String, Object> leaveAndEvctionMap = leaveAndEvctionList.get(0);
                    String leaveAndEvctionkssj = analysisDate + " " + Util.null2String(leaveAndEvctionMap.get("dtkssj"));
                    //最大开始弹性时间
                    String minkssjStart = DateUtil.beforeMinutes(kssjStart,zddxfz);
                    String maxkssjStart = DateUtil.AfterMinutes(kssjStart,zddxfz);
                    //请假开始时间在最大开始弹性时间之内
                    if (DateUtil.getTime(leaveAndEvctionkssj).compareTo(DateUtil.getTime(maxkssjStart))<=0){
                        //弹性上班卡
                        flexibleWorkTime = leaveAndEvctionkssj;
                        if (DateUtil.getTime(leaveAndEvctionkssj).compareTo(DateUtil.getTime(minkssjStart)) <0){
                            flexibleWorkTime=minkssjStart;
                        }

                        //弹性下班时间点
                        int betweenToWorkTime = DateUtil.getBetWeenMinutes(flexibleWorkTime, kssjStart);
                        //弹性下班时间点
                        flexibleOffWorkTime = jssjEnd;
                        if (betweenToWorkTime >= 0) {
                            flexibleOffWorkTime = DateUtil.beforeMinutes(flexibleOffWorkTime, Math.abs(betweenToWorkTime));
                        } else if (betweenToWorkTime < 0) {
                            flexibleOffWorkTime = DateUtil.AfterMinutes(flexibleOffWorkTime, Math.abs(betweenToWorkTime));
                        }

                    }
                }
                //弹性上班卡
                for (int i = 0; i < clcokInTimeData.size(); i++) {
                    Map<String, Map<String, Object>> clcokInTimeMap = clcokInTimeData.get(i);
                    //卡点
                    String point = "";
                    //当天打卡数据
                    Map<String, Object> clcokInTime = null;
                    for (Map.Entry<String, Map<String, Object>> entry : clcokInTimeMap.entrySet()) {
                        point = entry.getKey();
                        clcokInTime = entry.getValue();
                    }
                    //需要计算的班次打卡时间点
                    String pointTime = point.split("\\|")[0];
                    //start：开始打卡时间点，end：结束打卡时间点
                    String pointType = point.split("\\|")[1];
                    //empty:漏卡，equal:打卡时间和班次时间相等，before：打卡时间在班次时间之前，after：打卡时间在班次时间之后
                    String timeType = point.split("\\|")[2];

                    if (pointTime.equals(kssjStart) && ClockPointEnum.START.getKey().equals(pointType) && clcokInTime != null
                            && CheckBoxEnum.CHECKED.getKey().equals(ifToWorkClock)) {
                        String signTime = clcokInTime.get("signdate") + " " + clcokInTime.get("signtime");
                        //该卡点是弹性开始时间
                        if ("".equals(flexibleWorkTime) ){
                            //弹性上班期间未被请假开始时间占据
                            if (ClockPointEnum.BEFORE.getKey().equals(timeType)) {
                                int betWeenTime = DateUtil.getBetWeenMinutes(signTime, kssjStart);
                                String newPonit = point;
                                if (betWeenTime <= zddxfz) {
                                    betWeenTime = Double.valueOf(Utils.getItemdurationDown(dxhs, AccountingUnitEnum.MINUTES.getKey(), betWeenTime, AccountingUnitEnum.MINUTES)).intValue();
                                    flexibleWorkTime = DateUtil.beforeMinutes(kssjStart, betWeenTime);
                                    newPonit = pointTime + "|" + pointType + "|" + ClockPointEnum.EQUAL.getKey() + "|" + flexibleWorkTime;
                                } else if (betWeenTime > zddxfz) {
                                    flexibleWorkTime = DateUtil.beforeMinutes(kssjStart, zddxfz);
                                    newPonit = point + "|" + flexibleWorkTime;
                                }
                                clcokInTimeMap.remove(point);
                                clcokInTimeMap.put(newPonit, clcokInTime);
                            } else if (ClockPointEnum.AFTER.getKey().equals(timeType)) {
                                //迟到
                                String newPonit = point;
                                int betWeenTime = DateUtil.getBetWeenMinutes(kssjStart, signTime);
                                if (betWeenTime <= zddxfz) {
                                    betWeenTime = Double.valueOf(Utils.getItemduration(dxhs, AccountingUnitEnum.MINUTES.getKey(), betWeenTime, AccountingUnitEnum.MINUTES)).intValue();
                                    flexibleWorkTime = DateUtil.AfterMinutes(kssjStart, betWeenTime);
                                    newPonit = pointTime + "|" + pointType + "|" + ClockPointEnum.EQUAL.getKey() + "|" + flexibleWorkTime;
                                } else if (betWeenTime > zddxfz) {
                                    flexibleWorkTime = DateUtil.AfterMinutes(kssjStart, zddxfz);
                                    newPonit = point + "|" + flexibleWorkTime;
                                }
                                clcokInTimeMap.remove(point);
                                clcokInTimeMap.put(newPonit, clcokInTime);
                            }
                        }else {
                            //弹性上班期间被请假开始时间占据
                            String newPonit = point +"|"+flexibleWorkTime;
                            clcokInTimeMap.remove(point);
                            clcokInTimeMap.put(newPonit, clcokInTime);
                        }
                    } else if (pointTime.equals(jssjEnd) && ClockPointEnum.END.getKey().equals(pointType) && CheckBoxEnum.CHECKED.getKey().equals(ifToCloseClock)) {
                        //该卡点是弹性下班点
                        if ("".equals(flexibleOffWorkTime) && !"".equals(flexibleWorkTime)){
                            int betweenToWorkTime = DateUtil.getBetWeenMinutes(flexibleWorkTime, kssjStart);
                            //弹性下班时间点
                            flexibleOffWorkTime = jssjEnd;
                            if (betweenToWorkTime >= 0) {
                                flexibleOffWorkTime = DateUtil.beforeMinutes(flexibleOffWorkTime, Math.abs(betweenToWorkTime));
                            } else if (betweenToWorkTime < 0) {
                                flexibleOffWorkTime = DateUtil.AfterMinutes(flexibleOffWorkTime, Math.abs(betweenToWorkTime));
                            }
                        }
                        if (!"".equals(flexibleOffWorkTime)){
                            //根据弹性下班时间点重新计算
                            Map<String, Map<String, Object>> jsdkNearestClcokInTime = Utils.getNearestClcokInTimeCmd(flexibleOffWorkTime, clockInTimeList);

                            String newtimeType = ClockPointEnum.EMPTY.getKey();
                            if (jsdkNearestClcokInTime.get(ClockPointEnum.EQUAL.getKey()) != null) {
                                newtimeType = ClockPointEnum.EQUAL.getKey();
                            }
                            if (ClockPointEnum.EMPTY.getKey().equals(newtimeType) && jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()) != null) {
                                String clockInTime = jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signdate") + " " + jsdkNearestClcokInTime.get(ClockPointEnum.AFTER.getKey()).get("signtime");
                                if (DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(DateUtil.AfterMinutes(flexibleOffWorkTime, thdkfzs))) <= 0) {
                                    newtimeType = ClockPointEnum.AFTER.getKey();
                                }
                            }
                            if (ClockPointEnum.EMPTY.getKey().equals(newtimeType) && jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()) != null) {
                                String clockInTime = jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signdate") + " " + jsdkNearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()).get("signtime");
                                if (DateUtil.getTime(clockInTime).compareTo(DateUtil.getTime(getBeforeClockTime(needClockDateList,jssjEnd))) > 0) {
                                    newtimeType = ClockPointEnum.BEFORE.getKey();
                                }
                            }
                            String newPonit = jssjEnd + "|" + ClockPointEnum.END.getKey() + "|" + newtimeType + "|" + flexibleOffWorkTime;

                            clcokInTimeMap.remove(point);
                            clcokInTimeMap.put(newPonit, jsdkNearestClcokInTime.get(newtimeType));
                        }
                    }
                }
            }
        }

        /**
         * 计算休息时间段的弹性上下班
         */
        if (scheduleResult.size() > 0) {
            List<Map<String, Object>> restScheduleList = scheduleResult.stream().filter(e -> ClassSegmentTypeEnum.REST_AND_DINE.getKey().equals(e.get("bdlx")) || ClassSegmentTypeEnum.REST_PERIOD.getKey().equals(e.get("bdlx"))
                                                                                        || ClassSegmentTypeEnum.DINING_PERIOD.getKey().equals(e.get("bdlx"))).collect(Collectors.toList());
            for (int i=0;i<restScheduleList.size();i++){
                Map<String, Object> restSchedule = restScheduleList.get(i);
                String dtsfdx = Util.null2String(restSchedule.get("dtsfdx"));
                String dtzddxfz = Util.null2String(restSchedule.get("dtzddxfz"));
                String dtdxhs = Util.null2String(restSchedule.get("dtdxhs"));
                if (CheckBoxEnum.CHECKED.getKey().equals(dtsfdx)){

                }
            }
        }
        /**
         * 当有2笔需要打卡时，可能会有打卡歧义的情况，歧义情况取2个时间点的中间值，当打卡时间小于中间值归属前一个打卡，大于则相反
         */
        if (clcokInTimeData.size() > 1) {
            for (int i = 0; i < clcokInTimeData.size() - 1; i++) {
                Map<String, Map<String, Object>> beforeClcokInTimeData = clcokInTimeData.get(i);
                Map<String, Map<String, Object>> afterClcokInTimeData = clcokInTimeData.get(i + 1);
                Map<String, Object> beforeClcokInTimeMap = null;
                String beforeClcokInTime = "";
                String afterClcokInTime = "";
                Map<String, Object> afterClcokInTimeMap = null;
                for (Map.Entry<String, Map<String, Object>> beforeEntry : beforeClcokInTimeData.entrySet()) {
                    beforeClcokInTimeMap = beforeEntry.getValue();
                    beforeClcokInTime = beforeEntry.getKey();
                }
                for (Map.Entry<String, Map<String, Object>> afterEntry : afterClcokInTimeData.entrySet()) {
                    afterClcokInTimeMap = afterEntry.getValue();
                    afterClcokInTime = afterEntry.getKey();
                }
                //重复
                if (beforeClcokInTimeMap != null && beforeClcokInTimeMap == afterClcokInTimeMap) {
                    String beforeTime = beforeClcokInTime.split("\\|")[0];
                    if (beforeClcokInTime.split("\\|").length ==4 && !"0".equals(beforeClcokInTime.split("\\|")[3])){
                        beforeTime = beforeClcokInTime.split("\\|")[3];
                    }
                    String afterTime = afterClcokInTime.split("\\|")[0];
                    if (afterClcokInTime.split("\\|").length ==4 && !"0".equals(afterClcokInTime.split("\\|")[3])){
                        afterTime = afterClcokInTime.split("\\|")[3];
                    }
                    long betWeenMinutes = DateUtil.getBetWeenMinutes(beforeTime, afterTime);

                    String middileTime = DateUtil.AfterMinutes(beforeTime, betWeenMinutes / 2);

                    String signdateTime = beforeClcokInTimeMap.get("signdate") + " " + beforeClcokInTimeMap.get("signtime");

                    if (DateUtil.getTime(signdateTime).compareTo(DateUtil.getTime(middileTime)) <= 0) {
                        //该打卡归属前一个打卡点

                        Map<String, Map<String, Object>> nearestClcokInTime = Utils.getNearestClcokInTimeCmd(afterTime, clockInTimeList);
                        //start：开始打卡时间点，end：结束打卡时间点
                        String pointType = afterClcokInTime.split("\\|")[1];
                        //empty:漏卡，equal:打卡时间和班次时间相等，before：打卡时间在班次时间之前，after：打卡时间在班次时间之后
                        String timeType = afterClcokInTime.split("\\|")[2];
                        String time = afterClcokInTime.split("\\|")[0];
                        String newPonit = time+"|"+pointType;

                        String newtimeType = "";
                        if (timeType.equals(ClockPointEnum.BEFORE.getKey())){
                            newtimeType = ClockPointEnum.AFTER.getKey();
                        }else if (timeType.equals(ClockPointEnum.AFTER.getKey())){
                            newtimeType = ClockPointEnum.BEFORE.getKey();
                        }
                        if (nearestClcokInTime.get(newtimeType) != null && (i+2)<clcokInTimeData.size()){
                            newPonit = newPonit +"|"+newtimeType;
                            if (afterClcokInTime.split("\\|").length ==4){
                                newPonit = newPonit +"|"+afterClcokInTime.split("\\|")[3];
                            }
                            Map<String, Object> newClockTimeMap = nearestClcokInTime.get(newtimeType);
                            String newClockTime = newClockTimeMap.get("signdate")+ " "+newClockTimeMap.get("signtime");
                            if (newtimeType.equals(ClockPointEnum.BEFORE.getKey())){
                                if (!getBeforeClockTime(needClockDateList,time).equals("") && DateUtil.getTime(newClockTime).compareTo(DateUtil.getTime(getBeforeClockTime(needClockDateList,time))) <= 0){
                                    newClockTimeMap = null;
                                }
                            }else if (newtimeType.equals(ClockPointEnum.AFTER.getKey())){
                                if (!getNextClockTime(needClockDateList,time).equals("") && DateUtil.getTime(newClockTime).compareTo(DateUtil.getTime(getNextClockTime(needClockDateList,time))) >= 0){
                                    newClockTimeMap = null;
                                }
                            }

                            int index = clcokInTimeData.indexOf(afterClcokInTimeData);
                            clcokInTimeData.remove(afterClcokInTimeData);
                            afterClcokInTimeData = Maps.newHashMap();
                            afterClcokInTimeData.put(newPonit,newClockTimeMap);
                            clcokInTimeData.add(index,afterClcokInTimeData);
                        }else {
                            afterClcokInTimeData.put(afterClcokInTime, null);
                        }

//                        if (pointType.equals(ClockPointEnum.END.getKey())){
//                            if (nearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()) != null && (i+2)<clcokInTimeData.size()){
//                                newPonit = newPonit +"|"+ClockPointEnum.BEFORE.getKey();
//                                if (afterClcokInTime.split("\\|").length ==4){
//                                    newPonit = newPonit +"|"+afterClcokInTime.split("\\|")[3];
//                                }
//                                clcokInTimeData.remove(afterClcokInTimeData);
//                                afterClcokInTimeData = Maps.newHashMap();
//                                afterClcokInTimeData.put(newPonit,nearestClcokInTime.get(ClockPointEnum.BEFORE.getKey()));
//                                clcokInTimeData.add(afterClcokInTimeData);
//                            }else {
//                                afterClcokInTimeData.put(afterClcokInTime, null);
//                            }
//                        }else if (pointType.equals(ClockPointEnum.START.getKey())){
//                            if (nearestClcokInTime.get(ClockPointEnum.AFTER.getKey()) != null){
//                                newPonit = newPonit +"|"+ClockPointEnum.AFTER.getKey();
//                                if (afterClcokInTime.split("\\|").length ==4){
//                                    newPonit = newPonit +"|"+afterClcokInTime.split("\\|")[3];
//                                }
//                                clcokInTimeData.remove(afterClcokInTimeData);
//                                afterClcokInTimeData = Maps.newHashMap();
//                                afterClcokInTimeData.put(newPonit,nearestClcokInTime.get(ClockPointEnum.AFTER.getKey()));
//                                clcokInTimeData.add(i + 1,afterClcokInTimeData);
//                            }else {
//                                afterClcokInTimeData.put(afterClcokInTime, null);
//                            }
//                        }

                    } else if (DateUtil.getTime(signdateTime).compareTo(DateUtil.getTime(middileTime)) > 0) {
                        //该打卡归属后一个打卡点
                        beforeClcokInTimeData.put(beforeClcokInTime, null);
                    }
                }
            }
        }

        return clcokInTimeData;
    }

    public String getNextClockTime(List<String> needClockDateList,String time){
        int index = 0;
        for (int i=0;i<needClockDateList.size();i++){
            if (needClockDateList.get(i).equals(time)){
                index = i+1;
                break;
            }
        }
        if (index < needClockDateList.size() && index!=0){
            return needClockDateList.get(index);
        }else {
            return "";
        }
    }

    public String getBeforeClockTime(List<String> needClockDateList,String time){
        int index = 0;
        for (int i=0;i<needClockDateList.size();i++){
            if (needClockDateList.get(i).equals(time)){
                index = i-1;
                break;
            }
        }
        if (index >= 0){
            return needClockDateList.get(index);
        }else {
            return "";
        }
    }


}
