Explorar el Código

update

master
CANCERYS\kw093 hace 20 horas
padre
commit
b8a0bf85be
Se han modificado 2 ficheros con 70 adiciones y 50 borrados
  1. +28
    -2
      src/main/java/com/ffii/fpsms/modules/deliveryOrder/entity/DeliveryOrderRepository.kt
  2. +42
    -48
      src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt

+ 28
- 2
src/main/java/com/ffii/fpsms/modules/deliveryOrder/entity/DeliveryOrderRepository.kt Ver fichero

@@ -118,6 +118,32 @@ fun searchDoLitePage(
@Param("etaStart") etaStart: LocalDateTime?,
@Param("etaEnd") etaEnd: LocalDateTime?,
pageable: Pageable
): Page<DeliveryOrderInfoLite>
): Page<DeliveryOrderInfoLite>

/**
* 與 [searchDoLitePage] 相同條件,但僅包含指定供應商代碼;分頁須在此集合上計算,否則總筆數與每頁筆數會不一致。
*/
@Query(
"""
select distinct d from DeliveryOrder d
where d.deleted = false
and (:code is null or d.code like concat('%', :code, '%'))
and (:shopName is null or d.shop.name like concat('%', :shopName, '%'))
and (:status is null or d.status = :status)
and (:etaStart is null or d.estimatedArrivalDate >= :etaStart)
and (:etaEnd is null or d.estimatedArrivalDate < :etaEnd)
and d.supplier is not null
and d.supplier.code in :allowedSupplierCodes
order by d.id desc
"""
)
fun searchDoLitePageWithSupplierCodes(
@Param("code") code: String?,
@Param("shopName") shopName: String?,
@Param("status") status: DeliveryOrderStatus?,
@Param("etaStart") etaStart: LocalDateTime?,
@Param("etaEnd") etaEnd: LocalDateTime?,
@Param("allowedSupplierCodes") allowedSupplierCodes: List<String>,
pageable: Pageable,
): Page<DeliveryOrderInfoLite>
}

+ 42
- 48
src/main/java/com/ffii/fpsms/modules/deliveryOrder/service/DeliveryOrderService.kt Ver fichero

@@ -300,71 +300,65 @@ open class DeliveryOrderService(
} else {
emptyList()
}
return RecordsRes(paginatedRecords, totalCount)
} else {
// 如果没有提供 truckLanceCode,使用分页查询
val result = deliveryOrderRepository.searchDoLitePage(
// 未提供 truckLanceCode:在 DB 層依允許的供應商分頁,避免先取 10 筆再過濾導致每頁顯示少於 pageSize
val allowedSupplierCodes = listOf("P06B", "P07", "P06D")
val result = deliveryOrderRepository.searchDoLitePageWithSupplierCodes(
code = code?.ifBlank { null },
shopName = shopName?.ifBlank { null },
status = statusEnum,
etaStart = etaStart,
etaEnd = etaEnd,
pageable = PageRequest.of(page.coerceAtLeast(0), size)
allowedSupplierCodes = allowedSupplierCodes,
pageable = PageRequest.of(page.coerceAtLeast(0), size),
)

val allowedSuppliers = setOf("P06B", "P07", "P06D")

// 处理当前页的记录,只保留这三个 supplier
val records = result.content.mapNotNull { info ->
val records = result.content.map { info ->
val deliveryOrder = deliveryOrderRepository.findByIdAndDeletedIsFalse(info.id)
val supplierCode = deliveryOrder?.supplier?.code
if (supplierCode !in allowedSuppliers) {
null // 过滤掉其他 supplier
} else {
val preferredFloor = when (supplierCode) {
"P06B" -> "4F"
"P07", "P06D" -> "2F"
else -> "2F"
}
val shop = deliveryOrder?.shop
val shopId = shop?.id
val estimatedArrivalDate = info.estimatedArrivalDate

val calculatedTruckLanceCode =
if (deliveryOrder != null && shopId != null && estimatedArrivalDate != null) {
val targetDate = estimatedArrivalDate.toLocalDate()
val dayAbbr = getDayOfWeekAbbr(targetDate)
val trucks = truckRepository.findByShopIdAndStoreIdAndDayOfWeek(shopId, preferredFloor, dayAbbr)

val matchedTruck = if (trucks.isEmpty()) {
truckRepository.findByShopIdAndDeletedFalse(shopId)
.filter { it.storeId == preferredFloor }
.minByOrNull { it.departureTime ?: LocalTime.of(23, 59, 59) }
} else {
trucks.minByOrNull { it.departureTime ?: LocalTime.of(23, 59, 59) }
}
val preferredFloor = when (supplierCode) {
"P06B" -> "4F"
"P07", "P06D" -> "2F"
else -> "2F"
}
val shop = deliveryOrder?.shop
val shopId = shop?.id
val estimatedArrivalDate = info.estimatedArrivalDate

val calculatedTruckLanceCode =
if (deliveryOrder != null && shopId != null && estimatedArrivalDate != null) {
val targetDate = estimatedArrivalDate.toLocalDate()
val dayAbbr = getDayOfWeekAbbr(targetDate)
val trucks = truckRepository.findByShopIdAndStoreIdAndDayOfWeek(shopId, preferredFloor, dayAbbr)

matchedTruck?.truckLanceCode
val matchedTruck = if (trucks.isEmpty()) {
truckRepository.findByShopIdAndDeletedFalse(shopId)
.filter { it.storeId == preferredFloor }
.minByOrNull { it.departureTime ?: LocalTime.of(23, 59, 59) }
} else {
null
trucks.minByOrNull { it.departureTime ?: LocalTime.of(23, 59, 59) }
}

DeliveryOrderInfoLiteDto(
id = info.id,
code = info.code,
orderDate = info.orderDate,
estimatedArrivalDate = info.estimatedArrivalDate,
status = info.status,
shopName = info.shopName,
supplierName = info.supplierName,
shopAddress = info.shopAddress,
truckLanceCode = calculatedTruckLanceCode
)
}
matchedTruck?.truckLanceCode
} else {
null
}

DeliveryOrderInfoLiteDto(
id = info.id,
code = info.code,
orderDate = info.orderDate,
estimatedArrivalDate = info.estimatedArrivalDate,
status = info.status,
shopName = info.shopName,
supplierName = info.supplierName,
shopAddress = info.shopAddress,
truckLanceCode = calculatedTruckLanceCode,
)
}

// 函数自己的返回
return RecordsRes(records, result.totalElements.toInt())
}



Cargando…
Cancelar
Guardar