import java.sql.*;

public class InsertUsers {
    public static void main(String[] args) throws Exception {
        Class.forName("dm.jdbc.driver.DmDriver");
        Connection conn = DriverManager.getConnection(
            "jdbc:dm://39.98.38.2:30236", "TBA_HZZ", "TBA_HZZ_123");
        Statement stmt = conn.createStatement();

        stmt.execute("DELETE FROM SYS_USER");
        stmt.execute("DELETE FROM SYS_USER_ROLE");
        stmt.execute("DELETE FROM SYS_USER_POST");
        stmt.execute("DELETE FROM SYS_ROLE_DEPT");

        String hash = "$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2";

        PreparedStatement ps = conn.prepareStatement(
            "INSERT INTO SYS_USER VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        ps.setInt(1, 1); ps.setInt(2, 103); ps.setString(3, "admin");
        ps.setString(4, "ruoyi"); ps.setString(5, "00"); ps.setString(6, "ry@163.com");
        ps.setString(7, "15888888888"); ps.setString(8, "1"); ps.setString(9, "");
        ps.setString(10, hash); ps.setString(11, "0"); ps.setString(12, "0");
        ps.setString(13, "127.0.0.1");
        ps.setTimestamp(14, new Timestamp(System.currentTimeMillis()));
        ps.setTimestamp(15, new Timestamp(System.currentTimeMillis()));
        ps.setString(16, "admin");
        ps.setTimestamp(17, new Timestamp(System.currentTimeMillis()));
        ps.setString(18, ""); ps.setString(19, "admin_user");
        ps.executeUpdate();

        ps.setInt(1, 2); ps.setInt(2, 105); ps.setString(3, "ry");
        ps.setString(4, "ruoyi"); ps.setString(5, "00"); ps.setString(6, "ry@qq.com");
        ps.setString(7, "15666666666"); ps.setString(8, "1"); ps.setString(9, "");
        ps.setString(10, hash); ps.setString(11, "0"); ps.setString(12, "0");
        ps.setString(13, "127.0.0.1");
        ps.setTimestamp(14, new Timestamp(System.currentTimeMillis()));
        ps.setTimestamp(15, new Timestamp(System.currentTimeMillis()));
        ps.setString(16, "admin");
        ps.setTimestamp(17, new Timestamp(System.currentTimeMillis()));
        ps.setString(18, ""); ps.setString(19, "tester");
        ps.executeUpdate();

        stmt.execute("INSERT INTO SYS_USER_ROLE VALUES('1','1')");
        stmt.execute("INSERT INTO SYS_USER_ROLE VALUES('2','2')");
        stmt.execute("INSERT INTO SYS_USER_POST VALUES('1','1')");
        stmt.execute("INSERT INTO SYS_USER_POST VALUES('2','2')");
        stmt.execute("INSERT INTO SYS_ROLE_DEPT VALUES('2','100')");
        stmt.execute("INSERT INTO SYS_ROLE_DEPT VALUES('2','101')");
        stmt.execute("INSERT INTO SYS_ROLE_DEPT VALUES('2','105')");

        conn.commit();

        ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM SYS_USER");
        rs.next(); System.out.println("Users: " + rs.getInt(1));
        rs = stmt.executeQuery("SELECT user_name, password FROM SYS_USER");
        while(rs.next()) System.out.println(rs.getString(1) + ": " + rs.getString(2).substring(0,10)+"...");

        conn.close();
        System.out.println("Done!");
    }
}
