|
|
|
@@ -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 |
|
|
|
} |
|
|
|
|
|
|
|
|