feat(wave4): GET /all/flights and SCHD day-plan processing (ACM2-80, ACM2-85)
Expose projection read API with MAID filtering and 503 on failure; complete schedule snapshot sweep, field clearing, batched PG via FlightCommit, and contract/PARAM docs with regression tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.gzzn.omms.msgexchange.ingress
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.gzzn.omms.msgexchange.processing.FlightProjectionPort
|
||||
import io.micronaut.http.HttpResponse
|
||||
import io.micronaut.http.HttpStatus
|
||||
import io.micronaut.http.MediaType
|
||||
import io.micronaut.http.annotation.Controller
|
||||
import io.micronaut.http.annotation.Get
|
||||
import io.micronaut.http.annotation.Produces
|
||||
|
||||
/**
|
||||
* `GET /all/flights`:从 Redis 查询投影读当前全部动态航班,不含共享航班(`US-12`、`C-11`)。
|
||||
*
|
||||
* 数据只从投影来,不回落 PG:查询与网页客户端必须读同一份,不然两边会看到不同的航班
|
||||
* (`INV-11`)。投影读不出来就返回错误——空列表会被前端当成"现在没有航班"(`US-12` AC2)。
|
||||
*
|
||||
* 响应口径暂定(`Q21`):成功是裸 JSON 数组、不套旧系统的 `ResponseDto`;失败是 503 加一个
|
||||
* 错误对象。投影载荷的形状与 `KAFKA:schd` 同一份,尚未按旧系统 `SCHD.FLTR` 逐字对拍。
|
||||
*/
|
||||
@Controller("/all/flights")
|
||||
class FlightQueryController(
|
||||
private val projection: FlightProjectionPort,
|
||||
private val mapper: ObjectMapper,
|
||||
) {
|
||||
private val log = org.slf4j.LoggerFactory.getLogger(FlightQueryController::class.java)
|
||||
|
||||
@Get
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
fun all(): HttpResponse<String> =
|
||||
try {
|
||||
HttpResponse.ok(mapper.writeValueAsString(nonSharedFlights()))
|
||||
} catch (e: Exception) {
|
||||
// 读投影失败(Redis 不可用、未接通、载荷读不动)一律报错:这里没有可信的兜底数据源
|
||||
val reason = e.message ?: e.javaClass.simpleName
|
||||
log.error("GET /all/flights unavailable reason={}", reason, e)
|
||||
HttpResponse.status<String>(HttpStatus.SERVICE_UNAVAILABLE)
|
||||
.body(mapper.writeValueAsString(mapOf("error" to PROJECTION_UNAVAILABLE, "reason" to reason)))
|
||||
}
|
||||
|
||||
/**
|
||||
* 共享航班由 `MAID`(主航班 FLID)非空标识,随主航班下发,不单独出现在列表里
|
||||
* (`US-06` AC2 的主/共享关系,见 docs/implementation.md「航班域」)。
|
||||
*/
|
||||
private fun nonSharedFlights(): List<com.fasterxml.jackson.databind.JsonNode> =
|
||||
projection.readAll()
|
||||
.map { mapper.readTree(it) }
|
||||
.filter { it.path("scalars").path("MAID").asText("").isBlank() }
|
||||
|
||||
private companion object {
|
||||
private const val PROJECTION_UNAVAILABLE = "FLIGHT_PROJECTION_UNAVAILABLE"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user