Преглед изворни кода

考勤导出修改20260106

lxy_01 пре 6 дана
родитељ
комит
e406fe7394

+ 42 - 8
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/AttendanceServiceImpl.java

@@ -71,6 +71,9 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
     @Resource
     WxCorpInfoMapper wxCorpInfoMapper;
 
+    @Resource
+    private AttendanceMapper attendanceMapper;
+
     private static final List<String> holidays = Arrays.asList("2025-01-01",
             "2025-01-28", "2025-01-29", "2025-01-30", "2025-01-31", "2025-02-03", "2025-02-04",
             "2025-04-04",
@@ -261,6 +264,7 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
         List<Department> departmentList = departmentService.list(new QueryWrapper<Department>());
         List<AttendanceStaff> staffList = attendanceStaffService.list(new QueryWrapper<AttendanceStaff>().between("clock_date", firstDay, lastDay));
         List<ApplyForm> applyFormList = applyFormService.getListByFirstDateAndLastDate(startDate, endDate);
+        List<Attendance>  attendanceList = attendanceMapper.selectList(new QueryWrapper<Attendance>().between("clock_time", startDate.atStartOfDay(), endDate.atStartOfDay()));//enddate为下月第一天
         //对于请假,按照交叉的部分重新计算时长
         for (ApplyForm applyForm : applyFormList) {
             if (applyForm.getType() == 3) {
@@ -308,9 +312,14 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
             strings.add(u.getInactiveDate()==null?"":u.getInactiveDate().format(formatter1));//离职日期
             strings.add("");//备注
 
-            List<AttendanceStaff> staffCollect = staffList.stream().filter(s -> s.getJobNumber().equals(u.getJobNumber())).collect(Collectors.toList());
+            List<AttendanceStaff> staffCollect = staffList.stream().filter(s -> s.getJobNumber().equalsIgnoreCase(u.getJobNumber())).collect(Collectors.toList());
             List<AttendanceStaff> workDaysCollect = staffCollect.stream().filter(s -> s.getAttendanceType() != 12).collect(Collectors.toList());
             strings.add(workDaysCollect.size()+"");//实际出勤天
+            if(u.getJobNumber().equals("LEW3385")){
+                for (AttendanceStaff staff : workDaysCollect) {
+                    System.out.println(staff.getJobNumber());
+                }
+            }
 
             BigDecimal total8 = getDecimal(applyFormList,"病假",u.getJobNumber());
             strings.add(total8.toString());
@@ -588,17 +597,42 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
             }
             strings.add(countLess+"");
             strings.add(countMore+"");
-            List<ApplyForm> fixDakaCollection = applyFormList.stream().filter(a -> a.getType() == 6&&a.getApplyId().equals(u.getJobNumber())).collect(Collectors.toList());
-            List<ApplyForm> qingjiaCollection = applyFormList.stream().filter(a -> a.getType() == 3&&a.getApplyId().equals(u.getJobNumber())).collect(Collectors.toList());
+            List<ApplyForm> fixDakaCollection = applyFormList.stream().filter(a -> a.getType() == 6&&a.getApplyId().equalsIgnoreCase(u.getJobNumber())).collect(Collectors.toList());
+            List<ApplyForm> qingjiaCollection = applyFormList.stream().filter(a -> a.getType() == 3&&a.getApplyId().equalsIgnoreCase(u.getJobNumber())).collect(Collectors.toList());
             List<AttendanceStaff> unDaKacollect = staffCollect.stream().filter(s -> s.getClockStartTime() == null || s.getClockEndTime() == null).collect(Collectors.toList());
             //两次没打卡,视为旷工,1次则为未打卡
-            int kuanggongCount = (int) unDaKacollect.stream().filter(un -> un.getClockStartTime() == null && un.getClockEndTime() == null && !fixDakaCollection.stream().anyMatch(fix -> fix.getStartTime().toLocalDate().equals(un.getClockDate()))).count();
-            unDaKacollect = unDaKacollect.stream().filter(un->(un.getClockStartTime() != null || un.getClockEndTime() != null )&& !fixDakaCollection.stream().anyMatch(fix->fix.getStartTime().toLocalDate().equals(un.getClockDate()))).collect(Collectors.toList());
-            strings.add(unDaKacollect.size()+"");
 
+            /*
+            处理只打了1次卡,没有记录入attendance_staff表的情况
+            * */
+            List<Attendance> attendances = attendanceList.stream().filter(attendance -> attendance.getJobNumber().equalsIgnoreCase(u.getJobNumber())).collect(Collectors.toList());
+
+            Map<LocalDate, List<Attendance>> dailyAttendances = attendances.stream().collect(Collectors.groupingBy(attendance -> {
+                //7点以前,算前一天的打卡
+                if (attendance.getClockTime().getHour() <= 6) {
+                    return attendance.getClockTime().toLocalDate().minusDays(1);
+                }
+                else {
+                    return attendance.getClockTime().toLocalDate();
+                }
+            }));
+            //工作日列表
             List<LocalDate> workDaysListInRange = WorkDayCalculateUtils.getWorkDaysListInRange(((LocalDate)monthInfo.get("firstDay")).toString(),((LocalDate)monthInfo.get("lastDay")).toString(),2);
+
+            Set<Map.Entry<LocalDate, List<Attendance>>> onceAttendance = dailyAttendances.entrySet().stream()
+                    .filter(entry -> workDaysListInRange.stream().anyMatch(workDay -> workDay.equals(entry.getKey()))
+                    )
+                    .filter(entry -> entry.getValue().size() == 1
+                            && staffCollect.stream()
+                            .noneMatch(unDaKa -> unDaKa.getClockDate().equals(entry.getKey()))
+                    ).collect(Collectors.toSet());
+
+            int kuanggongCount = (int) unDaKacollect.stream().filter(un -> un.getClockStartTime() == null && un.getClockEndTime() == null && !fixDakaCollection.stream().anyMatch(fix -> fix.getStartTime().toLocalDate().equals(un.getClockDate()))).filter(un-> workDaysListInRange.stream().anyMatch(workDay->workDay.equals(un.getClockDate()))).count();
+            unDaKacollect = unDaKacollect.stream().filter(un->(un.getClockStartTime() != null || un.getClockEndTime() != null )&& !fixDakaCollection.stream().anyMatch(fix->fix.getStartTime().toLocalDate().equals(un.getClockDate()))).collect(Collectors.toList());
+            int unDaKaco = unDaKacollect.size() + onceAttendance.size();
+            strings.add(unDaKaco + "");
             kuanggongCount += workDaysListInRange.stream().filter(wD -> staffCollect.stream().noneMatch(sC -> sC.getClockDate().equals(wD)) && fixDakaCollection.stream().noneMatch(aF -> aF.getStartTime().toLocalDate().equals(wD))  && qingjiaCollection.stream().noneMatch(aF -> aF.getStartTime().toLocalDate().equals(wD))).collect(Collectors.toList()).size();
-            strings.add(kuanggongCount + "");
+            //strings.add(kuanggongCount + "");
             strings.set(12,kuanggongCount * 8.0 + "");
             int xiaoyeCount = (int) staffCollect.stream().filter(s -> s.getAttendanceTypeName() != null && s.getAttendanceTypeName().contains("小夜班")).count();
             int dayeCount = (int) staffCollect.stream().filter(s -> s.getAttendanceTypeName() != null && s.getAttendanceTypeName().contains("大夜班")).count();
@@ -608,7 +642,7 @@ public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attenda
             strings.add(xiaoyeCount+"");//小夜班
             strings.add(dayeCount+"");//大夜班
 
-            List<ApplyForm> jiabanList = applyFormList.stream().filter(a -> a.getType() == 4 && a.getApplyId().equals(u.getJobNumber())).collect(Collectors.toList());
+            List<ApplyForm> jiabanList = applyFormList.stream().filter(a -> a.getType() == 4 && a.getApplyId().equalsIgnoreCase(u.getJobNumber())).collect(Collectors.toList());
             BigDecimal zhouMoSum = jiabanList.stream().filter(a -> (a.getStartTime().toLocalDate().getDayOfWeek() == DayOfWeek.SATURDAY || a.getStartTime().toLocalDate().getDayOfWeek() == DayOfWeek.SUNDAY))
                     .map(ApplyForm::getSumTime)
                     .reduce(BigDecimal.ZERO, BigDecimal::add);

+ 8 - 12
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/ExcelUtil.java

@@ -661,7 +661,7 @@ public class ExcelUtil {
 
             // 创建表头行第一行
             Row headerRowFirst = sheetOne.createRow(0);
-            int totalCount=28;
+            int totalCount=27;
             for (int i = 0; i < totalCount; i++) {
                 Cell cell = headerRowFirst.createCell(i);
                 cell.setCellStyle(headStyle);
@@ -754,15 +754,13 @@ public class ExcelUtil {
                     cell.setCellValue("加班数据/h");
                 }else if (i==26){
                     cell.setCellValue("");
-                }else if (i==27){
-                    cell.setCellValue("");
                 }else {
                     cell.setCellValue("");
                 }
             }
-            sheetOne.addMergedRegion(new CellRangeAddress(2, 2, 18, 21));//合并第三行
-            sheetOne.addMergedRegion(new CellRangeAddress(2, 2, 22, 24));//合并第三行
-            sheetOne.addMergedRegion(new CellRangeAddress(2, 2, 25, 27));//合并第三行
+            sheetOne.addMergedRegion(new CellRangeAddress(2, 2, 18, 20));//合并第三行
+            sheetOne.addMergedRegion(new CellRangeAddress(2, 2, 21, 23));//合并第三行
+            sheetOne.addMergedRegion(new CellRangeAddress(2, 2, 24, 26));//合并第三行
 
             // 创建表头行第二行
             Row headerRowFourth = sheetOne.createRow(3);
@@ -778,16 +776,14 @@ public class ExcelUtil {
                 }else if (i==20){
                     cell.setCellValue("未打卡");
                 }else if (i==21){
-                    cell.setCellValue("旷工");
-                }else if (i==22){
                     cell.setCellValue("其他/H");
-                }else if (i==23){
+                }else if (i==22){
                     cell.setCellValue("车间小夜");
-                }else if (i==24){
+                }else if (i==23){
                     cell.setCellValue("车间大夜");
-                }else if (i==25){
+                }else if (i==24){
                     cell.setCellValue("周末");
-                }else if (i==26){
+                }else if (i==25){
                     cell.setCellValue("法定");
                 }else {
                     cell.setCellValue("平时");