|
|
|
@@ -7,6 +7,7 @@ import com.ffii.fpsms.modules.master.entity.projections.ShopCombo |
|
|
|
import com.ffii.fpsms.modules.master.enums.ShopType |
|
|
|
import com.ffii.fpsms.modules.master.web.models.SaveShopRequest |
|
|
|
import com.ffii.fpsms.modules.master.web.models.SaveShopResponse |
|
|
|
import org.slf4j.LoggerFactory |
|
|
|
import org.springframework.stereotype.Service |
|
|
|
import kotlin.jvm.optionals.getOrDefault |
|
|
|
|
|
|
|
@@ -14,6 +15,8 @@ import kotlin.jvm.optionals.getOrDefault |
|
|
|
open class ShopService( |
|
|
|
val shopRepository: ShopRepository |
|
|
|
) { |
|
|
|
private val logger = LoggerFactory.getLogger(ShopService::class.java) |
|
|
|
|
|
|
|
open fun findAll(): List<Shop> { |
|
|
|
return shopRepository.findAllByDeletedIsFalse() |
|
|
|
} |
|
|
|
@@ -26,10 +29,23 @@ open class ShopService( |
|
|
|
return shopRepository.findByM18IdAndTypeAndDeletedIsFalse(m18Id, ShopType.SUPPLIER) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Supplier by code. [shop] may contain duplicate codes (e.g. PF/PP vendor rows); picks one with |
|
|
|
* [Shop.m18Id] when present, else the newest row by id. |
|
|
|
*/ |
|
|
|
open fun findVendorByCode(code: String): Shop? { |
|
|
|
val trimmed = code.trim() |
|
|
|
if (trimmed.isEmpty()) return null |
|
|
|
return shopRepository.findByCodeAndTypeAndDeletedIsFalse(trimmed, ShopType.SUPPLIER) |
|
|
|
val matches = shopRepository.findAllByCodeAndTypeAndDeletedIsFalseOrderByIdDesc(trimmed, ShopType.SUPPLIER) |
|
|
|
if (matches.isEmpty()) return null |
|
|
|
if (matches.size > 1) { |
|
|
|
logger.warn( |
|
|
|
"Multiple supplier shop rows for code={} (count={}); using row with m18Id or newest id", |
|
|
|
trimmed, |
|
|
|
matches.size, |
|
|
|
) |
|
|
|
} |
|
|
|
return matches.firstOrNull { (it.m18Id ?: 0L) > 0L } ?: matches.first() |
|
|
|
} |
|
|
|
|
|
|
|
open fun findShopByM18Id(m18Id: Long): Shop? { |
|
|
|
|