@@ -13,6 +13,10 @@ import {
|
||||
import {
|
||||
createGuideRouteRepository
|
||||
} from '@/repositories/createGuideRouteRepository'
|
||||
import {
|
||||
applyRouteReadinessGate,
|
||||
NAV_ROUTE_READINESS
|
||||
} from '@/domain/guideReadiness'
|
||||
|
||||
const toSearchText = (target: GuideRouteTarget) => [
|
||||
target.name,
|
||||
@@ -41,13 +45,15 @@ export class GuideRouteUseCase {
|
||||
constructor(private readonly repository: GuideRouteRepository = createGuideRouteRepository()) {}
|
||||
|
||||
async getRouteReadiness() {
|
||||
if (this.readinessCache) return this.readinessCache
|
||||
if (this.readinessCache) return applyRouteReadinessGate(this.readinessCache)
|
||||
|
||||
this.readinessCache = await this.repository.getRouteReadiness()
|
||||
return this.readinessCache
|
||||
this.readinessCache = applyRouteReadinessGate(await this.repository.getRouteReadiness())
|
||||
return applyRouteReadinessGate(this.readinessCache)
|
||||
}
|
||||
|
||||
async listTargets() {
|
||||
const readiness = await this.getRouteReadiness()
|
||||
if (!readiness.ready) return []
|
||||
if (this.targetsCache) return this.targetsCache
|
||||
|
||||
this.targetsCache = (await this.repository.listRouteTargets())
|
||||
@@ -69,11 +75,11 @@ export class GuideRouteUseCase {
|
||||
|
||||
async planRoute(request: GuideRoutePlanRequest): Promise<GuideRoutePlanResult> {
|
||||
try {
|
||||
const readiness = await this.getRouteReadiness()
|
||||
const readiness = applyRouteReadinessGate(await this.getRouteReadiness())
|
||||
if (!readiness.ready) {
|
||||
return {
|
||||
route: null,
|
||||
error: readiness.message || '当前可查看位置预览和位置关系,暂不提供正式室内导航'
|
||||
error: readiness.message || NAV_ROUTE_READINESS.message
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user