📄 managerserviceimpl.java
字号:
package com.REP.ServiceImpl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import com.REP.DAO.iface.IAccountDAO;
import com.REP.DAO.iface.IManagerDAO;
import com.REP.IService.IManagerService;
import com.REP.bean.Account;
import com.REP.bean.Manager;
import com.REP.excptions.AccountIsExistException;
import com.REP.excptions.AccountNotExistException;
public class ManagerServiceImpl implements IManagerService {
//定义DAO对象
public IAccountDAO accountdao ;
public IManagerDAO managerdao;
public IAccountDAO getAccountdao() {
return accountdao;
}
public void setAccountdao(IAccountDAO accountdao) {
this.accountdao = accountdao;
}
//删除帐户
public void delAccount(Account account) throws AccountNotExistException {
if(account == null)throw new AccountNotExistException();
accountdao.delete(account);
}
//以Account对象为参数修改帐户
public void modifyAccount(Account account) throws AccountNotExistException {
if(account==null)throw new AccountNotExistException();
accountdao.update(account);
}
////以就餐帐户名称和帐户id为参数修改帐户
public void modifyAccount(String repastCard ,String id) throws AccountIsExistException {
Account account = new Account();
//根据帐户名称获得帐户对象
account = accountdao.getAccountbyName(repastCard);
//如果帐户不存在,则抛出异常
if(!(account==null)) throw new AccountIsExistException();
//如果帐户存在,对帐户的名称进行修改
account = getAccountById(id);
account.setLoginName(repastCard);
accountdao.update(account);
}
//帐户充值
public void fillAccount(Account account,String fee) throws AccountNotExistException {
//如果帐户为空,则无法充值,抛出异常
if(account==null)throw new AccountNotExistException();
//如果帐户存在,获得帐户余额
BigDecimal banlances = account.getBalance();
Integer overDrawNub = account.getOverdrawNumber();
//增加帐户余额
banlances =banlances.add(new BigDecimal(fee));
//如果帐户余额大于0则,将透支次数设为0
if(banlances.compareTo(new BigDecimal("0"))>=0){
overDrawNub = 0;
}
//更新帐户
account.setBalance(banlances);
account.setOverdrawNumber(overDrawNub);
accountdao.update(account);
}
////检查用户是否存在
public Boolean checkUser(String username, String password) {
Manager manager = managerdao.findUser(username,password);
if(manager==null) return false;
return true;
}
public void setManagerdao(IManagerDAO managerdao) {
this.managerdao = managerdao;
}
//获得所有帐户
public List findAllAccount(){
List list = new ArrayList();
list = accountdao.findAll();
return list;
}
//根据帐户id获得帐户
public Account getAccountById(String id){
Account account = accountdao.get(Integer.valueOf(id));
return account;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -