From ee756969610b6b0aaa39df85cebcdd0c8cef960e Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Thu, 16 Oct 2025 05:49:51 +0000
Subject: [PATCH] 企微通信redis锁问题修改

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/service/impl/UserLevelWageServiceImpl.java |   52 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/service/impl/UserLevelWageServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/service/impl/UserLevelWageServiceImpl.java
index 76849a2..7905158 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/service/impl/UserLevelWageServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/service/impl/UserLevelWageServiceImpl.java
@@ -21,6 +21,7 @@
 import me.zhengjie.modules.attendance.domain.AttendanceOvertime;
 import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository;
 import me.zhengjie.modules.attendance.repository.AttendanceOvertimeRepository;
+import me.zhengjie.modules.constant.Constant;
 import me.zhengjie.modules.system.domain.SysConfigProportion;
 import me.zhengjie.modules.system.domain.User;
 import me.zhengjie.modules.system.repository.SysConfigProportionRepository;
@@ -52,6 +53,7 @@
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * @author 姚增春
@@ -159,7 +161,7 @@
         return travelSubsidy;
     }
 
-        @Override
+    @Override
     public Double queryTravelAllowance(UserLevelWageQueryCriteria criteria) {
 
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -170,14 +172,46 @@
         LocalDateTime firstDayOfNextMonth = firstDayOfMonth.plusMonths(1);
 
         // 查询出差表的记录
-        Integer bussSameMonthDays = attendanceBusinessTravelRepository.findByUserIdAndYearMonth(criteria.getUserId(), firstDayOfMonth, firstDayOfNextMonth);
-        // 查询配置表
-        SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("出差补助金额");
+        List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserIdAndYearMonth(criteria.getUserId(), firstDayOfMonth, firstDayOfNextMonth);
+        // TODO:因一天可填多条出差记录,每条最小的时长是0.5天,导致可能会有当天总时长超出1天的情况。(每天出差类型只会有一种,不考虑多种的情况)
+        List<AttendanceBusinessTravel> calcAttendanceBusinessTravelList = attendanceBusinessTravelList.stream().collect(Collectors.groupingBy(
+                (AttendanceBusinessTravel businessTravel) -> businessTravel.getTravelStartTime().toLocalDateTime().toLocalDate().toString(),
+                Collectors.reducing(null, (AttendanceBusinessTravel prev, AttendanceBusinessTravel cur) -> {
+                    if (prev == null) {
+                        return cur;
+                    }
+                    // 计算工时
+                    prev.setTravelDuration(new BigDecimal(prev.getTravelDuration()).add(new BigDecimal(cur.getTravelDuration())).min(BigDecimal.ONE).doubleValue());
+                    return prev;
+                })
+        )).values().stream().collect(Collectors.toList());
+        Map<String, Double> attendanceBusinessTravelMap = calcAttendanceBusinessTravelList.stream().collect(Collectors.groupingBy(AttendanceBusinessTravel::getCategory, Collectors.summingDouble(AttendanceBusinessTravel::getTravelDuration)));
 
-        // 出差补助金
-        Double travelSubsidy = (bussSameMonthDays == null ? 0 : bussSameMonthDays) * sysConfigProportion.getProportion();
-
-        return travelSubsidy;
+        BigDecimal travelSubsidy = new BigDecimal(0.0);
+        for (Map.Entry<String, Double> entry : attendanceBusinessTravelMap.entrySet()) {
+            if (entry.getKey().equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_TRAVEL)) {
+                // 出差补助金
+                SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("出差补助金额");
+                travelSubsidy = travelSubsidy.add(BigDecimal.valueOf(entry.getValue() * sysConfigProportion.getProportion()));
+            } else if (entry.getKey().equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_SAME_PLACE)) {
+                // 客户现场补助金
+//                SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("客户现场补助金额");
+                travelSubsidy = travelSubsidy.add(BigDecimal.valueOf(entry.getValue() * 30)); // 按30元/天计算 TODO 待调整
+            }
+        }
+//        // 出差补助金
+//        attendanceBusinessTravelMap.forEach((key, value) -> {
+//            if (key.equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_TRAVEL)) {
+//                // 出差补助金
+//                SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("出差补助金额");
+//                travelSubsidy = travelSubsidy.add(BigDecimal.valueOf(value * sysConfigProportion.getProportion()));
+//            } else if (key.equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_SAME_PLACE)) {
+//                // 客户现场补助金
+////                SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("客户现场补助金额");
+//                travelSubsidy = travelSubsidy.add(BigDecimal.valueOf(value * 30)); // 按30元/天计算 TODO 待调整
+//            }
+//        });
+        return travelSubsidy.doubleValue();
     }
 
     @Override
@@ -265,7 +299,7 @@
         List<Map<String, Object>> list = new ArrayList<>();
         for (UserLevelWageDto userLevelWage : all) {
             // 将实体类转换成DTO
-            User user = userRepository.findById(userLevelWage.getUserId()).orElseGet(User::new);;
+            User user = userRepository.findById(userLevelWage.getUserId()).orElseGet(User::new);
 
             Map<String, Object> map = new LinkedHashMap<>();
             map.put("员工姓名", user.getNickName());

--
Gitblit v1.9.3