BAOLH
2025-09-22 dac503c1ce37ca44c8a69dabfd432dea7d3d794e
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceGoOutServiceImpl.java
@@ -74,13 +74,9 @@
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;
    private final SysConfigHolidayRepository sysConfigHolidayRepository;
    private final AttendanceLeaveServiceImpl attendanceLeaveService;
    private final AttendanceRepository attendanceRepository;
    private final AttendanceLeaveRepository attendanceLeaveRepository;
    private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
    private final ApproveEventRepository approveEventRepository;
@@ -171,6 +167,7 @@
        } else {
            // 获取当前登陆人信息,设置为请假发起人
            User user = userRepository.getOne(resources.getUserId() == null ? SecurityUtils.getCurrentUserId() : resources.getUserId());
            User approvalUser = userRepository.getOne(resources.getApprovalUserId());
            LocalDate startDate = resources.getOutStartTime().toLocalDateTime().toLocalDate();
            LocalDate endDate = resources.getOutEndTime().toLocalDateTime().toLocalDate();
@@ -197,17 +194,15 @@
                // 判断是否提交企微审批
                List<DictDetail> siteTypes = dictDetailRepository.findByDictName(Constant.APPROVAL_SITE_TYPE).stream().filter(siteType -> siteType.getValue().toLowerCase().equals("wecom")).collect(Collectors.toList());
                if (siteTypes.size() > 0) {
                    // 企微申请时审批人需要默认值
                    resources.setApprovalUserId(0L);
                    // 添加企微申请参数
                    resources.setWecomType(dictDetailRepository.findByDictNameAndValue("go_out_type", resources.getOutOfOfficeType()).getLabel());
                    resources.setWecomLocation("暂无");
                    resources.setWecomDateType(ElAdminConstant.Constant.TEMPLATE_DATE_TYPE_HOUR);
                    resources.setWecomDateType(ElAdminConstant.Constant.TEMPLATE_DATE_RANGE_TYPE_HOUR);
                    resources.setWecomDuration(String.valueOf(new BigDecimal(resources.getOutDuration()).multiply(new BigDecimal(3600)).longValue()));
                    resources.setWecomAttendanceType("4");
                    resources.setWecomApproveWecomId(approvalUser.getWeComId());
                    // 提交申请
                    String weComId = userRepository.findById(resources.getUserId()).orElse(new User()).getWeComId();
                    Map<String, String> approvalResultMap = templateControlFieldService.createWecomApproval(resources, weComId);
                    Map<String, String> approvalResultMap = templateControlFieldService.createWecomApproval(resources, user.getWeComId());
                    if (approvalResultMap.containsKey("spNo")) {
                        resources.setWecomSpNo(approvalResultMap.get("spNo"));
                    } else {
@@ -527,31 +522,41 @@
        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())) {
//            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;
//                }
//            } else {
//                LocalDateTime goOutStartTime = localDate.atTime(startTime);
//                LocalDateTime goOutEndTime = localDate.atTime(endTime);
//                return ChronoUnit.SECONDS.between(goOutStartTime, goOutEndTime);
//            }
                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;
                }
            } else {
                LocalDateTime goOutStartTime = localDate.atTime(startTime);
                LocalDateTime goOutEndTime = localDate.atTime(endTime);
                return ChronoUnit.SECONDS.between(goOutStartTime, goOutEndTime);
            }
            // TODO:20250806修改 减去下班后休息时段
            LocalDateTime goOutStartTime = localDate.atTime(startTime);
            LocalDateTime goOutEndTime = localDate.atTime(endTime);
            LocalDateTime lunchStartTime = localDate.atTime(sysRostering.getLunchStartTime());
            LocalDateTime lunchEndTime = localDate.atTime(sysRostering.getLunchEndTime());
            LocalDateTime offStartTime = localDate.atTime(sysRostering.getWorkEndTime());
            LocalDateTime offEndTime = offStartTime.plusMinutes(30L);
            Duration duration = Calculate.calculateRemainingDuration(new Calculate(goOutStartTime, goOutEndTime), new Calculate(lunchStartTime, lunchEndTime), new Calculate(offStartTime, offEndTime));
            return duration.get(ChronoUnit.SECONDS);
        }).reduce(0L, (result, current) -> result + current);
    }