| @@ -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<Long>() { | |||||
| @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<ProductMaterialWeightUnit> = HashSet() | |||||
| @OneToMany(mappedBy = "material", cascade = [CascadeType.ALL], orphanRemoval = true) | |||||
| @JsonManagedReference("material-uom") | |||||
| @JsonInclude(JsonInclude.Include.NON_NULL) | |||||
| private val uom: Set<ProductMaterialWeightUnit> = HashSet() | |||||
| @OneToMany(mappedBy = "material", cascade = [CascadeType.ALL], orphanRemoval = true) | |||||
| @JsonManagedReference("material-uom") | |||||
| @JsonInclude(JsonInclude.Include.NON_NULL) | |||||
| private val type: Set<ProductMaterialType> = 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 | |||||
| } | |||||
| @@ -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<Material, Long> { | |||||
| // fun findAllByDeletedFalse(): List<Material>; | |||||
| } | |||||
| @@ -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<Long>() { | |||||
| @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<ProductMaterialWeightUnit> = HashSet() | |||||
| @OneToMany(mappedBy = "product", cascade = [CascadeType.ALL], orphanRemoval = true) | |||||
| @JsonManagedReference("product-uom") | |||||
| @JsonInclude(JsonInclude.Include.NON_NULL) | |||||
| private val uom: Set<ProductMaterialWeightUnit> = HashSet() | |||||
| @OneToMany(mappedBy = "product", cascade = [CascadeType.ALL], orphanRemoval = true) | |||||
| @JsonManagedReference("product-uom") | |||||
| @JsonInclude(JsonInclude.Include.NON_NULL) | |||||
| private val type: Set<ProductMaterialType> = 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 | |||||
| } | |||||
| @@ -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 | |||||
| } | |||||
| @@ -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 | |||||
| } | |||||
| @@ -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 | |||||
| } | |||||
| @@ -0,0 +1,8 @@ | |||||
| package com.ffii.fpsms.modules.master.entity | |||||
| import com.ffii.core.support.AbstractRepository | |||||
| interface ProductRepository: AbstractRepository<Product, Long> { | |||||
| fun findAllByDeletedFalse(): List<Product>; | |||||
| } | |||||
| @@ -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<Material, Long, MaterialRepository>(jdbcDao, materialRepository) { | |||||
| // do mapping with projection | |||||
| open fun getMaterials(): List<Material> { | |||||
| // TODO: Replace by actual logic | |||||
| val materials = materialRepository.findAll() | |||||
| return materials | |||||
| } | |||||
| } | |||||
| @@ -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<Product, Long, ProductRepository>(jdbcDao, productRepository) { | |||||
| } | |||||
| @@ -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<Material> { | |||||
| return materialService.getMaterials() | |||||
| } | |||||
| } | |||||
| @@ -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); | |||||