diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLog.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLog.kt similarity index 69% rename from src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLog.kt rename to src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLog.kt index 5a8343e..3d5f173 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLog.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLog.kt @@ -1,6 +1,8 @@ package com.ffii.fpsms.modules.stock.entity import com.ffii.core.entity.BaseEntity +import com.ffii.fpsms.modules.stock.enums.EscalationLogStatus +import com.ffii.fpsms.modules.stock.enums.EscalationLogStatusConverter import com.ffii.fpsms.modules.user.entity.User import jakarta.persistence.* import jakarta.validation.constraints.NotNull @@ -8,15 +10,14 @@ import jakarta.validation.constraints.Size import java.time.LocalDateTime @Entity -@Table(name = "supervision_approval_log") -open class SupervisionApprovalLog : BaseEntity() { +@Table(name = "escalation_log") +open class EscalationLog : BaseEntity() { @NotNull @ManyToOne @JoinColumn(name = "personInCharge", nullable = false, referencedColumnName = "id") open var personInCharge: User? = null @Size(max = 100) - @NotNull @Column(name = "type", nullable = false, length = 100) open var type: String? = null @@ -31,13 +32,19 @@ open class SupervisionApprovalLog : BaseEntity() { @Column(name = "recordDate") open var recordDate: LocalDateTime? = null - @Size(max = 100) @NotNull + @Convert(converter = EscalationLogStatusConverter::class) @Column(name = "status", nullable = false, length = 100) - open var status: String? = null + open var status: EscalationLogStatus? = null @Size(max = 500) @NotNull @Column(name = "reason", nullable = false, length = 500) open var reason: String? = null + + @Column(name = "qcTotalCount") + open var qcTotalCount: Int? = null + + @Column(name = "qcFailCount") + open var qcFailCount: Int? = null } \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogInfo.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogInfo.kt new file mode 100644 index 0000000..4b1e7cd --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogInfo.kt @@ -0,0 +1,57 @@ +package com.ffii.fpsms.modules.stock.entity + +import org.springframework.beans.factory.annotation.Value +import java.math.BigDecimal +import java.time.LocalDateTime + +interface EscalationLogInfo { + val id: Long? + + @get:Value("#{target.stockInLine?.stockIn?.purchaseOrder?.id}") + val poId: Long? + + @get:Value("#{target.stockInLine?.purchaseOrderLine?.id}") + val polId: Long? + + @get:Value("#{target.stockInLine?.stockIn?.code}") + val poCode: String? + + @get:Value("#{target.stockInLine?.id}") + val stockInLineId: Long? + + @get:Value("#{target.stockOutLine?.id}") + val stockOutLineId: Long? + + @get:Value("#{target.stockInLine?.dnNo}") + val dnNo: String? + + @get:Value("#{target.stockInLine?.dnDate}") + val dnDate: LocalDateTime? + + @get:Value("#{target.stockInLine?.item?.code}") + val itemCode: String? + + @get:Value("#{target.stockInLine?.item?.name}") + val itemName: String? + + @get:Value("#{target.stockInLine?.demandQty}") + val demandQty: BigDecimal? + + @get:Value("#{target.stockInLine?.acceptedQty}") + val acceptedQty: BigDecimal? + + @get:Value("#{target.personInCharge?.id}") + val personInChargeId: Long? + @get:Value("#{target.personInCharge?.name}") + val personInChargeName: String? + @get:Value("#{target.personInCharge?.title}") + val personInChargeTitle: String? + @get:Value("#{target.personInCharge?.department}") + val personInChargeDepartment: String? + + // @get:Value("#{target.type}") +// val escalationLevel: String + val qcTotalCount: Int?; + val qcFailCount: Int?; + val reason: String?; +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogRepository.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogRepository.kt new file mode 100644 index 0000000..4fe53bf --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogRepository.kt @@ -0,0 +1,15 @@ +package com.ffii.fpsms.modules.stock.entity + +import com.ffii.core.support.AbstractRepository +import org.springframework.stereotype.Repository +import java.io.Serializable + +@Repository +interface EscalationLogRepository: AbstractRepository { +// fun findAllByPersonInCharge(personInCharge: Long): List + fun findAllInfoByDeletedFalse(): List + + fun findAllInfoByDeletedFalseAndStockInLineIdIn(stockInLineIds: List): List + + fun findAllInfoByDeletedFalseAndPersonInChargeIdIs(personInChargeId: Serializable): List +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogInfo.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogInfo.kt deleted file mode 100644 index 1ddf36a..0000000 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogInfo.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.ffii.fpsms.modules.stock.entity - -import org.springframework.beans.factory.annotation.Value - -interface SupervisionApprovalLogInfo { - val id: Long - @get:Value("#{target.stockInLine?.stockIn.purchaseOrder.id}") - val poId: Long - @get:Value("#{target.stockInLine?.purchaseOrderLine.id}") - val polId: Long - @get:Value("#{target.stockInLine?.stockIn.code}") - val poCode: String - @get:Value("#{target.stockInLine?.id}") - val stockInLineId: Long - @get:Value("#{target.stockInLine?.item.name}") - val itemName: String - @get:Value("#{target.type}") - val escalationLevel: String - val reason: String -} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogRepository.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogRepository.kt deleted file mode 100644 index 10d64aa..0000000 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogRepository.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.ffii.fpsms.modules.stock.entity - -import com.ffii.core.support.AbstractRepository -import com.ffii.fpsms.modules.user.entity.User -import org.springframework.stereotype.Repository - -@Repository -interface SupervisionApprovalLogRepository: AbstractRepository { -// fun findAllByPersonInCharge(personInCharge: Long): List - fun findAllInfoByDeletedFalse(): List -} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnum.kt b/src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnum.kt new file mode 100644 index 0000000..65aa291 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnum.kt @@ -0,0 +1,7 @@ +package com.ffii.fpsms.modules.stock.enums + +enum class EscalationLogStatus(val value: String) { + PENDING("pending"), + ACCEPTED("accepted"), + REJECTED("rejected"), +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnumConverter.kt b/src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnumConverter.kt new file mode 100644 index 0000000..d7c5471 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnumConverter.kt @@ -0,0 +1,18 @@ +package com.ffii.fpsms.modules.stock.enums + +import jakarta.persistence.AttributeConverter +import jakarta.persistence.Converter + +// Escalation Log Status +@Converter(autoApply = true) +class EscalationLogStatusConverter : AttributeConverter{ + override fun convertToDatabaseColumn(status: EscalationLogStatus?): String? { + return status?.value + } + + override fun convertToEntityAttribute(value: String?): EscalationLogStatus? { + return value?.let { v -> + EscalationLogStatus.entries.find { it.value == v } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/EscalationLogService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/EscalationLogService.kt new file mode 100644 index 0000000..51ff04a --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/EscalationLogService.kt @@ -0,0 +1,88 @@ +package com.ffii.fpsms.modules.stock.service + +import com.ffii.core.support.AbstractBaseEntityService +import com.ffii.core.support.JdbcDao +import com.ffii.fpsms.modules.common.SecurityUtils +import com.ffii.fpsms.modules.stock.entity.* +import com.ffii.fpsms.modules.stock.enums.EscalationLogStatus +import com.ffii.fpsms.modules.stock.web.model.SaveEscalationLogRequest +import com.ffii.fpsms.modules.stock.web.model.SaveEscalationLogResponse +import com.ffii.fpsms.modules.user.service.UserService +import org.springframework.stereotype.Service +import kotlin.jvm.optionals.getOrNull + +@Service +open class EscalationLogService( + private val jdbcDao: JdbcDao, + private val escalationLogRepository: EscalationLogRepository, + private val userService: UserService, + private val stockInLineService: StockInLineService, + private val stockOutLineService: StockOutLineService, + private val stockInLineRepository: StockInLineRepository, + private val stockOutLIneRepository: StockOutLIneRepository, +): AbstractBaseEntityService(jdbcDao, escalationLogRepository) { + open fun getAllLogs(): List { + return escalationLogRepository.findAll() + } + + open fun getLogsByStockInLines(stockInLineIds: List?): List { + val logs = stockInLineIds?.let { escalationLogRepository.findAllInfoByDeletedFalseAndStockInLineIdIn(it) } ?: listOf() + return logs + } + + open fun getLogsByStockInLine(stockInLineId: Long?): List { + val logs = stockInLineId?.let { getLogsByStockInLines(listOf(it)) } ?: listOf() + return logs + } + + open fun getLogsByUser(): List { + val user = SecurityUtils.getUser().orElseThrow() + val logs = user.id?.let { escalationLogRepository.findAllInfoByDeletedFalseAndPersonInChargeIdIs(it) } ?: listOf() + return logs + } + + open fun saveEscalationLog(request: SaveEscalationLogRequest): SaveEscalationLogResponse{ + val escalationLog = request.id?.let { escalationLogRepository.findById(it).getOrNull() } ?: EscalationLog() + val personInCharge = request.personInChargeId.let { userService.getUserById(it) } + if (personInCharge == null && escalationLog.personInCharge == null) { + throw NoSuchElementException("Person In Charge is null."); + } + + val stockInLine = request.stockInLineId?.let { stockInLineRepository.findById(it).getOrNull() } + val stockOutLine = request.stockOutLineId?.let { stockOutLIneRepository.findById(it).getOrNull() } + if (stockInLine == null && stockOutLine == null) { + throw NoSuchElementException("Both stock in line and stock out line are null."); + } + + val status = request.status.let { status -> EscalationLogStatus.entries.find{ it.value == status} } + + escalationLog.apply { + this.personInCharge = personInCharge + type = request.type + this.stockInLine = stockInLine + this.stockOutLine = stockOutLine + recordDate = request.recordDate + this.status = status + reason = request.reason + qcTotalCount = request.qcTotalCount + qcFailCount = request.qcFailCount + } + + val response = escalationLogRepository.save(escalationLog).let { + SaveEscalationLogResponse( + id = it.id, + stockInLineId = it.stockInLine?.id, + stockOutLineId = it.stockOutLine?.id, + personInChargeId = it.personInCharge?.id, + personInChargeName = it.personInCharge?.name, + personInChargeTitle = it.personInCharge?.title, + personInChargeDepartment = it.personInCharge?.department, + recordDate = it.recordDate, + status = it.status?.value, + reason = it.reason, + ) + } + + return response + } +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/SupervisionApprovalLogService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/SupervisionApprovalLogService.kt deleted file mode 100644 index fa52e67..0000000 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/SupervisionApprovalLogService.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.ffii.fpsms.modules.stock.service - -import com.ffii.core.support.AbstractBaseEntityService -import com.ffii.core.support.JdbcDao -import com.ffii.fpsms.modules.common.SecurityUtils -import com.ffii.fpsms.modules.stock.entity.SupervisionApprovalLog -import com.ffii.fpsms.modules.stock.entity.SupervisionApprovalLogInfo -import com.ffii.fpsms.modules.stock.entity.SupervisionApprovalLogRepository -import org.springframework.stereotype.Service - -@Service -open class SupervisionApprovalLogService( - private val jdbcDao: JdbcDao, - private val supervisionApprovalLogRepository: SupervisionApprovalLogRepository - ): AbstractBaseEntityService(jdbcDao, supervisionApprovalLogRepository) { - open fun getAllLogs(): List { - return supervisionApprovalLogRepository.findAll() - } - - open fun getStockInLog(): List { - val stockInLog = getAllLogs().filter { - it.stockInLine != null - } - return stockInLog - } - open fun getLogByUser(): List { - val user = SecurityUtils.getUser().orElseThrow() - val filterLog = supervisionApprovalLogRepository - .findAllInfoByDeletedFalse() -// .findAll() -// .findAllByPersonInCharge(user.id!!).filter { -// it.stockInLine != null -// } - println("filterLog") - println(filterLog) - return filterLog - } -} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/EscalationLogController.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/EscalationLogController.kt new file mode 100644 index 0000000..36df776 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/EscalationLogController.kt @@ -0,0 +1,40 @@ +package com.ffii.fpsms.modules.stock.web + +import com.ffii.fpsms.modules.stock.entity.EscalationLogInfo +import com.ffii.fpsms.modules.stock.service.EscalationLogService +import com.ffii.fpsms.modules.stock.web.model.SaveEscalationLogRequest +import com.ffii.fpsms.modules.stock.web.model.SaveEscalationLogResponse +import com.ffii.fpsms.modules.stock.web.model.SearchEscalationLogRequest +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.ModelAttribute +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/escalationLog") +class EscalationLogController( + private val escalationLogService: EscalationLogService +) { + @GetMapping("/stockInLines") + fun getLogsByStockInLines(@ModelAttribute request: SearchEscalationLogRequest): List { + return escalationLogService.getLogsByStockInLines(request.stockInLineIds); + } + + @GetMapping("/stockInLine") + fun getLogsByStockInLine(@ModelAttribute request: SearchEscalationLogRequest): List { + return escalationLogService.getLogsByStockInLine(request.stockInLineId); + } + + @GetMapping("/user") + fun getLogsByUser(): List { + return escalationLogService.getLogsByUser(); + } + + @PostMapping("/save") + fun saveEscalationLog(@Valid @RequestBody request: SaveEscalationLogRequest): SaveEscalationLogResponse { + return escalationLogService.saveEscalationLog(request); + } +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/SupervisionApprovalLogController.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/SupervisionApprovalLogController.kt deleted file mode 100644 index a0a1364..0000000 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/SupervisionApprovalLogController.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.ffii.fpsms.modules.stock.web - -import com.ffii.fpsms.modules.stock.entity.SupervisionApprovalLog -import com.ffii.fpsms.modules.stock.entity.SupervisionApprovalLogInfo -import com.ffii.fpsms.modules.stock.service.SupervisionApprovalLogService -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -@RequestMapping("/supervisionApprovalLog") -class SupervisionApprovalLogController( - private val supervisionApprovalLogService: SupervisionApprovalLogService -) { - @GetMapping("/stock-in") - fun getStockInQcLog(): List { - return supervisionApprovalLogService.getLogByUser() - } -} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogRequest.kt new file mode 100644 index 0000000..c3bf6ef --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogRequest.kt @@ -0,0 +1,20 @@ +package com.ffii.fpsms.modules.stock.web.model + +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import java.time.LocalDateTime + +data class SaveEscalationLogRequest( + val id: Long?, + @field:NotNull(message = "Person In Charge cannot be empty") + val personInChargeId: Long, + val type: String?, + val stockInLineId: Long?, + val stockOutLineId: Long?, + val recordDate: LocalDateTime?, + @field:NotBlank(message = "Status cannot be empty") + val status: String, + val reason: String?, + val qcTotalCount: Int?, + val qcFailCount: Int?, +) diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogResponse.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogResponse.kt new file mode 100644 index 0000000..557df4c --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogResponse.kt @@ -0,0 +1,16 @@ +package com.ffii.fpsms.modules.stock.web.model + +import java.time.LocalDateTime + +data class SaveEscalationLogResponse( + val id: Long?, + val stockInLineId: Long?, + val stockOutLineId: Long?, + val personInChargeId: Long?, + val personInChargeName: String?, + val personInChargeTitle: String?, + val personInChargeDepartment: String?, + val recordDate: LocalDateTime?, + val status: String?, + val reason: String?, +) diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchEscalationLogRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchEscalationLogRequest.kt new file mode 100644 index 0000000..92c3469 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchEscalationLogRequest.kt @@ -0,0 +1,7 @@ +package com.ffii.fpsms.modules.stock.web.model + +data class SearchEscalationLogRequest( + val stockInLineIds: List?, + val stockInLineId: Long?, + val userId: Long?, +) diff --git a/src/main/resources/db/changelog/changes/20250818_01_cyril/01_update_supervision_approval_log.sql b/src/main/resources/db/changelog/changes/20250818_01_cyril/01_update_supervision_approval_log.sql new file mode 100644 index 0000000..3f3e060 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20250818_01_cyril/01_update_supervision_approval_log.sql @@ -0,0 +1,6 @@ +-- liquibase formatted sql +-- changeset cyril:update_supervision_approval_log + +ALTER TABLE `supervision_approval_log` + ADD COLUMN `qcFailCount` INT NULL AFTER `reason`, + ADD COLUMN `qcTotalCount` INT NULL AFTER `qcFailCount`; diff --git a/src/main/resources/db/changelog/changes/20250818_01_cyril/02_update_supervision_approval_log.sql b/src/main/resources/db/changelog/changes/20250818_01_cyril/02_update_supervision_approval_log.sql new file mode 100644 index 0000000..b9409ab --- /dev/null +++ b/src/main/resources/db/changelog/changes/20250818_01_cyril/02_update_supervision_approval_log.sql @@ -0,0 +1,5 @@ +-- liquibase formatted sql +-- changeset cyril:update_supervision_approval_log + +ALTER TABLE `supervision_approval_log` + CHANGE COLUMN `type` `type` VARCHAR(100) NULL; diff --git a/src/main/resources/db/changelog/changes/20250818_01_cyril/03_rename_supervision_approval_log.sql b/src/main/resources/db/changelog/changes/20250818_01_cyril/03_rename_supervision_approval_log.sql new file mode 100644 index 0000000..12950a0 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20250818_01_cyril/03_rename_supervision_approval_log.sql @@ -0,0 +1,5 @@ +-- liquibase formatted sql +-- changeset cyril:rename_supervision_approval_log + +ALTER TABLE `supervision_approval_log` + RENAME TO `escalation_log` ;