@@ -25,9 +25,8 @@ open class M18DataLog : BaseEntity<Long>() { | |||||
@Column(name = "m18Id", nullable = false) | @Column(name = "m18Id", nullable = false) | ||||
open var m18Id: Long? = null | open var m18Id: Long? = null | ||||
@NotNull | |||||
@JdbcTypeCode(SqlTypes.JSON) | @JdbcTypeCode(SqlTypes.JSON) | ||||
@Column(name = "dataLog", nullable = false) | |||||
@Column(name = "dataLog") | |||||
open var dataLog: MutableMap<String, Any?>? = null | open var dataLog: MutableMap<String, Any?>? = null | ||||
@NotNull | @NotNull | ||||
@@ -1,10 +1,11 @@ | |||||
package com.ffii.fpsms.m18.entity | package com.ffii.fpsms.m18.entity | ||||
import com.ffii.core.support.AbstractRepository | import com.ffii.core.support.AbstractRepository | ||||
import com.ffii.fpsms.m18.enums.M18DataLogStatus | |||||
import org.springframework.stereotype.Repository | import org.springframework.stereotype.Repository | ||||
@Repository | @Repository | ||||
interface M18DataLogRepository : AbstractRepository<M18DataLog, Long> { | interface M18DataLogRepository : AbstractRepository<M18DataLog, Long> { | ||||
// find latest m18 data log by m18 id & ref type & status is true & deleted is false (order by id asc limit 1) | // find latest m18 data log by m18 id & ref type & status is true & deleted is false (order by id asc limit 1) | ||||
fun findTopByM18IdAndRefTypeAndDeletedIsFalseAndStatusIsTrueOrderByIdDesc(m18Id: Long, refType: String): M18DataLog? | |||||
fun findTopByM18IdAndRefTypeAndDeletedIsFalseAndStatusOrderByIdDesc(m18Id: Long, refType: String, status: M18DataLogStatus): M18DataLog? | |||||
} | } |
@@ -8,6 +8,7 @@ enum class StSearchType(val value: String) { | |||||
UNIT("unit"), | UNIT("unit"), | ||||
CURRENCY("cur"), | CURRENCY("cur"), | ||||
BOM("udfbomforshop"), | BOM("udfbomforshop"), | ||||
BUSINESS_UNIT("virDept"), | |||||
} | } | ||||
/** M18 Common Master Data Request */ | /** M18 Common Master Data Request */ | ||||
@@ -191,4 +191,44 @@ data class M18BomUdfProduct ( | |||||
val udfProduct: Long, | val udfProduct: Long, | ||||
val udfIngredients: String, | val udfIngredients: String, | ||||
val udfBaseUnit: String, | val udfBaseUnit: String, | ||||
) | |||||
/** Shop Response */ | |||||
data class M18BusinessUnitResponse ( | |||||
val data: M18BusinessUnitData?, | |||||
val messages: List<M18ErrorMessages>? | |||||
) | |||||
data class M18BusinessUnitData ( | |||||
val virdept: List<M18BusinessUnitVirdept>? | |||||
) | |||||
data class M18BusinessUnitVirdept ( | |||||
val id: Long, | |||||
val code: String, | |||||
/** name */ | |||||
val desc: String, | |||||
val `desc_zh-TW`: String, | |||||
/** contactNo */ | |||||
val tel: String, | |||||
val email: String, | |||||
val addr: String, | |||||
val addr_en: String, | |||||
val addr2: String, | |||||
val addr2_en: String, | |||||
val addr3: String, | |||||
val addr3_en: String, | |||||
val udfdistrict: Long, | |||||
val lastModifyDate: Long, | |||||
) | |||||
/** BusinessUnit List Response */ | |||||
data class M18BusinessUnitListResponse ( | |||||
val values: List<M18BusinessUnitListValue>?, | |||||
val messages: List<M18ErrorMessages>? | |||||
) | |||||
data class M18BusinessUnitListValue ( | |||||
val id: Long, | |||||
val lastModifyDate: String?, | |||||
) | ) |
@@ -27,6 +27,8 @@ data class M18PurchaseOrderMainPo ( | |||||
val tDate: Long, | val tDate: Long, | ||||
val lastModifyDate: Long, | val lastModifyDate: Long, | ||||
val curId: Long, | val curId: Long, | ||||
/** Business Unit (Shop) */ | |||||
val virDeptId: Long?, | |||||
) | ) | ||||
data class M18PurchaseOrderPot ( | data class M18PurchaseOrderPot ( | ||||
@@ -19,6 +19,7 @@ data class M18PurchaseQuotationMainvqu( | |||||
val tDate: Long, | val tDate: Long, | ||||
val venId: Long, | val venId: Long, | ||||
val manId: Long, | val manId: Long, | ||||
val curId: Long, | |||||
val code: String, | val code: String, | ||||
) | ) | ||||
@@ -5,7 +5,6 @@ import com.ffii.fpsms.m18.entity.M18DataLogRepository | |||||
import com.ffii.fpsms.m18.enums.M18DataLogStatus | import com.ffii.fpsms.m18.enums.M18DataLogStatus | ||||
import com.ffii.fpsms.m18.model.M18DataLogResponse | import com.ffii.fpsms.m18.model.M18DataLogResponse | ||||
import com.ffii.fpsms.m18.model.SaveM18DataLogRequest | import com.ffii.fpsms.m18.model.SaveM18DataLogRequest | ||||
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus | |||||
import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
import kotlin.jvm.optionals.getOrDefault | import kotlin.jvm.optionals.getOrDefault | ||||
@@ -13,8 +12,8 @@ import kotlin.jvm.optionals.getOrDefault | |||||
class M18DataLogService( | class M18DataLogService( | ||||
val m18DataLogRepository: M18DataLogRepository | val m18DataLogRepository: M18DataLogRepository | ||||
) { | ) { | ||||
fun findLatestM18DataLog(m18Id: Long, refType: String): M18DataLog? { | |||||
return m18DataLogRepository.findTopByM18IdAndRefTypeAndDeletedIsFalseAndStatusIsTrueOrderByIdDesc(m18Id, refType) | |||||
fun findLatestM18DataLogWithSuccess(m18Id: Long, refType: String): M18DataLog? { | |||||
return m18DataLogRepository.findTopByM18IdAndRefTypeAndDeletedIsFalseAndStatusOrderByIdDesc(m18Id, refType, M18DataLogStatus.SUCCESS) | |||||
} | } | ||||
fun saveM18DataLog(request: SaveM18DataLogRequest): M18DataLogResponse { | fun saveM18DataLog(request: SaveM18DataLogRequest): M18DataLogResponse { | ||||
@@ -27,7 +26,7 @@ class M18DataLogService( | |||||
refType = request.refType ?: this.refType | refType = request.refType ?: this.refType | ||||
m18Id = request.m18Id ?: this.m18Id | m18Id = request.m18Id ?: this.m18Id | ||||
m18LastModifyDate = request.m18LastModifyDate ?: this.m18LastModifyDate | m18LastModifyDate = request.m18LastModifyDate ?: this.m18LastModifyDate | ||||
dataLog = request.dataLog ?: request.dataLog | |||||
dataLog = request.dataLog ?: this.dataLog | |||||
this.status = status | this.status = status | ||||
} | } | ||||
@@ -54,6 +54,7 @@ open class M18MasterDataService( | |||||
val M18_LOAD_UNIT_API = "${M18_COMMON_LOAD_LINE_API}/${StSearchType.UNIT.value}" | val M18_LOAD_UNIT_API = "${M18_COMMON_LOAD_LINE_API}/${StSearchType.UNIT.value}" | ||||
val M18_LOAD_CURRENCY_API = "${M18_COMMON_LOAD_LINE_API}/${StSearchType.CURRENCY.value}" | val M18_LOAD_CURRENCY_API = "${M18_COMMON_LOAD_LINE_API}/${StSearchType.CURRENCY.value}" | ||||
val M18_LOAD_BOM_API = "${M18_COMMON_LOAD_LINE_API}/${StSearchType.BOM.value}" | val M18_LOAD_BOM_API = "${M18_COMMON_LOAD_LINE_API}/${StSearchType.BOM.value}" | ||||
val M18_LOAD_BUSINESS_UNIT_API = "${M18_COMMON_LOAD_LINE_API}/${StSearchType.BUSINESS_UNIT.value}" // for shop po? | |||||
// --------------------------------------------- Common Function --------------------------------------------- /// | // --------------------------------------------- Common Function --------------------------------------------- /// | ||||
private inline fun <reified T : Any> getList( | private inline fun <reified T : Any> getList( | ||||
@@ -302,7 +303,7 @@ open class M18MasterDataService( | |||||
logger.info("--------------------------------------------End - Saving M18 Vendors--------------------------------------------") | logger.info("--------------------------------------------End - Saving M18 Vendors--------------------------------------------") | ||||
} | } | ||||
// --------------------------------------------- Unit --------------------------------------------- /// | |||||
// --------------------------------------------- Unit (UoM) --------------------------------------------- /// | |||||
open fun getUnits(): M18UnitListResponse? { | open fun getUnits(): M18UnitListResponse? { | ||||
// seems no beId | // seems no beId | ||||
return getList<M18UnitListResponse>( | return getList<M18UnitListResponse>( | ||||
@@ -487,7 +488,6 @@ open class M18MasterDataService( | |||||
logger.info(bomUdfProduct.toString()) | logger.info(bomUdfProduct.toString()) | ||||
if (bomUdfBomForShop != null && bomUdfProduct != null) { | if (bomUdfBomForShop != null && bomUdfProduct != null) { | ||||
// Save Bom | // Save Bom | ||||
logger.info("AAAAA") | |||||
val saveBomRequest = SaveBomRequest( | val saveBomRequest = SaveBomRequest( | ||||
// itemId = itemsService.findByNameAndM18UomId(bomUdfBomForShop.desc, bomUdfBomForShop.udfUnit)?.id, | // itemId = itemsService.findByNameAndM18UomId(bomUdfBomForShop.desc, bomUdfBomForShop.udfUnit)?.id, | ||||
code = bomUdfBomForShop.code, | code = bomUdfBomForShop.code, | ||||
@@ -500,7 +500,6 @@ open class M18MasterDataService( | |||||
m18Id = bomUdfBomForShop.id, | m18Id = bomUdfBomForShop.id, | ||||
m18LastModifyDate = commonUtils.timestampToLocalDateTime(bomUdfBomForShop.lastModifyDate) | m18LastModifyDate = commonUtils.timestampToLocalDateTime(bomUdfBomForShop.lastModifyDate) | ||||
) | ) | ||||
logger.info("BBBBB") | |||||
val bomId = bomService.saveBom(saveBomRequest).id | val bomId = bomService.saveBom(saveBomRequest).id | ||||
successList += bom.id | successList += bom.id | ||||
@@ -560,4 +559,90 @@ open class M18MasterDataService( | |||||
logger.info("--------------------------------------------End - Saving Boms--------------------------------------------") | logger.info("--------------------------------------------End - Saving Boms--------------------------------------------") | ||||
} | } | ||||
// --------------------------------------------- Business Unit (Shop) --------------------------------------------- /// | |||||
open fun getBusinessUnits(): M18BusinessUnitListResponse? { | |||||
// seems no beId | |||||
return getList<M18BusinessUnitListResponse>( | |||||
stSearch = StSearchType.BUSINESS_UNIT.value, | |||||
params = null, | |||||
// conds = beIdConds | |||||
) | |||||
} | |||||
open fun getBusinessUnit(id: Long): M18BusinessUnitResponse? { | |||||
logger.info("M18 Business Unit ID: $id") | |||||
return getLine<M18BusinessUnitResponse>( | |||||
id = id, | |||||
params = null, | |||||
api = M18_LOAD_BUSINESS_UNIT_API | |||||
) | |||||
} | |||||
open fun saveBusinessUnits() { | |||||
logger.info("--------------------------------------------Start - Saving M18 Business Units (Shops)--------------------------------------------") | |||||
val businessUnits = getBusinessUnits() | |||||
val successList = mutableListOf<Long>() | |||||
val failList = mutableListOf<Long>() | |||||
val values = businessUnits?.values?.sortedBy { it.id } | |||||
val busMessages = if(businessUnits?.messages?.isNotEmpty() == true) businessUnits.messages[0] else null | |||||
if (values != null) { | |||||
values.forEach { businessUnit -> | |||||
// if (vendor.id in exampleVendors) { | |||||
try { | |||||
val businessUnitDetail = getBusinessUnit(businessUnit.id) | |||||
val virdept = businessUnitDetail?.data?.virdept?.get(0) | |||||
val buMessages = if(businessUnitDetail?.messages?.isNotEmpty() == true) businessUnitDetail?.messages[0] else null | |||||
if (virdept != null) { | |||||
val saveShopRequest = SaveShopRequest( | |||||
id = null, | |||||
code = virdept.code, | |||||
name = virdept.desc.ifEmpty { virdept.`desc_zh-TW` }, | |||||
brNo = null, | |||||
contactNo = virdept.tel, | |||||
contactEmail = virdept.email, | |||||
contactName = null, | |||||
addr1 = virdept.addr.ifEmpty { virdept.addr_en }, | |||||
addr2 = virdept.addr2.ifEmpty { virdept.addr2_en }, | |||||
addr3 = virdept.addr3.ifEmpty { virdept.addr3_en }, | |||||
addr4 = null, | |||||
district = null, | |||||
type = ShopType.SHOP.value, | |||||
m18Id = businessUnit.id, | |||||
m18LastModifyDate = commonUtils.timestampToLocalDateTime(virdept.lastModifyDate) | |||||
) | |||||
shopService.saveShop(saveShopRequest) | |||||
successList.add(businessUnit.id) | |||||
logger.info("Success Count ${successList.size}: ${businessUnit.id} | ${virdept.code} | ${virdept.desc}") | |||||
} else { | |||||
failList.add(businessUnit.id) | |||||
logger.error("(Business Unit) Fail Message: ${buMessages?.msgDetail}") | |||||
logger.error("(Business Unit) Fail Count ${failList.size}: Business Unit ID - ${businessUnit.id} Not Found") | |||||
} | |||||
} catch (e: Exception) { | |||||
failList.add(businessUnit.id) | |||||
logger.error("(Business Unit) Exception") | |||||
logger.error("(Business Unit) Fail Message: ${e.message}") | |||||
logger.error("(Business Unit) Fail Count ${failList.size}: Business Unit ID - ${businessUnit.id}") | |||||
} | |||||
// } | |||||
} | |||||
} else { | |||||
logger.error("(Business Unit) Business Unit List is null. May occur errors.") | |||||
logger.error("(Business Unit)) Fail Message: ${busMessages?.msgDetail}") | |||||
logger.error("(Business Unit) Business Unit List is null. May occur errors.") | |||||
} | |||||
logger.info("Total Success (${successList.size})") | |||||
if (failList.size > 0) { | |||||
logger.error("Total Fail (${failList.size}): $failList") | |||||
} | |||||
logger.info("--------------------------------------------End - Saving M18 Business Units--------------------------------------------") | |||||
} | |||||
} | } |
@@ -56,7 +56,7 @@ open class M18PurchaseOrderService( | |||||
val materialPoBuyers = | val materialPoBuyers = | ||||
commonUtils.listToString(listOf(m18Config.BEID_PP, m18Config.BEID_PF), "beId=equal=", "=or=") | commonUtils.listToString(listOf(m18Config.BEID_PP, m18Config.BEID_PF), "beId=equal=", "=or=") | ||||
val materialPoSupplierNot = commonUtils.listToString( | val materialPoSupplierNot = commonUtils.listToString( | ||||
shopService.findM18VendorIdsByCodeNotRegexp(m18Config.MATERIAL_PO_SUPPLIER_NOT), | |||||
shopService.findM18VendorIdsByCodeRegexp(m18Config.MATERIAL_PO_SUPPLIER_NOT), | |||||
"venId=unequal=", | "venId=unequal=", | ||||
"=or=" | "=or=" | ||||
) | ) | ||||
@@ -194,8 +194,9 @@ open class M18PurchaseOrderService( | |||||
// Find the latest m18 data log by m18 id & type | // Find the latest m18 data log by m18 id & type | ||||
logger.info("${poRefType}: Finding For Latest M18 Data Log...") | logger.info("${poRefType}: Finding For Latest M18 Data Log...") | ||||
val latestPurchaseOrderLog = | val latestPurchaseOrderLog = | ||||
m18DataLogService.findLatestM18DataLog(purchaseOrder.id, poRefType) | |||||
m18DataLogService.findLatestM18DataLogWithSuccess(purchaseOrder.id, poRefType) | |||||
logger.info(latestPurchaseOrderLog.toString()) | |||||
// Save to m18_data_log table | // Save to m18_data_log table | ||||
logger.info("${poRefType}: Saving for M18 Data Log...") | logger.info("${poRefType}: Saving for M18 Data Log...") | ||||
val mainpoJson = | val mainpoJson = | ||||
@@ -228,6 +229,7 @@ open class M18PurchaseOrderService( | |||||
id = existingPurchaseOrder?.id, | id = existingPurchaseOrder?.id, | ||||
code = mainpo.code, | code = mainpo.code, | ||||
m18SupplierId = mainpo.venId, | m18SupplierId = mainpo.venId, | ||||
m18ShopId = mainpo.virDeptId, | |||||
m18CurrencyId = mainpo.curId, | m18CurrencyId = mainpo.curId, | ||||
orderDate = commonUtils.timestampToLocalDateTime(mainpo.tDate), | orderDate = commonUtils.timestampToLocalDateTime(mainpo.tDate), | ||||
estimatedArrivalDate = commonUtils.timestampToLocalDateTime(mainpo.dDate), | estimatedArrivalDate = commonUtils.timestampToLocalDateTime(mainpo.dDate), | ||||
@@ -243,7 +245,7 @@ open class M18PurchaseOrderService( | |||||
// Update m18_data_log with success | // Update m18_data_log with success | ||||
val successSaveM18PurchaseOrderLogRequest = SaveM18DataLogRequest( | val successSaveM18PurchaseOrderLogRequest = SaveM18DataLogRequest( | ||||
id = saveM18PurchaseOrderLogRequest.id, | |||||
id = saveM18PurchaseOrderLog.id, | |||||
dataLog = mainpoJson, | dataLog = mainpoJson, | ||||
statusEnum = M18DataLogStatus.SUCCESS | statusEnum = M18DataLogStatus.SUCCESS | ||||
) | ) | ||||
@@ -261,7 +263,7 @@ open class M18PurchaseOrderService( | |||||
logger.error(e.message) | logger.error(e.message) | ||||
val errorSaveM18PurchaseOrderLogRequest = SaveM18DataLogRequest( | val errorSaveM18PurchaseOrderLogRequest = SaveM18DataLogRequest( | ||||
id = saveM18PurchaseOrderLogRequest.id, | |||||
id = saveM18PurchaseOrderLog.id, | |||||
dataLog = mutableMapOf(Pair("Exception Message", e.message)), | dataLog = mutableMapOf(Pair("Exception Message", e.message)), | ||||
statusEnum = M18DataLogStatus.FAIL | statusEnum = M18DataLogStatus.FAIL | ||||
) | ) | ||||
@@ -279,7 +281,7 @@ open class M18PurchaseOrderService( | |||||
// Find the latest m18 data log by m18 id & type | // Find the latest m18 data log by m18 id & type | ||||
logger.info("${poLineRefType}: Finding For Latest M18 Data Log...") | logger.info("${poLineRefType}: Finding For Latest M18 Data Log...") | ||||
val latestPurchaseOrderLineLog = | val latestPurchaseOrderLineLog = | ||||
m18DataLogService.findLatestM18DataLog(line.id, poLineRefType) | |||||
m18DataLogService.findLatestM18DataLogWithSuccess(line.id, poLineRefType) | |||||
// logger.info("${poLineRefType}: Latest M18 Data Log ID: ${latestPurchaseOrderLineLog?.id}") | // logger.info("${poLineRefType}: Latest M18 Data Log ID: ${latestPurchaseOrderLineLog?.id}") | ||||
// Save to m18_data_log table | // Save to m18_data_log table | ||||
@@ -118,6 +118,7 @@ open class M18PurchaseQuotationService( | |||||
expiryDate = commonUtils.timestampToLocalDateTime(mainvqu.expDate), | expiryDate = commonUtils.timestampToLocalDateTime(mainvqu.expDate), | ||||
effectiveDate = commonUtils.timestampToLocalDateTime(mainvqu.tDate), | effectiveDate = commonUtils.timestampToLocalDateTime(mainvqu.tDate), | ||||
m18ShopId = mainvqu.venId, | m18ShopId = mainvqu.venId, | ||||
m18CurrencyId = mainvqu.curId, | |||||
remarks = remvqu?.remarks, | remarks = remvqu?.remarks, | ||||
m18Id = mainvqu.id, | m18Id = mainvqu.id, | ||||
m18LastModifyDate = commonUtils.timestampToLocalDateTime(mainvqu.lastModifyDate) | m18LastModifyDate = commonUtils.timestampToLocalDateTime(mainvqu.lastModifyDate) | ||||
@@ -57,6 +57,18 @@ class M18TestController ( | |||||
println(response?.uom?.id) | println(response?.uom?.id) | ||||
return response | return response | ||||
} | } | ||||
// --------------------------------------------- Master Data --------------------------------------------- /// | |||||
@GetMapping("/master-data") | |||||
fun m18MasterData() { | |||||
// Master Data | |||||
m18MasterDataService.saveUnits() | |||||
m18MasterDataService.saveProducts() | |||||
m18MasterDataService.saveVendors() | |||||
m18MasterDataService.saveBusinessUnits() | |||||
m18MasterDataService.saveCurrencies() | |||||
m18MasterDataService.saveBoms() | |||||
} | |||||
// --------------------------------------------- Master Data --------------------------------------------- /// | // --------------------------------------------- Master Data --------------------------------------------- /// | ||||
@GetMapping("/product") | @GetMapping("/product") | ||||
fun m18Products() { | fun m18Products() { | ||||
@@ -88,6 +100,12 @@ class M18TestController ( | |||||
m18MasterDataService.saveBoms() | m18MasterDataService.saveBoms() | ||||
} | } | ||||
@GetMapping("/businessUnit") | |||||
fun m18BusinessUnit() { | |||||
logger.info("Access token: ${m18Config.ACCESS_TOKEN}") | |||||
m18MasterDataService.saveBusinessUnits() | |||||
} | |||||
// --------------------------------------------- Purchase Order --------------------------------------------- /// | // --------------------------------------------- Purchase Order --------------------------------------------- /// | ||||
@GetMapping("/po") | @GetMapping("/po") | ||||
fun m18PO() { | fun m18PO() { | ||||
@@ -1,5 +1,6 @@ | |||||
package com.ffii.fpsms.modules.master.entity | package com.ffii.fpsms.modules.master.entity | ||||
import com.fasterxml.jackson.annotation.JsonManagedReference | |||||
import com.ffii.core.entity.BaseEntity | import com.ffii.core.entity.BaseEntity | ||||
import jakarta.persistence.* | import jakarta.persistence.* | ||||
import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
@@ -20,9 +21,9 @@ open class Bom : BaseEntity<Long>() { | |||||
@Column(name = "code", nullable = false, length = 30) | @Column(name = "code", nullable = false, length = 30) | ||||
open var code: String? = null | open var code: String? = null | ||||
@Size(max = 30) | |||||
@Size(max = 100) | |||||
@NotNull | @NotNull | ||||
@Column(name = "name", nullable = false, length = 30) | |||||
@Column(name = "name", nullable = false, length = 100) | |||||
open var name: String? = null | open var name: String? = null | ||||
@Size(max = 100) | @Size(max = 100) | ||||
@@ -44,6 +45,10 @@ open class Bom : BaseEntity<Long>() { | |||||
@JoinColumn(name = "uomId") | @JoinColumn(name = "uomId") | ||||
open var uom: UomConversion? = null | open var uom: UomConversion? = null | ||||
@JsonManagedReference | |||||
@OneToMany(mappedBy = "bom", cascade = [CascadeType.ALL], orphanRemoval = true) | |||||
open var bomMaterials: MutableList<BomMaterial> = mutableListOf() | |||||
@Column(name = "m18Id") | @Column(name = "m18Id") | ||||
open var m18Id: Long? = null | open var m18Id: Long? = null | ||||
@@ -1,5 +1,6 @@ | |||||
package com.ffii.fpsms.modules.master.entity | package com.ffii.fpsms.modules.master.entity | ||||
import com.fasterxml.jackson.annotation.JsonBackReference | |||||
import com.ffii.core.entity.BaseEntity | import com.ffii.core.entity.BaseEntity | ||||
import jakarta.persistence.* | import jakarta.persistence.* | ||||
import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
@@ -15,8 +16,8 @@ open class BomMaterial : BaseEntity<Long>() { | |||||
@JoinColumn(name = "itemId") | @JoinColumn(name = "itemId") | ||||
open var item: Items? = null | open var item: Items? = null | ||||
@Size(max = 50) | |||||
@Column(name = "itemName", length = 50) | |||||
@Size(max = 100) | |||||
@Column(name = "itemName", length = 100) | |||||
open var itemName: String? = null | open var itemName: String? = null | ||||
@NotNull | @NotNull | ||||
@@ -31,13 +32,14 @@ open class BomMaterial : BaseEntity<Long>() { | |||||
@JoinColumn(name = "uomId") | @JoinColumn(name = "uomId") | ||||
open var uom: UomConversion? = null | open var uom: UomConversion? = null | ||||
@Size(max = 50) | |||||
@Column(name = "uomName", length = 50) | |||||
@Size(max = 100) | |||||
@Column(name = "uomName", length = 100) | |||||
open var uomName: String? = null | open var uomName: String? = null | ||||
@NotNull | @NotNull | ||||
@ManyToOne(optional = false) | @ManyToOne(optional = false) | ||||
@JoinColumn(name = "bomId", nullable = false) | @JoinColumn(name = "bomId", nullable = false) | ||||
@JsonBackReference | |||||
open var bom: Bom? = null | open var bom: Bom? = null | ||||
@NotNull | @NotNull | ||||
@@ -6,6 +6,8 @@ import java.io.Serializable | |||||
@Repository | @Repository | ||||
interface BomRepository : AbstractRepository<Bom, Long> { | interface BomRepository : AbstractRepository<Bom, Long> { | ||||
fun findAllByDeletedIsFalse(): List<Bom> | |||||
fun findByIdAndDeletedIsFalse(id: Serializable): Bom? | fun findByIdAndDeletedIsFalse(id: Serializable): Bom? | ||||
fun findByM18IdAndDeletedIsFalse(m18Id: Long): Bom? | fun findByM18IdAndDeletedIsFalse(m18Id: Long): Bom? |
@@ -44,5 +44,5 @@ open class Items : BaseEntity<Long>() { | |||||
@JsonManagedReference | @JsonManagedReference | ||||
@OneToMany(mappedBy = "item", cascade = [CascadeType.ALL], orphanRemoval = true) | @OneToMany(mappedBy = "item", cascade = [CascadeType.ALL], orphanRemoval = true) | ||||
open var itemUoms: MutableSet<ItemUom> = mutableSetOf() | |||||
open var itemUoms: MutableList<ItemUom> = mutableListOf() | |||||
} | } |
@@ -7,6 +7,8 @@ import java.time.LocalDateTime | |||||
@Repository | @Repository | ||||
interface UomConversionRepository : AbstractRepository<UomConversion, Long> { | interface UomConversionRepository : AbstractRepository<UomConversion, Long> { | ||||
//fun importFromM18(): ArrayList<UomConversion>; | //fun importFromM18(): ArrayList<UomConversion>; | ||||
fun findAllByDeletedFalse(): List<UomConversion>; | |||||
fun findByIdAndDeletedFalse(id: Long): UomConversion?; | fun findByIdAndDeletedFalse(id: Long): UomConversion?; | ||||
fun findByM18IdAndDeletedFalse(m18Id: Long): UomConversion?; | fun findByM18IdAndDeletedFalse(m18Id: Long): UomConversion?; | ||||
@@ -14,6 +14,10 @@ open class BomService( | |||||
val uomConversionService: UomConversionService | val uomConversionService: UomConversionService | ||||
) { | ) { | ||||
open fun findAll(): List<Bom> { | |||||
return bomRepository.findAll() | |||||
} | |||||
open fun findById(id: Long): Bom? { | open fun findById(id: Long): Bom? { | ||||
return bomRepository.findByIdAndDeletedIsFalse(id) | return bomRepository.findByIdAndDeletedIsFalse(id) | ||||
} | } | ||||
@@ -25,6 +25,10 @@ open class ShopService( | |||||
return shopRepository.findByM18IdAndTypeAndDeletedIsFalse(m18Id, ShopType.SUPPLIER) | return shopRepository.findByM18IdAndTypeAndDeletedIsFalse(m18Id, ShopType.SUPPLIER) | ||||
} | } | ||||
open fun findShopByM18Id(m18Id: Long): Shop? { | |||||
return shopRepository.findByM18IdAndTypeAndDeletedIsFalse(m18Id, ShopType.SHOP) | |||||
} | |||||
open fun findM18VendorIdsByCodeRegexp(code: List<String>): List<Long>? { | open fun findM18VendorIdsByCodeRegexp(code: List<String>): List<Long>? { | ||||
val codeRegexp = code.joinToString("|") | val codeRegexp = code.joinToString("|") | ||||
return shopRepository.findM18IdsByCodeRegexpAndTypeAndDeletedIsFalse(codeRegexp, type = ShopType.SUPPLIER.value) | return shopRepository.findM18IdsByCodeRegexpAndTypeAndDeletedIsFalse(codeRegexp, type = ShopType.SUPPLIER.value) | ||||
@@ -195,6 +195,9 @@ open class UomConversionService( | |||||
} | } | ||||
} | } | ||||
} | } | ||||
open fun findAll(): List<UomConversion> { | |||||
return uomConversionRepository.findAllByDeletedFalse(); | |||||
} | |||||
open fun findById(id: Long): UomConversion? { | open fun findById(id: Long): UomConversion? { | ||||
return uomConversionRepository.findByIdAndDeletedFalse(id) | return uomConversionRepository.findByIdAndDeletedFalse(id) | ||||
@@ -0,0 +1,18 @@ | |||||
package com.ffii.fpsms.modules.master.web | |||||
import com.ffii.fpsms.modules.master.entity.Bom | |||||
import com.ffii.fpsms.modules.master.service.BomService | |||||
import org.springframework.web.bind.annotation.GetMapping | |||||
import org.springframework.web.bind.annotation.RequestMapping | |||||
import org.springframework.web.bind.annotation.RestController | |||||
@RestController | |||||
@RequestMapping("/bom") | |||||
class BomController ( | |||||
val bomService: BomService, | |||||
) { | |||||
@GetMapping | |||||
fun getBoms(): List<Bom> { | |||||
return bomService.findAll() | |||||
} | |||||
} |
@@ -24,6 +24,11 @@ class UomConversionController( | |||||
// return uomConversionService.allItems() | // return uomConversionService.allItems() | ||||
// } | // } | ||||
@GetMapping | |||||
fun getUoms(): List<UomConversion> { | |||||
return uomConversionService.findAll() | |||||
} | |||||
@RequestMapping(value = ["/castBom"], method = [RequestMethod.GET]) | @RequestMapping(value = ["/castBom"], method = [RequestMethod.GET]) | ||||
fun convertBom(request: HttpServletRequest?): ArrayList<UomConversion> { | fun convertBom(request: HttpServletRequest?): ArrayList<UomConversion> { | ||||
try { | try { | ||||
@@ -25,6 +25,10 @@ open class PurchaseOrder : BaseEntity<Long>() { | |||||
@JoinColumn(name = "supplierId") | @JoinColumn(name = "supplierId") | ||||
open var supplier: Shop? = null | open var supplier: Shop? = null | ||||
@ManyToOne | |||||
@JoinColumn(name = "shopId") | |||||
open var shop: Shop? = null | |||||
@Column(name = "orderDate") | @Column(name = "orderDate") | ||||
open var orderDate: LocalDateTime? = null | open var orderDate: LocalDateTime? = null | ||||
@@ -92,6 +92,8 @@ open class PurchaseOrderService( | |||||
request.id?.let { purchaseOrderRepository.findById(it).getOrDefault(PurchaseOrder()) } ?: PurchaseOrder() | request.id?.let { purchaseOrderRepository.findById(it).getOrDefault(PurchaseOrder()) } ?: PurchaseOrder() | ||||
val supplier = request.m18SupplierId?.let { shopService.findVendorByM18Id(it) } | val supplier = request.m18SupplierId?.let { shopService.findVendorByM18Id(it) } | ||||
?: request.supplierId?.let { shopService.findById(it) } | ?: request.supplierId?.let { shopService.findById(it) } | ||||
val shop = request.m18ShopId?.let { shopService.findShopByM18Id(it) } | |||||
?: request.shopId?.let { shopService.findById(it) } | |||||
val currency = request.m18CurrencyId?.let { currencyService.findByM18Id(it) } | val currency = request.m18CurrencyId?.let { currencyService.findByM18Id(it) } | ||||
?: request.currencyId?.let { currencyService.findById(it) } | ?: request.currencyId?.let { currencyService.findById(it) } | ||||
val status = request.status?.let { status -> PurchaseOrderStatus.entries.find { it.value == status } } | val status = request.status?.let { status -> PurchaseOrderStatus.entries.find { it.value == status } } | ||||
@@ -99,10 +101,10 @@ open class PurchaseOrderService( | |||||
val m18DataLog = request.m18DataLogId?.let { m18DataLogRepository.findById(it).getOrNull() } | val m18DataLog = request.m18DataLogId?.let { m18DataLogRepository.findById(it).getOrNull() } | ||||
//Need check duplicate? | //Need check duplicate? | ||||
purchaseOrder.apply { | purchaseOrder.apply { | ||||
code = request.code | code = request.code | ||||
this.supplier = supplier | this.supplier = supplier | ||||
this.shop = shop | |||||
this.currency = currency | this.currency = currency | ||||
orderDate = request.orderDate | orderDate = request.orderDate | ||||
estimatedArrivalDate = request.estimatedArrivalDate | estimatedArrivalDate = request.estimatedArrivalDate | ||||
@@ -117,6 +119,7 @@ open class PurchaseOrderService( | |||||
id = it.id, | id = it.id, | ||||
code = it.code, | code = it.code, | ||||
supplierCode = it.supplier?.code, | supplierCode = it.supplier?.code, | ||||
shopCode = it.shop?.code, | |||||
currencyCode = it.currency?.code, | currencyCode = it.currency?.code, | ||||
orderDate = it.orderDate, | orderDate = it.orderDate, | ||||
estimatedArrivalDate = it.estimatedArrivalDate, | estimatedArrivalDate = it.estimatedArrivalDate, | ||||
@@ -9,6 +9,8 @@ data class SavePurchaseOrderRequest ( | |||||
val code: String?, | val code: String?, | ||||
val supplierId: Long? = null, | val supplierId: Long? = null, | ||||
val m18SupplierId: Long? = null, | val m18SupplierId: Long? = null, | ||||
val shopId: Long? = null, | |||||
val m18ShopId: Long? = null, | |||||
val currencyId: Long? = null, | val currencyId: Long? = null, | ||||
val m18CurrencyId: Long? = null, | val m18CurrencyId: Long? = null, | ||||
val orderDate: LocalDateTime?, | val orderDate: LocalDateTime?, | ||||
@@ -8,6 +8,7 @@ data class SavePurchaseOrderResponse ( | |||||
val id: Long?, | val id: Long?, | ||||
val code: String?, | val code: String?, | ||||
val supplierCode: String?, | val supplierCode: String?, | ||||
val shopCode: String?, | |||||
val currencyCode: String?, | val currencyCode: String?, | ||||
val orderDate: LocalDateTime?, | val orderDate: LocalDateTime?, | ||||
val estimatedArrivalDate: LocalDateTime?, | val estimatedArrivalDate: LocalDateTime?, | ||||
@@ -23,8 +23,8 @@ open class PurchaseQuotationLine : BaseEntity<Long>() { | |||||
@Column(name = "code", length = 30) | @Column(name = "code", length = 30) | ||||
open var code: String? = null | open var code: String? = null | ||||
@Size(max = 30) | |||||
@Column(name = "description", length = 30) | |||||
@Size(max = 300) | |||||
@Column(name = "description", length = 300) | |||||
open var description: String? = null | open var description: String? = null | ||||
@ManyToOne | @ManyToOne | ||||
@@ -23,6 +23,7 @@ open class PurchaseQuotationService( | |||||
open fun savePurchaseQuotation(request: SavePurchaseQuotationRequest): SavePurchaseQuotationResponse { | open fun savePurchaseQuotation(request: SavePurchaseQuotationRequest): SavePurchaseQuotationResponse { | ||||
val purchaseQuotation = request.m18Id?.let { findByM18Id(it) } ?: request.id?.let { findById(it) } ?: PurchaseQuotation() | val purchaseQuotation = request.m18Id?.let { findByM18Id(it) } ?: request.id?.let { findById(it) } ?: PurchaseQuotation() | ||||
val shop = request.m18ShopId?.let { shopService.findVendorByM18Id(it) } ?: request.shopId?.let { shopService.findById(it) } | val shop = request.m18ShopId?.let { shopService.findVendorByM18Id(it) } ?: request.shopId?.let { shopService.findById(it) } | ||||
val currency = request.m18CurrencyId?.let { } | |||||
purchaseQuotation.apply { | purchaseQuotation.apply { | ||||
code = request.code | code = request.code | ||||
@@ -9,6 +9,8 @@ data class SavePurchaseQuotationRequest( | |||||
val effectiveDate: LocalDateTime? = null, | val effectiveDate: LocalDateTime? = null, | ||||
val shopId: Long? = null, | val shopId: Long? = null, | ||||
val m18ShopId: Long? = null, | val m18ShopId: Long? = null, | ||||
val currencyId: Long? = null, | |||||
val m18CurrencyId: Long? = null, | |||||
val remarks: String? = null, | val remarks: String? = null, | ||||
val m18Id: Long? = null, | val m18Id: Long? = null, | ||||
val m18LastModifyDate: LocalDateTime? = null, | val m18LastModifyDate: LocalDateTime? = null, | ||||
@@ -0,0 +1,26 @@ | |||||
-- liquibase formatted sql | |||||
-- changeset cyril:update bom | |||||
ALTER TABLE `bom` | |||||
CHANGE COLUMN `name` `name` VARCHAR(100) NOT NULL ; | |||||
ALTER TABLE `bom_material` | |||||
ADD COLUMN `itemName` VARCHAR(100) NULL AFTER `itemId`, | |||||
ADD COLUMN `uomName` VARCHAR(100) NULL AFTER `uomId`, | |||||
ADD COLUMN `remarks` VARCHAR(1000) NULL AFTER `bomId` | |||||
; | |||||
ALTER TABLE `bom_material` | |||||
DROP FOREIGN KEY `FK_BOM_MATERIAL_ON_ITEMID`, | |||||
DROP FOREIGN KEY `FK_BOM_MATERIAL_ON_UOMID`; | |||||
ALTER TABLE `bom_material` | |||||
CHANGE COLUMN `itemId` `itemId` INT NULL, | |||||
CHANGE COLUMN `uomId` `uomId` INT NULL; | |||||
ALTER TABLE `bom_material` | |||||
ADD CONSTRAINT `FK_BOM_MATERIAL_ON_ITEMID` | |||||
FOREIGN KEY (`itemId`) | |||||
REFERENCES `items` (`id`), | |||||
ADD CONSTRAINT `FK_BOM_MATERIAL_ON_UOMID` | |||||
FOREIGN KEY (`uomId`) | |||||
REFERENCES `uom_conversion` (`id`); |
@@ -0,0 +1,9 @@ | |||||
-- liquibase formatted sql | |||||
-- changeset cyril:update purchase order | |||||
ALTER TABLE `purchase_order` | |||||
ADD COLUMN `shopId` INT NULL AFTER `supplierId`, | |||||
ADD CONSTRAINT `FK_PURCHASE_ORDER_ON_SHOPID` | |||||
FOREIGN KEY (`shopId`) | |||||
REFERENCES `shop` (`id`); |
@@ -0,0 +1,6 @@ | |||||
-- liquibase formatted sql | |||||
-- changeset cyril:update m18 data log | |||||
ALTER TABLE `m18_data_log` | |||||
CHANGE COLUMN `dataLog` `dataLog` JSON NULL ; |