From 1f4da6ef6cf3266fbe78f16ed34a30fc53b4368b Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Tue, 4 Mar 2025 17:55:05 +0800 Subject: [PATCH] material related --- .../fpsms/modules/master/entity/Material.kt | 71 +++++++++++++++++ .../master/entity/MaterialRepository.kt | 10 +++ .../fpsms/modules/master/entity/Product.kt | 71 +++++++++++++++++ .../master/entity/ProductMaterialType.kt | 27 +++++++ .../master/entity/ProductMaterialUom.kt | 26 +++++++ .../entity/ProductMaterialWeightUnit.kt | 31 ++++++++ .../master/entity/ProductRepository.kt | 8 ++ .../modules/master/service/MaterialService.kt | 20 +++++ .../modules/master/service/ProductService.kt | 15 ++++ .../modules/master/web/MaterialController.kt | 18 +++++ .../20250304_01_derek/01_master_tables.sql | 77 +++++++++++++++++++ 11 files changed, 374 insertions(+) create mode 100644 src/main/java/com/ffii/fpsms/modules/master/entity/Material.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/entity/MaterialRepository.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/entity/Product.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialType.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialUom.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialWeightUnit.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/entity/ProductRepository.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/service/MaterialService.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/service/ProductService.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/master/web/MaterialController.kt create mode 100644 src/main/resources/db/changelog/changes/20250304_01_derek/01_master_tables.sql diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/Material.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/Material.kt new file mode 100644 index 0000000..c98e8a0 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/Material.kt @@ -0,0 +1,71 @@ +package com.ffii.fpsms.modules.master.entity + +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonManagedReference +import com.ffii.core.entity.BaseEntity +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + +@Entity +@Table(name = "material") +open class Material : BaseEntity() { + @NotNull + @Column(name = "code") + open var code: String? = null + + @NotNull + @Column(name = "name") + open var name: String? = null + + @Column(name = "description") + open var description: String? = null + + @Column(name = "remarks") + open var remarks: String? = null + + @NotNull + @Column(name = "isConsumables") + open var isConsumables: Boolean? = null + + @OneToMany(mappedBy = "material", cascade = [CascadeType.ALL], orphanRemoval = true) + @JsonManagedReference("material-weight-unit") + @JsonInclude(JsonInclude.Include.NON_NULL) + private val weightUnit: Set = HashSet() + + @OneToMany(mappedBy = "material", cascade = [CascadeType.ALL], orphanRemoval = true) + @JsonManagedReference("material-uom") + @JsonInclude(JsonInclude.Include.NON_NULL) + private val uom: Set = HashSet() + + @OneToMany(mappedBy = "material", cascade = [CascadeType.ALL], orphanRemoval = true) + @JsonManagedReference("material-uom") + @JsonInclude(JsonInclude.Include.NON_NULL) + private val type: Set = HashSet() + + @Column(name = "shelfLife") + open var shelfLife: Number? = null + + @Column(name = "countryOfOrigin") + 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 +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/MaterialRepository.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/MaterialRepository.kt new file mode 100644 index 0000000..275e429 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/MaterialRepository.kt @@ -0,0 +1,10 @@ +package com.ffii.fpsms.modules.master.entity + +import com.ffii.core.support.AbstractRepository +import org.springframework.stereotype.Repository + +@Repository +interface MaterialRepository : AbstractRepository { +// fun findAllByDeletedFalse(): List; + +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/Product.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/Product.kt new file mode 100644 index 0000000..2cd0e34 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/Product.kt @@ -0,0 +1,71 @@ +package com.ffii.fpsms.modules.master.entity + +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonManagedReference +import com.ffii.core.entity.BaseEntity +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + +@Entity +@Table(name = "product") +open class Product : BaseEntity() { + @NotNull + @Column(name = "code") + open var code: String? = null + + @NotNull + @Column(name = "name") + open var name: String? = null + + @Column(name = "description") + open var description: String? = null + + @Column(name = "remarks") + open var remarks: String? = null + + @NotNull + @Column(name = "isConsumables") + open var isConsumables: Boolean? = null + + @OneToMany(mappedBy = "product", cascade = [CascadeType.ALL], orphanRemoval = true) + @JsonManagedReference("product-weight-unit") + @JsonInclude(JsonInclude.Include.NON_NULL) + private val weightUnit: Set = HashSet() + + @OneToMany(mappedBy = "product", cascade = [CascadeType.ALL], orphanRemoval = true) + @JsonManagedReference("product-uom") + @JsonInclude(JsonInclude.Include.NON_NULL) + private val uom: Set = HashSet() + + @OneToMany(mappedBy = "product", cascade = [CascadeType.ALL], orphanRemoval = true) + @JsonManagedReference("product-uom") + @JsonInclude(JsonInclude.Include.NON_NULL) + private val type: Set = HashSet() + + @Column(name = "shelfLife") + open var shelfLife: Number? = null + + @Column(name = "countryOfOrigin") + 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 +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialType.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialType.kt new file mode 100644 index 0000000..2448498 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialType.kt @@ -0,0 +1,27 @@ +package com.ffii.fpsms.modules.master.entity + +import com.fasterxml.jackson.annotation.JsonBackReference +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + + +@Entity +@Table(name = "product_material_type") +open class ProductMaterialType { + @ManyToOne + @JoinColumn(name = "productId") + @JsonBackReference + @NotNull + open var product: Product? = null + + @ManyToOne + @JoinColumn(name = "materialId") + @JsonBackReference + @NotNull + open var material: Material? = null + + @Id + @NotNull + @Column(name = "name") + open var name: String? = null +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialUom.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialUom.kt new file mode 100644 index 0000000..99ed014 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialUom.kt @@ -0,0 +1,26 @@ +package com.ffii.fpsms.modules.master.entity + +import com.fasterxml.jackson.annotation.JsonBackReference +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + +@Entity +@Table(name = "product_material_uom") +open class ProductMaterialUom { + @ManyToOne + @JoinColumn(name = "productId") + @JsonBackReference + @NotNull + open var product: Product? = null + + @ManyToOne + @JoinColumn(name = "materialId") + @JsonBackReference + @NotNull + open var material: Material? = null + + @Id + @NotNull + @Column(name = "uom") + open var uom: String? = null +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialWeightUnit.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialWeightUnit.kt new file mode 100644 index 0000000..db01d69 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductMaterialWeightUnit.kt @@ -0,0 +1,31 @@ +package com.ffii.fpsms.modules.master.entity + +import com.fasterxml.jackson.annotation.JsonBackReference +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + +@Entity +@Table(name = "product_material_weightUnit") +open class ProductMaterialWeightUnit { + @ManyToOne + @JoinColumn(name = "productId") + @JsonBackReference + @NotNull + open var product: Product? = null + + @ManyToOne + @JoinColumn(name = "materialId") + @JsonBackReference + @NotNull + open var material: Material? = null + + @Id + @NotNull + @Column(name = "weightUnit") + open var weightUnit: String? = null + + @NotNull + @Column(name = "conversion") + open var conversion: Double? = null + +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/ProductRepository.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductRepository.kt new file mode 100644 index 0000000..73735fd --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductRepository.kt @@ -0,0 +1,8 @@ +package com.ffii.fpsms.modules.master.entity + +import com.ffii.core.support.AbstractRepository + +interface ProductRepository: AbstractRepository { + fun findAllByDeletedFalse(): List; + +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/service/MaterialService.kt b/src/main/java/com/ffii/fpsms/modules/master/service/MaterialService.kt new file mode 100644 index 0000000..c63e43c --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/service/MaterialService.kt @@ -0,0 +1,20 @@ +package com.ffii.fpsms.modules.master.service + +import com.ffii.core.support.AbstractBaseEntityService +import com.ffii.core.support.JdbcDao +import com.ffii.fpsms.modules.master.entity.Material +import com.ffii.fpsms.modules.master.entity.MaterialRepository +import org.springframework.stereotype.Service + +@Service +open class MaterialService( + private val jdbcDao: JdbcDao, + private val materialRepository: MaterialRepository, +): AbstractBaseEntityService(jdbcDao, materialRepository) { + // do mapping with projection + open fun getMaterials(): List { + // TODO: Replace by actual logic + val materials = materialRepository.findAll() + return materials + } +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/service/ProductService.kt b/src/main/java/com/ffii/fpsms/modules/master/service/ProductService.kt new file mode 100644 index 0000000..e5efebf --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/service/ProductService.kt @@ -0,0 +1,15 @@ +package com.ffii.fpsms.modules.master.service + +import com.ffii.core.support.AbstractBaseEntityService +import com.ffii.core.support.JdbcDao +import com.ffii.fpsms.modules.master.entity.Material +import com.ffii.fpsms.modules.master.entity.MaterialRepository +import com.ffii.fpsms.modules.master.entity.Product +import com.ffii.fpsms.modules.master.entity.ProductRepository + +class ProductService( + private val jdbcDao: JdbcDao, + private val productRepository: ProductRepository +): AbstractBaseEntityService(jdbcDao, productRepository) { + +} \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/web/MaterialController.kt b/src/main/java/com/ffii/fpsms/modules/master/web/MaterialController.kt new file mode 100644 index 0000000..879e4fc --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/master/web/MaterialController.kt @@ -0,0 +1,18 @@ +package com.ffii.fpsms.modules.master.web + +import com.ffii.fpsms.modules.master.entity.Material +import com.ffii.fpsms.modules.master.service.MaterialService +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/materials") +class MaterialController( + private val materialService: MaterialService +) { + @GetMapping + fun allMaterial(): List { + return materialService.getMaterials() + } +} \ No newline at end of file diff --git a/src/main/resources/db/changelog/changes/20250304_01_derek/01_master_tables.sql b/src/main/resources/db/changelog/changes/20250304_01_derek/01_master_tables.sql new file mode 100644 index 0000000..7d937a1 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20250304_01_derek/01_master_tables.sql @@ -0,0 +1,77 @@ +-- liquibase formatted sql + +-- changeset derek:material and product +CREATE TABLE material ( + id INT NOT NULL AUTO_INCREMENT, + version INT NOT NULL DEFAULT '0', + created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + createdBy VARCHAR(30) NULL, + modified datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + modifiedBy VARCHAR(30) NULL, + deleted TINYINT(1) NOT NULL DEFAULT '0', + `code` VARCHAR(50) NOT NULL, + `name` VARCHAR(50) NOT NULL, + description VARCHAR(100) NULL, + remarks varchar(500) NULL, + isConsumables TINYINT(1) NOT NULL default 0, + shelfLife INT(11) NULL, + countryOfOrigin varchar(50) NULL, + minHumid DECIMAL(16,2) NULL, + maxHumid DECIMAL(16,2) NULL, + minTemp DECIMAL(16,2) NULL, + maxTemp DECIMAL(16,2) NULL, + sampleRate DECIMAL(16,2) NULL, + passingRate DECIMAL(16,2) NULL, + netWeight DECIMAL(16,2) NULL, + CONSTRAINT pk_material PRIMARY KEY (id) +); + +CREATE TABLE product ( + id INT NOT NULL AUTO_INCREMENT, + version INT NOT NULL DEFAULT '0', + created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + createdBy VARCHAR(30) NULL, + modified datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + modifiedBy VARCHAR(30) NULL, + deleted TINYINT(1) NOT NULL DEFAULT '0', + `code` VARCHAR(50) NOT NULL, + `name` VARCHAR(50) NOT NULL, + description VARCHAR(100) NULL, + remarks varchar(500) NULL, + isConsumables TINYINT(1) NOT NULL default 0, + shelfLife INT(11) NULL, + countryOfOrigin varchar(50) NULL, + minHumid DECIMAL(16,2) NULL, + maxHumid DECIMAL(16,2) NULL, + minTemp DECIMAL(16,2) NULL, + maxTemp DECIMAL(16,2) NULL, + sampleRate DECIMAL(16,2) NULL, + passingRate DECIMAL(16,2) NULL, + netWeight DECIMAL(16,2) NULL, + CONSTRAINT pk_product PRIMARY KEY (id) +); + +CREATE TABLE product_material_weightUnit ( + productId INT NULL, + materialId INT NULL, + weightUnit VARCHAR(30) NOT NULL, + conversion DECIMAL(16,2) NOT NULL DEFAULT 1 + +); +CREATE TABLE product_material_uom ( + productId INT NULL, + materialId INT NULL, + uom VARCHAR(30) NOT NULL +); +CREATE TABLE product_material_type ( + productId INT NULL, + materialId INT NULL, + name VARCHAR(30) NOT NULL +); + +ALTER TABLE product_material_weightUnit ADD CONSTRAINT FK_PRODUCT_ON_WEIGHTUNIT FOREIGN KEY (productId) REFERENCES product (id); +ALTER TABLE product_material_weightUnit ADD CONSTRAINT FK_MATERIAL_ON_WEIGHTUNIT FOREIGN KEY (materialId) REFERENCES material (id); +ALTER TABLE product_material_uom ADD CONSTRAINT FK_PRODUCT_ON_UOM FOREIGN KEY (productId) REFERENCES product (id); +ALTER TABLE product_material_uom ADD CONSTRAINT FK_MATERIAL_ON_UOM FOREIGN KEY (materialId) REFERENCES material (id); +ALTER TABLE product_material_type ADD CONSTRAINT FK_PRODUCT_ON_TYPE FOREIGN KEY (productId) REFERENCES product (id); +ALTER TABLE product_material_type ADD CONSTRAINT FK_MATERIAL_ON_TYPE FOREIGN KEY (materialId) REFERENCES material (id);