ATM统需求
ATM自动动取款机是银行在银行营业大厅、超市、商业机构、机场、车站、码头和闹市区设置的一种小型机器,利用一张信用卡大小的胶卡上的磁带〔或芯片卡上的芯片〕记录客户的基本户口资料,让客户可以透过机器进行提款、存款、转帐等银行柜台服务
1) 客户将银行卡插入读卡器,读卡器识别卡的真伪,并在显示器上提示输入密码。
2) 客户通过键盘输入密码,取款机验证密码是否有效。如果密码错误提示错误信息,如果正确,提示客户进行选择操作的业务。
3) 客户根据自己的需要可进行存款、取款、查询账户、转账、修改密码等操作。
4) 在客户选择后显示器进行交互提示和操作确认等信息。
5) 操作完毕之后,客户可自行选择打印或不打印凭条。
ATM系统设计
系统流程和主要的功能
系统类图
登录时序图
存款时序图
取款时序图
查询账户
行内转账时序图
跨行转账时序图
数据库设计
先建立一个atm数据库
再建立三个表
用户信息表t_customer_info
字段包括:卡号、确认编号、用户名字、密码、余额、创建时间、开卡的银行、状态、保存类型
日志表t_log_info
字段包括:日志id、日志信息、日志类型、日志时间、操作人员、日志状态
交易记录表t_record_info
字段包括:交易id、交易时间、交易金额、用户名字、卡号、交易类型、余额
凭条设计
转账、存款、取款的凭条
交易信息的凭条
ATM系统实现
登陆界面
登陆成功后进入主界面
存款界面(演示打印凭条功能,其他功能就不再演示打印凭条功能)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-snpUWrgp-1611683753229)(https://picture.hs-vae.com/存款界面.png)]
存款成功后提示是否打印凭条
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ueyFMacX-1611683753230)(https://picture.hs-vae.com/是否打印凭条.png)]
选择保存的路径
凭条已生成到指定的位置(桌面)
查看生成的凭条(注意这里的银行的logo是我自己本地的,你们要使用的话要重新编译jrml文件,图片选择你自己本地的logo,最后生成jasper文件,放在项目的jasper文件夹里)
取款界面
转账界面
交易信息界面
操作后的日志信息表和交易记录表
部分代码
项目结构
策略模式(对转账(行内和跨行)、存款、取款、修改密码、登录、登出等业务进行选择)
策略模式总接口
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
/**
* 策略模式总接口
*/
public interface IStrategy {
CommonResult process(CommonAtmVO commonAtmVO);
}
处理上下文的Context
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.util.StatusEnumEntity;
import java.util.ArrayList;
import java.util.List;
/**
* 策略模式中处理上下文
*/
public class ProcessContext {
private String type;
private IStrategy is;
private static List<ProcessContext> strategyList = new ArrayList<ProcessContext>();
static {
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_SAVE”),new StrategyDepositImpl()));
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_LOGIN”),new StrategyLoginImpl()));
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_LOGINFAILED”),new StrategyLoginImpl()));
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_CHANGEPWD”),new StrategyChangePwdImpl()));
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_LOGOUT”),new StrategyLogoutImpl()));
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_INTRANSFER”),new StrategyTransferInnerImpl()));
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_OUTTRANSFER”),new StrategyTransferOuterImpl()));
strategyList.add(new ProcessContext(StatusEnumEntity.getValue(“STATUS_FETCH”),new StrategyWithdrawImpl()));
}
public CommonResult delStrategy(CommonAtmVO commonAtmVO) {
IStrategy is = null;
for (ProcessContext pc : strategyList) {
if (pc.getType().equals(commonAtmVO.getType())) {
is = pc.getIs();
}
}
return is.process(commonAtmVO);
}
public ProcessContext() {
}
public ProcessContext(String type, IStrategy is) {
this.type = type;
this.is = is;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public IStrategy getIs() {
return is;
}
public void setIs(IStrategy is) {
this.is = is;
}
}
策略选择
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
/**
* 策略选择
*/
public class ServerProcessIOUtil {
public ServerProcessIOUtil(Socket socket){
ObjectInputStream ois = null;
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream(socket.getInputStream());
CommonAtmVO commonAtmVO=(CommonAtmVO)ois.readObject();
if (commonAtmVO!=null){
ProcessContext pc = new ProcessContext();
//调用策略选择方法
CommonResult commonResult = pc.delStrategy(commonAtmVO);
oos.writeObject(commonResult);
oos.flush();
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
try {
if (ois!=null || oos!=null){
ois.close();
oos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
修改密码策略实现类
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.service.LoginLogoutService;
/**
* 策略模式修改账户密码实现类
*/
public class StrategyChangePwdImpl implements IStrategy{
LoginLogoutService loginLogoutService = new LoginLogoutService();
@Override
public CommonResult process(CommonAtmVO commonAtmVO) {
return loginLogoutService.changePwdBank(commonAtmVO.getSourceCardNumber(),
commonAtmVO.getCustomerInfo().getPassword());
}
}
存款策略实现类
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.service.ChargeService;
* 策略模式中存款实现类
public class StrategyDepositImpl implements IStrategy{
ChargeService chargeService = new ChargeService();
@Override
public CommonResult process(CommonAtmVO commonAtmVO) {
return chargeService.depositBank(commonAtmVO.getSourceCardNumber(),commonAtmVO.getOperatorMoney());
}
}
登录策略实现类
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.service.LoginLogoutService;
/**
* 策略模式中登陆实现类
*/
public class StrategyLoginImpl implements IStrategy{
LoginLogoutService loginLogoutService = new LoginLogoutService();
@Override
public CommonResult process(CommonAtmVO commonAtmVO) {
return loginLogoutService.loginBank(commonAtmVO.getSourceCardNumber(),
commonAtmVO.getCustomerInfo().getPassword());
}
}
登出策略实现类
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.service.LoginLogoutService;
/**
* 策略模式中登出实现类
*/
public class StrategyLogoutImpl implements IStrategy{
LoginLogoutService loginLogoutService = new LoginLogoutService();
@Override
public CommonResult process(CommonAtmVO commonAtmVO) {
return loginLogoutService.logoutBank(commonAtmVO.getSourceCardNumber());
}
}
行内转账策略实现类
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.service.ChargeService;
/**
* 策略模式中行内转账实现类
*/
public class StrategyTransferInnerImpl implements IStrategy{
ChargeService chargeService = new ChargeService();
@Override
public CommonResult process(CommonAtmVO commonAtmVO) {
return chargeService.transferInnerBank(commonAtmVO.getSourceCardNumber(),
commonAtmVO.getTargetCardNumber(),
commonAtmVO.getOperatorMoney(),
commonAtmVO.getCustomerInfo().getPassword());
}
}
跨行转账策略实现类
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.service.ChargeService;
/**
* 策略模式中跨行转账实现类
*/
public class StrategyTransferOuterImpl implements IStrategy{
ChargeService chargeService = new ChargeService();
@Override
public CommonResult process(CommonAtmVO commonAtmVO) {
return chargeService.transferOuterBank(commonAtmVO.getSourceCardNumber(),
commonAtmVO.getOperatorMoney(),
commonAtmVO.getCustomerInfo().getPassword());
}
}
取款策略实现类
package com.atm.server;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import com.atm.service.ChargeService;
/**
* 策略模式中取款实现类
*/
public class StrategyWithdrawImpl implements IStrategy{
ChargeService chargeService = new ChargeService();
@Override
public CommonResult process(CommonAtmVO commonAtmVO) {
return chargeService.withdrawBank(commonAtmVO.getSourceCardNumber(),
commonAtmVO.getOperatorMoney(),
commonAtmVO.getCustomerInfo().getPassword());
}
}
ATM系统服务端
package com.atm.server;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* 银行管理系统服务器端
*/
public class BankCenterServer {
public BankCenterServer(){
new LoopReceiver().start();
}
private class LoopReceiver extends Thread{
private ServerSocket serverSocket =null;
public LoopReceiver(){
try {
serverSocket = new ServerSocket(2021);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void run() {
while (this.isAlive()){ //利用while循环直到该线程死亡
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
if (clientSocket!=null){
new ServerProcessIOUtil(clientSocket);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (clientSocket!=null) {
clientSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public static void main(String[] args) {
BankCenterServer bankCenterServer = new BankCenterServer();
}
}
ATM系统客户端
package com.atm.service;
import com.atm.entity.CommonAtmVO;
import com.atm.entity.CommonResult;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
/**
* 客户端
*/
public class ClientService {
public CommonResult clientSendObject(CommonAtmVO commonAtmVO){
CommonResult commonResult = new CommonResult();
Socket clientSocket = null;
try {
clientSocket = new Socket(“localhost”,2021);
ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
ObjectOutputStream oos = new ObjectOutputStream(clientSocket.getOutputStream());
oos.writeObject(commonAtmVO);
oos.flush();
commonResult = (CommonResult) ois.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return commonResult;
}
}