|
|
|
@@ -3,9 +3,14 @@ package com.ffii.fpsms.modules.master.service |
|
|
|
import com.ffii.core.support.AbstractBaseEntityService |
|
|
|
import com.ffii.fpsms.modules.master.entity.QcCategory |
|
|
|
import com.ffii.fpsms.modules.master.entity.QcCategoryRepository |
|
|
|
import com.ffii.fpsms.modules.master.entity.QcItem |
|
|
|
import com.ffii.fpsms.modules.master.entity.projections.QcCategoryCombo |
|
|
|
import com.ffii.fpsms.modules.master.web.models.SaveQcCategoryRequest |
|
|
|
import com.ffii.fpsms.modules.master.web.models.SaveQcCategoryResponse |
|
|
|
import com.ffii.fpsms.modules.qc.entity.projection.QcCategoryInfo |
|
|
|
import jakarta.validation.Valid |
|
|
|
import org.springframework.stereotype.Service |
|
|
|
import org.springframework.web.bind.annotation.RequestBody |
|
|
|
|
|
|
|
@Service |
|
|
|
open class QcCategoryService( |
|
|
|
@@ -16,6 +21,10 @@ open class QcCategoryService( |
|
|
|
return qcCategoryRepository.findAllByDeletedIsFalse() |
|
|
|
} |
|
|
|
|
|
|
|
open fun findQcCategoryById(id: Long): QcCategory? { |
|
|
|
return qcCategoryRepository.findByIdAndDeletedIsFalse(id) |
|
|
|
} |
|
|
|
|
|
|
|
open fun getQcCategoryCombo(): List<QcCategoryCombo> { |
|
|
|
return qcCategoryRepository.findQcCategoryComboByDeletedIsFalse(); |
|
|
|
} |
|
|
|
@@ -40,4 +49,57 @@ open class QcCategoryService( |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
open fun markDeleted(id: Long): List<QcCategory> { |
|
|
|
val qcItem = qcCategoryRepository.findById(id).orElseThrow().apply { |
|
|
|
deleted = true |
|
|
|
} |
|
|
|
|
|
|
|
qcCategoryRepository.save(qcItem) |
|
|
|
|
|
|
|
return allQcCategories() |
|
|
|
} |
|
|
|
|
|
|
|
open fun saveQcCategory(@Valid @RequestBody request: SaveQcCategoryRequest): SaveQcCategoryResponse { |
|
|
|
val errors = mutableMapOf<String, String>() |
|
|
|
val id = request.id |
|
|
|
val qcCategory = if (id != null) qcCategoryRepository.findById(id).orElseThrow() else QcCategory() |
|
|
|
|
|
|
|
// check duplicated code |
|
|
|
// val duplicateQcCategory = findQcCategoryByCode(request.code) |
|
|
|
// if (duplicateQcCategory != null && duplicateQcCategory.id != qcCategory.id) { |
|
|
|
// errors["code"] = "Code is duplicated" |
|
|
|
// } |
|
|
|
|
|
|
|
if (errors.isNotEmpty()) { |
|
|
|
request.let { |
|
|
|
SaveQcCategoryResponse( |
|
|
|
id = it.id, |
|
|
|
code = it.code, |
|
|
|
name = it.name, |
|
|
|
description = it.description, |
|
|
|
errors = errors |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Save Qc Item |
|
|
|
qcCategory.apply { |
|
|
|
code = request.code |
|
|
|
name = request.name |
|
|
|
description = request.description |
|
|
|
} |
|
|
|
|
|
|
|
val savedQcCategory = qcCategoryRepository.save(qcCategory) |
|
|
|
|
|
|
|
return savedQcCategory.let { |
|
|
|
SaveQcCategoryResponse( |
|
|
|
id = it.id, |
|
|
|
code = it.code, |
|
|
|
name = it.name, |
|
|
|
description = it.description, |
|
|
|
errors = null |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |