package com.mortals.xhx.module.attendance.service.impl;

import com.mortals.framework.service.IUser;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.module.attendance.model.*;
import com.mortals.xhx.module.attendance.service.*;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffService;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.attendance.dao.AttendanceRecordHikDao;
import com.mortals.framework.model.Context;


import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * AttendanceRecordHikService
 * 海康考勤打卡记录汇总信息 service实现
 *
 * @author zxfei
 * @date 2023-04-08
 */
@Service("attendanceRecordHikService")
public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<AttendanceRecordHikDao, AttendanceRecordHikEntity, Long> implements AttendanceRecordHikService {

    @Autowired
    private DeptService deptService;
    @Autowired
    private AttendanceRecordService attendanceRecordService;
    @Autowired
    private AttendanceRecordHikService attendanceRecordHikService;
    @Autowired
    private AttendanceGroupStaffService attendanceGroupStaffService;
    @Autowired
    private AttendanceGroupService attendanceGroupService;
    @Autowired
    private AttendanceGroupFixedworkService attendanceGroupFixedworkService;
    @Autowired
    private AttendanceClassService attendanceClassService;
    @Autowired
    private AttendanceClassDetailService attendanceClassDetailService;
    @Autowired
    private StaffService staffService;
    @Autowired
    private AttendanceRecordErrorService errorService;

    @Override
    public void addAttendanceRecord(AttendanceRecordHikEntity entity, Context context) throws Exception {

        List<AttendanceRecordHikEntity> hikEntityList = attendanceRecordHikService.find(entity);
        //对考勤数据根据考勤时间进行排序
        List<AttendanceRecordHikEntity> collect = hikEntityList.stream().sorted(Comparator.comparing(AttendanceRecordHikEntity::getAttendanceDate)).collect(Collectors.toList());
        //根据工号对考勤数据进行分组
        Map<String, List<AttendanceRecordHikEntity>> listMap = collect.stream().collect(Collectors.groupingBy(AttendanceRecordHikEntity::getWorkNum));
        //Map<String, Map<String, List<AttendanceRecordHikEntity>>> groupMap = collect.stream().collect(Collectors.groupingBy(AttendanceRecordHikEntity::getWorkNum, Collectors.groupingBy(x -> com.mortals.framework.util.DateUtils.getDateTimeStr(x.getAttendanceDate(), "yyyy-MM-dd"))));
        //map遍历.先把所有键取出来
        Set<String> workNumSet = listMap.keySet();
        //根据键取出value
        for (String workNum : workNumSet) {
            List<AttendanceRecordHikEntity> attendanceRecordHikEntities1 = listMap.get(workNum);
            //对按照工号分组了的数据attendanceRecordHikEntities进行时间分组
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            Map<String, List<AttendanceRecordHikEntity>> map = attendanceRecordHikEntities1.stream().collect(Collectors.groupingBy(hikEntity -> hikEntity.getAttendanceDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().format(formatter)));
            Set<String> dateSet = map.keySet();
            for (String s : dateSet) {
                List<AttendanceRecordHikEntity> attendanceRecordHikEntities = map.get(s);
                //对相同工号的人员进行遍历判断考勤规则.
                AttendanceRecordEntity attendanceRecordEntity = new AttendanceRecordEntity();
                attendanceRecordEntity.initAttrValue();
                List<AttendanceRecordDetailEntity> detailEntity = new ArrayList<>();
                for (AttendanceRecordHikEntity item : attendanceRecordHikEntities) {
                    //对主表的对象进行赋值
                    if (StringUtils.isNull(attendanceRecordEntity) || StringUtils.isEmpty(attendanceRecordEntity.getStaffName())) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        attendanceRecordEntity.setStaffId(item.getStaffId());
                        attendanceRecordEntity.setStaffName(item.getStaffName());
                        attendanceRecordEntity.setDeptId(item.getDeptId());
                        attendanceRecordEntity.setDeptName(item.getDeptName());
                        attendanceRecordEntity.setPositionId(item.getPositionId());
                        attendanceRecordEntity.setPositionName(item.getPositionName());
                        attendanceRecordEntity.setWorkNum(item.getWorkNum());
                        attendanceRecordEntity.setAttendanceDate(sdf.parse(sdf.format(item.getAttendanceDate())));
                        attendanceRecordEntity.setCreateTime(new Date());
                        attendanceRecordEntity.setCreateUserId(this.getContextUserId(context));
                    }
                    //获取考勤打卡时间
                    Date attendanceDate = item.getAttendanceDate();
                    //通过工号查询员工信息
                    StaffEntity staffEntity = staffService.selectOne(new StaffQuery().workNum(item.getWorkNum()));
                    //通过员工id查询考勤人员信息
                    List<AttendanceGroupStaffEntity> attendanceGroupStaffEntities = attendanceGroupStaffService.find(new AttendanceGroupStaffQuery().staffId(staffEntity.getId()));
                    //查询该考勤人员,如果查出来的考勤人员信息list长度为1 则该考勤人员只有一个考勤组
                    if (StringUtils.isNotNull(attendanceGroupStaffEntities) && attendanceGroupStaffEntities.size() == 1) {
                        //查询考勤组
                        AttendanceGroupQuery attendanceGroupQuery = new AttendanceGroupQuery();
                        AttendanceGroupEntity attendanceGroupEntity = attendanceGroupService.selectOne(attendanceGroupQuery.id(attendanceGroupStaffEntities.get(0).getGroupId()));
                        attendanceRecordEntity.setAttendanceGroupId(attendanceGroupEntity.getId());
                        attendanceRecordEntity.setAttendanceGroupName(attendanceGroupEntity.getGroupName());
                        //查询考勤组详细信息获取班次
                        AttendanceGroupFixedworkQuery attendanceGroupFixedworkQuery = new AttendanceGroupFixedworkQuery();
                        AttendanceGroupFixedworkEntity attendanceGroupFixedworkEntity = attendanceGroupFixedworkService.selectOne(attendanceGroupFixedworkQuery.groupId(attendanceGroupEntity.getId()));
                        //判断当前考勤日期为周几
                        Date attendanceDate1 = attendanceDate;
                        String week = this.getWeek(attendanceDate1);
                        //通过考勤日期的星期拿到班次id.
                        Long weekClassId = this.getWeekClassId(attendanceGroupFixedworkEntity, week);
                        //weekClassId为-1 则不在考勤
                        if (weekClassId == -1L) {
                            //跳过本次循环
                            continue;
                        }
                        //获取班次信息
                        AttendanceClassQuery attendanceClassQuery = new AttendanceClassQuery();
                        AttendanceClassEntity attendanceClassEntity = attendanceClassService.selectOne(attendanceClassQuery.id(weekClassId));
                        //获取班次详细信息
                        AttendanceClassDetailQuery attendanceClassDetailQuery = new AttendanceClassDetailQuery();
                        List<AttendanceClassDetailEntity> attendanceClassDetailEntities = attendanceClassDetailService.find(attendanceClassDetailQuery.classId(attendanceClassEntity.getId()));
                        Integer orderNum = 0;
                        if (detailEntity == null || detailEntity.size() == 0) {
                            for (AttendanceClassDetailEntity classDetailEntity : attendanceClassDetailEntities) {
                                orderNum++;
                                AttendanceRecordDetailEntity recordDetailEntity = new AttendanceRecordDetailEntity();
                                recordDetailEntity.setShiftsId(classDetailEntity.getId());
                                recordDetailEntity.setShiftsName(classDetailEntity.getClassName());
                                recordDetailEntity.setGoWorkResult(3);
                                recordDetailEntity.setOffWorkResult(3);
                                recordDetailEntity.setOrderNum(orderNum);
                                detailEntity.add(recordDetailEntity);
                            }
                        }
                        for (AttendanceClassDetailEntity classDetail : attendanceClassDetailEntities) {
                            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                            //上班打卡前时间
                            Date goWorkDateBefore = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getGoWorkDate(), -classDetail.getGoWorkDateBefore())));
                            //上班打卡后时间
                            Date goWorkDateAfter = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getGoWorkDate(), classDetail.getGoWorkDateAfter())));
                            //下班打卡前时间
                            Date offWorkDateBefore = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getOffWorkDate(), -classDetail.getOffWorkDateBefore())));
                            //下班打卡后时间
                            Date offWorkDateAfter = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getOffWorkDate(), classDetail.getOffWorkDateAfter())));
                            //判断考勤时间是否在上班打卡区间内  true 在 false 不在
                            boolean goInTime = isInTime(sdf.parse(sdf.format(attendanceDate)), goWorkDateBefore, goWorkDateAfter);
                            //判断考勤时间是否在下班打卡区间内
                            boolean offInTime = isInTime(sdf.parse(sdf.format(attendanceDate)), offWorkDateBefore, offWorkDateAfter);
                            if (goInTime == false && offInTime == false) {
                                continue;
                            }
                            if (goInTime) {
                                //如果是上班打卡,判断是否迟到
                                boolean inTime = isInTime(sdf.parse(sdf.format(attendanceDate)), goWorkDateBefore, sdf.parse(sdf.format(classDetail.getGoWorkDate())));
                                if (!inTime) {
                                    for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                        if (attendanceRecordDetailEntity.getShiftsId().longValue() == classDetail.getId().longValue()) {
                                            attendanceRecordDetailEntity.setGoWorkResult(4);
                                            attendanceRecordDetailEntity.setGoWorkDate(attendanceDate);
                                        }
                                    }
                                }
                                if (inTime) {
                                    for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                        if (attendanceRecordDetailEntity.getShiftsId().longValue() == classDetail.getId().longValue()) {
                                            attendanceRecordDetailEntity.setGoWorkResult(1);
                                            attendanceRecordDetailEntity.setGoWorkDate(attendanceDate);
                                        }
                                    }
                                }
                            }
                            if (offInTime) {
                                boolean inTime = isInTime(sdf.parse(sdf.format(attendanceDate)), sdf.parse(sdf.format(classDetail.getOffWorkDate())), offWorkDateAfter);
                                if (!inTime) {
                                    for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                        if (attendanceRecordDetailEntity.getShiftsId().longValue() == classDetail.getId().longValue()) {
                                            attendanceRecordDetailEntity.setOffWorkResult(5);
                                            attendanceRecordDetailEntity.setOffWorkDate(attendanceDate);
                                        }
                                    }
                                }
                                if (inTime) {
                                    for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                        if (attendanceRecordDetailEntity.getShiftsId().longValue() == classDetail.getId().longValue()) {
                                            attendanceRecordDetailEntity.setOffWorkResult(1);
                                            attendanceRecordDetailEntity.setOffWorkDate(attendanceDate);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //如果考勤人员信息list长度大于1 则该考勤人员有多个考勤组.
                    if (StringUtils.isNotNull(attendanceGroupStaffEntities) && attendanceGroupStaffEntities.size() > 1) {
                        for (AttendanceGroupStaffEntity groupStaffEntity : attendanceGroupStaffEntities) {
                            {
                                //查询考勤组
                                AttendanceGroupQuery attendanceGroupQuery = new AttendanceGroupQuery();
                                AttendanceGroupEntity attendanceGroupEntity = attendanceGroupService.selectOne(attendanceGroupQuery.id(groupStaffEntity.getGroupId()));
                                //查询考勤组详细信息获取班次
                                AttendanceGroupFixedworkQuery attendanceGroupFixedworkQuery = new AttendanceGroupFixedworkQuery();
                                AttendanceGroupFixedworkEntity attendanceGroupFixedworkEntity = attendanceGroupFixedworkService.selectOne(attendanceGroupFixedworkQuery.groupId(attendanceGroupEntity.getId()));
                                //判断当前考勤日期为周几
                                Date attendanceDate1 = attendanceDate;
                                String week = this.getWeek(attendanceDate1);
                                //通过考勤日期的星期拿到班次id.
                                Long weekClassId = this.getWeekClassId(attendanceGroupFixedworkEntity, week);
                                //weekClassId为-1 则不在考勤
                                if (weekClassId == -1L) {
                                    //跳过本次循环
                                    continue;
                                }
                                attendanceRecordEntity.setAttendanceGroupId(attendanceGroupEntity.getId());
                                attendanceRecordEntity.setAttendanceGroupName(attendanceGroupEntity.getGroupName());
                                //获取班次信息
                                AttendanceClassQuery attendanceClassQuery = new AttendanceClassQuery();
                                AttendanceClassEntity attendanceClassEntity = attendanceClassService.selectOne(attendanceClassQuery.id(weekClassId));
                                //获取班次详细信息
                                AttendanceClassDetailQuery attendanceClassDetailQuery = new AttendanceClassDetailQuery();
                                List<AttendanceClassDetailEntity> attendanceClassDetailEntities = attendanceClassDetailService.find(attendanceClassDetailQuery.classId(attendanceClassEntity.getId()));
                                Integer orderNum = 0;
                                if (detailEntity != null || detailEntity.size() == 0) {
                                    for (AttendanceClassDetailEntity classDetailEntity : attendanceClassDetailEntities) {
                                        orderNum++;
                                        AttendanceRecordDetailEntity recordDetailEntity = new AttendanceRecordDetailEntity();
                                        recordDetailEntity.setShiftsId(classDetailEntity.getId());
                                        recordDetailEntity.setShiftsName(classDetailEntity.getClassName());
                                        recordDetailEntity.setGoWorkResult(3);
                                        recordDetailEntity.setOffWorkResult(3);
                                        recordDetailEntity.setOrderNum(orderNum);
                                        detailEntity.add(recordDetailEntity);
                                    }
                                }
                                for (AttendanceClassDetailEntity classDetail : attendanceClassDetailEntities) {
                                    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                                    //上班打卡前时间
                                    Date goWorkDateBefore = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getGoWorkDate(), -classDetail.getGoWorkDateBefore())));
                                    //上班打卡后时间
                                    Date goWorkDateAfter = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getGoWorkDate(), classDetail.getGoWorkDateAfter())));
                                    //下班打卡前时间
                                    Date offWorkDateBefore = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getOffWorkDate(), -classDetail.getOffWorkDateBefore())));
                                    //下班打卡后时间
                                    Date offWorkDateAfter = sdf.parse(sdf.format(DateUtils.addMinutes(classDetail.getOffWorkDate(), classDetail.getOffWorkDateAfter())));
                                    //判断考勤时间是否在上班打卡区间内  true 在 false 不在
                                    boolean goInTime = isInTime(sdf.parse(sdf.format(attendanceDate)), goWorkDateBefore, goWorkDateAfter);
                                    //判断考勤时间是否在下班打卡区间内
                                    boolean offInTime = isInTime(sdf.parse(sdf.format(attendanceDate)), offWorkDateBefore, offWorkDateAfter);
                                    if (goInTime == false && offInTime == false) {
                                        continue;
                                    }
                                    if (goInTime) {
                                        //如果是上班打卡,判断是否迟到
                                        boolean inTime = isInTime(sdf.parse(sdf.format(attendanceDate)), goWorkDateBefore, sdf.parse(sdf.format(classDetail.getGoWorkDate())));
                                        if (!inTime) {
                                            for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                                if (attendanceRecordDetailEntity.getShiftsId().equals(classDetail.getId())) {
                                                    attendanceRecordDetailEntity.setGoWorkResult(4);
                                                    attendanceRecordDetailEntity.setGoWorkDate(attendanceDate);
                                                }
                                            }
                                        }
                                        if (inTime) {
                                            for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                                if (attendanceRecordDetailEntity.getShiftsId().equals(classDetail.getId())) {
                                                    attendanceRecordDetailEntity.setGoWorkResult(1);
                                                    attendanceRecordDetailEntity.setGoWorkDate(attendanceDate);
                                                }
                                            }
                                        }
                                    }
                                    if (offInTime) {
                                        boolean inTime = isInTime(sdf.parse(sdf.format(attendanceDate)), sdf.parse(sdf.format(classDetail.getOffWorkDate())), offWorkDateAfter);
                                        if (!inTime) {
                                            for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                                if (attendanceRecordDetailEntity.getShiftsId().equals(classDetail.getId())) {
                                                    attendanceRecordDetailEntity.setOffWorkResult(5);
                                                    attendanceRecordDetailEntity.setOffWorkDate(attendanceDate);
                                                }
                                            }
                                        }
                                        if (inTime) {
                                            for (AttendanceRecordDetailEntity attendanceRecordDetailEntity : detailEntity) {
                                                if (attendanceRecordDetailEntity.getShiftsId().equals(classDetail.getId())) {
                                                    attendanceRecordDetailEntity.setOffWorkResult(1);
                                                    attendanceRecordDetailEntity.setOffWorkDate(attendanceDate);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                List<AttendanceRecordErrorEntity> errorEntityList = new ArrayList<>();
                for (AttendanceRecordDetailEntity recordDetailEntity : detailEntity) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    SimpleDateFormat sdft = new SimpleDateFormat("HH:mm:ss");
                    Integer goWorkResult = recordDetailEntity.getGoWorkResult();
                    Integer offWorkResult = recordDetailEntity.getOffWorkResult();
                    if (goWorkResult != 1) {
                        AttendanceRecordErrorEntity errorEntity = new AttendanceRecordErrorEntity();
                        errorEntity.setStaffId(attendanceRecordEntity.getStaffId());
                        errorEntity.setStaffName(attendanceRecordEntity.getStaffName());
                        errorEntity.setWorkNum(attendanceRecordEntity.getWorkNum());
                        errorEntity.setDeptId(attendanceRecordEntity.getDeptId());
                        errorEntity.setDeptName(attendanceRecordEntity.getDeptName());
                        errorEntity.setPositionId(attendanceRecordEntity.getPositionId());
                        errorEntity.setPositionName(attendanceRecordEntity.getPositionName());
                        errorEntity.setShiftsId(recordDetailEntity.getShiftsId());
                        errorEntity.setShiftsName(recordDetailEntity.getShiftsName());
                        Date goWorkDate = attendanceClassDetailService.selectOne(new AttendanceClassDetailQuery().id(recordDetailEntity.getShiftsId())).getGoWorkDate();
                        errorEntity.setGoOffDateTime(goWorkDate);
                        if (recordDetailEntity.getGoWorkDate() != null && !recordDetailEntity.getGoWorkDate().equals("")) {
                            errorEntity.setErrorDateTime(recordDetailEntity.getGoWorkDate());
                            errorEntity.setActualAttendanceDateTime(recordDetailEntity.getGoWorkDate());
                        } else {
                            String s1 = s + " " + sdft.format(goWorkDate);
                            errorEntity.setErrorDateTime(sdf.parse(s1));
                            errorEntity.setActualAttendanceDateTime(sdf.parse(s1));
                        }
                        if (recordDetailEntity.getGoWorkResult() == 3) {
                            errorEntity.setErrorStatus(0);
                        }
                        if (recordDetailEntity.getGoWorkResult() == 4) {
                            errorEntity.setErrorStatus(2);
                        }
                        errorEntity.setProcessStatus(0);
                        errorEntity.setCreateTime(new Date());
                        errorEntity.setCreateUserId(this.getContextUserId(context));
                        errorEntityList.add(errorEntity);
                    }
                    if (offWorkResult != 1) {
                        AttendanceRecordErrorEntity errorEntity = new AttendanceRecordErrorEntity();
                        errorEntity.setStaffId(attendanceRecordEntity.getStaffId());
                        errorEntity.setStaffName(attendanceRecordEntity.getStaffName());
                        errorEntity.setWorkNum(attendanceRecordEntity.getWorkNum());
                        errorEntity.setDeptId(attendanceRecordEntity.getDeptId());
                        errorEntity.setDeptName(attendanceRecordEntity.getDeptName());
                        errorEntity.setPositionId(attendanceRecordEntity.getPositionId());
                        errorEntity.setPositionName(attendanceRecordEntity.getPositionName());
                        errorEntity.setShiftsId(recordDetailEntity.getShiftsId());
                        errorEntity.setShiftsName(recordDetailEntity.getShiftsName());
                        Date offWorkDate = attendanceClassDetailService.selectOne(new AttendanceClassDetailQuery().id(recordDetailEntity.getShiftsId())).getOffWorkDate();
                        errorEntity.setGoOffDateTime(offWorkDate);
                        if (recordDetailEntity.getOffWorkDate() != null && !recordDetailEntity.getOffWorkDate().equals("")) {
                            errorEntity.setErrorDateTime(recordDetailEntity.getOffWorkDate());
                            errorEntity.setActualAttendanceDateTime(recordDetailEntity.getOffWorkDate());
                        } else {
                            errorEntity.setErrorDateTime(sdf.parse(s + " " + sdft.format(offWorkDate)));
                            errorEntity.setActualAttendanceDateTime(sdf.parse(s + " " + sdft.format(offWorkDate)));
                        }
                        if (recordDetailEntity.getOffWorkResult() == 3) {
                            errorEntity.setErrorStatus(0);
                        }
                        if (recordDetailEntity.getOffWorkResult() == 5) {
                            errorEntity.setErrorStatus(1);
                        }
                        errorEntity.setProcessStatus(0);
                        errorEntity.setCreateTime(new Date());
                        errorEntity.setCreateUserId(this.getContextUserId(context));
                        errorEntityList.add(errorEntity);
                    }

                }
                if (detailEntity != null && detailEntity.size() > 0) {
                    if (errorEntityList != null && errorEntityList.size() > 0) {
                        errorService.save(errorEntityList, context);
                    }
                    attendanceRecordEntity.setShiftsName(detailEntity.get(0).getShiftsName());
                    attendanceRecordEntity.setShiftsId(attendanceClassDetailService.selectOne(new AttendanceClassDetailQuery().id(detailEntity.get(0).getShiftsId())).getClassId());
                    attendanceRecordEntity.setAttendanceRecordDetailList(detailEntity);
                    attendanceRecordService.save(attendanceRecordEntity, context);
                }

            }

        }
    }

    public String getWeek(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
        String week = sdf.format(date);
        return week;
    }

    /**
     * 获取通过星期获取班次id  如果返参为-1 则不在考勤
     *
     * @return
     */
    public Long getWeekClassId(AttendanceGroupFixedworkEntity attendanceGroupFixedworkEntity, String week) {
        Long weekClassId = 0L;
        switch (week) {
            case "星期一":
                if (attendanceGroupFixedworkEntity.getMonday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getMondayClassId();
                break;
            case "星期二":
                if (attendanceGroupFixedworkEntity.getTuesday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getTuesdayClassId();
                break;
            case "星期三":
                if (attendanceGroupFixedworkEntity.getWednesday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getWednesdayClassId();
                break;
            case "星期四":
                if (attendanceGroupFixedworkEntity.getThursday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getThursdayClassId();
                break;
            case "星期五":
                if (attendanceGroupFixedworkEntity.getFriday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getFridayClassId();
                break;
            case "星期六":
                if (attendanceGroupFixedworkEntity.getSaturday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getSaturdayClassId();
                break;
            case "星期日":
                if (attendanceGroupFixedworkEntity.getSunday() == 0) {
                    weekClassId = -1L;
                    return weekClassId;
                }
                weekClassId = attendanceGroupFixedworkEntity.getSundayClassId();
                break;
        }
        return weekClassId;
    }

    /**
     * @param nowTime   当前时间
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return 判断当前时间在时间区间内
     */
    public static boolean isInTime(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }
}
