-- Freight forecasting module. Monthly report enterprise data stays in h2032_enterprise_monthly. -- Source base values are the 2026 monthly below-scale series in 42-2026年基数.xlsx L14:W15. CREATE TABLE IF NOT EXISTS freight_forecast_base_month ( id BIGINT AUTO_INCREMENT PRIMARY KEY, stat_year SMALLINT NOT NULL COMMENT 'Statistical year', report_month TINYINT NOT NULL COMMENT 'Month 1-12', below_freight DOUBLE NOT NULL COMMENT 'Below-scale freight volume, 10k tons', below_turnover DOUBLE NOT NULL COMMENT 'Below-scale turnover, 10k ton-km', source_file VARCHAR(255) NULL COMMENT 'Source workbook', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UNIQUE KEY uk_freight_forecast_base_month (stat_year, report_month) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Freight forecast annual base months'; CREATE TABLE IF NOT EXISTS freight_forecast_below_result ( id BIGINT AUTO_INCREMENT PRIMARY KEY, report_period VARCHAR(20) NOT NULL COMMENT 'Report period yyyy-MM', result_type VARCHAR(10) NOT NULL COMMENT 'GROWTH/ACTUAL', base_freight DOUBLE NOT NULL, base_turnover DOUBLE NOT NULL, highway_freight_base DOUBLE NULL, highway_freight_current DOUBLE NULL, highway_freight_growth DOUBLE NULL, provincial_freight_base DOUBLE NULL, provincial_freight_current DOUBLE NULL, provincial_freight_growth DOUBLE NULL, highway_turnover_base DOUBLE NULL, highway_turnover_current DOUBLE NULL, highway_turnover_growth DOUBLE NULL, provincial_turnover_base DOUBLE NULL, provincial_turnover_current DOUBLE NULL, provincial_turnover_growth DOUBLE NULL, below_freight DOUBLE NOT NULL, below_turnover DOUBLE NOT NULL, below_freight_yoy DOUBLE NULL, below_turnover_yoy DOUBLE NULL, note VARCHAR(500) NULL, calculated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_freight_forecast_below_result (report_period, result_type) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Below-scale monthly forecast result'; CREATE TABLE IF NOT EXISTS freight_forecast_above_enterprise ( id BIGINT AUTO_INCREMENT PRIMARY KEY, report_period VARCHAR(20) NOT NULL, city VARCHAR(50) NOT NULL, enterprise_name VARCHAR(200) NOT NULL, tractor_count INT NOT NULL DEFAULT 0, other_tons DOUBLE NOT NULL DEFAULT 0, monthly_mileage DOUBLE NOT NULL DEFAULT 0, anomaly_mileage DOUBLE NOT NULL DEFAULT 0, tracked_vehicles INT NOT NULL DEFAULT 0, effective_mileage DOUBLE NOT NULL DEFAULT 0, forecast_turnover DOUBLE NOT NULL DEFAULT 0, track_source VARCHAR(30) NULL, calculation_status VARCHAR(30) NOT NULL, calculated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_freight_forecast_above_enterprise (report_period, enterprise_name), KEY idx_freight_forecast_above_enterprise_city (report_period, city) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Above-scale enterprise turnover forecast snapshot'; CREATE TABLE IF NOT EXISTS freight_forecast_above_history ( id BIGINT AUTO_INCREMENT PRIMARY KEY, stat_year SMALLINT NOT NULL, through_period VARCHAR(20) NOT NULL, city VARCHAR(50) NOT NULL, enterprise_name VARCHAR(200) NOT NULL, first_half_forecast DOUBLE NULL, month7_forecast DOUBLE NULL, month8_forecast DOUBLE NULL, month9_forecast DOUBLE NULL, month10_forecast DOUBLE NULL, month11_forecast DOUBLE NULL, month12_forecast DOUBLE NULL, cumulative_forecast DOUBLE NOT NULL, source_cumulative_forecast DOUBLE NOT NULL, corrected TINYINT(1) NOT NULL DEFAULT 0, calculation_note VARCHAR(500) NULL, source_file_name VARCHAR(255) NULL, imported_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_freight_forecast_above_history (stat_year, through_period, enterprise_name), KEY idx_freight_forecast_above_history_period (stat_year, through_period) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Historical above-scale forecast by period'; -- Application startup inserts the packaged 2026-10 history seed idempotently. CREATE TABLE IF NOT EXISTS freight_forecast_report_round ( id BIGINT AUTO_INCREMENT PRIMARY KEY, report_period VARCHAR(20) NOT NULL, report_stage VARCHAR(10) NOT NULL COMMENT 'AUDIT/FINAL', revision_no INT NOT NULL, file_name VARCHAR(255) NULL, row_count INT NOT NULL DEFAULT 0, note VARCHAR(500) NULL, imported_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_freight_forecast_report_round (report_period, report_stage, revision_no), KEY idx_freight_forecast_report_round_period (report_period, report_stage, imported_at) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Freight monthly report import rounds';