| @@ -1,15 +0,0 @@ | |||||
| package com.ffii.fpsms.modules.master.entity | |||||
| import com.fasterxml.jackson.annotation.JsonBackReference | |||||
| import com.ffii.core.entity.IdEntity | |||||
| import jakarta.persistence.* | |||||
| import jakarta.validation.constraints.NotNull | |||||
| @Entity | |||||
| @Table(name = "item_type") | |||||
| open class ItemType: IdEntity<Long>() { | |||||
| @NotNull | |||||
| @Column(name = "name") | |||||
| open var name: String? = null | |||||
| } | |||||
| @@ -1,10 +0,0 @@ | |||||
| package com.ffii.fpsms.modules.master.entity | |||||
| import com.ffii.core.support.AbstractRepository | |||||
| import org.springframework.stereotype.Repository | |||||
| import org.springframework.transaction.annotation.Transactional | |||||
| @Repository | |||||
| interface ItemTypeRepository : AbstractRepository<ItemType, Long> { | |||||
| } | |||||
| @@ -1,6 +1,7 @@ | |||||
| package com.ffii.fpsms.modules.master.entity | package com.ffii.fpsms.modules.master.entity | ||||
| import com.ffii.core.entity.BaseEntity | import com.ffii.core.entity.BaseEntity | ||||
| import com.ffii.fpsms.modules.master.web.models.ItemType | |||||
| import jakarta.persistence.* | import jakarta.persistence.* | ||||
| import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
| @@ -21,10 +22,9 @@ open class Items : BaseEntity<Long>() { | |||||
| @Column(name = "remarks") | @Column(name = "remarks") | ||||
| open var remarks: String? = null | open var remarks: String? = null | ||||
| // (mappedBy = "items", cascade = [CascadeType.ALL], orphanRemoval = true) | |||||
| @OneToOne | |||||
| @JoinColumn(name = "typeId", referencedColumnName = "id") | |||||
| open var type: ItemType? = null | |||||
| @NotNull | |||||
| @Column(name = "type") | |||||
| open var type: String? = null | |||||
| @Column(name = "shelfLife") | @Column(name = "shelfLife") | ||||
| open var shelfLife: Double? = null | open var shelfLife: Double? = null | ||||
| @@ -32,24 +32,6 @@ open class Items : BaseEntity<Long>() { | |||||
| @Column(name = "countryOfOrigin") | @Column(name = "countryOfOrigin") | ||||
| open var countryOfOrigin: String? = null | open var countryOfOrigin: String? = null | ||||
| @Column(name = "minHumid") | |||||
| open var minHumid: Double? = null | |||||
| @Column(name = "maxHumid") | |||||
| open var maxHumid: Double? = null | |||||
| @Column(name = "minTemp") | |||||
| open var minTemp: Double? = null | |||||
| @Column(name = "maxTemp") | |||||
| open var maxTemp: Double? = null | |||||
| @Column(name = "sampleRate") | |||||
| open var sampleRate: Double? = null | |||||
| @Column(name = "passingRate") | |||||
| open var passingRate: Double? = null | |||||
| @Column(name = "netWeight") | |||||
| open var netWeight: Double? = null | |||||
| @Column(name = "maxQty") | |||||
| open var maxQty: Double? = null | |||||
| } | } | ||||
| @@ -1,11 +1,12 @@ | |||||
| package com.ffii.fpsms.modules.master.entity | package com.ffii.fpsms.modules.master.entity | ||||
| import com.ffii.core.support.AbstractRepository | import com.ffii.core.support.AbstractRepository | ||||
| import com.ffii.fpsms.modules.master.web.models.ItemType | |||||
| import org.springframework.stereotype.Repository | import org.springframework.stereotype.Repository | ||||
| @Repository | @Repository | ||||
| interface ItemsRepository : AbstractRepository<Items, Long> { | interface ItemsRepository : AbstractRepository<Items, Long> { | ||||
| fun findAllByDeletedFalse(): List<Items>; | fun findAllByDeletedFalse(): List<Items>; | ||||
| fun findByIdAndTypeIdAndDeletedFalse(id: Long, typeId: Long): Items; | |||||
| fun findByCodeAndTypeIdAndDeletedFalse(code: String, typeId: Long): Items?; | |||||
| fun findByIdAndDeletedFalse(id: Long): Items; | |||||
| fun findByCodeAndTypeAndDeletedFalse(code: String, type: ItemType): Items?; | |||||
| } | } | ||||
| @@ -1,17 +0,0 @@ | |||||
| package com.ffii.fpsms.modules.master.service | |||||
| import com.ffii.core.support.AbstractBaseEntityService | |||||
| import com.ffii.core.support.AbstractIdEntityService | |||||
| import com.ffii.core.support.JdbcDao | |||||
| import com.ffii.fpsms.modules.master.entity.* | |||||
| import com.ffii.fpsms.modules.master.web.models.MessageResponse | |||||
| import org.springframework.stereotype.Service | |||||
| import org.springframework.transaction.annotation.Transactional | |||||
| @Service | |||||
| open class ItemTypeService( | |||||
| private val jdbcDao: JdbcDao, | |||||
| private val itemTypeRepository: ItemTypeRepository | |||||
| ): AbstractIdEntityService<ItemType, Long, ItemTypeRepository>(jdbcDao, itemTypeRepository) { | |||||
| } | |||||
| @@ -2,9 +2,8 @@ package com.ffii.fpsms.modules.master.service | |||||
| import com.ffii.core.support.AbstractBaseEntityService | import com.ffii.core.support.AbstractBaseEntityService | ||||
| import com.ffii.core.support.JdbcDao | import com.ffii.core.support.JdbcDao | ||||
| import com.ffii.fpsms.modules.master.entity.ItemTypeRepository | |||||
| import com.ffii.fpsms.modules.master.entity.Items | |||||
| import com.ffii.fpsms.modules.master.entity.ItemsRepository | |||||
| import com.ffii.fpsms.modules.master.entity.* | |||||
| import com.ffii.fpsms.modules.master.web.models.ItemWithQcResponse | |||||
| import com.ffii.fpsms.modules.master.web.models.MessageResponse | import com.ffii.fpsms.modules.master.web.models.MessageResponse | ||||
| import com.ffii.fpsms.modules.master.web.models.NewItemRequest | import com.ffii.fpsms.modules.master.web.models.NewItemRequest | ||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| @@ -16,7 +15,7 @@ import kotlin.jvm.optionals.getOrNull | |||||
| open class ItemsService( | open class ItemsService( | ||||
| private val jdbcDao: JdbcDao, | private val jdbcDao: JdbcDao, | ||||
| private val itemsRepository: ItemsRepository, | private val itemsRepository: ItemsRepository, | ||||
| private val itemTypeRepository: ItemTypeRepository, | |||||
| private val qcCheckRepository: QcCheckRepository, | |||||
| ): AbstractBaseEntityService<Items, Long, ItemsRepository>(jdbcDao, itemsRepository) { | ): AbstractBaseEntityService<Items, Long, ItemsRepository>(jdbcDao, itemsRepository) { | ||||
| // do mapping with projection | // do mapping with projection | ||||
| open fun allItems(): List<Items> { | open fun allItems(): List<Items> { | ||||
| @@ -24,27 +23,42 @@ open class ItemsService( | |||||
| val items = itemsRepository.findAll() | val items = itemsRepository.findAll() | ||||
| return items | return items | ||||
| } | } | ||||
| open fun getItem(id: Long): Items? { | |||||
| return itemsRepository.findById(id).getOrNull() | |||||
| // QcCheck included item | |||||
| open fun getItem(id: Long): ItemWithQcResponse { | |||||
| val list = listOf(1,2) | |||||
| val item = itemsRepository.findByIdAndDeletedFalse(id) | |||||
| val qcChecks = qcCheckRepository.findAllByItemIdAndDeletedFalse(id).map { qcCheck -> | |||||
| } | |||||
| val response = ItemWithQcResponse( | |||||
| item = item | |||||
| ) | |||||
| // val test = ItemWithQC(list) | |||||
| // TODO: Return with QC items | |||||
| return response | |||||
| } | } | ||||
| // open fun getItem(id: Long): Items? { | |||||
| // // TODO: Return with QC items | |||||
| // return itemsRepository.findById(id).get() | |||||
| // } | |||||
| @Throws(IOException::class) | @Throws(IOException::class) | ||||
| @Transactional | @Transactional | ||||
| open fun saveItem(request: NewItemRequest): MessageResponse { | open fun saveItem(request: NewItemRequest): MessageResponse { | ||||
| val type = itemTypeRepository.findById(request.typeId).get() | |||||
| val duplicatedItem = itemsRepository.findByCodeAndTypeIdAndDeletedFalse(request.code, request.typeId) | |||||
| val duplicatedItem = itemsRepository.findByCodeAndTypeAndDeletedFalse(request.code, request.type) | |||||
| if (duplicatedItem != null && duplicatedItem.id != request.id) { | if (duplicatedItem != null && duplicatedItem.id != request.id) { | ||||
| return MessageResponse( | return MessageResponse( | ||||
| id = request.id, | id = request.id, | ||||
| code = request.code, | code = request.code, | ||||
| name = request.name, | name = request.name, | ||||
| type = type.name, | |||||
| type = request.type.toString(), | |||||
| message = "The item code has already existed", | message = "The item code has already existed", | ||||
| errorPosition = "code" | errorPosition = "code" | ||||
| ) | ) | ||||
| } | } | ||||
| val item = if (request.id != null && request.id > 0) itemsRepository.findByIdAndTypeIdAndDeletedFalse(request.id, request.typeId) | |||||
| val item = if (request.id != null && request.id > 0) itemsRepository.findByIdAndDeletedFalse(request.id) | |||||
| else Items() | else Items() | ||||
| println(request.netWeight) | |||||
| item.apply { | item.apply { | ||||
| code = request.code | code = request.code | ||||
| name = request.name | name = request.name | ||||
| @@ -52,13 +66,7 @@ open class ItemsService( | |||||
| remarks = request.remarks | remarks = request.remarks | ||||
| shelfLife = request.shelfLife | shelfLife = request.shelfLife | ||||
| countryOfOrigin = request.countryOfOrigin | countryOfOrigin = request.countryOfOrigin | ||||
| minHumid = request.minHumid | |||||
| maxHumid = request.maxHumid | |||||
| minTemp = request.minTemp | |||||
| maxTemp = request.maxTemp | |||||
| sampleRate = request.sampleRate | |||||
| passingRate = request.passingRate | |||||
| netWeight = request.netWeight | |||||
| maxQty = request.maxQty | |||||
| this.type = type | this.type = type | ||||
| } | } | ||||
| val savedItem = itemsRepository.saveAndFlush(item) | val savedItem = itemsRepository.saveAndFlush(item) | ||||
| @@ -66,7 +74,7 @@ open class ItemsService( | |||||
| id = savedItem.id, | id = savedItem.id, | ||||
| name = savedItem.name, | name = savedItem.name, | ||||
| code = savedItem.code, | code = savedItem.code, | ||||
| type = type.name, | |||||
| type = savedItem.type.toString(), | |||||
| message = "Item Save Success", | message = "Item Save Success", | ||||
| errorPosition = null, | errorPosition = null, | ||||
| ) | ) | ||||
| @@ -0,0 +1,15 @@ | |||||
| package com.ffii.fpsms.modules.master.web.models | |||||
| import com.ffii.fpsms.modules.master.entity.Items | |||||
| import com.ffii.fpsms.modules.master.entity.QcItem | |||||
| data class ItemQc( | |||||
| val id: Long, | |||||
| val description: String?, | |||||
| val lowerLimit: Double?, | |||||
| val upperLimit: Double?, | |||||
| ) | |||||
| data class ItemWithQcResponse( | |||||
| val item: Items, | |||||
| val qcChecks: List<ItemQc> | |||||
| ) | |||||
| @@ -3,26 +3,26 @@ package com.ffii.fpsms.modules.master.web.models | |||||
| import jakarta.validation.constraints.NotBlank | import jakarta.validation.constraints.NotBlank | ||||
| import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
| enum class ItemType(type: String) { | |||||
| MATERIAL("mat"), | |||||
| BY_PRODUCT("byp"), | |||||
| PRODUCT("product"), | |||||
| CONSUMABLE("consumables"), | |||||
| } | |||||
| data class NewItemRequest( | data class NewItemRequest( | ||||
| @field:NotBlank(message = "material code cannot be empty") | @field:NotBlank(message = "material code cannot be empty") | ||||
| val code: String, | val code: String, | ||||
| @field:NotBlank(message = "material name cannot be empty") | @field:NotBlank(message = "material name cannot be empty") | ||||
| val name: String, | val name: String, | ||||
| @field:NotNull(message = "typeId cannot be null") | @field:NotNull(message = "typeId cannot be null") | ||||
| val typeId: Long, | |||||
| val type: ItemType, | |||||
| val id: Long?, | val id: Long?, | ||||
| val description: String?, | val description: String?, | ||||
| val remarks: String?, | val remarks: String?, | ||||
| val shelfLife: Double?, | val shelfLife: Double?, | ||||
| val countryOfOrigin: String?, | val countryOfOrigin: String?, | ||||
| val minHumid: Double?, | |||||
| val maxHumid: Double?, | |||||
| val minTemp: Double?, | |||||
| val maxTemp: Double?, | |||||
| val sampleRate: Double?, | |||||
| val passingRate: Double?, | |||||
| val netWeight: Double?, | |||||
| val maxQty: Double?, | |||||
| // val type: List<NewTypeRequest>?, | // val type: List<NewTypeRequest>?, | ||||
| // val uom: List<NewUomRequest>?, | // val uom: List<NewUomRequest>?, | ||||
| // val weightUnit: List<NewWeightUnitRequest>?, | // val weightUnit: List<NewWeightUnitRequest>?, | ||||
| @@ -19,8 +19,7 @@ CREATE TABLE items ( | |||||
| shelfLife INT(11) NULL, | shelfLife INT(11) NULL, | ||||
| countryOfOrigin varchar(50) NULL, | countryOfOrigin varchar(50) NULL, | ||||
| maxQty DECIMAL(16,2) NULL, | maxQty DECIMAL(16,2) NULL, | ||||
| CONSTRAINT pk_material PRIMARY KEY (id), | |||||
| CONSTRAINT fk_items FOREIGN KEY (`typeId`) REFERENCES `item_type` (`id`) | |||||
| CONSTRAINT pk_material PRIMARY KEY (id) | |||||
| ); | ); | ||||
| CREATE TABLE uom_conversion ( | CREATE TABLE uom_conversion ( | ||||
| id INT NOT NULL AUTO_INCREMENT, | id INT NOT NULL AUTO_INCREMENT, | ||||