Sfoglia il codice sorgente

fixing the error that if item deleted

master
Fai Luk 6 ore fa
parent
commit
f15898662d
1 ha cambiato i file con 13 aggiunte e 3 eliminazioni
  1. +13
    -3
      src/main/java/com/ffii/fpsms/modules/master/service/ItemsService.kt

+ 13
- 3
src/main/java/com/ffii/fpsms/modules/master/service/ItemsService.kt Vedi File

@@ -450,10 +450,20 @@ open class ItemsService(
val avg = row["avgUp"] as? BigDecimal ?: return@mapNotNull null
id to avg.toPlainString()
}.toMap()
// Use JDBC UPDATE instead of load+save: avoids ObjectOptimisticLockingFailureException when the same
// Items row was already updated earlier in this transaction (e.g. M18 PO sync) or concurrently.
idList.forEach { itemId ->
val item = itemsRepository.findById(itemId).orElse(null) ?: return@forEach
item.averageUnitPrice = avgByItem[itemId]
itemsRepository.saveAndFlush(item)
val avg = avgByItem[itemId]
jdbcDao.executeUpdate(
"""
UPDATE items
SET AverageUnitPrice = :avg,
modified = NOW(),
version = version + 1
WHERE id = :id AND deleted = 0
""".trimIndent(),
mapOf("avg" to avg, "id" to itemId),
)
}
}



Caricamento…
Annulla
Salva