Jelajahi Sumber

加班申请报表导出12.22改动

lxy_01 2 minggu lalu
induk
melakukan
727a8df5d7

+ 33 - 12
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/WorkOvertimeController.java

@@ -204,6 +204,12 @@ public class WorkOvertimeController {
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", targetUser.getCompanyId()));
             Company company = companyMapper.selectById(targetUser.getCompanyId());
 
+            /*
+            导出的部门顺序写死
+            * */
+            String[] departmentReportOV = {"生产办公室","维修班","折弯成型工位","下料工位","数控加工工位","铆焊一工位","铆焊二工位","铆焊三工位","铆焊四工位","铆焊五工位","铆焊六工位"
+                    ,"牵枕缓一工位","牵枕缓二工位","车顶工位","动车车钩工位","司机室工位","搅拌摩擦焊工位","组装工位","硫化工位","机加工工位","热处理工位"};
+
             //非管理员只能看到自己的
             if (!targetUser.getRoleName().equals("超级管理员") && !targetUser.getRoleName().equals("系统管理员") && !sysFunctionService.hasPriviledge(targetUser.getRoleId(),"查看全部人员加班")) {
                 applicant = token;
@@ -280,25 +286,40 @@ public class WorkOvertimeController {
                     }
                 }
 
-
                 /*
-                * 每日加班申请按照部门id-加班时段排序
+                * 每日加班申请按照部门写死的顺排序
                 * */
-                dateOvertimes.sort((s1,s2) ->{
-                    int res = -1;
-                    if(s1.getWorkstationId() != null && s2.getWorkstationId() != null){
-                        res = s1.getWorkstationId().compareTo(s2.getWorkstationId());
+                List<Map.Entry<String,List<WorkOvertime>>> worksationMaps = new ArrayList<>();
+                for (String s : departmentReportOV) {
+                    Integer departmentId;
+                    List<Department> departments = departmentMapper.selectList(new QueryWrapper<Department>().eq("department_name", s));
+                    if (departments != null && !departments.isEmpty()) {
+                        departmentId = departments.get(0).getDepartmentId();
+                    } else {
+                        departmentId = null;
                     }
-                    if(res == 0){
-                        if (s1.getTimeTypeId() != null && s2.getTimeTypeId() != null) {
-                            res = s1.getTimeTypeId().compareTo(s2.getTimeTypeId());
+                    /*
+                    只有找到对应的需要导出的记录才增加数据
+                    * */
+                    if (departmentId != null) {
+                        List<WorkOvertime>  list =
+                                dateOvertimes.stream().filter(workOvertime -> workOvertime.getWorkstationId().equals(departmentId)).sorted(Comparator.comparing(WorkOvertime::getTimeTypeId)).collect(Collectors.toList());
+                        /*
+                        只有找到对应的需要导出的记录才增加数据
+                        * */
+                        if (!list.isEmpty()) {
+                            worksationMaps.add(new AbstractMap.SimpleEntry<>(s,list));
                         }
                     }
-                    return res;
-                });
+                }
+
+                List<WorkOvertime> dateOvertimesResult = new ArrayList<>();
+                for (Map.Entry<String,List<WorkOvertime>> entry :worksationMaps){
+                    dateOvertimesResult.addAll(entry.getValue());
+                }
 
                 List<ExcelUtil.WorkstationData> workstationDataList = new ArrayList<>();
-                for (WorkOvertime workOvertime : dateOvertimes) {
+                for (WorkOvertime workOvertime : dateOvertimesResult) {
                     ExcelUtil.WorkstationData overtimeStatisticsData = createWorkstationData(workOvertime);
                     if(overtimeStatisticsData == null){
                         continue;

+ 44 - 3
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/ExcelUtil.java

@@ -921,6 +921,7 @@ public class ExcelUtil {
                 List<WorkstationData> workstations = dateData.getWorkstations();
                 
                 int dateStartRow = currentRow; // 记录当前日期开始的行号
+                int workstationStartRow = dateStartRow;//记录当前日期开始的行号,作为第一个worK
                 
                 for (WorkstationData workstation : workstations) {
                     Row dataRow = sheet.createRow(currentRow++);
@@ -961,7 +962,12 @@ public class ExcelUtil {
                     // 人员
                     Cell employeesCell = dataRow.createCell(6);
                     employeesCell.setCellStyle(cellStyle);
-                    employeesCell.setCellValue(workstation.getEmployees());
+                    String employees = "";
+                    employees = workstation.getEmployees();
+                    if (employees.length() > 1) {
+                        employees = employees.substring(1, employees.length() - 1);
+                    }
+                    employeesCell.setCellValue(employees);
                     
                     // 任务安排
                     Cell taskCell = dataRow.createCell(7);
@@ -976,9 +982,38 @@ public class ExcelUtil {
                     // 备注
                     Cell remarksCell = dataRow.createCell(9);
                     remarksCell.setCellStyle(cellStyle);
-                    remarksCell.setCellValue("");
+                    if(workstation.getWorkstationName().equals("搅拌摩擦焊工位")){
+                        remarksCell.setCellValue("不在高新厂区用餐");
+                    }
+                    else {
+                        remarksCell.setCellValue("");
+                    }
+
+                }
+                List<Integer> countList = new ArrayList<>();
+                if (workstations != null && !workstations.isEmpty()) {
+                    String currentWorkName = workstations.get(0).getWorkstationName();
+                    int currentCount = 1;
+
+                    // 从第二个元素开始遍历(索引从1开始)
+                    for (int i = 1; i < workstations.size(); i++) {
+                        WorkstationData currentData = workstations.get(i);
+                        String workName = currentData.getWorkstationName();
+
+                        // 如果当前元素的workId和基准workId相同,计数+1
+                        if (currentWorkName.equals(workName)) {
+                            currentCount++;
+                        } else {
+                            // 不同则将当前计数存入结果列表,更新基准workId和计数
+                            countList.add(currentCount);
+                            currentWorkName = workName;
+                            currentCount = 1;
+                        }
+                    }
+
+                    // 遍历结束后,将最后一个workId的计数存入结果列表(容易遗漏)
+                    countList.add(currentCount);
                 }
-                
                 // 添加合计行
                 if (!workstations.isEmpty()) {
                     Row totalRow = sheet.createRow(currentRow++);
@@ -1023,6 +1058,12 @@ public class ExcelUtil {
                 if (dateEndRow > dateStartRow) {
                     dateMergeRanges.add(new CellRangeAddress(dateStartRow, dateEndRow, 0, 0));
                 }
+                for(Integer length :countList) {
+                    if (length > 1){
+                        dateMergeRanges.add(new CellRangeAddress(workstationStartRow, workstationStartRow + length - 1, 1, 1));
+                    }
+                    workstationStartRow += length;
+                }
             }
             
             // 执行日期列的单元格合并