ATM系统实现[16]——交易事务类[00原创]

来源:互联网 发布:钢铁侠玩具模型淘宝 编辑:程序博客网 时间:2024/04/28 21:02
package cn.edu.ynu.sei.atm.transactions;

import cn.edu.ynu.sei.atm.account.BankAccount;
import cn.edu.ynu.sei.atm.interfaceDef.ITransaction;
import cn.edu.ynu.sei.atm.sqlManager.SqlStatementsManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * 实现了帐户的基本交易事务功能
 * 
 * 
@author 88250
 
*/
public class Transaction extends UnicastRemoteObject implements ITransaction
{
    
/**
     * SQL语句管理器实例
     
*/
    
private SqlStatementsManager sqlSM = SqlStatementsManager.getInstance();

    
/**
     * 构造一个交易实例
     * 
@throws RemoteException
     
*/
    
public Transaction() throws RemoteException
    {
    
super();
    }

    
/**
     * 转帐事务处理
     * 
@param sourceAccountID 源帐户帐号
     * 
@param targetAccountID 目标帐户帐号
     * 
@param amount 转帐金额
     * 
@throws RemoteException
     
*/
    
public void transfer(int sourceAccountID, int targetAccountID, float amount)
        
throws RemoteException
    {
    String sourceAccountTableName 
= null;
    String targetAccountTableName 
= null;
    String sourceAccountType 
= sqlSM.getAccountType(sourceAccountID);
    String targetAccountType 
= sqlSM.getAccountType(targetAccountID);

    
if (sourceAccountType.equals("cur"))
    {
        sourceAccountTableName 
= "CurrentAccount";
    }
    
else if (sourceAccountType.equals("dep"))
    {
        sourceAccountTableName 
= "DepositAccount";
    }
    
else
    {
        sourceAccountTableName 
= "CreditAccount";
    }

    
if (targetAccountType.equals("cur"))
    {
        targetAccountTableName 
= "CurrentAccount";
    }
    
else if (targetAccountType.equals("dep"))
    {
        targetAccountTableName 
= "DepositAccount";
    }
    
else
    {
        targetAccountTableName 
= "CreditAccount";
    }
    GregorianCalendar theTime 
= new GregorianCalendar();
    String date 
= BankAccount.formatTime(theTime.get(Calendar.YEAR),
        theTime.get(Calendar.MONTH),
        theTime.get(Calendar.DAY_OF_MONTH), theTime
            .get(Calendar.HOUR_OF_DAY), theTime
            .get(Calendar.MINUTE), theTime.get(Calendar.SECOND));
    sqlSM.transfer(sourceAccountID, targetAccountID, date, amount,
        sourceAccountTableName, targetAccountTableName);
    }

    
/**
     * 返回转帐历史事务列表
     * 
@param accountID 帐户帐号
     * 
@param queryType 查询类型
     * 
@see #getDWInfoList(int, int)
     * 
@throws RemoteException
     * 
@return 转帐历史事务列表
     
*/
    
public ArrayList getTransferInfoList(int accountID, int queryType)
        
throws RemoteException
    {
    
return sqlSM.getTransferInfoList(accountID, queryType);
    }

    
/**
     * 返回存款/取款历史事务列表
     * 
@param accountID 帐户帐号
     * 
@param queryType 查询类型,包括:
     * <ul>
     * <li>0:最近一次交易事务查询</li>
     * <li>1:最近一个月交易事务查询</li>
     * <li>2:最近一年交易事务查询</li>
     * </ul>
     * 
@see #getTransferInfoList(int, int)
     * 
@return 存款/取款历史事务列表
     * 
@throws RemoteException
     
*/
    
public ArrayList getDWInfoList(int accountID, int queryType)
        
throws RemoteException
    {
    
return sqlSM.getDWInfoList(accountID, queryType);
    }
}