Parcourir la source

update egg routing

master
CANCERYS\kw093 il y a 1 jour
Parent
révision
d5b7585022
2 fichiers modifiés avec 88 ajouts et 27 suppressions
  1. +33
    -3
      src/main/java/com/ffii/fpsms/modules/pickOrder/service/PickOrderService.kt
  2. +55
    -24
      src/main/java/com/ffii/fpsms/modules/stock/service/StockOutLineService.kt

+ 33
- 3
src/main/java/com/ffii/fpsms/modules/pickOrder/service/PickOrderService.kt Voir le fichier

@@ -1519,7 +1519,7 @@ open class PickOrderService(
}
}

open fun createGroup(name: String, targetDate: LocalDate, pickOrderId: Long?): PickOrderGroup {
val group = PickOrderGroup().apply {
this.name = name
@@ -3520,6 +3520,12 @@ AND (spl.pickOrderLineId IS NOT NULL OR sol.pickOrderLineId IS NOT NULL)
ORDER BY
CASE WHEN sol.status = 'rejected' THEN 0 ELSE 1 END,
COALESCE(w.`order`, 999999) ASC, -- 改用 warehouse.order
-- Add frontpart (floor) sorting: 1F > 2F/4F
CASE
WHEN w.store_id = '1F' THEN 1
WHEN w.store_id IN ('2F', '4F') THEN 2
ELSE 3
END ASC,
po.code ASC,
i.code ASC,
il.expiryDate ASC,
@@ -3961,11 +3967,35 @@ open fun getAllPickOrderLotsWithDetailsHierarchical(userId: Long): Map<String, A
val firstLot = lots?.firstOrNull()
val router = firstLot?.get("router") as? Map<String, Any?>
val indexValue = router?.get("index")
// 修复:支持字符串和数字两种格式,新格式为 "store_id-number" (如 "2F-004")
// 提取楼层排序值:1F = 1, 2F/4F = 2, 其他 = 3
val floorSortValue = when (indexValue) {
is String -> {
val parts = indexValue.split("-")
if (parts.isNotEmpty()) {
val floorPart = parts[0].uppercase() // "1F", "2F", "4F"
when (floorPart) {
"1F" -> 1
"2F", "4F" -> 2
else -> 3
}
} else {
3
}
}
else -> 3
}
floorSortValue
},
{ line ->
val lots = line["lots"] as? List<Map<String, Any?>>
val firstLot = lots?.firstOrNull()
val router = firstLot?.get("router") as? Map<String, Any?>
val indexValue = router?.get("index")
// 提取数字部分:格式为 "store_id-number" (如 "2F-004")
when (indexValue) {
is Number -> indexValue.toInt()
is String -> {
// 提取数字部分:格式为 "store_id-number",取 "-" 后的数字
val parts = indexValue.split("-")
if (parts.size > 1) {
parts.last().toIntOrNull() ?: 999999


+ 55
- 24
src/main/java/com/ffii/fpsms/modules/stock/service/StockOutLineService.kt Voir le fichier

@@ -1166,23 +1166,42 @@ open fun newBatchSubmit(request: QrPickBatchSubmitRequest): MessageResponse {
val actualInventoryLotLineId = line.inventoryLotLineId
?: stockOutLine.inventoryLotLine?.id
if (submitQty > BigDecimal.ZERO && actualInventoryLotLineId != null) {
println(" Updating inventory lot line ${actualInventoryLotLineId} with qty $submitQty")
inventoryLotLineService.updateInventoryLotLineQuantities(
UpdateInventoryLotLineQuantitiesRequest(
inventoryLotLineId = actualInventoryLotLineId,
qty = submitQty,
operation = "pick"
)
)
if (submitQty > BigDecimal.ZERO) {
createStockLedgerForPickDelta(line.stockOutLineId, submitQty)
}
} else if (submitQty > BigDecimal.ZERO && actualInventoryLotLineId == null) {
// ✅ 修复:即使没有 inventoryLotLineId,也应该创建 stock_ledger(用于无批次物品或批次切换后的情况)
println(" Warning: No inventoryLotLineId found, but creating stock ledger anyway for stockOutLineId ${line.stockOutLineId}")
createStockLedgerForPickDelta(line.stockOutLineId, submitQty)
}
// 在 newBatchSubmit 方法中,修改这部分代码(大约在 1169-1185 行)
if (submitQty > BigDecimal.ZERO && actualInventoryLotLineId != null) {
println(" Updating inventory lot line ${actualInventoryLotLineId} with qty $submitQty")
// ✅ 修复:在更新 inventory_lot_line 之前获取 inventory 的当前 onHandQty
val item = stockOutLine.item
val inventoryBeforeUpdate = item?.let {
inventoryRepository.findByItemId(it.id!!).orElse(null)
}
val onHandQtyBeforeUpdate = (inventoryBeforeUpdate?.onHandQty ?: BigDecimal.ZERO).toDouble()
println(" Inventory before update: onHandQty=$onHandQtyBeforeUpdate")
inventoryLotLineService.updateInventoryLotLineQuantities(
UpdateInventoryLotLineQuantitiesRequest(
inventoryLotLineId = actualInventoryLotLineId,
qty = submitQty,
operation = "pick"
)
)
if (submitQty > BigDecimal.ZERO) {
// ✅ 修复:传入更新前的 onHandQty,让 createStockLedgerForPickDelta 使用它
createStockLedgerForPickDelta(line.stockOutLineId, submitQty, onHandQtyBeforeUpdate)
}
} else if (submitQty > BigDecimal.ZERO && actualInventoryLotLineId == null) {
// ✅ 修复:即使没有 inventoryLotLineId,也应该获取 inventory.onHandQty
val item = stockOutLine.item
val inventoryBeforeUpdate = item?.let {
inventoryRepository.findByItemId(it.id!!).orElse(null)
}
val onHandQtyBeforeUpdate = (inventoryBeforeUpdate?.onHandQty ?: BigDecimal.ZERO).toDouble()
println(" Warning: No inventoryLotLineId found, but creating stock ledger anyway for stockOutLineId ${line.stockOutLineId}")
createStockLedgerForPickDelta(line.stockOutLineId, submitQty, onHandQtyBeforeUpdate)
}
try {
val stockOutLine = stockOutLines[line.stockOutLineId]
val item = stockOutLine?.item
@@ -1369,7 +1388,11 @@ private fun createStockLedgerForStockOut(stockOutLine: StockOutLine) {
}


private fun createStockLedgerForPickDelta(stockOutLineId: Long, deltaQty: BigDecimal) {
private fun createStockLedgerForPickDelta(
stockOutLineId: Long,
deltaQty: BigDecimal,
onHandQtyBeforeUpdate: Double? = null // ✅ 新增参数:更新前的 onHandQty
) {
if (deltaQty <= BigDecimal.ZERO) return
val sol = stockOutLineRepository.findById(stockOutLineId).orElse(null) ?: return
@@ -1377,22 +1400,30 @@ private fun createStockLedgerForStockOut(stockOutLine: StockOutLine) {
val inventory = inventoryRepository.findAllByItemIdAndDeletedIsFalse(item.id!!)
.firstOrNull() ?: return

val latestLedger = stockLedgerRepository.findLatestByItemId(item.id!!).firstOrNull()
val previousBalance = latestLedger?.balance
?: (inventory.onHandQty ?: BigDecimal.ZERO).toDouble()
// ✅ 修复:如果传入了 onHandQtyBeforeUpdate,使用它;否则回退到原来的逻辑
val previousBalance = if (onHandQtyBeforeUpdate != null) {
// 使用更新前的 onHandQty 作为基础
onHandQtyBeforeUpdate
} else {
// 回退逻辑:优先使用最新的 ledger balance,如果没有则使用 inventory.onHandQty
val latestLedger = stockLedgerRepository.findLatestByItemId(item.id!!).firstOrNull()
latestLedger?.balance ?: (inventory.onHandQty ?: BigDecimal.ZERO).toDouble()
}
val newBalance = previousBalance - deltaQty.toDouble()
println(" Creating stock ledger: previousBalance=$previousBalance, deltaQty=$deltaQty, newBalance=$newBalance")
if (onHandQtyBeforeUpdate != null) {
println(" Using onHandQtyBeforeUpdate: $onHandQtyBeforeUpdate")
}
val ledger = StockLedger().apply {
this.stockOutLine = sol
this.inventory = inventory
this.inQty = null
this.outQty = deltaQty.toDouble()
this.balance = newBalance // ✅ 使用计算后的新 balance
this.balance = newBalance
this.type = "NOR"
this.itemId = item.id
this.itemCode = item.code


Chargement…
Annuler
Enregistrer