DELIMITER
$$

DROP PROCEDURE IF EXISTS truncate_hot_tables $$
CREATE PROCEDURE truncate_hot_tables()
BEGIN
    DECLARE
done INT DEFAULT 0;
    DECLARE
v_table_name VARCHAR(128);

    DECLARE
cur CURSOR FOR
SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE()
  AND (
    (
        LEFT(TABLE_NAME, 4) = 'hot_'
        AND RIGHT (TABLE_NAME, 7) <> '_config'
        AND RIGHT (TABLE_NAME, 9) <> '_template'
        AND TABLE_NAME NOT IN (
        'hot_course_resource',
        'hot_media_resource',
        'hot_question_bank',
        'hot_exam_paper',
        'hot_system_agreement',
        'hot_law_regulation',
        'hot_vehicle_type',
        'hot_vehicle_brand_model',
        'hot_company_basic_config',
        'hot_company_dept_config',
        'hot_driver_annual_assessment_config',
        'hot_sign_audit_permission_config',
        'hot_vehicle_three_inspect_config',
        'hot_hidden_danger_inspect_store',
        'hot_hidden_danger_check_config',
        'hot_vehicle_inspection_config',
        'hot_vehicle_secondary_maintenance_config',
        'hot_accident_likelihood_level_config',
        'hot_accident_severity_level_config',
        'hot_accident_level_config',
        'hot_risk_level_config',
        'hot_risk_score_level',
        'hot_system_template',
        'hot_file_type_config'
        )
        )
        OR TABLE_NAME IN ('sys_flow_instance', 'sys_flow_task', 'sys_flow_task_his')
    )
ORDER BY TABLE_NAME;

DECLARE
CONTINUE HANDLER FOR NOT FOUND SET done = 1;

    SET
FOREIGN_KEY_CHECKS = 0;

OPEN cur;
read_loop
: LOOP
        FETCH cur INTO v_table_name;
        IF
done = 1 THEN
            LEAVE read_loop;
END IF;

        SET
@sql = CONCAT('TRUNCATE TABLE `', v_table_name, '`');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END LOOP;
CLOSE cur;

SET
FOREIGN_KEY_CHECKS = 1;
END $$

DELIMITER ;

CALL truncate_hot_tables();
DROP PROCEDURE truncate_hot_tables;