Sfoglia il codice sorgente

fixing the non-unique vendor result of bom finding

production
[email protected] 1 settimana fa
parent
commit
4d01f1d84f
2 ha cambiato i file con 18 aggiunte e 2 eliminazioni
  1. +1
    -1
      src/main/java/com/ffii/fpsms/modules/master/entity/ShopRepository.kt
  2. +17
    -1
      src/main/java/com/ffii/fpsms/modules/master/service/ShopService.kt

+ 1
- 1
src/main/java/com/ffii/fpsms/modules/master/entity/ShopRepository.kt Vedi File

@@ -31,7 +31,7 @@ interface ShopRepository : AbstractRepository<Shop, Long> {

fun findByCode(code: String): Shop?

fun findByCodeAndTypeAndDeletedIsFalse(code: String, type: ShopType): Shop?
fun findAllByCodeAndTypeAndDeletedIsFalseOrderByIdDesc(code: String, type: ShopType): List<Shop>

@Query(
"""


+ 17
- 1
src/main/java/com/ffii/fpsms/modules/master/service/ShopService.kt Vedi File

@@ -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? {


Caricamento…
Annulla
Salva