@ -0,0 +1,30 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
.idea/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@ -0,0 +1,5 @@
|
||||
import java.util.Map;
|
||||
public interface AccountService {
|
||||
void setAccounts(String type);
|
||||
Map<String, String> getAccounts();
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AccountServiceImpl implements AccountService {
|
||||
private Map<String, String> accounts = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void setAccounts(String type) {
|
||||
|
||||
switch (type) {
|
||||
case "小学":
|
||||
accounts.put("张三1", "123");
|
||||
accounts.put("张三2", "123");
|
||||
accounts.put("张三3", "123");
|
||||
break;
|
||||
case "初中":
|
||||
accounts.put("李四1", "123");
|
||||
accounts.put("李四2", "123");
|
||||
accounts.put("李四3", "123");
|
||||
break;
|
||||
case "高中":
|
||||
accounts.put("王五1", "123");
|
||||
accounts.put("王五2", "123");
|
||||
accounts.put("王五3", "123");
|
||||
break;
|
||||
default:
|
||||
System.out.println("未知账户类型!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAccounts() {
|
||||
return accounts; // 返回账户数据
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
public interface LoginService {
|
||||
boolean authenticate(String username, String password);
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
import java.util.Map;
|
||||
|
||||
public class LoginServiceImpl implements LoginService {
|
||||
private AccountService accountService;
|
||||
|
||||
public LoginServiceImpl(AccountService accountService) {
|
||||
this.accountService = accountService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authenticate(String username, String password) {
|
||||
|
||||
username = username.trim();
|
||||
password = password.trim();
|
||||
|
||||
|
||||
Map<String, String> accounts = accountService.getAccounts();
|
||||
|
||||
|
||||
if (accounts.containsKey(username)) {
|
||||
String storedPassword = accounts.get(username);
|
||||
return storedPassword.equals(password); // 密码匹配
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
public interface UserService {
|
||||
boolean switchAccount(String type);
|
||||
String getAccountType();
|
||||
}
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
public class UserServiceImpl implements UserService {
|
||||
private AccountService accountService;
|
||||
private String accountType = "";
|
||||
|
||||
public UserServiceImpl(AccountService accountService) {
|
||||
this.accountService = accountService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean switchAccount(String type) {
|
||||
if ("小学".equals(type) || "初中".equals(type) || "高中".equals(type)) {
|
||||
accountType = type;
|
||||
accountService.setAccounts(accountType);
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("请选择正确的账户类型!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccountType() {
|
||||
return accountType;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue