Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit ff84d00

Browse files
committed
add: add function about users
1 parent dffa578 commit ff84d00

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

.idea/encodings.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/top/mryan2005/managesysteminjava/BasicClass/LoginPart.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.apache.commons.codec.digest.DigestUtils;
55

66
import java.io.UnsupportedEncodingException;
7-
import java.nio.charset.StandardCharsets;
87
import java.sql.ResultSet;
98
import java.sql.SQLException;
109
import java.util.HashMap;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package top.mryan2005.managesysteminjava.BasicClass;
2+
3+
import top.mryan2005.managesysteminjava.SQLs.SQLLinker;
4+
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.util.HashMap;
8+
9+
public class UserGroup {
10+
public final HashMap<String, Integer> userGroup = new HashMap<>();
11+
12+
public final void getCurrentGroup(SQLLinker sql) {
13+
try {
14+
ResultSet res = sql.runSQL("SELECT * FROM Users.[permission]");
15+
if (res != null) {
16+
while (res.next()) {
17+
userGroup.put(res.getString("permissionName"), res.getInt("id"));
18+
}
19+
}
20+
} catch (SQLException e) {
21+
throw new RuntimeException(e);
22+
}
23+
}
24+
25+
public final int getGroupID(String groupName) {
26+
return userGroup.get(groupName);
27+
}
28+
29+
public final String getGroupName(int groupID) {
30+
for (String key : userGroup.keySet()) {
31+
if (userGroup.get(key) == groupID) {
32+
return key;
33+
}
34+
}
35+
return null;
36+
}
37+
38+
public final String addGroup(String groupName, int groupID, SQLLinker sql) {
39+
if(userGroup.containsKey(groupName)) {
40+
return "Group name already exists!";
41+
}
42+
userGroup.put(groupName, groupID);
43+
sql.runSQL("INSERT INTO Users.[permission] (permissionName, id) VALUES ('" + groupName + "', " + groupID + ")");
44+
return "Group added successfully!";
45+
}
46+
47+
public final String removeGroup(String groupName, SQLLinker sql) {
48+
if(!userGroup.containsKey(groupName)) {
49+
return "Group name does not exist!";
50+
}
51+
userGroup.remove(groupName);
52+
sql.runSQL("DELETE FROM Users.[permission] WHERE permissionName = '" + groupName + "'");
53+
return "Group removed successfully!";
54+
}
55+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package top.mryan2005.managesysteminjava.BasicClass;
2+
3+
public class UserManager {
4+
}

0 commit comments

Comments
 (0)