Pu Zhibing
2025-08-05 16cee07f274c039bf0dcb5da347859053b7c2586
UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/pdf/TripSheetGenerator.java
@@ -43,7 +43,7 @@
            throw new IllegalArgumentException("订单列表不能为空");
        }
        String fileName = "行程单_" + UUID.randomUUID() + ".pdf";
        String fileName = "贵人家园行程单_" + UUID.randomUUID() + ".pdf";
        String filePath = pdfDir + fileName;
        File file = new File(filePath);
        FileUtils.forceMkdirParent(file);
@@ -142,12 +142,14 @@
        Font infoFont = getChineseFont(10, Font.NORMAL);
        // 申请时间现在的时间
        String applyTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
// 首先定义SimpleDateFormat(可以是类的静态成员)
        SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 行程时间格式化
        String tripTimeStart = first.getBoardingTime() != null
                ? DATE_TIME_FORMATTER.format(first.getBoardingTime()) : "N/A";
                ? DATE_FORMATTER.format(first.getBoardingTime()) : "N/A";
        String tripTimeEnd = last.getBoardingTime() != null
                ? DATE_TIME_FORMATTER.format(last.getBoardingTime()) : "N/A";
                ? DATE_FORMATTER.format(last.getBoardingTime()) : "N/A";
        String tripTime = tripTimeStart + " 至 " + tripTimeEnd;
        // 总金额计算(修复:先定义 totalText 并拼接内容)
@@ -261,7 +263,7 @@
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
        }
           SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 格式可根据需求调整
        // 单元格样式(居中对齐,统一处理)
        Font cellFont = getChineseFont(9, Font.NORMAL);
        for (int i = 0; i < orders.size(); i++) {
@@ -272,7 +274,7 @@
            addCenteredCell(table, order.getServerCarModel(), cellFont);
            addCenteredCell(table,
                    order.getBoardingTime() != null
                            ? DATE_TIME_FORMATTER.format(order.getBoardingTime())
                            ? DATE_FORMATTER.format(order.getBoardingTime())  // Date类型用SimpleDateFormat的format方法
                            : "N/A",
                    cellFont);
            addCenteredCell(table, order.getCity(), cellFont);
@@ -301,11 +303,6 @@
        table.addCell(cell);
    }
    private void addTableCell(PdfPTable table, String text, Font font) {
        PdfPCell cell = new PdfPCell(new Paragraph(text != null ? text : "", font));
        cell.setPadding(5);
        table.addCell(cell);
    }
    /**
     * 获取中文字体,优先自定义字体,fallback到 CJK 内置