Browse Source

TruckRoutingSummary Update

master
B.E.N.S.O.N 12 hours ago
parent
commit
2d9cfcdb46
2 changed files with 90 additions and 60 deletions
  1. +47
    -9
      src/main/java/com/ffii/fpsms/modules/deliveryOrder/web/TruckRoutingSummaryController.kt
  2. +43
    -51
      src/main/resources/DeliveryNote/TruckRoutingSummaryPDF.jrxml

+ 47
- 9
src/main/java/com/ffii/fpsms/modules/deliveryOrder/web/TruckRoutingSummaryController.kt View File

@@ -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<Map<String, String>> =
@@ -35,12 +39,53 @@ class TruckRoutingSummaryController(
@RequestParam(required = false) truckLanceCode: String?,
@RequestParam(required = false) date: String?
): ResponseEntity<ByteArray> {
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<Void> {
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<String, Any>(
@@ -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)
}
}

+ 43
- 51
src/main/resources/DeliveryNote/TruckRoutingSummaryPDF.jrxml View File

@@ -11,142 +11,134 @@
<field name="shopName" class="java.lang.String"/>
<field name="address" class="java.lang.String"/>
<field name="noOfCartons" class="java.lang.String"/>
<group name="DropOffSequenceGroup">
<groupExpression><![CDATA[$F{dropOffSequence}]]></groupExpression>
<groupFooter>
<band height="10"/>
</groupFooter>
</group>
<title>
<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>
</title>
<pageHeader>
<band height="25">
<band height="27">
<staticText>
<reportElement x="0" y="0" width="60" height="20" uuid="117504db-1b66-4838-a84b-1b0e5a9245cc"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="11" isBold="true"/>
</textElement>
<text><![CDATA[送貨路線:]]></text>
</staticText>
<textField>
<reportElement x="60" y="0" width="130" height="20" uuid="71f86ded-88e6-4ab7-a62d-b9c7de8b6c37"/>
<reportElement x="0" y="0" width="130" height="22" uuid="9d3f5b73-ceaa-4653-909f-e8534d19c61e"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$P{TRUCK_ROUTE}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="200" y="0" width="110" height="20" uuid="9d3f5b73-ceaa-4653-909f-e8534d19c61e"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="11" isBold="true"/>
<font fontName="微軟正黑體" size="12" isBold="true"/>
</textElement>
<text><![CDATA[計劃車次出發時間:]]></text>
</staticText>
<textField>
<reportElement x="310" y="0" width="110" height="20" uuid="92335393-c410-4935-bd28-29a6175a9769"/>
<reportElement x="130" y="0" width="90" height="22" uuid="92335393-c410-4935-bd28-29a6175a9769"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="11"/>
<font fontName="微軟正黑體" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$P{DEPARTURE_TIME}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="430" y="0" width="40" height="20" uuid="8770a6e7-8a03-47ab-aa3c-00f02815d3b4"/>
<reportElement x="430" y="0" width="45" height="22" uuid="8770a6e7-8a03-47ab-aa3c-00f02815d3b4"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="11" isBold="true"/>
<font fontName="微軟正黑體" size="12" isBold="true"/>
</textElement>
<text><![CDATA[日期:]]></text>
</staticText>
<textField>
<reportElement x="470" y="0" width="85" height="20" uuid="1a628742-c50c-47a8-9f3d-df91dbc4b184"/>
<reportElement x="475" y="0" width="80" height="22" uuid="1a628742-c50c-47a8-9f3d-df91dbc4b184"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="微軟正黑體" size="11"/>
<font fontName="微軟正黑體" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$P{REPORT_DATE}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="20" width="555" height="1" uuid="593aa99a-7978-473d-b70f-93f79fb64289"/>
<reportElement x="0" y="22" width="555" height="1" uuid="593aa99a-7978-473d-b70f-93f79fb64289"/>
</line>
</band>
</pageHeader>
<columnHeader>
<band height="24">
<band height="28">
<staticText>
<reportElement x="0" y="4" width="60" height="18" uuid="7dbf4192-d9d9-4f3e-95bc-d2700d4e5798"/>
<reportElement x="0" y="4" width="50" height="20" uuid="7dbf4192-d9d9-4f3e-95bc-d2700d4e5798"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10" isBold="true"/>
<font fontName="微軟正黑體" size="12" isBold="true"/>
</textElement>
<text><![CDATA[卸貨順序]]></text>
</staticText>
<staticText>
<reportElement x="60" y="4" width="50" height="18" uuid="9c31b1d9-d866-4555-9ee9-57b924ff2540"/>
<reportElement x="60" y="4" width="60" height="20" uuid="9c31b1d9-d866-4555-9ee9-57b924ff2540"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10" isBold="true"/>
<font fontName="微軟正黑體" size="12" isBold="true"/>
</textElement>
<text><![CDATA[店鋪代碼]]></text>
</staticText>
<staticText>
<reportElement x="110" y="4" width="130" height="18" uuid="e7d49961-b1c8-40b0-a109-29da1142fc8d"/>
<reportElement x="120" y="4" width="140" height="20" uuid="e7d49961-b1c8-40b0-a109-29da1142fc8d"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10" isBold="true"/>
<font fontName="微軟正黑體" size="12" isBold="true"/>
</textElement>
<text><![CDATA[店鋪名稱]]></text>
</staticText>
<staticText>
<reportElement x="240" y="4" width="260" height="18" uuid="d2538a2b-ebbb-4cbb-a6c1-51249b831afe"/>
<reportElement x="260" y="4" width="260" height="20" uuid="d2538a2b-ebbb-4cbb-a6c1-51249b831afe"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10" isBold="true"/>
<font fontName="微軟正黑體" size="12" isBold="true"/>
</textElement>
<text><![CDATA[地址]]></text>
</staticText>
<staticText>
<reportElement x="500" y="4" width="54" height="18" uuid="8473f6ea-a5bd-4739-bc05-618c0afb06d2"/>
<reportElement x="520" y="4" width="34" height="20" uuid="8473f6ea-a5bd-4739-bc05-618c0afb06d2"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10" isBold="true"/>
<font fontName="微軟正黑體" size="12" isBold="true"/>
</textElement>
<text><![CDATA[箱數]]></text>
</staticText>
<line>
<reportElement x="0" y="23" width="555" height="1" uuid="a370b2d2-4853-460a-900a-a15d2e1b8e94"/>
<reportElement x="0" y="27" width="555" height="1" uuid="a370b2d2-4853-460a-900a-a15d2e1b8e94"/>
</line>
</band>
</columnHeader>
<detail>
<band height="20">
<band height="24">
<textField isBlankWhenNull="true">
<reportElement x="0" y="2" width="60" height="16" uuid="31c8d1cf-9298-4866-9dca-d5bbaa08b277"/>
<reportElement x="0" y="3" width="50" height="18" uuid="31c8d1cf-9298-4866-9dca-d5bbaa08b277"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10"/>
<font fontName="微軟正黑體" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$F{dropOffSequence}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="60" y="2" width="50" height="16" uuid="f4ed6642-ce1c-4130-bf80-1024c5453db4"/>
<reportElement x="60" y="3" width="60" height="18" uuid="f4ed6642-ce1c-4130-bf80-1024c5453db4"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10"/>
<font fontName="微軟正黑體" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$F{shopCode}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="110" y="2" width="130" height="16" uuid="a44a3df4-a77f-4dda-8b82-d77b47e56eaf"/>
<reportElement x="120" y="3" width="140" height="18" uuid="a44a3df4-a77f-4dda-8b82-d77b47e56eaf"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10"/>
<font fontName="微軟正黑體" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$F{shopName}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="240" y="2" width="260" height="16" uuid="553b201d-910f-40d9-aea3-711852ebff59"/>
<reportElement x="260" y="3" width="260" height="18" uuid="553b201d-910f-40d9-aea3-711852ebff59"/>
<textElement verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10"/>
<font fontName="微軟正黑體" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="500" y="2" width="54" height="16" uuid="ff0c3947-9dd6-48eb-8ba9-83e47b7cd8e1"/>
<reportElement x="520" y="3" width="34" height="18" uuid="ff0c3947-9dd6-48eb-8ba9-83e47b7cd8e1"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="微軟正黑體" size="10"/>
<font fontName="微軟正黑體" size="11"/>
</textElement>
<textFieldExpression><![CDATA[$F{noOfCartons}]]></textFieldExpression>
</textField>


Loading…
Cancel
Save