From 2d9cfcdb467197d501d8850a550609eb2014e803 Mon Sep 17 00:00:00 2001 From: "B.E.N.S.O.N" Date: Thu, 9 Apr 2026 17:21:08 +0800 Subject: [PATCH] TruckRoutingSummary Update --- .../web/TruckRoutingSummaryController.kt | 56 +++++++++-- .../DeliveryNote/TruckRoutingSummaryPDF.jrxml | 94 +++++++++---------- 2 files changed, 90 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/ffii/fpsms/modules/deliveryOrder/web/TruckRoutingSummaryController.kt b/src/main/java/com/ffii/fpsms/modules/deliveryOrder/web/TruckRoutingSummaryController.kt index 99d5177..3890e46 100644 --- a/src/main/java/com/ffii/fpsms/modules/deliveryOrder/web/TruckRoutingSummaryController.kt +++ b/src/main/java/com/ffii/fpsms/modules/deliveryOrder/web/TruckRoutingSummaryController.kt @@ -1,6 +1,8 @@ package com.ffii.fpsms.modules.deliveryOrder.web import com.ffii.fpsms.modules.deliveryOrder.service.TruckRoutingSummaryService +import com.ffii.fpsms.modules.master.print.A4PrintDriverRegistry +import com.ffii.fpsms.modules.master.service.PrinterService import com.ffii.fpsms.modules.report.service.ReportService import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus @@ -10,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController +import java.io.File import java.time.LocalDate import java.time.format.DateTimeFormatter @@ -18,6 +21,7 @@ import java.time.format.DateTimeFormatter class TruckRoutingSummaryController( private val truckRoutingSummaryService: TruckRoutingSummaryService, private val reportService: ReportService, + private val printerService: PrinterService, ) { @GetMapping("/store-options") fun getStoreOptions(): List> = @@ -35,12 +39,53 @@ class TruckRoutingSummaryController( @RequestParam(required = false) truckLanceCode: String?, @RequestParam(required = false) date: String? ): ResponseEntity { + val pdfBytes = buildTruckRoutingSummaryPdf(storeId, truckLanceCode, date) + + val headers = HttpHeaders().apply { + contentType = MediaType.APPLICATION_PDF + setContentDispositionFormData("attachment", "TruckRoutingSummary.pdf") + set("filename", "TruckRoutingSummary.pdf") + } + return ResponseEntity(pdfBytes, headers, HttpStatus.OK) + } + + @GetMapping("/print-direct") + fun printDirect( + @RequestParam printerId: Long, + @RequestParam(required = false) printQty: Int?, + @RequestParam(required = false) storeId: String?, + @RequestParam(required = false) truckLanceCode: String?, + @RequestParam(required = false) date: String? + ): ResponseEntity { + val printer = printerService.findById(printerId) + ?: throw NoSuchElementException("No such printer") + val pdfBytes = buildTruckRoutingSummaryPdf(storeId, truckLanceCode, date) + val tempPdfFile = File.createTempFile("truck_routing_summary_", ".pdf") + try { + tempPdfFile.writeBytes(pdfBytes) + val copies = if (printQty == null || printQty <= 0) 1 else printQty + printer.ip?.let { ip -> + val port = printer.port ?: 9100 + val driver = A4PrintDriverRegistry.getDriver(printer.brand) + driver.print(tempPdfFile, ip, port, copies) + } + } finally { + // keep temp files for now to match current project behavior + // tempPdfFile.delete() + } + return ResponseEntity.ok().build() + } + + private fun buildTruckRoutingSummaryPdf( + storeId: String?, + truckLanceCode: String?, + date: String? + ): ByteArray { val reportDate = if (date.isNullOrBlank()) { LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) } else { date } - val departureLabel = truckRoutingSummaryService.getDepartureTimeLabel(storeId, truckLanceCode) val lane = (truckLanceCode ?: "").trim() val params = mutableMapOf( @@ -50,17 +95,10 @@ class TruckRoutingSummaryController( "REPORT_DATE" to reportDate, ) val rows = truckRoutingSummaryService.search(storeId, truckLanceCode, reportDate) - val pdfBytes = reportService.createPdfResponse( + return reportService.createPdfResponse( "/DeliveryNote/TruckRoutingSummaryPDF.jrxml", params, rows ) - - val headers = HttpHeaders().apply { - contentType = MediaType.APPLICATION_PDF - setContentDispositionFormData("attachment", "TruckRoutingSummary.pdf") - set("filename", "TruckRoutingSummary.pdf") - } - return ResponseEntity(pdfBytes, headers, HttpStatus.OK) } } diff --git a/src/main/resources/DeliveryNote/TruckRoutingSummaryPDF.jrxml b/src/main/resources/DeliveryNote/TruckRoutingSummaryPDF.jrxml index 1c2b282..5750d3e 100644 --- a/src/main/resources/DeliveryNote/TruckRoutingSummaryPDF.jrxml +++ b/src/main/resources/DeliveryNote/TruckRoutingSummaryPDF.jrxml @@ -11,142 +11,134 @@ + + + + + + <band height="28"> - <staticText> + <textField> <reportElement x="0" y="0" width="555" height="24" uuid="c1d2c147-cf58-41e6-9214-3f8251dd8aa5"/> <textElement textAlignment="Center" verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="16" isBold="true"/> + <font fontName="微軟正黑體" size="18" isBold="true"/> </textElement> - <text><![CDATA[送貨路線摘要]]></text> - </staticText> + <textFieldExpression><![CDATA["送貨路線摘要(" + $P{TRUCK_ROUTE} + ")"]]></textFieldExpression> + </textField> </band> - + - - - - - - - - + - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +