|
|
@@ -54,6 +54,7 @@ open class M18MasterDataService( |
|
|
|
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_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 --------------------------------------------- /// |
|
|
|
private inline fun <reified T : Any> getList( |
|
|
@@ -302,7 +303,7 @@ open class M18MasterDataService( |
|
|
|
logger.info("--------------------------------------------End - Saving M18 Vendors--------------------------------------------") |
|
|
|
} |
|
|
|
|
|
|
|
// --------------------------------------------- Unit --------------------------------------------- /// |
|
|
|
// --------------------------------------------- Unit (UoM) --------------------------------------------- /// |
|
|
|
open fun getUnits(): M18UnitListResponse? { |
|
|
|
// seems no beId |
|
|
|
return getList<M18UnitListResponse>( |
|
|
@@ -487,7 +488,6 @@ open class M18MasterDataService( |
|
|
|
logger.info(bomUdfProduct.toString()) |
|
|
|
if (bomUdfBomForShop != null && bomUdfProduct != null) { |
|
|
|
// Save Bom |
|
|
|
logger.info("AAAAA") |
|
|
|
val saveBomRequest = SaveBomRequest( |
|
|
|
// itemId = itemsService.findByNameAndM18UomId(bomUdfBomForShop.desc, bomUdfBomForShop.udfUnit)?.id, |
|
|
|
code = bomUdfBomForShop.code, |
|
|
@@ -500,7 +500,6 @@ open class M18MasterDataService( |
|
|
|
m18Id = bomUdfBomForShop.id, |
|
|
|
m18LastModifyDate = commonUtils.timestampToLocalDateTime(bomUdfBomForShop.lastModifyDate) |
|
|
|
) |
|
|
|
logger.info("BBBBB") |
|
|
|
val bomId = bomService.saveBom(saveBomRequest).id |
|
|
|
successList += bom.id |
|
|
|
|
|
|
@@ -560,4 +559,90 @@ open class M18MasterDataService( |
|
|
|
|
|
|
|
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--------------------------------------------") |
|
|
|
} |
|
|
|
} |