| @@ -43,7 +43,7 @@ open class M18BomForShopService( | |||||
| private val purchaseOrderLineRepository: PurchaseOrderLineRepository, | private val purchaseOrderLineRepository: PurchaseOrderLineRepository, | ||||
| private val m18BomShopSyncLogRepository: M18BomShopSyncLogRepository, | private val m18BomShopSyncLogRepository: M18BomShopSyncLogRepository, | ||||
| private val shopService: ShopService, | private val shopService: ShopService, | ||||
| private val m18MasterDataService: M18MasterDataService, | |||||
| private val m18VendorLookupService: M18VendorLookupService, | |||||
| ) { | ) { | ||||
| private val logger: Logger = LoggerFactory.getLogger(M18BomForShopService::class.java) | private val logger: Logger = LoggerFactory.getLogger(M18BomForShopService::class.java) | ||||
| @@ -415,14 +415,14 @@ open class M18BomForShopService( | |||||
| cache[cacheKey]?.let { return it } | cache[cacheKey]?.let { return it } | ||||
| val resolved = when (flowTypeId) { | val resolved = when (flowTypeId) { | ||||
| 2 -> m18MasterDataService.findVendorM18IdByCode(supplierCode, m18Config.BEID_PF) | |||||
| 2 -> m18VendorLookupService.findVendorM18IdByCode(supplierCode, m18Config.BEID_PF) | |||||
| ?: directM18Id.also { | ?: directM18Id.also { | ||||
| if (it == null) { | if (it == null) { | ||||
| logger.warn("[M18 BOM] PF vendor M18 id not found for supplierCode=$supplierCode") | logger.warn("[M18 BOM] PF vendor M18 id not found for supplierCode=$supplierCode") | ||||
| } | } | ||||
| } | } | ||||
| 3 -> shopService.findVendorByCode(supplierCode)?.m18Id?.takeIf { it > 0L } | 3 -> shopService.findVendorByCode(supplierCode)?.m18Id?.takeIf { it > 0L } | ||||
| ?: m18MasterDataService.findVendorM18IdByCode(supplierCode, m18Config.BEID_PP) | |||||
| ?: m18VendorLookupService.findVendorM18IdByCode(supplierCode, m18Config.BEID_PP) | |||||
| ?: directM18Id | ?: directM18Id | ||||
| else -> shopService.findVendorByCode(supplierCode)?.m18Id?.takeIf { it > 0L } | else -> shopService.findVendorByCode(supplierCode)?.m18Id?.takeIf { it > 0L } | ||||
| ?: directM18Id | ?: directM18Id | ||||
| @@ -557,25 +557,6 @@ open class M18MasterDataService( | |||||
| ) | ) | ||||
| } | } | ||||
| /** M18 vendor id for [code] scoped to [beId] (e.g. [M18Config.BEID_PF] vs [M18Config.BEID_PP]). */ | |||||
| open fun findVendorM18IdByCode(code: String, beId: String): Long? { | |||||
| val trimmed = code.trim() | |||||
| if (trimmed.isEmpty() || beId.isBlank()) return null | |||||
| val conds = "(code=equal=$trimmed)=and=(beId=equal=$beId)" | |||||
| val listResponse = try { | |||||
| getList<M18VendorListResponse>( | |||||
| stSearch = StSearchType.VENDOR.value, | |||||
| params = null, | |||||
| conds = conds, | |||||
| request = M18CommonRequest(), | |||||
| ) | |||||
| } catch (e: Exception) { | |||||
| logger.warn("(findVendorM18IdByCode) M18 search failed code=$trimmed beId=$beId: ${e.message}") | |||||
| null | |||||
| } | |||||
| return listResponse?.values?.firstOrNull()?.id?.takeIf { it > 0L } | |||||
| } | |||||
| open fun saveVendors(request: M18CommonRequest) : SyncResult{ | open fun saveVendors(request: M18CommonRequest) : SyncResult{ | ||||
| logger.info("--------------------------------------------Start - Saving M18 Vendors--------------------------------------------") | logger.info("--------------------------------------------Start - Saving M18 Vendors--------------------------------------------") | ||||
| val vendors = getVendors(request) | val vendors = getVendors(request) | ||||
| @@ -0,0 +1,43 @@ | |||||
| package com.ffii.fpsms.m18.service | |||||
| import com.ffii.fpsms.api.service.ApiCallerService | |||||
| import com.ffii.fpsms.m18.model.M18CommonListRequest | |||||
| import com.ffii.fpsms.m18.model.M18VendorListResponse | |||||
| import com.ffii.fpsms.m18.model.StSearchType | |||||
| import org.slf4j.Logger | |||||
| import org.slf4j.LoggerFactory | |||||
| import org.springframework.stereotype.Service | |||||
| /** | |||||
| * Lightweight M18 vendor search — kept separate from [M18MasterDataService] to avoid a Spring cycle | |||||
| * ([M18BomForShopService] → [M18MasterDataService] → [com.ffii.fpsms.modules.master.service.BomService] → [M18BomForShopService]). | |||||
| */ | |||||
| @Service | |||||
| open class M18VendorLookupService( | |||||
| private val apiCallerService: ApiCallerService, | |||||
| ) { | |||||
| private val logger: Logger = LoggerFactory.getLogger(M18VendorLookupService::class.java) | |||||
| private val fetchListApi = "/search/search" | |||||
| /** M18 vendor id for [code] scoped to [beId] (e.g. PF vs PP business entity). */ | |||||
| open fun findVendorM18IdByCode(code: String, beId: String): Long? { | |||||
| val trimmed = code.trim() | |||||
| if (trimmed.isEmpty() || beId.isBlank()) return null | |||||
| val conds = "(code=equal=$trimmed)=and=(beId=equal=$beId)" | |||||
| val listResponse = try { | |||||
| apiCallerService.get<M18VendorListResponse, M18CommonListRequest>( | |||||
| fetchListApi, | |||||
| M18CommonListRequest( | |||||
| stSearch = StSearchType.VENDOR.value, | |||||
| params = null, | |||||
| conds = conds, | |||||
| ), | |||||
| ).block() | |||||
| } catch (e: Exception) { | |||||
| logger.warn("(findVendorM18IdByCode) M18 search failed code=$trimmed beId=$beId: ${e.message}") | |||||
| null | |||||
| } | |||||
| return listResponse?.values?.firstOrNull()?.id?.takeIf { it > 0L } | |||||
| } | |||||
| } | |||||