| | |
| | | userIds.add(uid); |
| | | } |
| | | |
| | | // 3) 插入 20 个学员(audit_state=0 未审核) |
| | | // 3) 插入 20 个学员 |
| | | List<Long> playerIds = new ArrayList<>(); |
| | | for (int i = 1; i <= 20; i++) { |
| | | long pid = insertPlayer(conn, |
| | | "学员" + i, |
| | | "1380013" + String.format("%04d", i), |
| | | 1, // role_id |
| | | 0, // audit_state 未审核 |
| | | 1, // state=1 正常 |
| | | userIds.get(i - 1)); |
| | | playerIds.add(pid); |
| | |
| | | throw new SQLException("插入用户失败"); |
| | | } |
| | | |
| | | private long insertPlayer(Connection conn, String name, String phone, long roleId, int auditState, int state, long userId) throws SQLException { |
| | | String sql = "INSERT INTO t_player (name, phone, role_id, audit_state, state, user_id) VALUES (?, ?, ?, ?, ?, ?)"; |
| | | private long insertPlayer(Connection conn, String name, String phone, long roleId, int state, long userId) throws SQLException { |
| | | String sql = "INSERT INTO t_player (name, phone, role_id, state, user_id) VALUES (?, ?, ?, ?, ?)"; |
| | | try (PreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { |
| | | ps.setString(1, name); |
| | | ps.setString(2, phone); |
| | | ps.setLong(3, roleId); |
| | | ps.setInt(4, auditState); |
| | | ps.setInt(5, state); |
| | | ps.setLong(6, userId); |
| | | ps.setInt(4, state); |
| | | ps.setLong(5, userId); |
| | | ps.executeUpdate(); |
| | | try (ResultSet keys = ps.getGeneratedKeys()) { |
| | | if (keys.next()) return keys.getLong(1); |