From 4d730af0447c686133130d0116a0fa3dd82c2dca Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Tue, 10 Nov 2026 01:41:03 +0000
Subject: [PATCH] Merge branch 'wcd-2411-update' into wcd

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceGoOutServiceImpl.java |  100 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 60 insertions(+), 40 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceGoOutServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceGoOutServiceImpl.java
index 957b05d..f4db864 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceGoOutServiceImpl.java
+++ b/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,43 +167,51 @@
         } 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();
             LocalTime startTime = resources.getOutStartTime().toLocalDateTime().toLocalTime();
             LocalTime endTime = resources.getOutEndTime().toLocalDateTime().toLocalTime();
             long distance = ChronoUnit.DAYS.between(startDate, endDate);
+            List<DictDetail> siteTypes = dictDetailRepository.findByDictName(Constant.APPROVAL_SITE_TYPE).stream().filter(siteType -> siteType.getValue().toLowerCase().equals("wecom")).collect(Collectors.toList());
             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说明是添加,反之
+                // resUserId为null说明是添加,反之
                 if (resources.getUserId() == null) {
                     resources.setUserId(user.getId());
                 }
-                resources.setOutStartTime(Timestamp.valueOf(localDate.atTime(startTime)));
-                resources.setOutEndTime(Timestamp.valueOf(localDate.atTime(endTime)));
+
+                LocalDateTime goOutStartTime = localDate.atStartOfDay();
+                LocalDateTime goOutEndTime = localDate.atTime(23, 59, 59);
+                if (localDate.equals(endDate)) {
+                    goOutEndTime = localDate.atTime(endTime);
+                }
+                if (localDate.equals(startDate)) {
+                    goOutStartTime = localDate.atTime(startTime);
+                }
+                resources.setOutStartTime(Timestamp.valueOf(goOutStartTime));
+                resources.setOutEndTime(Timestamp.valueOf(goOutEndTime));
 
                 Double result = getRemainingTime(resources);
                 resources.setOutDuration(result);
                 resources.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REVIEWED);
 
                 // 判断是否提交企微审批
-                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 {
@@ -278,7 +282,7 @@
         User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId());
         Role role = user1.getRoles().iterator().next();
         //除超管、总经理只能修改自己信息
-        if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) {
+        if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
             if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())) {
                 throw new BadRequestException("只能修改自己的记录");
             }
@@ -450,11 +454,11 @@
                 throw new BadRequestException("审核通过或退回的不能进行删除");
             }
 
-            //获取当前登入人信息
+            // 获取当前登入人信息
             User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
             Role role = user.getRoles().iterator().next();
-            //除超管、总经理只能删除自己信息
-            if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) {
+            // 除超管、总经理只能删除自己信息
+            if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
                 if (!Long.valueOf(attendanceGoOut.get().getUserId()).equals(SecurityUtils.getCurrentUserId())) {
                     throw new BadRequestException("只能删除自己的记录");
                 }
@@ -527,31 +531,47 @@
         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.atStartOfDay();
+            LocalDateTime goOutEndTime = localDate.atTime(LocalTime.MAX);
+            if (localDate.equals(endDate)) {
+                goOutEndTime = localDate.atTime(endTime);
             }
+            if (localDate.equals(startDate)) {
+                goOutStartTime = localDate.atTime(startTime);
+            }
+            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);
     }
 

--
Gitblit v1.9.3