From c3b645d67e91384de144b737bad90e6b5913df24 Mon Sep 17 00:00:00 2001 From: kelvinsuen Date: Thu, 28 Aug 2025 14:01:52 +0800 Subject: [PATCH] update new escalation flow --- .../ffii/fpsms/modules/qc/entity/QcResult.kt | 5 +++++ .../stock/service/StockInLineService.kt | 20 ++++++++++++++----- .../stock/web/model/SaveStockInRequest.kt | 1 + .../01_update_stock_in_line.sql | 4 ++++ .../01_update_qc_result.sql | 4 ++++ 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/db/changelog/changes/20250827_01_kelvin/01_update_stock_in_line.sql create mode 100644 src/main/resources/db/changelog/changes/20250828_01_kelvin/01_update_qc_result.sql diff --git a/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResult.kt b/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResult.kt index bd5391a..67414ce 100644 --- a/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResult.kt +++ b/src/main/java/com/ffii/fpsms/modules/qc/entity/QcResult.kt @@ -3,6 +3,7 @@ package com.ffii.fpsms.modules.qc.entity import com.ffii.core.entity.BaseEntity import com.ffii.fpsms.modules.master.entity.Items import com.ffii.fpsms.modules.master.entity.QcItem +import com.ffii.fpsms.modules.stock.entity.EscalationLog import com.ffii.fpsms.modules.stock.entity.StockInLine import com.ffii.fpsms.modules.stock.entity.StockOutLine import jakarta.persistence.* @@ -29,6 +30,10 @@ open class QcResult: BaseEntity() { @JoinColumn(name = "stockOutLineId") open var stockOutLine: StockOutLine? = null + @ManyToOne + @JoinColumn(name = "escalationLogId") + open var escalationLog: EscalationLog? = null + @Column(name = "failQty") open var failQty: Double? = null diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt index fe62b0c..4e475ea 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt @@ -41,6 +41,7 @@ import kotlinx.serialization.encodeToString import net.sf.jasperreports.engine.JasperExportManager import net.sf.jasperreports.engine.JasperPrint import java.io.File +import kotlin.jvm.optionals.getOrNull import kotlin.math.max @Serializable @@ -196,11 +197,13 @@ open class StockInLineService( @Throws(IOException::class) @Transactional - fun saveQcResultWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): List? { + fun saveQcResultWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine, escLogId: Long?= 0): List? { if (!request.qcResult.isNullOrEmpty()) { val qcResultEntries = request.qcResult!!.map { val qcItem = qcItemsRepository.findById(it.qcItemId).orElseThrow() val item = itemRepository.findById(stockInLine.item!!.id!!).orElseThrow() + val qcResult = QcResult(); + QcResult().apply { this.qcItem = qcItem this.item = item @@ -209,6 +212,7 @@ open class StockInLineService( this.qcPassed = it.qcPassed this.type = "qc" // default as qc for now this.remarks = it.remarks + this.escalationLog = escalationLogService.find(escLogId).getOrNull() } } return qcResultRepository.saveAllAndFlush(qcResultEntries) @@ -247,7 +251,6 @@ open class StockInLineService( val res = escalationLogService.saveEscalationLog(escReq) return res.id?.let { escalationLogRepository.findById(it).orElseThrow() }; }; -// return qcResultRepository.saveAllAndFlush(qcResultEntries) } return null } @@ -367,11 +370,17 @@ open class StockInLineService( if (inventoryLotLines.sumOf { it.inQty ?: BigDecimal.ZERO } >= request.acceptQty?.times(ratio)) { stockInLine.apply { - this.status = StockInLineStatus.COMPLETE.status + this.status = if (request.acceptQty?.compareTo(request.acceptedQty) == 0) + StockInLineStatus.COMPLETE.status else StockInLineStatus.PARTIALLY_COMPLETE.status // this.inventoryLotLine = savedInventoryLotLine } } } else if (request.status == StockInLineStatus.PENDING.status || request.status == StockInLineStatus.ESCALATED.status) { + var escLogId : Long? = 0L; + // Escalation + if (request.status == StockInLineStatus.ESCALATED.status) { + // + } // QC if (request.qcAccept == true) { // Accepted @@ -473,7 +482,7 @@ open class StockInLineService( stockInLine.apply { this.status = StockInLineStatus.ESCALATED.status } - saveEscalationLogWhenStockIn(request, stockInLine); + escLogId = saveEscalationLogWhenStockIn(request, stockInLine)?.id; } else { // Rejected stockInLine.apply { @@ -481,7 +490,8 @@ open class StockInLineService( } } } - saveQcResultWhenStockIn(request, stockInLine) + + saveQcResultWhenStockIn(request, stockInLine, escLogId) } val savedStockInLine = saveAndFlush(stockInLine) // check if all line completed diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt index 32cf3c1..4575a82 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt @@ -20,6 +20,7 @@ enum class StockInLineStatus(val status: String) { RECEIVING("receiving"), RECEIVED("received"), COMPLETE("completed"), + PARTIALLY_COMPLETE("partially_completed"), REJECT("rejected"); } data class SaveStockInRequest( diff --git a/src/main/resources/db/changelog/changes/20250827_01_kelvin/01_update_stock_in_line.sql b/src/main/resources/db/changelog/changes/20250827_01_kelvin/01_update_stock_in_line.sql new file mode 100644 index 0000000..952cc90 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20250827_01_kelvin/01_update_stock_in_line.sql @@ -0,0 +1,4 @@ +-- liquibase formatted sql +-- changeset kelvin:update stock in line table +ALTER TABLE `stock_in_line` +CHANGE COLUMN `status` `status` VARCHAR(100) NOT NULL DEFAULT 'pending' ; diff --git a/src/main/resources/db/changelog/changes/20250828_01_kelvin/01_update_qc_result.sql b/src/main/resources/db/changelog/changes/20250828_01_kelvin/01_update_qc_result.sql new file mode 100644 index 0000000..cefa017 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20250828_01_kelvin/01_update_qc_result.sql @@ -0,0 +1,4 @@ +-- liquibase formatted sql +-- changeset kelvin:update qc result table +ALTER TABLE `qc_result` +ADD COLUMN `escalationLogId` INT NULL DEFAULT NULL AFTER `stockOutLineId`;