⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employeeserviceimpl.java

📁 是Eclipse web开发从入门到精通的源码
💻 JAVA
字号:
package com.REP.ServiceImpl;

import java.math.BigDecimal;

import com.REP.DAO.iface.IAccountDAO;
import com.REP.DAO.iface.IEmployeeDAO;
import com.REP.IService.IEmployeeService;
import com.REP.bean.Account;
import com.REP.bean.Employee;
import com.REP.excptions.AccountIsExistException;
import com.REP.excptions.AccountNotExistException;
import com.REP.excptions.EmployeeBeUsedException;
import com.REP.excptions.EmployeeNotExistException;
import com.REP.excptions.OverDrawException;

public class EmployeeServiceImpl implements IEmployeeService {
   //定义DAO对象
    private IEmployeeDAO employeedao ;
    private IAccountDAO accountdao ;
    //以Account对象为参数的员工注册业务逻
    public void regist(Account account) throws AccountIsExistException {
        //根据帐户名称来获得Account对象
        Account acnt = accountdao.getAccountbyName(account.getLoginName());
        //判断是否已经存在同名帐户,如果存在抛出异常
        if(!acnt.equals(null)) throw new AccountIsExistException();
        //如果帐户不存在,对此帐户进行保存,完成注册业务
        accountdao.save(account);
        
    }
  //以就餐帐户名称、员工姓名、员工身份证号为参数的注册业务逻辑 
    public void registByName(String repastCard,String employeeName,String idCard) throws AccountIsExistException, EmployeeNotExistException, EmployeeBeUsedException {
        //根据员工姓名和身份证号查找数据库中是否存在该名员工
        Employee employee = employeedao.findEmployee(employeeName,idCard);
        
        //如果员工不存在,则抛出异常,不允许注册
        if(employee==null) throw new EmployeeNotExistException();
        
        //如果员工存在,接下来要判断注册的帐户名是否已存在
        Account acnt = accountdao.getAccountbyName(repastCard);
        
        //如果存在,抛出异常,不允许注册
        if(!(acnt==null)) throw new AccountIsExistException();
        
        //如果帐户不存在,查找该员工是否已经注册过
        Account account = employee.getAccount();
        
        //如果注册过,则不允许多次注册,抛出异常
        if(!(account==null))throw new EmployeeBeUsedException();
        
        //如果员工没有注册过,允许注册
        account = new Account();
        account.setBalance(new BigDecimal("0"));
        account.setLoginName(repastCard);
        account.setOverdrawNumber(0);
        account.setEmployee(employee);
        accountdao.save(account);
        
        
    }
    //无返回值的员工就餐刷卡业务逻辑
    public void  repast(String name,String fee) throws AccountNotExistException, OverDrawException {
        Account account = accountdao.getAccountbyName(name);
        if(account==null) throw new AccountNotExistException();
        Integer overdrawNub = account.getOverdrawNumber();
        if(overdrawNub.equals(3))throw new OverDrawException();
        BigDecimal balances = account.getBalance();
        BigDecimal repastFee = new BigDecimal(fee);
        if(balances.compareTo(repastFee)<=0){
            balances = balances.subtract(repastFee);
            account.setBalance(balances);
            
            overdrawNub = overdrawNub+1;
            account.setOverdrawNumber(overdrawNub);
            
            accountdao.update(account);
        }else{
            balances = balances.subtract(repastFee);
            account.setBalance(balances);
            accountdao.update(account);
        }
    }
    //返回Account对象的就餐刷卡业务逻辑
    public Account  repastAccount(String name,String fee) throws AccountNotExistException, OverDrawException {
        //根据帐户名称获得就餐帐户对象
        Account account = accountdao.getAccountbyName(name);
        //如果帐户不存在,不允许就餐,抛出异常
        if(account==null) throw new AccountNotExistException();
        //如果帐户存在,查看透支次数
        Integer overdrawNub = account.getOverdrawNumber();
        //如果透支次数超过三次,不允许就餐,抛出异常
        if(overdrawNub.equals(3))throw new OverDrawException();
        //如果透支次数没有超过三次,允许就餐,获得余额和就餐标准
        BigDecimal balances = account.getBalance();
        BigDecimal repastFee = new BigDecimal(fee);
        //如过就餐标准超过余额,则余额减少的同时需要增加一次透支次数
        if(balances.compareTo(repastFee)<=0){
            balances = balances.subtract(repastFee);
            account.setBalance(balances);
            
            overdrawNub = overdrawNub+1;
            account.setOverdrawNumber(overdrawNub);
            
            accountdao.update(account);
        }else{
            //否则只需减少余额
            balances = balances.subtract(repastFee);
            account.setBalance(balances);
            accountdao.update(account);
        }
        return account;
    }
    //以就餐帐户名称为参数的余额查询业务逻辑
    public BigDecimal searchBanlances(String repastCard) throws AccountNotExistException{
        Account account = accountdao.getAccountbyName(repastCard); 
        if(account==null) throw new AccountNotExistException();
        BigDecimal banlances = account.getBalance();
        return banlances;
    }
    //以Account对象为参数的余额查询业务逻辑
    public BigDecimal searchBanlancesByAccount(Account account){
        BigDecimal banlances = account.getBalance();
        return banlances;
    }
    //以就餐帐户名称为参数的透支次数查询业务逻辑
    public Integer searchOverDrawNub(String repastCard) throws AccountNotExistException{
        Account account = accountdao.getAccountbyName(repastCard); 
        if(account==null) throw new AccountNotExistException();
        Integer overDrawNub = account.getOverdrawNumber();
        return overDrawNub;
    }
    //以Account对象为参数的透支次数查询业务逻辑
    public Integer searchOverDrawNubByAccount(Account account){
        Integer overDrawNub = account.getOverdrawNumber();
        return overDrawNub;
    }
    public IAccountDAO getAccountdao() {
        return accountdao;
    }

    public void setAccountdao(IAccountDAO accountdao) {
        this.accountdao = accountdao;
    }

    public IEmployeeDAO getEmployeedao() {
        return employeedao;
    }

    public void setEmployeedao(IEmployeeDAO employeedao) {
        this.employeedao = employeedao;
    }
    
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -