gaoluyang
10 天以前 344a18cc69dd2f728734e940421b717cacb85563
src/main/java/com/ruoyi/staff/service/impl/PersonalShiftServiceImpl.java
@@ -156,6 +156,12 @@
                }
            }
        }
        // 合计出勤天数以实际打卡记录为准(排班只代表计划)
        Map<String, Integer> attendanceDays = loadMonthAttendanceDays(time, userName, sysDeptId);
        for (PerformanceShiftMapDto i : mapIPage.getRecords()) {
            i.getMonthlyAttendance().put("totalAttendance",
                    attendanceDays.getOrDefault(i.getUserId(), 0));
        }
        // 获取header时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -190,7 +196,8 @@
        IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, sysDeptId);
        //查询所有班次(打卡规则)
        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null);
        mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), personalAttendanceLocationConfigs));
        Map<String, Map<Integer, Integer>> attendanceCounts = loadYearAttendanceDays(time, userName, sysDeptId);
        mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), personalAttendanceLocationConfigs, attendanceCounts));
        return mapYearIPage;
    }
@@ -204,7 +211,8 @@
        LocalDateTime localDateTime = LocalDateTime.parse(time, formatters);
        map.put("header", getYearHeader(localDateTime.getYear() + " 年", personalAttendanceLocationConfigs));
        List<Map<String, Object>> mapYearList = baseMapper.performanceShiftYearList(time, userName, sysDeptId);
        annualAttendanceProcessing(mapYearList, personalAttendanceLocationConfigs);
        Map<String, Map<Integer, Integer>> attendanceCounts = loadYearAttendanceDays(time, userName, sysDeptId);
        annualAttendanceProcessing(mapYearList, personalAttendanceLocationConfigs, attendanceCounts);
        List<List<Object>> lists = dataRequiredForProcessingIntoExcel(mapYearList, personalAttendanceLocationConfigs);
        map.put("data", lists);
        return map;
@@ -215,6 +223,8 @@
        //查询所有班次(打卡规则)
        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null);
        List<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftList(time, userName, sysDeptId);
        // 合计出勤天数以实际打卡记录为准(排班只代表计划)
        Map<String, Integer> attendanceDays = loadMonthAttendanceDays(time, userName, sysDeptId);
        mapIPage.forEach(i -> {
            String[] shiftTimes = i.getShiftTime().split(";");
            double totalAttendance = 0;
@@ -249,6 +259,8 @@
            }
            i.setList(map);
            i.setShiftTime(null);
            i.getMonthlyAttendance().put("totalAttendance",
                    attendanceDays.getOrDefault(i.getUserId(), 0));
        });
        Map<Object, Object> map = new HashMap<>();
        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -270,16 +282,46 @@
        return map;
    }
    // 实际打卡出勤天数(按月)
    private Map<String, Integer> loadMonthAttendanceDays(String time, String userName, Integer sysDeptId) {
        Map<String, Integer> result = new HashMap<>();
        for (Map<String, Object> row : baseMapper.attendanceDayCountByMonth(time, userName, sysDeptId)) {
            Object userId = row.get("user_id");
            Object days = row.get("days");
            if (userId != null && days != null) {
                result.put(String.valueOf(userId), new BigDecimal(days.toString()).intValue());
            }
        }
        return result;
    }
    // 实际打卡出勤天数(按年,每人每月)
    private Map<String, Map<Integer, Integer>> loadYearAttendanceDays(String time, String userName, Integer sysDeptId) {
        Map<String, Map<Integer, Integer>> result = new HashMap<>();
        for (Map<String, Object> row : baseMapper.attendanceMonthCountByYear(time, userName, sysDeptId)) {
            Object userId = row.get("user_id");
            Object month = row.get("month");
            Object days = row.get("days");
            if (userId == null || month == null || days == null) {
                continue;
            }
            result.computeIfAbsent(String.valueOf(userId), k -> new HashMap<>())
                    .put(Integer.parseInt(month.toString()), new BigDecimal(days.toString()).intValue());
        }
        return result;
    }
    // 年分页与导出共同使用
    public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList,List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) {
    public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList, List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs, Map<String, Map<Integer, Integer>> attendanceCounts) {
        for (Map<String, Object> map : mapYearList) {
            Map<String, Object> resultMap = new LinkedHashMap<>();
            Map<String, Object> hashMapYear = new LinkedHashMap<>();
            double totalYearAttendance = 0;
            // 每个月的合计出勤天数以实际打卡记录为准
            Map<Integer, Integer> staffMonthAttendance = attendanceCounts.getOrDefault(String.valueOf(map.get("user_id")), Collections.emptyMap());
            // 一年12个月
            for (int i = 1; i < 13; i++) {
                Map<String, Object> hashMapMonth = new LinkedHashMap<>();
                double totalMonthAttendance = 0;
                for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) {
                    // 初始化赋值
                    if (!hashMapYear.containsKey(personalAttendanceLocationConfig.getShift())){
@@ -291,14 +333,6 @@
                        int count = countOccurrences(charArray, i + ":" + personalAttendanceLocationConfig.getShift());
                        hashMapMonth.put(personalAttendanceLocationConfig.getShift(), count);
                        hashMapYear.put(personalAttendanceLocationConfig.getShift(), new BigDecimal(hashMapYear.get(personalAttendanceLocationConfig.getShift()).toString()).add(new BigDecimal(count)));
                        // 早,中,夜,差
                        if (personalAttendanceLocationConfig.getShift().contains("早") ||
                                personalAttendanceLocationConfig.getShift().contains("中") ||
                                personalAttendanceLocationConfig.getShift().contains("晚") ||
                                personalAttendanceLocationConfig.getShift().contains("夜")) {
                            totalMonthAttendance += count;
                            totalYearAttendance += count;
                        }
                    }
                    // 空数据
                    else {
@@ -306,7 +340,9 @@
                        hashMapMonth.put(personalAttendanceLocationConfig.getShift(), 0);
                    }
                }
                hashMapMonth.put("totalMonthAttendance", totalMonthAttendance);
                int monthAttendance = staffMonthAttendance.getOrDefault(i, 0);
                totalYearAttendance += monthAttendance;
                hashMapMonth.put("totalMonthAttendance", monthAttendance);
                hashMapYear.put("totalYearAttendance", totalYearAttendance);
                resultMap.put(i + "", hashMapMonth);
            }