From eb290fd6e70b6523ea0889936dba4d9f2d5c4b53 Mon Sep 17 00:00:00 2001
From: “mitao” <“2763622819@qq.com”>
Date: 星期二, 10 三月 2026 18:58:39 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpSchedulingDetailServiceImpl.java |  170 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 97 insertions(+), 73 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 2709dd2..042d2c0 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
@@ -32,6 +32,10 @@
 import com.xiaopeng.maintenance.service.IXpSchedulingService;
 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.ss.util.CellRangeAddress;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -182,6 +186,7 @@
 
     /**
      * 给每天的字段赋值
+     *
      * @param day
      * @param dto
      * @param map
@@ -286,6 +291,7 @@
 
     /**
      * 给每天的字段赋值
+     *
      * @param day
      * @param dto
      * @param shiftName
@@ -401,7 +407,7 @@
         List<XpSchedulingDetail> list = this.list(new QueryWrapper<XpSchedulingDetail>().eq("is_deleted", 0).last(" and DATE_FORMAT(plan_time,'%Y-%m') = '" + month + "'"));
         //保存排班数据
         XpScheduling xpScheduling = xpSchedulingService.getOne(new QueryWrapper<XpScheduling>().eq("is_deleted", 0).last(" and DATE_FORMAT(scheduling_date,'%Y-%m') = '" + month + "'"));
-        if(null == xpScheduling){
+        if (null == xpScheduling) {
             xpScheduling = new XpScheduling();
             xpScheduling.setDeleted(false);
             xpScheduling.setCreateTime(LocalDateTime.now());
@@ -434,23 +440,23 @@
                         && s.getPlanTime().equals(parse)
                 ).findAny().orElse(null);
                 //构建存储对象
-                if(null == schedulingDetail){
+                if (null == schedulingDetail) {
                     schedulingDetail = new XpSchedulingDetail();
                     schedulingDetail.setCreateBy(userId.toString());
                     schedulingDetail.setCreateTime(LocalDateTime.now());
                     schedulingDetail.setUpdateBy(userId.toString());
                     schedulingDetail.setUpdateTime(LocalDateTime.now());
                     schedulingDetail.setDeleted(false);
-                }else{
+                } else {
                     //构建通知消息
                     Long old_shiftId = schedulingDetail.getShiftId();
-                    if(!old_shiftId.equals(shiftId)){
+                    if (!old_shiftId.equals(shiftId)) {
                         //获取车队的所有人员
                         XpShift xpShift1 = xpShifts.stream().filter(s -> s.getId().equals(old_shiftId)).findAny().orElse(null);
                         XpShift xpShift2 = xpShifts.stream().filter(s -> s.getId().equals(shiftId)).findAny().orElse(null);
 
                         List<Long> operationsIds = xpFleetOperationsClient.getOperationsIdsByFleetId(fleetId).getData();
-                        if(null != operationsIds && !operationsIds.isEmpty()){
+                        if (null != operationsIds && !operationsIds.isEmpty()) {
                             List<XpOperationsUser> data1 = xpOperationUserClient.listByIds(operationsIds).getData();
                             for (XpOperationsUser xpOperationsUser : data1) {
                                 String nickName = xpOperationsUser.getNickName();
@@ -471,7 +477,7 @@
                 schedulingDetail.setShiftId(shiftId);
 
                 XpShift xpShift = xpShifts.stream().filter(s -> s.getId().equals(shiftId)).findAny().orElse(null);
-                if(null != xpShift){
+                if (null != xpShift) {
                     schedulingDetail.setIsAllDay(xpShift.getShiftName().contains("全天"));
                     schedulingDetail.setPlanTime(parse);
                     schedulingDetails.add(schedulingDetail);
@@ -479,7 +485,7 @@
             }
         }
         //批量保存排班明细数据
-        if(!schedulingDetails.isEmpty()){
+        if (!schedulingDetails.isEmpty()) {
             this.saveOrUpdateBatch(schedulingDetails);
         }
         //异步处理消息通知数据
@@ -490,11 +496,12 @@
 
     /**
      * 构建推送消息对象
+     *
      * @param message
      * @param xpOperationsUser
      * @return
      */
-    private AliPushMessageDTO buildPushMessage(String message, XpOperationsUser xpOperationsUser){
+    private AliPushMessageDTO buildPushMessage(String message, XpOperationsUser xpOperationsUser) {
         JSONObject body = new JSONObject();
         body.put("content", message);
         body.put("strategy", 4);
@@ -513,11 +520,12 @@
 
     /**
      * 构建消息存储
+     *
      * @param body
      * @param xpOperationsUser
      * @return
      */
-    private XpOperationsUserNotification buildXpOperationsUserNotification(String message, String body, XpOperationsUser xpOperationsUser){
+    private XpOperationsUserNotification buildXpOperationsUserNotification(String message, String body, XpOperationsUser xpOperationsUser) {
         XpOperationsUserNotification operationsUserNotification = new XpOperationsUserNotification();
         operationsUserNotification.setNotificationType(NotificationTypeEnum.SCHEDULE_CHANGED.getCode());
         operationsUserNotification.setNotificationContent(message);
@@ -530,11 +538,12 @@
 
     /**
      * 异步处理消息推送
+     *
      * @param pushMessage
      * @param notifications
      */
     private void pushMessage(List<AliPushMessageDTO> pushMessage, List<XpOperationsUserNotification> notifications) {
-        if(pushMessage.isEmpty()){
+        if (pushMessage.isEmpty()) {
             return;
         }
         ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
@@ -547,10 +556,9 @@
     }
 
 
-
-
     /**
      * 导出排班数据
+     *
      * @param month
      * @param response
      */
@@ -558,51 +566,80 @@
     public void exportExcel(String month, HttpServletResponse response) {
         PageInfo<SchedulingDetailDto> pageInfo = new PageInfo<>(0, 10000);
         List<SchedulingDetailDto> schedulingDetailDtos = this.baseMapper.pageList(pageInfo, month);
-        List<ExportSchedulingDetailDto> exportSchedulingDetailDtos = new ArrayList<>();
         //获取月份的最大天数
+        int m = Integer.parseInt(month.split("-")[1]);
         LocalDate parse1 = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
         int dayOfMonth = parse1.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
-        //构建表头第二行数据
-        ExportSchedulingDetailDto exportSchedulingDetailDto = new ExportSchedulingDetailDto();
-        exportSchedulingDetailDto.setFleetName("");
-        for (int i = 1; i <= dayOfMonth; i++) {
-            LocalDate parse = LocalDate.parse(month + "-" + String.format("%02d", i), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-            String week = "";
-            switch (parse.getDayOfWeek()){
-                case MONDAY:
-                    week = "一";
-                    break;
-                case TUESDAY:
-                    week = "二";
-                    break;
-                case WEDNESDAY:
-                    week = "三";
-                    break;
-                case THURSDAY:
-                    week = "四";
-                    break;
-                case FRIDAY:
-                    week = "五";
-                    break;
-                case SATURDAY:
-                    week = "六";
-                    break;
-                case SUNDAY:
-                    week = "日";
-                    break;
-            }
-            setEnglishDay(i, exportSchedulingDetailDto, week);
-        }
-        exportSchedulingDetailDto.setAllDay("全天");
-        exportSchedulingDetailDto.setMorning("早");
-        exportSchedulingDetailDto.setMidDay("中");
-        exportSchedulingDetailDto.setEvening("晚");
-        exportSchedulingDetailDtos.add(exportSchedulingDetailDto);
+        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
+        HSSFSheet hssfSheet = hssfWorkbook.createSheet();
+        hssfSheet.setColumnWidth(0, 6 * 256);
+        hssfSheet.setDefaultRowHeightInPoints(20f);
 
+        //添加第一行标题
+        HSSFRow hssfRow = hssfSheet.createRow(0);
+        List<XpShift> xpShifts = xpShiftService.list(new QueryWrapper<XpShift>().eq("is_deleted", 0));
+        //设置单元格数量
+        int totalCell = dayOfMonth + 1 + xpShifts.size();
+
+        //设置表头样式,合并单元格
+        CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
+        hssfSheet.addMergedRegion(region);
+        region = new CellRangeAddress(0, 1, dayOfMonth + 1, totalCell);
+        hssfSheet.addMergedRegion(region);
+
+
+        //设置单元格数据
+        for (int i = 0; i < totalCell; i++) {
+            HSSFCell cell = hssfRow.createCell(i);
+            if(0 == i){
+                cell.setCellValue("车队");
+            }else if(i <= dayOfMonth){
+                cell.setCellValue(m + "/" + i);
+            }else{
+                cell.setCellValue("排班小计");
+            }
+        }
+        //添加第二行标题
+        HSSFRow hssfRow1 = hssfSheet.createRow(1);
+        //设置单元格数量
+        //设置单元格数据
+        for (int i = 0; i < totalCell; i++) {
+            HSSFCell cell = hssfRow1.createCell(i);
+            if(i > 0 && i <= dayOfMonth){
+                LocalDate parse = LocalDate.parse(month + "-" + String.format("%02d", i), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+                String week = "";
+                switch (parse.getDayOfWeek()) {
+                    case MONDAY:
+                        week = "一";
+                        break;
+                    case TUESDAY:
+                        week = "二";
+                        break;
+                    case WEDNESDAY:
+                        week = "三";
+                        break;
+                    case THURSDAY:
+                        week = "四";
+                        break;
+                    case FRIDAY:
+                        week = "五";
+                        break;
+                    case SATURDAY:
+                        week = "六";
+                        break;
+                    case SUNDAY:
+                        week = "日";
+                        break;
+                }
+                cell.setCellValue(week);
+            }
+        }
         //构建数据部分的内容
+        int rowNum = 2;
         for (SchedulingDetailDto schedulingDetailDto : schedulingDetailDtos) {
-            exportSchedulingDetailDto = new ExportSchedulingDetailDto();
-            exportSchedulingDetailDto.setFleetName(schedulingDetailDto.getFleetName());
+            HSSFRow row = hssfSheet.createRow(rowNum);
+            row.createCell(0).setCellValue(schedulingDetailDto.getFleetName());
+
             String days = schedulingDetailDto.getDays();
             if (StringUtils.isNotBlank(days)) {
                 String[] split = days.split(",");
@@ -616,32 +653,19 @@
                             break;
                         }
                     }
-                    setEnglishDay(i, exportSchedulingDetailDto, shiftName);
+
+                    row.createCell(i).setCellValue(shiftName);
                 }
-                long allDay = list.stream().filter(s -> s.contains("全天")).count();
-                long morning = list.stream().filter(s -> s.contains("早")).count();
-                long midDay = list.stream().filter(s -> s.contains("中")).count();
-                long evening = list.stream().filter(s -> s.contains("晚")).count();
-                exportSchedulingDetailDto.setAllDay(allDay + "");
-                exportSchedulingDetailDto.setMorning(morning + "");
-                exportSchedulingDetailDto.setMidDay(midDay + "");
-                exportSchedulingDetailDto.setEvening(evening + "");
-            }else{
-                for (int i = 1; i <= 31; i++) {
-                    String shiftName = "休";
-                    setEnglishDay(i, exportSchedulingDetailDto, 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);
                 }
-                exportSchedulingDetailDto.setAllDay("0");
-                exportSchedulingDetailDto.setMorning("0");
-                exportSchedulingDetailDto.setMidDay("0");
-                exportSchedulingDetailDto.setEvening("0");
             }
-            exportSchedulingDetailDtos.add(exportSchedulingDetailDto);
         }
 
-        String[] split = month.split("-");
-        ExcelUtil<ExportSchedulingDetailDto> excelUtil = new ExcelUtil<>(ExportSchedulingDetailDto.class);
-        excelUtil.exportExcel(response, exportSchedulingDetailDtos, "排班计划[日期:" + split[0] + "年" + split[1] + "月]");
-
     }
+
+
 }

--
Gitblit v1.7.1