|
|
@@ -12,6 +12,11 @@ export const ENTITY_DETAIL_PATHS = Object.freeze({
|
|
|
[ENTITY_DETAIL_KIND.WORK_ORDER]: (id) => `/work-orders/${encodeURIComponent(id)}/detail`,
|
|
|
})
|
|
|
|
|
|
+/** 工单处理流程:后端按 orderId 返回 workOrder + timelineEntries(票 129)。 */
|
|
|
+export function workOrderTimelinePath(orderId) {
|
|
|
+ return orderId ? `/work-orders/${encodeURIComponent(orderId)}/timeline` : ''
|
|
|
+}
|
|
|
+
|
|
|
export function entityDetailPath(identityInput) {
|
|
|
const identity = entityIdentity(identityInput)
|
|
|
const build = ENTITY_DETAIL_PATHS[identity.kind]
|
|
|
@@ -22,14 +27,57 @@ export async function fetchEntityDetail(identityInput, options = {}) {
|
|
|
const identity = entityIdentity(identityInput)
|
|
|
const path = options.path || entityDetailPath(identity)
|
|
|
if (!identity.valid || !path) return { ok: false, identity, reason: 'invalid-identity', mode: '', data: null }
|
|
|
- // 工单:live 后端 /work-orders/{id}/detail 只认内部主键,而 /work-orders 列表不返回该主键
|
|
|
- // (仅 workOrderCode)。用列表 prefill 直接构造详情,避免点开工单卡片报“详情暂未取到”。
|
|
|
- // 工单时间线只读接口缺失,另见后端票。
|
|
|
+ // 工单:列表已下发 orderId(票 129),详情 + 处理流程都按主键取。
|
|
|
+ // 旧调用方没有 orderId 时仍退回列表 prefill,避免刚升级后端前整卡不可用。
|
|
|
if (identity.kind === ENTITY_DETAIL_KIND.WORK_ORDER) {
|
|
|
- const detail = normalizeEntityDetail(identity, {}, options.prefill)
|
|
|
+ const prefill = options.prefill && typeof options.prefill === 'object' ? options.prefill : {}
|
|
|
+ const orderId = String(prefill.orderId || prefill.identityPayload?.orderId || identity.id || '').trim()
|
|
|
+ if (!orderId || !/^\d+$/.test(orderId)) {
|
|
|
+ const detail = normalizeEntityDetail(identity, {}, prefill)
|
|
|
+ return detail
|
|
|
+ ? { ok: true, identity, mode: prefill ? 'prefill' : 'unavailable', path: '', data: detail }
|
|
|
+ : { ok: false, identity, mode: '', reason: 'bad-payload', data: null }
|
|
|
+ }
|
|
|
+ const detailPath = `/work-orders/${encodeURIComponent(orderId)}/detail`
|
|
|
+ const timelinePath = workOrderTimelinePath(orderId)
|
|
|
+ const [detailResult, timelineResult] = await Promise.all([
|
|
|
+ requestCockpitJson(detailPath, { config: options.config, fetchImpl: options.fetchImpl }),
|
|
|
+ requestCockpitJson(timelinePath, { config: options.config, fetchImpl: options.fetchImpl }),
|
|
|
+ ])
|
|
|
+ if (!detailResult.ok && !timelineResult.ok) {
|
|
|
+ const fallback = normalizeEntityDetail(identity, {}, prefill)
|
|
|
+ return fallback
|
|
|
+ ? { ok: true, identity, mode: prefill ? 'prefill' : 'unavailable', path: '', data: fallback }
|
|
|
+ : { ok: false, identity, mode: '', reason: detailResult.reason || timelineResult.reason || 'unavailable', data: null }
|
|
|
+ }
|
|
|
+ const detailData = detailResult.ok && detailResult.data ? detailResult.data : {}
|
|
|
+ const timelineData = timelineResult.ok && timelineResult.data ? timelineResult.data : {}
|
|
|
+ const order = {
|
|
|
+ ...prefill,
|
|
|
+ ...(timelineData.workOrder && typeof timelineData.workOrder === 'object' ? timelineData.workOrder : {}),
|
|
|
+ ...(detailData.order && typeof detailData.order === 'object' ? detailData.order : {}),
|
|
|
+ }
|
|
|
+ const source = {
|
|
|
+ ...prefill,
|
|
|
+ ...detailData,
|
|
|
+ ...timelineData,
|
|
|
+ order,
|
|
|
+ }
|
|
|
+ // 时间线端点成功时以它为准;只有它失败才保留 detail 自带的 logs 兜底。
|
|
|
+ if (timelineResult.ok) {
|
|
|
+ source.timelineEntries = Array.isArray(timelineData.timelineEntries) ? timelineData.timelineEntries : []
|
|
|
+ delete source.logs
|
|
|
+ }
|
|
|
+ const detail = normalizeEntityDetail(identity, source, prefill)
|
|
|
return detail
|
|
|
- ? { ok: true, identity, mode: options.prefill ? 'prefill' : 'unavailable', path: '', data: detail }
|
|
|
- : { ok: false, identity, mode: '', reason: 'bad-payload', data: null }
|
|
|
+ ? {
|
|
|
+ ok: true,
|
|
|
+ identity,
|
|
|
+ mode: detailResult.mode || timelineResult.mode || '',
|
|
|
+ path: detailResult.path || detailPath,
|
|
|
+ data: detail,
|
|
|
+ }
|
|
|
+ : { ok: false, identity, mode: '', path: detailPath, reason: 'bad-payload', data: null }
|
|
|
}
|
|
|
const result = await requestCockpitJson(path, { config: options.config, fetchImpl: options.fetchImpl })
|
|
|
if (!result.ok) return { ...result, identity, data: null }
|