- report_template에 schedule_enabled/period/hour/source 컬럼(ALTER IF NOT EXISTS,
p0_report.sql + 서비스 EnsureSchema 멱등).
- Hc900ReportScheduleService: 매 N초 활성 템플릿마다 완료된 기간(anchor)을
lookback 내 산출 → report_run 성공기록 없으면 FillAsync 생성·기록.
중복 0(HasSuccessfulRun dedup)·다운타임 자동복구. 윈도는 셀 토큰 period=가 결정.
- IReportTemplateStore.UpdateSchedule/HasSuccessfulRun, ListAsync에 스케줄 컬럼.
- PUT /api/report/template/{id}/schedule (period/hour 검증).
- UI: 목록에 스케줄 상태 표시 + 선택 템플릿 스케줄 편집기.
- appsettings Report:Schedule (간격·catchup) 추가.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
2.0 KiB
SQL
35 lines
2.0 KiB
SQL
-- P0 셀프서비스 리포트 — 테이블 2개 (hc900 스키마)
|
|
-- 적용: psql "host=localhost dbname=iiot_platform user=postgres" -f scripts/sql/p0_report.sql
|
|
SET search_path TO hc900;
|
|
|
|
-- 운전원이 올린 엑셀 템플릿 + 메타
|
|
CREATE TABLE IF NOT EXISTS hc900.report_template (
|
|
id serial PRIMARY KEY,
|
|
name text NOT NULL,
|
|
owner text,
|
|
xlsx_blob bytea NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
-- P2-C: 템플릿별 자동생성 스케줄 (Hc900ReportScheduleService가 기동 시 동일 ALTER 멱등 적용)
|
|
ALTER TABLE hc900.report_template ADD COLUMN IF NOT EXISTS schedule_enabled boolean NOT NULL DEFAULT false;
|
|
ALTER TABLE hc900.report_template ADD COLUMN IF NOT EXISTS schedule_period text NOT NULL DEFAULT 'DAILY'; -- DAILY|MONTHLY|YEARLY
|
|
ALTER TABLE hc900.report_template ADD COLUMN IF NOT EXISTS schedule_hour int NOT NULL DEFAULT 1; -- 기간 완료 후 발화 KST 시각
|
|
ALTER TABLE hc900.report_template ADD COLUMN IF NOT EXISTS schedule_source text NOT NULL DEFAULT 'history_table';
|
|
|
|
-- 생성 이력(감사·재현). 어떤 정의로 어떤 기간을 뽑았는지 박제
|
|
CREATE TABLE IF NOT EXISTS hc900.report_run (
|
|
id bigserial PRIMARY KEY,
|
|
template_id int REFERENCES hc900.report_template(id) ON DELETE CASCADE,
|
|
period_kind text NOT NULL, -- 'DAILY' | 'MONTHLY' | 'YEARLY'
|
|
period_date date NOT NULL, -- KST 기준 날짜
|
|
source_table text NOT NULL, -- 'history_table' | 'fast_record'
|
|
generated_at timestamptz NOT NULL DEFAULT now(),
|
|
status text NOT NULL, -- 'ok' | 'partial' | 'error'
|
|
cells_json jsonb, -- 채운 셀=메트릭+파라미터+값+sampling메타 박제
|
|
out_blob bytea -- 채워진 .xlsx (다운로드 캐시)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_report_run_template ON hc900.report_run(template_id, period_date);
|