java医疗项目系统设置管理模块:主要包括用户管理,权限管理功能,代码实现
时间: 2024-05-15 15:13:39 浏览: 181
以下是 Java 医疗项目系统设置管理模块的代码实现:
### 用户管理功能
#### User 类
```java
public class User {
private String username;
private String password;
private String name;
private String email;
private int role; // 角色:1-管理员,2-普通用户
// 构造函数
public User(String username, String password, String name, String email, int role) {
this.username = username;
this.password = password;
this.name = name;
this.email = email;
this.role = role;
}
// getter 和 setter 方法
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 getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
}
```
#### UserManager 类
```java
import java.util.ArrayList;
import java.util.List;
public class UserManager {
private List<User> userList;
// 构造函数
public UserManager() {
userList = new ArrayList<>();
}
// 添加用户
public void addUser(User user) {
userList.add(user);
}
// 删除用户
public void deleteUser(String username) {
for (int i = 0; i < userList.size(); i++) {
if (userList.get(i).getUsername().equals(username)) {
userList.remove(i);
break;
}
}
}
// 修改用户信息
public void updateUser(String username, String password, String name, String email, int role) {
for (int i = 0; i < userList.size(); i++) {
if (userList.get(i).getUsername().equals(username)) {
userList.get(i).setPassword(password);
userList.get(i).setName(name);
userList.get(i).setEmail(email);
userList.get(i).setRole(role);
break;
}
}
}
// 查询用户信息
public User getUser(String username) {
for (int i = 0; i < userList.size(); i++) {
if (userList.get(i).getUsername().equals(username)) {
return userList.get(i);
}
}
return null;
}
// 获取所有用户信息
public List<User> getUserList() {
return userList;
}
}
```
### 权限管理功能
#### Permission 类
```java
public class Permission {
private String name;
private String description;
// 构造函数
public Permission(String name, String description) {
this.name = name;
this.description = description;
}
// getter 和 setter 方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
```
#### Role 类
```java
import java.util.ArrayList;
import java.util.List;
public class Role {
private String name;
private List<Permission> permissionList;
// 构造函数
public Role(String name) {
this.name = name;
permissionList = new ArrayList<>();
}
// 添加权限
public void addPermission(Permission permission) {
permissionList.add(permission);
}
// 删除权限
public void deletePermission(String name) {
for (int i = 0; i < permissionList.size(); i++) {
if (permissionList.get(i).getName().equals(name)) {
permissionList.remove(i);
break;
}
}
}
// getter 和 setter 方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Permission> getPermissionList() {
return permissionList;
}
public void setPermissionList(List<Permission> permissionList) {
this.permissionList = permissionList;
}
}
```
#### RoleManager 类
```java
import java.util.ArrayList;
import java.util.List;
public class RoleManager {
private List<Role> roleList;
// 构造函数
public RoleManager() {
roleList = new ArrayList<>();
}
// 添加角色
public void addRole(Role role) {
roleList.add(role);
}
// 删除角色
public void deleteRole(String name) {
for (int i = 0; i < roleList.size(); i++) {
if (roleList.get(i).getName().equals(name)) {
roleList.remove(i);
break;
}
}
}
// 修改角色信息
public void updateRole(String name, List<Permission> permissionList) {
for (int i = 0; i < roleList.size(); i++) {
if (roleList.get(i).getName().equals(name)) {
roleList.get(i).setPermissionList(permissionList);
break;
}
}
}
// 查询角色信息
public Role getRole(String name) {
for (int i = 0; i < roleList.size(); i++) {
if (roleList.get(i).getName().equals(name)) {
return roleList.get(i);
}
}
return null;
}
// 获取所有角色信息
public List<Role> getRoleList() {
return roleList;
}
}
```
阅读全文