修复讲解详情接口并展示展厅统计
This commit is contained in:
@@ -35,6 +35,9 @@ import {
|
||||
import {
|
||||
dataSourceConfig
|
||||
} from '@/config/dataSource'
|
||||
import {
|
||||
normalizeExplainDetailTargetFromGuideStop
|
||||
} from '@/domain/explainDetailTarget'
|
||||
|
||||
export interface ExplainAudioSelection {
|
||||
exhibit: MuseumExhibit
|
||||
@@ -63,6 +66,12 @@ export interface ExhibitDetailAudioOptions {
|
||||
includeText?: boolean
|
||||
}
|
||||
|
||||
export interface ExplainHallSummary {
|
||||
hallId: string
|
||||
businessUnitCount: number
|
||||
guideStopCount: number
|
||||
}
|
||||
|
||||
export class ExplainUseCase {
|
||||
constructor(
|
||||
private readonly explain: ExplainRepository = explainRepository,
|
||||
@@ -355,14 +364,17 @@ export class ExplainUseCase {
|
||||
|
||||
async enterExplainDetail(request: ExplainDetailEntryRequest) {
|
||||
const entryTarget = await this.resolveDetailEntryTarget(request)
|
||||
const shouldLoadFallbackExhibit = entryTarget.targetType === 'ITEM'
|
||||
const [stopInfoResult, fallbackExhibit] = await Promise.all([
|
||||
this.audioPlayInfo.getStopInfo(entryTarget)
|
||||
.then((stopInfo) => ({ stopInfo, error: null }))
|
||||
.catch((error) => ({ stopInfo: null, error })),
|
||||
this.explain.getExhibitById(request.exhibitId)
|
||||
.catch(() => this.explain.listExplainExhibits()
|
||||
.then((items) => items.find((item) => item.id === request.exhibitId) || null)
|
||||
.catch(() => null))
|
||||
shouldLoadFallbackExhibit
|
||||
? this.explain.getExhibitById(request.exhibitId)
|
||||
.catch(() => this.explain.listExplainExhibits()
|
||||
.then((items) => items.find((item) => item.id === request.exhibitId) || null)
|
||||
.catch(() => null))
|
||||
: Promise.resolve(null)
|
||||
])
|
||||
|
||||
if (stopInfoResult.stopInfo) {
|
||||
@@ -419,6 +431,30 @@ export class ExplainUseCase {
|
||||
return this.listHalls()
|
||||
}
|
||||
|
||||
async loadExplainHallSummaries(hallIds: string[]): Promise<Record<string, ExplainHallSummary>> {
|
||||
const uniqueHallIds = Array.from(new Set(hallIds.map((id) => id.trim()).filter(Boolean)))
|
||||
const entries = await Promise.all(uniqueHallIds.map(async (hallId) => {
|
||||
try {
|
||||
const units = await this.loadTemporaryBusinessUnitsByHall(hallId)
|
||||
const guideStopCount = units.reduce((total, unit) => total + unit.guideStopCount, 0)
|
||||
return [hallId, {
|
||||
hallId,
|
||||
businessUnitCount: units.length,
|
||||
guideStopCount
|
||||
}] as const
|
||||
} catch (error) {
|
||||
console.warn('讲解展厅统计加载失败:', hallId, error)
|
||||
return [hallId, {
|
||||
hallId,
|
||||
businessUnitCount: 0,
|
||||
guideStopCount: 0
|
||||
}] as const
|
||||
}
|
||||
}))
|
||||
|
||||
return Object.fromEntries(entries)
|
||||
}
|
||||
|
||||
getHallById(id: string) {
|
||||
return this.explain.getHallById(id)
|
||||
}
|
||||
@@ -447,10 +483,11 @@ export class ExplainUseCase {
|
||||
}
|
||||
|
||||
openGuideStopDetail(stopId: string) {
|
||||
const target = normalizeExplainDetailTargetFromGuideStop({ id: stopId })
|
||||
return this.enterExplainDetail({
|
||||
exhibitId: stopId,
|
||||
targetType: 'STOP',
|
||||
targetId: stopId
|
||||
exhibitId: target.targetId,
|
||||
targetType: target.targetType,
|
||||
targetId: target.targetId
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user