CANCERYS\kw093 vor 2 Monaten
Ursprung
Commit
6979e53932
3 geänderte Dateien mit 60 neuen und 6 gelöschten Zeilen
  1. +54
    -5
      src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt
  2. +1
    -1
      src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt
  3. +5
    -0
      src/main/resources/db/changelog/changes/20251014_01_enson/01_altertable_enson.sql

+ 54
- 5
src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt Datei anzeigen

@@ -56,7 +56,7 @@ import net.sf.jasperreports.engine.JasperPrint
import org.springframework.core.io.ClassPathResource
import java.io.File
import java.io.FileNotFoundException
import com.ffii.core.support.JdbcDao;
import com.ffii.fpsms.modules.deliveryOrder.entity.DoPickOrderRecord
import com.ffii.fpsms.modules.deliveryOrder.entity.DoPickOrderRecordRepository
import com.ffii.fpsms.modules.deliveryOrder.web.models.ExportDNLabelsRequest
@@ -96,6 +96,7 @@ open class DeliveryOrderService(
private val inventoryLotService: InventoryLotService,
private val suggestedPickLotRepository: SuggestPickLotRepository,
private val inventoryLotRepository: InventoryLotRepository,
private val jdbcDao: JdbcDao,
) {

open fun findByM18DataLogId(m18DataLogId: Long): DeliveryOrder? {
@@ -482,11 +483,59 @@ val truck = deliveryOrder.shop?.id?.let { shopId ->
println("🔍 DEBUG: Looking for truck with shop ID: $shopId")
val trucks = truckRepository.findByShopIdAndDeletedFalse(shopId)
println("🔍 DEBUG: Found ${trucks.size} trucks for shop $shopId")
trucks.forEach { t ->
println("🔍 DEBUG: Truck ID: ${t.id}, DepartureTime: ${t.departureTime}")
if (trucks.size <= 1) {
// 如果只有一个或没有 truck,直接返回
return@let trucks.firstOrNull()
}
// ✅ 分析 DO order lines 中的 items 分布
val itemIds = deliveryOrder.deliveryOrderLines.mapNotNull { it.item?.id }.distinct()
println("🔍 DEBUG: Analyzing ${itemIds.size} unique items in DO order lines")
// 使用 SQL 查询统计每个楼层的库存数量
val inventoryQuery = """
SELECT w.store_id as floor, COUNT(*) as inventory_count
FROM inventory_lot_line ill
JOIN inventory_lot il ON il.id = ill.inventoryLotId
JOIN warehouse w ON w.id = ill.warehouseId
WHERE il.itemId IN (${itemIds.joinToString(",")})
AND ill.deleted = false
AND il.deleted = false
AND w.deleted = false
AND ill.inQty > ill.outQty + COALESCE(ill.holdQty, 0)
GROUP BY w.store_id
""".trimIndent()
val inventoryResults = jdbcDao.queryForList(inventoryQuery)
val floorInventoryCount = mutableMapOf<String, Int>()
inventoryResults.forEach { row: Map<String, Any> ->
val floor = row["floor"] as? String ?: "Other"
val count = (row["inventory_count"] as? Number)?.toInt() ?: 0
floorInventoryCount[floor] = count
}
println("🔍 DEBUG: Floor inventory distribution: $floorInventoryCount")

// 决定使用哪个楼层
val preferredFloor = when {
floorInventoryCount["2F"] ?: 0 > floorInventoryCount["4F"] ?: 0 -> "2F"
floorInventoryCount["4F"] ?: 0 > floorInventoryCount["2F"] ?: 0 -> "4F"
else -> "2F" // 默认使用 2F
}
println("🔍 DEBUG: Preferred floor based on inventory: $preferredFloor")
// 根据楼层选择对应的 truck
val selectedTruck = when (preferredFloor) {
"2F" -> trucks.find { it.storeId == 2 }
"4F" -> trucks.find { it.storeId == 4 }
else -> trucks.minByOrNull { it.departureTime ?: LocalTime.MAX }
}
val selectedTruck = trucks.minByOrNull { it.departureTime ?: LocalTime.MAX }
println("🔍 DEBUG: Selected truck: ID=${selectedTruck?.id}, DepartureTime=${selectedTruck?.departureTime}")
println("🔍 DEBUG: Selected truck: ID=${selectedTruck?.id}, StoreId=${selectedTruck?.storeId}, DepartureTime=${selectedTruck?.departureTime}")
selectedTruck
}



+ 1
- 1
src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt Datei anzeigen

@@ -42,5 +42,5 @@ interface InventoryLotLineRepository : AbstractRepository<InventoryLotLine, Long
fun findByInventoryLotStockInLineIdAndWarehouseId(inventoryLotStockInLineId: Long, warehouseId: Long): InventoryLotLine?

fun findAllByInventoryLotItemIdAndStatus(itemId: Long, status: String): List<InventoryLotLine>
fun findAllByInventoryLotItemIdAndStatus(itemId: Long, status: InventoryLotLineStatus): List<InventoryLotLine>
fun findAllByInventoryLotItemIdAndStatus(itemId: Long, status: InventoryLotLineStatus): List<InventoryLotLine>
}

+ 5
- 0
src/main/resources/db/changelog/changes/20251014_01_enson/01_altertable_enson.sql Datei anzeigen

@@ -0,0 +1,5 @@
-- liquibase formatted sql
-- changeset enson:altertable_warehouse

ALTER TABLE warehouse
ADD COLUMN `store_id` varchar(50) default null;

Laden…
Abbrechen
Speichern