parent
85d28410c3
commit
00a453a922
@ -0,0 +1,97 @@
|
||||
package self.cases.teams.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class STjiao {
|
||||
private String id;
|
||||
private String clubName;
|
||||
private String memberName;
|
||||
private double amount;
|
||||
private Date paymentDate;
|
||||
private String paymentMethod;
|
||||
private String transactionId;
|
||||
private boolean isPaid;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
|
||||
// Getters and Setters
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getClubName() {
|
||||
return clubName;
|
||||
}
|
||||
|
||||
public void setClubName(String clubName) {
|
||||
this.clubName = clubName;
|
||||
}
|
||||
|
||||
public String getMemberName() {
|
||||
return memberName;
|
||||
}
|
||||
|
||||
public void setMemberName(String memberName) {
|
||||
this.memberName = memberName;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Date getPaymentDate() {
|
||||
return paymentDate;
|
||||
}
|
||||
|
||||
public void setPaymentDate(Date paymentDate) {
|
||||
this.paymentDate = paymentDate;
|
||||
}
|
||||
|
||||
public String getPaymentMethod() {
|
||||
return paymentMethod;
|
||||
}
|
||||
|
||||
public void setPaymentMethod(String paymentMethod) {
|
||||
this.paymentMethod = paymentMethod;
|
||||
}
|
||||
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public void setTransactionId(String transactionId) {
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
public boolean isPaid() {
|
||||
return isPaid;
|
||||
}
|
||||
|
||||
public void setPaid(boolean paid) {
|
||||
isPaid = paid;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package self.cases.teams.entity;
|
||||
|
||||
public class STm {
|
||||
}
|
@ -0,0 +1,268 @@
|
||||
package self.cases.teams.teaa;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// 定义用户信息类
|
||||
class UserInfo {
|
||||
private String userId;
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
private String phone;
|
||||
private String role; // "admin", "moderator", "user"
|
||||
private boolean isActive;
|
||||
|
||||
public UserInfo(String userId, String username, String password, String email, String phone, String role, boolean isActive) {
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.phone = phone;
|
||||
this.role = role;
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
isActive = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"userId='" + userId + '\\' +
|
||||
", username='" + username + '\\' +
|
||||
", password='" + password + '\\' +
|
||||
", email='" + email + '\\' +
|
||||
", phone='" + phone + '\\' +
|
||||
", role='" + role + '\\' +
|
||||
", isActive=" + isActive +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
// 社团管理系统社团系统用户管理类
|
||||
public class STxtgl {
|
||||
// 模拟数据库
|
||||
private List<UserInfo> userInfos = new ArrayList<>();
|
||||
|
||||
// 注册新用户
|
||||
public boolean registerUser(String username, String password, String email, String phone, String role) {
|
||||
if (findUserByUsername(username) == null) {
|
||||
String userId = generateUniqueId();
|
||||
UserInfo newUser = new UserInfo(userId, username, password, email, phone, role, true);
|
||||
userInfos.add(newUser);
|
||||
System.out.println("用户注册成功: " + newUser);
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("用户名已存在,无法注册: " + username);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 登录用户
|
||||
public boolean login(String username, String password) {
|
||||
UserInfo userToLogin = findUserByUsernameAndPassword(username, password);
|
||||
if (userToLogin != null && userToLogin.isActive()) {
|
||||
System.out.println("用户登录成功: " + userToLogin);
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("用户名或密码错误,登录失败");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 查找用户
|
||||
private UserInfo findUserByUsername(String username) {
|
||||
for (UserInfo userInfo : userInfos) {
|
||||
if (userInfo.getUsername().equals(username)) {
|
||||
System.out.println("用户查找成功: " + userInfo);
|
||||
return userInfo;
|
||||
}
|
||||
}
|
||||
System.out.println("未找到用户: " + username);
|
||||
return null;
|
||||
}
|
||||
|
||||
private UserInfo findUserByUsernameAndPassword(String username, String password) {
|
||||
for (UserInfo userInfo : userInfos) {
|
||||
if (userInfo.getUsername().equals(username) && userInfo.getPassword().equals(password)) {
|
||||
return userInfo;
|
||||
}
|
||||
}
|
||||
System.out.println("未找到用户或密码错误");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 删除用户
|
||||
public boolean deleteUser(String userId) {
|
||||
UserInfo userToRemove = findUserById(userId);
|
||||
if (userToRemove != null) {
|
||||
userInfos.remove(userToRemove);
|
||||
System.out.println("用户删除成功: " + userToRemove);
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("未找到用户ID: " + userId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
public boolean updateUser(String userId, String field, Object newValue) {
|
||||
UserInfo userToUpdate = findUserById(userId);
|
||||
if (userToUpdate != null) {
|
||||
switch (field.toLowerCase()) {
|
||||
case "username":
|
||||
userToUpdate.setUsername(newValue.toString());
|
||||
break;
|
||||
case "password":
|
||||
userToUpdate.setPassword(newValue.toString());
|
||||
break;
|
||||
case "email":
|
||||
userToUpdate.setEmail(newValue.toString());
|
||||
break;
|
||||
case "phone":
|
||||
userToUpdate.setPhone(newValue.toString());
|
||||
break;
|
||||
case "role":
|
||||
userToUpdate.setRole(newValue.toString());
|
||||
break;
|
||||
case "active":
|
||||
try {
|
||||
userToUpdate.setActive(Boolean.parseBoolean(newValue.toString()));
|
||||
} catch (Exception e) {
|
||||
System.out.println("无效的活动状态: " + newValue);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效字段: " + field);
|
||||
return false;
|
||||
}
|
||||
System.out.println("用户信息更新成功: " + userToUpdate);
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("未找到用户ID: " + userId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询用户
|
||||
public UserInfo findUserById(String userId) {
|
||||
for (UserInfo userInfo : userInfos) {
|
||||
if (userInfo.getUserId().equals(userId)) {
|
||||
System.out.println("用户查找成功: " + userInfo);
|
||||
return userInfo;
|
||||
}
|
||||
}
|
||||
System.out.println("未找到用户ID: " + userId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 显示所有用户信息
|
||||
public void displayAllUsers() {
|
||||
if (userInfos.isEmpty()) {
|
||||
System.out.println("当前没有用户信息记录");
|
||||
} else {
|
||||
System.out.println("所有用户信息:");
|
||||
for (UserInfo userInfo : userInfos) {
|
||||
System.out.println(userInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理新用户注册
|
||||
public boolean addNewUser(String username, String password, String email, String phone, String role) {
|
||||
return registerUser(username, password, email, phone, role);
|
||||
}
|
||||
|
||||
// 生成唯一的ID
|
||||
private String generateUniqueId() {
|
||||
return "USR" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// 主方法演示功能
|
||||
public static void main(String[] args) {
|
||||
STxtgl manager = new STxtgl();
|
||||
|
||||
// 注册新用户
|
||||
manager.addNewUser("zhangsan", "123456", "zhangsan@example.com", "1234567890", "user");
|
||||
manager.addNewUser("lisi", "abcdef", "lisi@example.com", "0987654321", "moderator");
|
||||
|
||||
// 显示所有用户信息
|
||||
manager.displayAllUsers();
|
||||
|
||||
// 处理新用户注册
|
||||
manager.addNewUser("wangwu", "qwerty", "wangwu@example.com", "1122334455", "admin");
|
||||
|
||||
// 再次显示所有用户信息
|
||||
manager.displayAllUsers();
|
||||
|
||||
// 登录用户
|
||||
manager.login("zhangsan", "123456");
|
||||
manager.login("lisi", "abcdef");
|
||||
manager.login("wangwu", "qwerty");
|
||||
|
||||
// 更新用户信息
|
||||
manager.updateUser("USR1", "username", "zhangsan_new");
|
||||
manager.updateUser("USR2", "role", "admin");
|
||||
manager.updateUser("USR3", "active", false);
|
||||
|
||||
// 再次显示所有用户信息
|
||||
manager.displayAllUsers();
|
||||
|
||||
// 删除用户
|
||||
manager.deleteUser("USR2");
|
||||
|
||||
// 再次显示所有用户信息
|
||||
manager.displayAllUsers();
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue