yaozc
2024-03-25 9b2c90fa0abe194de3a32df97702fd009da88570
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceGoOutServiceImpl.java
@@ -15,45 +15,48 @@
*/
package me.zhengjie.modules.attendance.service.impl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.attendance.domain.*;
import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository;
import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository;
import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository;
import me.zhengjie.modules.attendance.repository.AttendanceRepository;
import me.zhengjie.modules.attendance.service.AttendanceGoOutService;
import me.zhengjie.modules.attendance.service.AttendanceOvertimeService;
import me.zhengjie.modules.attendance.service.AttendanceService;
import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveDto;
import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutDto;
import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutQueryCriteria;
import me.zhengjie.modules.attendance.service.mapstruct.AttendanceGoOutMapper;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.OpaiDingTalkService;
import me.zhengjie.modules.quartz.service.impl.DingTalkServiceImpl;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.domain.SysConfigHoliday;
import me.zhengjie.modules.system.domain.SysRostering;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.DictDetailRepository;
import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.modules.system.service.SysConfigHolidayService;
import me.zhengjie.modules.system.service.dto.SysConfigHolidayDto;
import me.zhengjie.utils.*;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository;
import me.zhengjie.modules.attendance.service.AttendanceGoOutService;
import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutDto;
import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutQueryCriteria;
import me.zhengjie.modules.attendance.service.mapstruct.AttendanceGoOutMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* @website https://eladmin.vip
@@ -66,6 +69,7 @@
public class AttendanceGoOutServiceImpl implements AttendanceGoOutService {
    private final AttendanceGoOutRepository attendanceGoOutRepository;
    private final AttendanceOvertimeService attendanceOvertimeService;
    private final AttendanceGoOutMapper attendanceGoOutMapper;
    private final UserRepository userRepository;
    private final AttendanceService attendanceService;
@@ -77,6 +81,8 @@
    private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
    private final DictDetailRepository dictDetailRepository;
    private final DingTalkServiceImpl dingTalkService;
    private final SysConfigHolidayService sysConfigHolidayService;
    @Override
    public Map<String,Object> queryAll(AttendanceGoOutQueryCriteria criteria, Pageable pageable){
@@ -120,8 +126,8 @@
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String goStartTime = df.format(resources.getOutStartTime());
        String goEndTime = df.format(resources.getOutEndTime());
        // 查询其他状态的表是否有重复
        repeatValidation(goStartTime, goEndTime, resources.getUserId() == null ? SecurityUtils.getCurrentUserId() : resources.getUserId());
//        // 查询其他状态的表是否有重复
//        repeatValidation(goStartTime, goEndTime, resources.getUserId() == null ? SecurityUtils.getCurrentUserId() : resources.getUserId());
        // 验证请假时间是否冲突
        List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(goStartTime, goEndTime, resources.getUserId());
        if(attendanceGoOutList.size() > 0){
@@ -142,30 +148,70 @@
        }else {
            // 获取当前登陆人信息,设置为请假发起人
            User user = userRepository.getOne(resources.getUserId() == null ? SecurityUtils.getCurrentUserId() : resources.getUserId());
            List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>();
            // 查询节假日
            List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
            for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){
                if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
                    //工作日
                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
                }else{
                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
            LocalDate startDate = resources.getOutStartTime().toLocalDateTime().toLocalDate();
            LocalDate endDate = resources.getOutEndTime().toLocalDateTime().toLocalDate();
            LocalTime startTime = resources.getOutStartTime().toLocalDateTime().toLocalTime();
            LocalTime endTime = resources.getOutEndTime().toLocalDateTime().toLocalTime();
            long distance = ChronoUnit.DAYS.between(startDate, endDate);
            Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).forEach(localDate -> {
//                SysConfigHolidayDto sysConfigHolidayDto = sysConfigHolidayService.queryByHolidayDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
//                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
//                if ((sysConfigHolidayDto == null && !isWeekend) ||
//                        sysConfigHolidayDto != null && Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHolidayDto.getDateType())) {
                    AttendanceGoOut attendanceGoOut = new AttendanceGoOut();
                    //resUserId为null说明是添加,反之
                    if (resources.getUserId() == null) {
                        resources.setUserId(user.getId());
                }
            }
            // 循环添加开始时间到结束时间的每一天
            List<String> dateList = attendanceLeaveService.getBetweenDate(resources.getOutStartTime().toLocalDateTime().toString(),resources.getOutEndTime().toLocalDateTime().toString());
            int i = 0;
            for(String date : dateList){
                LocalDate localDate = LocalDate.parse(date);
                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
                // 不是周末并且节假日表中不存在在创建
                if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
                    AttendanceGoOut attendanceGoOut = getAttendanceOut(resources,date,user,i,goStartTime,goEndTime,null);
                    i++;
                    resources.setOutStartTime(Timestamp.valueOf(localDate.atTime(startTime)));
                    resources.setOutEndTime(Timestamp.valueOf(localDate.atTime(endTime)));
                    Double result = getRemainingTime(resources);
                    resources.setOutDuration(result);
                    resources.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REVIEWED);
                    attendanceGoOut.copy(resources);
                    attendanceGoOutRepository.save(attendanceGoOut);
//                }
                SysConfigHolidayDto sysConfigHolidayDto = sysConfigHolidayService.queryByHolidayDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
                if ((sysConfigHolidayDto == null && isWeekend) ||
                        sysConfigHolidayDto != null && Constant.DATE_TYPE_HOLIDAYS.equals(sysConfigHolidayDto.getDateType())) {
                    AttendanceOvertime attendanceOvertime = new AttendanceOvertime();
                    attendanceOvertime.setUserId(resources.getUserId());
                    attendanceOvertime.setOvertimeStartTime(resources.getOutStartTime());
                    attendanceOvertime.setOvertimeEndTime(resources.getOutEndTime());
                    attendanceOvertime.setOvertimeDuration(resources.getOutDuration());
                    attendanceOvertime.setApprovalStatus(resources.getApprovalStatus());
                    attendanceOvertime.setRemarks(resources.getRemarks());
                    attendanceOvertimeService.create(attendanceOvertime);
                }
            }
            });
//
//            List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>();
//            // 查询节假日
//            List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
//            for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){
//                if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
//                    //工作日
//                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
//                }else{
//                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
//                }
//            }
//            // 循环添加开始时间到结束时间的每一天
//            List<String> dateList = attendanceLeaveService.getBetweenDate(resources.getOutStartTime().toLocalDateTime().toString(),resources.getOutEndTime().toLocalDateTime().toString());
//            int i = 0;
//            for(String date : dateList){
//                LocalDate localDate = LocalDate.parse(date);
//                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
//                // 不是周末并且节假日表中不存在在创建
//                if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
//                    AttendanceGoOut attendanceGoOut = getAttendanceOut(resources,date,user,i,goStartTime,goEndTime,null);
//                    i++;
//                    attendanceGoOutRepository.save(attendanceGoOut);
//                }
//            }
            //发送钉钉给审批人
            List<String> sendList = new ArrayList<>();
            //查询审批者信息
@@ -201,8 +247,8 @@
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String goStartTime = df.format(resources.getOutStartTime());
        String goEndTime = df.format(resources.getOutEndTime());
        // 查询其他状态的表是否有重复
        repeatValidation(goStartTime, goEndTime, resources.getUserId());
//        // 查询其他状态的表是否有重复
//        repeatValidation(goStartTime, goEndTime, resources.getUserId());
        // 验证是否存在时间冲突的请假记录
        Set<Long> ids = new HashSet<>();
        ids.add(attendanceGoOut.getId());
@@ -213,92 +259,121 @@
            throw new BadRequestException("外出时间冲突," + errorFormat.format(errorSysAskForLeave.getOutStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getOutEndTime())
                    + "已经存在外出记录,请调整时间");
        }else {
            //暂存userId
            Long resUserId = attendanceGoOut.getUserId();
            // 删除以前的记录
            for (Long id : ids) {
                attendanceGoOutRepository.deleteById(id);
            }
            // 获取当前登陆人信息,设置为请假发起人
            User user = userRepository.getOne(resources.getUserId());
            List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>();
            // 查询节假日
            List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
            for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){
                if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
                    //工作日
                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
                }else{
                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
                }
            }
            // 循环添加开始时间到结束时间的每一天
            List<String> dateList = attendanceLeaveService.getBetweenDate(resources.getOutStartTime().toLocalDateTime().toString(),resources.getOutEndTime().toLocalDateTime().toString());
            int i = 0;
            for(String date : dateList){
                LocalDate localDate = LocalDate.parse(date);
            User user = userRepository.getOne(resources.getUserId() == null ? SecurityUtils.getCurrentUserId() : resources.getUserId());
            LocalDate startDate = resources.getOutStartTime().toLocalDateTime().toLocalDate();
            LocalDate endDate = resources.getOutEndTime().toLocalDateTime().toLocalDate();
            LocalTime startTime = resources.getOutStartTime().toLocalDateTime().toLocalTime();
            LocalTime endTime = resources.getOutEndTime().toLocalDateTime().toLocalTime();
            long distance = ChronoUnit.DAYS.between(startDate, endDate);
            Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).forEach(localDate -> {
                SysConfigHolidayDto sysConfigHolidayDto = sysConfigHolidayService.queryByHolidayDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
                // 不是周末并且节假日表中不存在在创建
                if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
                    AttendanceGoOut attendanceGoOut1 = getAttendanceOut(resources,date,user,i,goStartTime,goEndTime,resUserId);
                    i++;
                if ((sysConfigHolidayDto == null && !isWeekend) ||
                        sysConfigHolidayDto != null && Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHolidayDto.getDateType())) {
                    AttendanceGoOut attendanceGoOut1 = new AttendanceGoOut();
                    //resUserId为null说明是添加,反之
                    if (resources.getUserId() == null) {
                        resources.setUserId(user.getId());
                    }
                    resources.setOutStartTime(Timestamp.valueOf(localDate.atTime(startTime)));
                    resources.setOutEndTime(Timestamp.valueOf(localDate.atTime(endTime)));
                    long timeSeconds = ChronoUnit.SECONDS.between(startTime, endTime);
                    Double result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                    resources.setOutDuration(result);
                    resources.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REVIEWED);
                    attendanceGoOut1.copy(resources);
                    attendanceGoOutRepository.save(attendanceGoOut1);
                }
            }
            });
//            //暂存userId
//            Long resUserId = attendanceGoOut.getUserId();
//            // 删除以前的记录
//            for (Long id : ids) {
//                attendanceGoOutRepository.deleteById(id);
//            }
//            // 获取当前登陆人信息,设置为请假发起人
//            User user = userRepository.getOne(resources.getUserId());
//            List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>();
//            // 查询节假日
//            List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
//            for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){
//                if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
//                    //工作日
//                    isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
//                }else{
//                    holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10));
//                }
//            }
//            // 循环添加开始时间到结束时间的每一天
//            List<String> dateList = attendanceLeaveService.getBetweenDate(resources.getOutStartTime().toLocalDateTime().toString(),resources.getOutEndTime().toLocalDateTime().toString());
//            int i = 0;
//            for(String date : dateList){
//                LocalDate localDate = LocalDate.parse(date);
//                Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
//                // 不是周末并且节假日表中不存在在创建
//                if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){
//                    AttendanceGoOut attendanceGoOut1 = getAttendanceOut(resources,date,user,i,goStartTime,goEndTime,resUserId);
//                    i++;
//                    attendanceGoOutRepository.save(attendanceGoOut1);
//                }
//            }
        }
    }
    /**
     * 添加多条记录
     * @param resources
     * @param date
     * @param user
     * @param i
     * @param LeaStartTime
     * @param LeaEndTime
     * @param resUserId
     * @return
     */
    public AttendanceGoOut getAttendanceOut(AttendanceGoOut resources,String date,User user,int i,String LeaStartTime,String LeaEndTime,Long resUserId){
        DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        AttendanceGoOut attendanceGoOut = new AttendanceGoOut();
        //resUserId为null说明是添加,反之
        if(resUserId == null){
            resources.setUserId(user.getId());
        }else{
            resources.setUserId(resUserId);
        }
            Calculate calculate = new Calculate();
            String startTime = date + " " + LeaStartTime.substring(11,19);
            String endTime = date + " " + LeaEndTime.substring(11,19);
            //外出开始时间结束时间不相等的情况
            if(!LeaStartTime.substring(0,10).equals(LeaEndTime.substring(0,10))){
                //第一次循环用下班基准时间和外出开始时间算时长
                if(i == 0){
                    calculate.setStart(LocalDateTime.parse(startTime,sdf));
                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00",sdf));
                    resources.setOutStartTime(Timestamp.valueOf(startTime));
                    resources.setOutEndTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkEndTime() + ":00"));
                }else if(date.equals(LeaEndTime.substring(0,10))){
                    //最后一次循环
                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00",sdf));
                    calculate.setEnd(LocalDateTime.parse(endTime,sdf));
                    resources.setOutStartTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkStartTime() + ":00"));
                    resources.setOutEndTime(Timestamp.valueOf(endTime));
                }else{
                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00",sdf));
                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00",sdf));
                    resources.setOutStartTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkStartTime() + ":00"));
                    resources.setOutEndTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkEndTime() + ":00"));
                }
                Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId());
                Double result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                resources.setOutDuration(result);
            }
        resources.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REVIEWED);
        attendanceGoOut.copy(resources);
        return attendanceGoOut;
    }
