From ef32f6913325bb593d537b4ff433545f73ecb79a Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 11 三月 2026 10:00:32 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpSchedulingDetailServiceImpl.java |   49 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpSchedulingDetailServiceImpl.java b/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpSchedulingDetailServiceImpl.java
index 042d2c0..637a99f 100644
--- a/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpSchedulingDetailServiceImpl.java
+++ b/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpSchedulingDetailServiceImpl.java
@@ -33,14 +33,16 @@
 import com.xiaopeng.maintenance.service.IXpShiftService;
 import com.xiaopeng.maintenance.vo.*;
 import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.ss.usermodel.CellType;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
+import java.net.URLEncoder;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -433,10 +435,12 @@
             List<SaveSchedulingDetailDay> days = data.getDays();
             for (SaveSchedulingDetailDay day : days) {
                 Long shiftId = day.getShiftId();
+                if(null == shiftId){
+                    continue;
+                }
                 LocalDate parse = LocalDate.parse(day.getDayTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 //查询判断数据是否存在
                 XpSchedulingDetail schedulingDetail = list.stream().filter(s -> s.getFleetId().equals(fleetId)
-                        && s.getShiftId().equals(shiftId)
                         && s.getPlanTime().equals(parse)
                 ).findAny().orElse(null);
                 //构建存储对象
@@ -479,9 +483,9 @@
                 XpShift xpShift = xpShifts.stream().filter(s -> s.getId().equals(shiftId)).findAny().orElse(null);
                 if (null != xpShift) {
                     schedulingDetail.setIsAllDay(xpShift.getShiftName().contains("全天"));
-                    schedulingDetail.setPlanTime(parse);
-                    schedulingDetails.add(schedulingDetail);
                 }
+                schedulingDetail.setPlanTime(parse);
+                schedulingDetails.add(schedulingDetail);
             }
         }
         //批量保存排班明细数据
@@ -571,9 +575,17 @@
         LocalDate parse1 = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
         int dayOfMonth = parse1.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
         HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
+        HSSFCellStyle cellStyle = hssfWorkbook.createCellStyle();
+        cellStyle.setAlignment(HorizontalAlignment.CENTER);
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
         HSSFSheet hssfSheet = hssfWorkbook.createSheet();
         hssfSheet.setColumnWidth(0, 6 * 256);
         hssfSheet.setDefaultRowHeightInPoints(20f);
+
+        HSSFCellStyle cellStyle1 = hssfWorkbook.createCellStyle();
+        cellStyle1.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.index);
+        cellStyle1.setAlignment(HorizontalAlignment.CENTER);
+        cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
 
         //添加第一行标题
         HSSFRow hssfRow = hssfSheet.createRow(0);
@@ -584,13 +596,14 @@
         //设置表头样式,合并单元格
         CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
         hssfSheet.addMergedRegion(region);
-        region = new CellRangeAddress(0, 1, dayOfMonth + 1, totalCell);
+        region = new CellRangeAddress(0, 1, dayOfMonth + 1, totalCell - 1);
         hssfSheet.addMergedRegion(region);
 
 
         //设置单元格数据
         for (int i = 0; i < totalCell; i++) {
             HSSFCell cell = hssfRow.createCell(i);
+            cell.setCellStyle(cellStyle1);
             if(0 == i){
                 cell.setCellValue("车队");
             }else if(i <= dayOfMonth){
@@ -605,6 +618,7 @@
         //设置单元格数据
         for (int i = 0; i < totalCell; i++) {
             HSSFCell cell = hssfRow1.createCell(i);
+            cell.setCellStyle(cellStyle1);
             if(i > 0 && i <= dayOfMonth){
                 LocalDate parse = LocalDate.parse(month + "-" + String.format("%02d", i), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 String week = "";
@@ -638,7 +652,9 @@
         int rowNum = 2;
         for (SchedulingDetailDto schedulingDetailDto : schedulingDetailDtos) {
             HSSFRow row = hssfSheet.createRow(rowNum);
-            row.createCell(0).setCellValue(schedulingDetailDto.getFleetName());
+            HSSFCell cell = row.createCell(0);
+            cell.setCellStyle(cellStyle);
+            cell.setCellValue(schedulingDetailDto.getFleetName());
 
             String days = schedulingDetailDto.getDays();
             if (StringUtils.isNotBlank(days)) {
@@ -654,17 +670,30 @@
                         }
                     }
 
-                    row.createCell(i).setCellValue(shiftName);
+                    HSSFCell cell1 = row.createCell(i);
+                    cell1.setCellValue(shiftName);
                 }
 
                 for (int i = 0; i < xpShifts.size(); i++) {
                     String shiftName = xpShifts.get(i).getShiftName();
                     long allDay = list.stream().filter(s -> s.contains(shiftName)).count();
-                    row.createCell(dayOfMonth + 1 + i).setCellValue(allDay + allDay);
+                    HSSFCell cell1 = row.createCell(dayOfMonth + 1 + i);
+                    cell1.setCellStyle(cellStyle);
+                    cell1.setCellValue(shiftName + " " + allDay);
                 }
             }
+            rowNum++;
         }
-
+        try {
+            response.setContentType("application/vnd.ms-excel");
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("排班计划管理.xls", "UTF-8"));
+            ServletOutputStream outputStream = response.getOutputStream();
+            hssfWorkbook.write(outputStream);
+            outputStream.flush();
+            outputStream.close();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
     }
 
 

--
Gitblit v1.7.1