|
|
@@ -79,6 +79,8 @@ import com.ffii.fpsms.modules.master.entity.ItemsRepository |
|
|
import kotlin.collections.emptyMap |
|
|
import kotlin.collections.emptyMap |
|
|
import com.ffii.fpsms.modules.master.print.A4PrintDriverRegistry |
|
|
import com.ffii.fpsms.modules.master.print.A4PrintDriverRegistry |
|
|
import com.ffii.core.response.RecordsRes |
|
|
import com.ffii.core.response.RecordsRes |
|
|
|
|
|
import net.sf.jasperreports.engine.JasperReport |
|
|
|
|
|
import org.slf4j.LoggerFactory |
|
|
import org.springframework.data.domain.PageRequest |
|
|
import org.springframework.data.domain.PageRequest |
|
|
import org.springframework.data.domain.Page |
|
|
import org.springframework.data.domain.Page |
|
|
import org.springframework.data.domain.Pageable |
|
|
import org.springframework.data.domain.Pageable |
|
|
@@ -87,6 +89,8 @@ import com.ffii.fpsms.modules.deliveryOrder.entity.models.DeliveryOrderInfoLiteD |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLine |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLine |
|
|
import com.ffii.fpsms.modules.stock.entity.projection.StockOutLineInfo |
|
|
import com.ffii.fpsms.modules.stock.entity.projection.StockOutLineInfo |
|
|
import java.util.Locale |
|
|
import java.util.Locale |
|
|
|
|
|
import org.slf4j.Logger |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
open class DeliveryOrderService( |
|
|
open class DeliveryOrderService( |
|
|
private val deliveryOrderRepository: DeliveryOrderRepository, |
|
|
private val deliveryOrderRepository: DeliveryOrderRepository, |
|
|
@@ -116,7 +120,7 @@ open class DeliveryOrderService( |
|
|
private val doPickOrderRepository: DoPickOrderRepository, |
|
|
private val doPickOrderRepository: DoPickOrderRepository, |
|
|
private val doPickOrderLineRepository: DoPickOrderLineRepository, |
|
|
private val doPickOrderLineRepository: DoPickOrderLineRepository, |
|
|
private val doPickOrderLineRecordRepository: DoPickOrderLineRecordRepository, |
|
|
private val doPickOrderLineRecordRepository: DoPickOrderLineRecordRepository, |
|
|
private val itemsRepository: ItemsRepository |
|
|
|
|
|
|
|
|
private val itemsRepository: ItemsRepository, |
|
|
) { |
|
|
) { |
|
|
open fun searchDoLiteByPage( |
|
|
open fun searchDoLiteByPage( |
|
|
code: String?, |
|
|
code: String?, |
|
|
@@ -1064,26 +1068,31 @@ open class DeliveryOrderService( |
|
|
@Throws(IOException::class) |
|
|
@Throws(IOException::class) |
|
|
@Transactional |
|
|
@Transactional |
|
|
open fun exportDeliveryNote(request: ExportDeliveryNoteRequest): Map<String, Any> { |
|
|
open fun exportDeliveryNote(request: ExportDeliveryNoteRequest): Map<String, Any> { |
|
|
|
|
|
|
|
|
// INPUT STREAM SETUP |
|
|
|
|
|
val DELIVERYNOTE_PDF = "DeliveryNote/DeliveryNotePDF.jrxml" |
|
|
|
|
|
val resource = ClassPathResource(DELIVERYNOTE_PDF) |
|
|
|
|
|
if (!resource.exists()) { |
|
|
|
|
|
throw FileNotFoundException("Report file not found: $DELIVERYNOTE_PDF") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val inputStream = resource.inputStream |
|
|
|
|
|
val deliveryNote = JasperCompileManager.compileReport(inputStream) |
|
|
|
|
|
|
|
|
val tAll0 = System.nanoTime() |
|
|
|
|
|
val tJ0 = System.nanoTime() |
|
|
|
|
|
val deliveryNote = deliveryNoteJasperTemplate |
|
|
|
|
|
val jasperGetMs = (System.nanoTime() - tJ0) / 1_000_000.0 |
|
|
|
|
|
|
|
|
val fields = mutableListOf<MutableMap<String, Any>>() |
|
|
val fields = mutableListOf<MutableMap<String, Any>>() |
|
|
val params = mutableMapOf<String, Any>() |
|
|
val params = mutableMapOf<String, Any>() |
|
|
|
|
|
|
|
|
// DRAFT & RECORD SEPARATION |
|
|
|
|
|
if (request.isDraft) { |
|
|
|
|
|
return exportDeliveryNoteFromDraft(request, deliveryNote, fields, params) |
|
|
|
|
|
|
|
|
val tFill0 = System.nanoTime() |
|
|
|
|
|
val result = if (request.isDraft) { |
|
|
|
|
|
exportDeliveryNoteFromDraft(request, deliveryNote, fields, params) |
|
|
} else { |
|
|
} else { |
|
|
return exportDeliveryNoteFromRecord(request, deliveryNote, fields, params) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
exportDeliveryNoteFromRecord(request, deliveryNote, fields, params) |
|
|
|
|
|
} |
|
|
|
|
|
val fillDataMs = (System.nanoTime() - tFill0) / 1_000_000.0 |
|
|
|
|
|
val totalMs = (System.nanoTime() - tAll0) / 1_000_000.0 |
|
|
|
|
|
log.info( |
|
|
|
|
|
"DeliveryNote export timing: jasperGetMs={} fillDataMs={} totalMs={} doPickOrderId={} isDraft={}", |
|
|
|
|
|
jasperGetMs, |
|
|
|
|
|
fillDataMs, |
|
|
|
|
|
totalMs, |
|
|
|
|
|
request.doPickOrderId, |
|
|
|
|
|
request.isDraft, |
|
|
|
|
|
) |
|
|
|
|
|
return result |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// DRAFT |
|
|
// DRAFT |
|
|
@@ -1413,6 +1422,7 @@ open class DeliveryOrderService( |
|
|
//Print Delivery Note |
|
|
//Print Delivery Note |
|
|
@Transactional |
|
|
@Transactional |
|
|
open fun printDeliveryNote(request: PrintDeliveryNoteRequest) { |
|
|
open fun printDeliveryNote(request: PrintDeliveryNoteRequest) { |
|
|
|
|
|
val t0 = System.nanoTime() |
|
|
val printer = |
|
|
val printer = |
|
|
printerService.findById(request.printerId) ?: throw java.util.NoSuchElementException("No such printer") |
|
|
printerService.findById(request.printerId) ?: throw java.util.NoSuchElementException("No such printer") |
|
|
|
|
|
|
|
|
@@ -1429,15 +1439,30 @@ open class DeliveryOrderService( |
|
|
val tempPdfFile = File.createTempFile("print_job_", ".pdf") |
|
|
val tempPdfFile = File.createTempFile("print_job_", ".pdf") |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
|
|
|
val t1 = System.nanoTime() |
|
|
JasperExportManager.exportReportToPdfFile(jasperPrint, tempPdfFile.absolutePath) |
|
|
JasperExportManager.exportReportToPdfFile(jasperPrint, tempPdfFile.absolutePath) |
|
|
|
|
|
val exportPdfToFileMs = (System.nanoTime() - t1) / 1_000_000.0 |
|
|
|
|
|
|
|
|
val printQty = if (request.printQty == null || request.printQty <= 0) 1 else request.printQty |
|
|
val printQty = if (request.printQty == null || request.printQty <= 0) 1 else request.printQty |
|
|
|
|
|
|
|
|
|
|
|
val t2 = System.nanoTime() |
|
|
printer.ip?.let { ip -> |
|
|
printer.ip?.let { ip -> |
|
|
val port = printer.port ?: 9100 |
|
|
val port = printer.port ?: 9100 |
|
|
val driver = A4PrintDriverRegistry.getDriver(printer.brand) |
|
|
val driver = A4PrintDriverRegistry.getDriver(printer.brand) |
|
|
driver.print(tempPdfFile, ip, port, printQty) |
|
|
driver.print(tempPdfFile, ip, port, printQty) |
|
|
} |
|
|
} |
|
|
|
|
|
val printToPrinterMs = (System.nanoTime() - t2) / 1_000_000.0 |
|
|
|
|
|
val totalMs = (System.nanoTime() - t0) / 1_000_000.0 |
|
|
|
|
|
log.info( |
|
|
|
|
|
"DeliveryNote print-DN timing: exportPdfToFileMs={} printToPrinterMs={} totalMs={} doPickOrderId={} printerId={} printQty={} printerIp={}", |
|
|
|
|
|
exportPdfToFileMs, |
|
|
|
|
|
printToPrinterMs, |
|
|
|
|
|
totalMs, |
|
|
|
|
|
request.doPickOrderId, |
|
|
|
|
|
request.printerId, |
|
|
|
|
|
printQty, |
|
|
|
|
|
printer.ip ?: "null", |
|
|
|
|
|
) |
|
|
updateRecordCartonQty(request.doPickOrderId, request.numOfCarton) |
|
|
updateRecordCartonQty(request.doPickOrderId, request.numOfCarton) |
|
|
} finally { |
|
|
} finally { |
|
|
//tempPdfFile.delete() |
|
|
//tempPdfFile.delete() |
|
|
@@ -2146,5 +2171,19 @@ val inventoryLotLine = illId?.let { inventoryLotLineMap[it] } |
|
|
problems = problems |
|
|
problems = problems |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private companion object { |
|
|
|
|
|
private val log: Logger = LoggerFactory.getLogger(DeliveryOrderService::class.java) |
|
|
|
|
|
|
|
|
|
|
|
private const val DELIVERYNOTE_JRXML = "DeliveryNote/DeliveryNotePDF.jrxml" |
|
|
|
|
|
|
|
|
|
|
|
/** Compile once; avoids per-request JRXML recompilation (shared by download + print). */ |
|
|
|
|
|
private val deliveryNoteJasperTemplate: JasperReport by lazy { |
|
|
|
|
|
val resource = ClassPathResource(DELIVERYNOTE_JRXML) |
|
|
|
|
|
if (!resource.exists()) { |
|
|
|
|
|
throw FileNotFoundException("Report file not found: $DELIVERYNOTE_JRXML") |
|
|
|
|
|
} |
|
|
|
|
|
resource.inputStream.use { inputStream -> JasperCompileManager.compileReport(inputStream) } |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|