提交 dda0b347 编写于 作者: 小刘28's avatar 小刘28 💬

feat:增加dao层,调整系统的数据处理逻辑;

上级 d82f2577
......@@ -3,6 +3,8 @@ package com.ubitgroup.controller.LoginM;
import com.ubitgroup.data.AccountT;
import com.ubitgroup.model.bean.Account;
import com.ubitgroup.model.bean.Result;
import com.ubitgroup.model.dao.AccountD;
import com.ubitgroup.model.dao.impl.AccountDI;
import java.time.LocalDateTime;
import java.util.ArrayList;
......@@ -16,15 +18,13 @@ public class LoginC {
* 登录处理
* */
public Result login(Account account){
AccountT accountT = AccountT.getInstance();
Integer type = accountT.getByAccoPass(account);
String data;
AccountD accountD = new AccountDI();
Integer type = accountD.login(account);
switch (type){
case 0:
// 获取账号的id
ArrayList<Account> list = accountT.getParam(account,null,null,null,null);
Account accountTemp = list.get(0);
account.setId(accountTemp.getId());
// 获取账号的信息
account = accountD.getAccoInfo(account);
account.setPassword(null);
return Result.success(account);
case 1:
......@@ -52,7 +52,7 @@ public class LoginC {
account.setId(UUID.randomUUID().toString());
account.setCreateTime(LocalDateTime.now());
account.setUpdateTime(LocalDateTime.now());
if (accountT.add(account)) {
if (AccountT.add(account) == 1) {
return Result.success(null);
}else{
data = "注册出错了,请联系管理员!";
......@@ -62,6 +62,10 @@ public class LoginC {
// 提示账号已存在
data = "账号已存在,请重新输入!";
return Result.error(1,data);
case 2:
// 提示账号已存在
data = "邮箱已存在,请重新输入!";
return Result.error(1,data);
default:
// 系统出错了
data = "注册出错了,请联系管理员!";
......
......@@ -23,16 +23,9 @@ public class AccountT {
}
/*
* 获取全部数据
* 查找元素在list中的索引
* */
public static ArrayList<Account> getArrayList() {
return arrayList;
}
/*
* 查找元素在list中的索引
* */
public Integer getIndex(String id){
public static Integer getIndex(String id){
int index = -1;
for (int i = 0; i < arrayList.size(); i++) {
Account account = arrayList.get(i);
......@@ -44,41 +37,48 @@ public class AccountT {
return index;
}
/*
* 获取全部数据
* */
public static ArrayList<Account> getArrayList() {
return arrayList;
}
/*
* 增加元素
* */
public Boolean add(Account account){
return arrayList.add(account);
public static Integer add(Account account){
Boolean flag = arrayList.add(account);
return flag?1:0;
}
/*
* 修改元素
* */
public Boolean set(Account account){
public static Integer set(Account account){
Integer index = getIndex(account.getId());
if (index == -1) {
return false;
return 0;
}else{
Account oldAccount = arrayList.set(index,account);
return !oldAccount.equals(account);
return oldAccount == null?0:1;
}
}
/*
* 删除元素
* */
public Integer remove(Account[] accounts){
Integer count = 0;
for (Account account : accounts) {
Integer index = getIndex(account.getId());
if (index != -1) {
boolean flag = arrayList.remove(index);
if (flag) {
count++;
}
public static Integer remove(Account account){
Integer index = getIndex(account.getId());
if (index != -1) {
boolean flag = arrayList.remove(index);
if (flag) {
return 1;
}else{
return 0;
}
}
return count;
return 0;
}
/*
......@@ -142,7 +142,7 @@ public class AccountT {
* 通过账号查找
* */
public Integer getByAcco(Account account){
int count = 0; // 0:账号和密码都正确,1:账号不存在,2:密码错误
int count = 0;
for (int i = 0; i < arrayList.size(); i++) {
Account accountTemp = arrayList.get(i);
if(accountTemp.getAccount().equals(account.getAccount())){
......@@ -152,4 +152,18 @@ public class AccountT {
return count;
}
/*
* 通过email查找
* */
public Integer getByEmail(Account account){
int count = 0;
for (int i = 0; i < arrayList.size(); i++) {
Account accountTemp = arrayList.get(i);
if(accountTemp.getEmail().equals(account.getEmail())){
return ++count;
}
}
return count;
}
}
package com.ubitgroup.model.dao;
import com.ubitgroup.model.bean.Account;
public interface AccountD {
/*
* 登录
* */
public Integer login(Account account);
/*
* 获取账号信息
* */
public Account getAccoInfo(Account account);
}
package com.ubitgroup.model.dao.impl;
import com.ubitgroup.data.AccountT;
import com.ubitgroup.model.bean.Account;
import com.ubitgroup.model.dao.AccountD;
import java.util.ArrayList;
public class AccountDI implements AccountD {
private AccountT accountT = AccountT.getInstance();
/*
* 登录
* */
@Override
public Integer login(Account account) {
// 判断账号是否存在
Account accountTemp = new Account();
accountTemp.setAccount(account.getAccount());
ArrayList<Account> list = accountT.getParam(accountTemp,null,null,null,null);
if (list == null){
return 500; // 系统出错了
}
if (list.size() == 0){
return 1; // 1:账号不存在
}
// 判断密码是否正确
accountTemp = list.get(0);
if (!accountTemp.getPassword().equals(account.getPassword())){
return 2; // 2:密码错误
}
return 0; // 0:账号密码均正确
}
/*
* 获取账号信息
* */
@Override
public Account getAccoInfo(Account account) {
ArrayList<Account> list = accountT.getParam(account,null,null,null,null);
account = list.get(0);
return account;
}
}
......@@ -97,6 +97,11 @@ public class LoginV {
if (inteOper(password)){
break;
}
System.out.println("请输入email:");
String email = sc.nextLine();
if (inteOper(email)){
break;
}
Account accountTemp = new Account();
accountTemp.setAccount(account);
accountTemp.setPassword(password);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册