| @@ -22,6 +22,10 @@ open class QcCategory : BaseEntity<Long>() { | |||||
| @Column(name = "description") | @Column(name = "description") | ||||
| open var description: String? = null | open var description: String? = null | ||||
| @NotNull | |||||
| @Column(name = "isDefault") | |||||
| open var isDefault: Boolean = false | |||||
| // @OneToMany(cascade = [CascadeType.ALL]) | // @OneToMany(cascade = [CascadeType.ALL]) | ||||
| // @JoinTable( | // @JoinTable( | ||||
| // name = "qc_item_category", | // name = "qc_item_category", | ||||
| @@ -30,5 +30,6 @@ interface QcCategoryRepository : AbstractRepository<QcCategory, Long> { | |||||
| """ | """ | ||||
| ) | ) | ||||
| fun findQcCategoryInfoByItemIdAndType(itemId: Long, type: String): QcCategoryInfo?; | fun findQcCategoryInfoByItemIdAndType(itemId: Long, type: String): QcCategoryInfo?; | ||||
| fun findQcCategoryInfoByIsDefault(isDefault: Boolean): QcCategoryInfo?; | |||||
| // fun findByItemIdAndType(itemId: Long, type: String): QcCategory?; | // fun findByItemIdAndType(itemId: Long, type: String): QcCategory?; | ||||
| } | } | ||||
| @@ -379,7 +379,8 @@ open class ItemsService( | |||||
| + " i.id " | + " i.id " | ||||
| + " FROM items i " | + " FROM items i " | ||||
| + " INNER JOIN items_qc_category_mapping iqcm ON iqcm.itemId = i.id AND iqcm.type = :qcType " | + " INNER JOIN items_qc_category_mapping iqcm ON iqcm.itemId = i.id AND iqcm.type = :qcType " | ||||
| + " WHERE i.deleted = false " | |||||
| + " LEFT JOIN qc_category qcc ON qcc.id = iqcm.qcCategoryId " | |||||
| + " WHERE i.deleted = false AND qcc.deleted = false" | |||||
| + " AND LEFT(i.code, 2) = (SELECT LEFT(code, 2) FROM items WHERE id = :itemId)" | + " AND LEFT(i.code, 2) = (SELECT LEFT(code, 2) FROM items WHERE id = :itemId)" | ||||
| + " AND i.id != :itemId " | + " AND i.id != :itemId " | ||||
| ) | ) | ||||
| @@ -28,7 +28,15 @@ open class QcCategoryService( | |||||
| "qcType" to type | "qcType" to type | ||||
| ) | ) | ||||
| val similarItemIds = itemsService.getItemsIdWithSameCategoryForQc(args); | val similarItemIds = itemsService.getItemsIdWithSameCategoryForQc(args); | ||||
| result = qcCategoryRepository.findQcCategoryInfoByItemIdAndType(similarItemIds[0].toLong(), type) | |||||
| // Comment the lines below to disable auto matching QC from similar items | |||||
| result = if (similarItemIds.isNotEmpty()) | |||||
| qcCategoryRepository.findQcCategoryInfoByItemIdAndType(similarItemIds[0].toLong(), type) | |||||
| else null | |||||
| // | |||||
| if (result == null) { // Use Default Template | |||||
| result = qcCategoryRepository.findQcCategoryInfoByIsDefault(true) | |||||
| } | |||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| @@ -0,0 +1,6 @@ | |||||
| -- liquibase formatted sql | |||||
| -- changeset kelvinS:alter qc category table | |||||
| ALTER TABLE `qc_category` | |||||
| ADD COLUMN `isDefault` TINYINT(1) NOT NULL DEFAULT '0' AFTER `deleted`, | |||||
| CHANGE COLUMN `name` `name` VARCHAR(255) NOT NULL ; | |||||