| | |
| | | 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); |
| | |
| | | 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 并拼接内容) |
| | |
| | | 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++) { |
| | |
| | | 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); |
| | |
| | | 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 内置 |