package com.ruoyi.web.controller.dz;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class SqlDataGenerator {

    public static void main(String[] args) {
        String fileName = "dz_classes_data.txt";

        // 范围定义
        int startSchoolId = 2480;
        int endSchoolId = 2910;
        int year = 2026;
        int maxClassName = 30;

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
            writer.write("-- 批量生成 dz_classes 插入数据\n");

            for (int schoolId = startSchoolId; schoolId <= endSchoolId; schoolId++) {
                StringBuilder sql = new StringBuilder();
                // 每个学校作为一个批量插入语句开始
                sql.append("INSERT INTO `dz_classes` (`school_id`, `year`, `name`) VALUES ");

                for (int nameVal = 1; nameVal <= maxClassName; nameVal++) {
                    sql.append(String.format("(%d, %d, '%d')", schoolId, year, nameVal));

                    // 如果不是最后一个值，加逗号分隔
                    if (nameVal < maxClassName) {
                        sql.append(", ");
                    }
                }

                // 语句结束
                sql.append(";\n");
                writer.write(sql.toString());
            }

            System.out.println("数据生成成功！");
            System.out.println("文件路径: " + "/Users/admin/Downloads/" + fileName);
            System.out.println("总生成条数: " + ((endSchoolId - startSchoolId + 1) * maxClassName));

        } catch (IOException e) {
            System.err.println("文件写入失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