//    /**
//     * 添加多条记录
//     * @param resources
//     * @param date
//     * @param user
//     * @param i
//     * @param LeaStartTime
//     * @param LeaEndTime
//     * @param resUserId
//     * @return
//     */
//    public AttendanceGoOut getAttendanceOut(AttendanceGoOut resources, User user, LocalDateTime LeaStartTime, LocalDateTime LeaEndTime){
//        DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        AttendanceGoOut attendanceGoOut = new AttendanceGoOut();
//        //resUserId为null说明是添加,反之
//        if (resUserId == null) {
//            resources.setUserId(user.getId());
//        } else {
//            resources.setUserId(resUserId);
//        }
//            Calculate calculate = new Calculate();
//            String startTime = date + " " + LeaStartTime.substring(11,19);
//            String endTime = date + " " + LeaEndTime.substring(11,19);
//            //外出开始时间结束时间不相等的情况
//            if(!LeaStartTime.substring(0,10).equals(LeaEndTime.substring(0,10))){
//                //第一次循环用下班基准时间和外出开始时间算时长
//                if(i == 0){
//                    calculate.setStart(LocalDateTime.parse(startTime,sdf));
//                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00",sdf));
//                    resources.setOutStartTime(Timestamp.valueOf(startTime));
//                    resources.setOutEndTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkEndTime() + ":00"));
//                }else if(date.equals(LeaEndTime.substring(0,10))){
//                    //最后一次循环
//                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00",sdf));
//                    calculate.setEnd(LocalDateTime.parse(endTime,sdf));
//                    resources.setOutStartTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkStartTime() + ":00"));
//                    resources.setOutEndTime(Timestamp.valueOf(endTime));
//                }else{
//                    calculate.setStart(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkStartTime() + ":00",sdf));
//                    calculate.setEnd(LocalDateTime.parse(date + " " + user.getSysRostering().getWorkEndTime() + ":00",sdf));
//                    resources.setOutStartTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkStartTime() + ":00"));
//                    resources.setOutEndTime(Timestamp.valueOf(date + " " + user.getSysRostering().getWorkEndTime() + ":00"));
//                }
//                Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId());
//                Double result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
//                resources.setOutDuration(result);
//            }
//        resources.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REVIEWED);
//        attendanceGoOut.copy(resources);
//        return attendanceGoOut;
//    }
    /**
     * 验证其他状态的表是否有重复
@@ -385,12 +460,47 @@
        Calculate calculate = new Calculate();
        calculate.setStart(attendanceGoOut.getOutStartTime().toLocalDateTime());
        calculate.setEnd(attendanceGoOut.getOutEndTime().toLocalDateTime());
        Double result = new Double(0.00);
        Integer timeSeconds = attendanceService.calculateTimes(calculate, SecurityUtils.getCurrentUserId());
        result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
        long timeSeconds = calculateTimes(calculate, SecurityUtils.getCurrentUserId());
        Double result = Double.valueOf(new BigDecimal((float) timeSeconds / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
        return result;
    }
    private Long calculateTimes(Calculate calculate, Long userId) {
        User userInfo = userRepository.getOne(userId);
        SysRostering sysRostering = userInfo.getSysRostering();
        LocalDate startDate = calculate.getStart().toLocalDate();
        LocalDate endDate = calculate.getEnd().toLocalDate();
        LocalTime startTime = calculate.getStart().toLocalTime();
        LocalTime endTime = calculate.getEnd().toLocalTime();
        long distance = ChronoUnit.DAYS.between(startDate, endDate);
        return Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).map(localDate -> {
            SysConfigHolidayDto sysConfigHolidayDto = sysConfigHolidayService.queryByHolidayDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
            if ((sysConfigHolidayDto == null && !isWeekend) ||
                    sysConfigHolidayDto != null && Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHolidayDto.getDateType())) {
                LocalDateTime goOutStartTime = localDate.atTime(startTime);
                LocalDateTime goOutEndTime = localDate.atTime(endTime);
                LocalDateTime lunchStartTime = localDate.atTime(sysRostering.getLunchStartTime());
                LocalDateTime lunchEndTime = localDate.atTime(sysRostering.getLunchEndTime());
                if (goOutEndTime.isBefore(lunchStartTime) || goOutStartTime.isAfter(lunchEndTime)) {
                    return ChronoUnit.SECONDS.between(goOutStartTime, goOutEndTime);
                } else if (!goOutEndTime.isBefore(lunchStartTime) && !goOutEndTime.isAfter(lunchEndTime)) {
                    return ChronoUnit.SECONDS.between(goOutStartTime, lunchStartTime);
                } else if (!goOutStartTime.isBefore(lunchStartTime) && !goOutStartTime.isAfter(lunchEndTime)) {
                    return ChronoUnit.SECONDS.between(lunchEndTime, goOutEndTime);
                } else {
                    return ChronoUnit.SECONDS.between(goOutStartTime, goOutEndTime) - 3600;
                }
            }
            return 0L;
        }).reduce(0L, (result, current) -> result + current);
    }
    /**
     * 审核/撤销功能
     * @param resources /