feat: clinic registry DB + pipeline audit P0 fixes
## Clinic Registry - data/clinic-registry/clinic_registry_working.csv — 91개 병원 채널 마스터 DB - data/clinic-registry/INFINITH_Outbound_List.csv — BD팀 아웃바운드 리스트 (17컬럼) - data/clinic-registry/update_csv.py — 안전 CSV 업데이트 스크립트 (빈 필드만 채움) - data/clinic-registry/extract_place_ids.py — 네이버 플레이스 ID 추출기 - scripts/import-registry.ts — CSV → Supabase clinic_registry 테이블 임포트 - supabase/migrations/20260406_clinic_registry.sql — clinic_registry 테이블 스키마 ## Pipeline P0 Bug Fixes (전수 감사 후) - fix(collect-channel-data): 강남언니 rating 0-10 스케일 오변환 제거 - 기존: rating ≤ 5이면 ×2 → 4.8/10을 9.6/10으로 잘못 변환 - 수정: Firecrawl 프롬프트가 이미 0-10 지시 → rawValue 직접 신뢰 - fix(generate-report): Perplexity 단일 fetch → fetchWithRetry 교체 - maxRetries:2, backoffMs:[5000,15000], timeoutMs:90s - 기존: 타임아웃/429 시 리포트 생성 전체 실패 - 수정: 자동 재시도로 일시적 API 오류 극복 ## Docs - docs/PIPELINE_IMPROVEMENT_PLAN.md — Sprint 0/1/2 완료 표시 + 전수 감사 결과 추가 - docs/REGISTRY_FUNCTIONAL_SPECS.md, DB_SCHEMA_V3.md 외 기획 문서 다수 추가 ## New Components & Features - supabase/functions/generate-content-plan, adjust-strategy — 콘텐츠 플랜/전략 조정 - src/components/plan/EditEntryModal, StrategyAdjustmentSection — 플랜 편집 UI - supabase/functions/_shared/dataQuality, foundingYearExtractor, urlClassifier — 데이터 품질 유틸 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec991057e6
commit
d5f7f24e0a
51 files changed
+5390
-252
No files matched your search
+124
-26
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useLocation } from 'react-router';
|
||||
import type { MarketingPlan } from '../types/plan';
|
||||
import { fetchReportById } from '../lib/supabase';
|
||||
import type { MarketingPlan, ChannelStrategyCard, CalendarData, ContentStrategyData } from '../types/plan';
|
||||
import { fetchReportById, fetchActiveContentPlan, supabase } from '../lib/supabase';
|
||||
import { transformReportToPlan } from '../lib/transformPlan';
|
||||
|
||||
interface UseMarketingPlanResult {
|
||||
@@ -14,6 +14,60 @@ interface LocationState {
|
||||
report?: Record<string, unknown>;
|
||||
metadata?: Record<string, unknown>;
|
||||
reportId?: string;
|
||||
clinicId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a MarketingPlan from content_plans DB row.
|
||||
* content_plans stores AI-generated strategy in JSONB columns.
|
||||
*/
|
||||
function buildPlanFromContentPlans(
|
||||
row: Record<string, unknown>,
|
||||
clinicName: string,
|
||||
clinicNameEn: string,
|
||||
targetUrl: string,
|
||||
): MarketingPlan {
|
||||
const channelStrategies = (row.channel_strategies || []) as ChannelStrategyCard[];
|
||||
const contentStrategy = (row.content_strategy || {}) as ContentStrategyData;
|
||||
const calendar = (row.calendar || { weeks: [], monthlySummary: [] }) as CalendarData;
|
||||
|
||||
return {
|
||||
id: row.id as string,
|
||||
reportId: (row.run_id as string) || (row.id as string),
|
||||
clinicName,
|
||||
clinicNameEn,
|
||||
createdAt: (row.created_at as string) || new Date().toISOString(),
|
||||
targetUrl,
|
||||
brandGuide: (row.brand_guide as MarketingPlan['brandGuide']) || {
|
||||
colors: [],
|
||||
fonts: [],
|
||||
logoRules: [],
|
||||
toneOfVoice: {
|
||||
personality: ['전문적', '친근한', '신뢰할 수 있는'],
|
||||
communicationStyle: '의료 전문 지식을 쉽고 친근하게 전달',
|
||||
doExamples: [],
|
||||
dontExamples: [],
|
||||
},
|
||||
channelBranding: [],
|
||||
brandInconsistencies: [],
|
||||
},
|
||||
channelStrategies,
|
||||
contentStrategy: {
|
||||
pillars: contentStrategy.pillars || [],
|
||||
typeMatrix: contentStrategy.typeMatrix || [],
|
||||
workflow: contentStrategy.workflow || [
|
||||
{ step: 1, name: '기획', description: 'AI 콘텐츠 주제 선정', owner: 'INFINITH AI', duration: '자동' },
|
||||
{ step: 2, name: '제작', description: 'AI 초안 생성 + 의료진 감수', owner: 'INFINITH AI', duration: '1시간' },
|
||||
{ step: 3, name: '편집', description: '영상/이미지 편집', owner: 'INFINITH Studio', duration: '30분' },
|
||||
{ step: 4, name: '배포', description: '채널별 최적화 배포', owner: 'INFINITH Distribution', duration: '자동' },
|
||||
{ step: 5, name: '분석', description: '성과 데이터 수집 + 전략 조정', owner: 'INFINITH Analytics', duration: '자동' },
|
||||
],
|
||||
repurposingSource: contentStrategy.repurposingSource || '1개 롱폼 영상',
|
||||
repurposingOutputs: contentStrategy.repurposingOutputs || [],
|
||||
},
|
||||
calendar,
|
||||
assetCollection: { assets: [], youtubeRepurpose: [] },
|
||||
};
|
||||
}
|
||||
|
||||
export function useMarketingPlan(id: string | undefined): UseMarketingPlanResult {
|
||||
@@ -31,35 +85,79 @@ export function useMarketingPlan(id: string | undefined): UseMarketingPlanResult
|
||||
|
||||
const state = location.state as LocationState | undefined;
|
||||
|
||||
// Source 1: Report data passed via navigation state
|
||||
if (state?.report && state?.metadata) {
|
||||
async function loadPlan() {
|
||||
try {
|
||||
const plan = transformReportToPlan({
|
||||
id: (state.reportId || id),
|
||||
url: (state.metadata.url as string) || '',
|
||||
clinic_name: (state.metadata.clinicName as string) || '',
|
||||
report: state.report,
|
||||
created_at: (state.metadata.generatedAt as string) || new Date().toISOString(),
|
||||
});
|
||||
setData(plan);
|
||||
setIsLoading(false);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to build marketing plan');
|
||||
setIsLoading(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// ─── Source 1: Try content_plans table (AI-generated strategy) ───
|
||||
// First, resolve clinicId from navigation state or analysis_runs
|
||||
let clinicId = state?.clinicId || null;
|
||||
let clinicName = '';
|
||||
let clinicNameEn = '';
|
||||
let targetUrl = '';
|
||||
|
||||
// Source 2: Fetch report from Supabase and transform to plan
|
||||
fetchReportById(id)
|
||||
.then((row) => {
|
||||
if (!clinicId) {
|
||||
// Try to find clinicId from analysis_runs by run/report ID
|
||||
const { data: run } = await supabase
|
||||
.from('analysis_runs')
|
||||
.select('clinic_id')
|
||||
.eq('id', id)
|
||||
.single();
|
||||
if (run) clinicId = run.clinic_id;
|
||||
}
|
||||
|
||||
if (clinicId) {
|
||||
// Fetch clinic info for plan metadata
|
||||
const { data: clinic } = await supabase
|
||||
.from('clinics')
|
||||
.select('name, name_en, url')
|
||||
.eq('id', clinicId)
|
||||
.single();
|
||||
if (clinic) {
|
||||
clinicName = clinic.name || '';
|
||||
clinicNameEn = clinic.name_en || '';
|
||||
targetUrl = clinic.url || '';
|
||||
}
|
||||
|
||||
// Try fetching active content plan
|
||||
const contentPlan = await fetchActiveContentPlan(clinicId);
|
||||
if (contentPlan) {
|
||||
const plan = buildPlanFromContentPlans(
|
||||
contentPlan,
|
||||
clinicName,
|
||||
clinicNameEn,
|
||||
targetUrl,
|
||||
);
|
||||
setData(plan);
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Source 2: Report data from navigation state (fallback) ───
|
||||
if (state?.report && state?.metadata) {
|
||||
const plan = transformReportToPlan({
|
||||
id: (state.reportId || id),
|
||||
url: (state.metadata.url as string) || '',
|
||||
clinic_name: (state.metadata.clinicName as string) || '',
|
||||
report: state.report,
|
||||
created_at: (state.metadata.generatedAt as string) || new Date().toISOString(),
|
||||
});
|
||||
setData(plan);
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// ─── Source 3: Fetch report from Supabase and transform (fallback) ───
|
||||
const row = await fetchReportById(id);
|
||||
const plan = transformReportToPlan(row);
|
||||
setData(plan);
|
||||
})
|
||||
.catch((err) => {
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to fetch marketing plan');
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
loadPlan();
|
||||
}, [id, location.state]);
|
||||
|
||||
return { data, isLoading, error };
|
||||
|
||||
Reference in new issue
Block a user