Sfoglia il codice sorgente

update escalation log table

master
cyril.tsui 6 giorni fa
parent
commit
d46343c266
17 ha cambiato i file con 296 aggiunte e 93 eliminazioni
  1. +12
    -5
      src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLog.kt
  2. +57
    -0
      src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogInfo.kt
  3. +15
    -0
      src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogRepository.kt
  4. +0
    -20
      src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogInfo.kt
  5. +0
    -11
      src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogRepository.kt
  6. +7
    -0
      src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnum.kt
  7. +18
    -0
      src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnumConverter.kt
  8. +88
    -0
      src/main/java/com/ffii/fpsms/modules/stock/service/EscalationLogService.kt
  9. +0
    -38
      src/main/java/com/ffii/fpsms/modules/stock/service/SupervisionApprovalLogService.kt
  10. +40
    -0
      src/main/java/com/ffii/fpsms/modules/stock/web/EscalationLogController.kt
  11. +0
    -19
      src/main/java/com/ffii/fpsms/modules/stock/web/SupervisionApprovalLogController.kt
  12. +20
    -0
      src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogRequest.kt
  13. +16
    -0
      src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogResponse.kt
  14. +7
    -0
      src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchEscalationLogRequest.kt
  15. +6
    -0
      src/main/resources/db/changelog/changes/20250818_01_cyril/01_update_supervision_approval_log.sql
  16. +5
    -0
      src/main/resources/db/changelog/changes/20250818_01_cyril/02_update_supervision_approval_log.sql
  17. +5
    -0
      src/main/resources/db/changelog/changes/20250818_01_cyril/03_rename_supervision_approval_log.sql

src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLog.kt → src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLog.kt Vedi File

@@ -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<Long>() {
@Table(name = "escalation_log")
open class EscalationLog : BaseEntity<Long>() {
@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<Long>() {
@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
}

+ 57
- 0
src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogInfo.kt Vedi File

@@ -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?;
}

+ 15
- 0
src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogRepository.kt Vedi File

@@ -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<EscalationLog, Long> {
// fun findAllByPersonInCharge(personInCharge: Long): List<SupervisionApprovalLog>
fun findAllInfoByDeletedFalse(): List<EscalationLogInfo>

fun findAllInfoByDeletedFalseAndStockInLineIdIn(stockInLineIds: List<Serializable>): List<EscalationLogInfo>

fun findAllInfoByDeletedFalseAndPersonInChargeIdIs(personInChargeId: Serializable): List<EscalationLogInfo>
}

+ 0
- 20
src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogInfo.kt Vedi File

@@ -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
}

+ 0
- 11
src/main/java/com/ffii/fpsms/modules/stock/entity/SupervisionApprovalLogRepository.kt Vedi File

@@ -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<SupervisionApprovalLog, Long> {
// fun findAllByPersonInCharge(personInCharge: Long): List<SupervisionApprovalLog>
fun findAllInfoByDeletedFalse(): List<SupervisionApprovalLogInfo>
}

+ 7
- 0
src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnum.kt Vedi File

@@ -0,0 +1,7 @@
package com.ffii.fpsms.modules.stock.enums

enum class EscalationLogStatus(val value: String) {
PENDING("pending"),
ACCEPTED("accepted"),
REJECTED("rejected"),
}

+ 18
- 0
src/main/java/com/ffii/fpsms/modules/stock/enums/EscalationLogEnumConverter.kt Vedi File

@@ -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<EscalationLogStatus, String>{
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 }
}
}
}

+ 88
- 0
src/main/java/com/ffii/fpsms/modules/stock/service/EscalationLogService.kt Vedi File

@@ -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<EscalationLog, Long, EscalationLogRepository>(jdbcDao, escalationLogRepository) {
open fun getAllLogs(): List<EscalationLog> {
return escalationLogRepository.findAll()
}

open fun getLogsByStockInLines(stockInLineIds: List<Long>?): List<EscalationLogInfo> {
val logs = stockInLineIds?.let { escalationLogRepository.findAllInfoByDeletedFalseAndStockInLineIdIn(it) } ?: listOf()
return logs
}

open fun getLogsByStockInLine(stockInLineId: Long?): List<EscalationLogInfo> {
val logs = stockInLineId?.let { getLogsByStockInLines(listOf(it)) } ?: listOf()
return logs
}

open fun getLogsByUser(): List<EscalationLogInfo> {
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
}
}

+ 0
- 38
src/main/java/com/ffii/fpsms/modules/stock/service/SupervisionApprovalLogService.kt Vedi File

@@ -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<SupervisionApprovalLog, Long, SupervisionApprovalLogRepository>(jdbcDao, supervisionApprovalLogRepository) {
open fun getAllLogs(): List<SupervisionApprovalLog> {
return supervisionApprovalLogRepository.findAll()
}

open fun getStockInLog(): List<SupervisionApprovalLog> {
val stockInLog = getAllLogs().filter {
it.stockInLine != null
}
return stockInLog
}
open fun getLogByUser(): List<SupervisionApprovalLogInfo> {
val user = SecurityUtils.getUser().orElseThrow()
val filterLog = supervisionApprovalLogRepository
.findAllInfoByDeletedFalse()
// .findAll()
// .findAllByPersonInCharge(user.id!!).filter {
// it.stockInLine != null
// }
println("filterLog")
println(filterLog)
return filterLog
}
}

+ 40
- 0
src/main/java/com/ffii/fpsms/modules/stock/web/EscalationLogController.kt Vedi File

@@ -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<EscalationLogInfo> {
return escalationLogService.getLogsByStockInLines(request.stockInLineIds);
}

@GetMapping("/stockInLine")
fun getLogsByStockInLine(@ModelAttribute request: SearchEscalationLogRequest): List<EscalationLogInfo> {
return escalationLogService.getLogsByStockInLine(request.stockInLineId);
}

@GetMapping("/user")
fun getLogsByUser(): List<EscalationLogInfo> {
return escalationLogService.getLogsByUser();
}

@PostMapping("/save")
fun saveEscalationLog(@Valid @RequestBody request: SaveEscalationLogRequest): SaveEscalationLogResponse {
return escalationLogService.saveEscalationLog(request);
}
}

+ 0
- 19
src/main/java/com/ffii/fpsms/modules/stock/web/SupervisionApprovalLogController.kt Vedi File

@@ -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<SupervisionApprovalLogInfo> {
return supervisionApprovalLogService.getLogByUser()
}
}

+ 20
- 0
src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogRequest.kt Vedi File

@@ -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?,
)

+ 16
- 0
src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveEscalationLogResponse.kt Vedi File

@@ -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?,
)

+ 7
- 0
src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchEscalationLogRequest.kt Vedi File

@@ -0,0 +1,7 @@
package com.ffii.fpsms.modules.stock.web.model

data class SearchEscalationLogRequest(
val stockInLineIds: List<Long>?,
val stockInLineId: Long?,
val userId: Long?,
)

+ 6
- 0
src/main/resources/db/changelog/changes/20250818_01_cyril/01_update_supervision_approval_log.sql Vedi File

@@ -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`;

+ 5
- 0
src/main/resources/db/changelog/changes/20250818_01_cyril/02_update_supervision_approval_log.sql Vedi File

@@ -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;

+ 5
- 0
src/main/resources/db/changelog/changes/20250818_01_cyril/03_rename_supervision_approval_log.sql Vedi File

@@ -0,0 +1,5 @@
-- liquibase formatted sql
-- changeset cyril:rename_supervision_approval_log

ALTER TABLE `supervision_approval_log`
RENAME TO `escalation_log` ;

Caricamento…
Annulla
Salva