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

📄 serverthread.java

📁 银行账户管理系统 简称BAM(项目介绍及源码)
💻 JAVA
字号:
package service;

import java.net.*;
import java.util.*;
import java.io.*;

import service.Bank;
import model.*;
import exception.*;

public class ServerThread extends Thread {
	Socket s;
	ObjectOutputStream out;
	ObjectInputStream in;
	Bank bank=Bank.getInstance();
	public ServerThread(Socket s) {
		this.s = s;
	}
	public void run(){
		try {
			out=new ObjectOutputStream(s.getOutputStream());
			in=new ObjectInputStream(s.getInputStream());
			while(true){
				Message m=(Message)in.readObject();
				if (m==null) break;
				int type=m.getType();
				Map<String,String> data=m.getData();
				//开户
				try {
					if (type==0){
						String accountType=data.get("AccountType");
						int at=Integer.parseInt(accountType);//账户类型
						int balance=0;//开户余额
						String password1=data.get("Password1");//密码
						String password2=data.get("Password2");//2次密码
						String name=data.get("Name");//帐户名
						String personId=data.get("PersonId");//身份证号码
						String email=data.get("Email");//电子邮件地址
											
						Account c=bank.registerAccount(password1,password2,name,personId,email,balance,at);
						out.writeObject(c);
						out.flush();
					}
					//登录
					else if (type==1){
						String accountId=data.get("Id");
						long id=Long.parseLong(accountId);
						String password=data.get("Password");
						Account c=bank.loginAccount(id,password);
						out.writeObject(c.clone());
						out.flush();
					}
//					else if(type==2){
//						String accountId=data.get("Id");
//						long id=Long.parseLong(accountId);
//						String password=data.get("Password");
//						Account c=bank.loginAccount(id,password);
//						out.writeObject(c.clone());
//						out.flush();
//					}
					//交易
					else{
						int btype=Integer.parseInt(data.get("BusinessType"));
						long id=Long.parseLong(data.get("Id"));
						double money=Double.parseDouble(data.get("Money"));
						Account c=null;
						if (btype==0){
							c=bank.depositAccount(id,money);
						}
						else if (btype==1){
							c=bank.withdrawAccount(id,money);
						}
						else if (btype==2){
							c=bank.setCeilingAccount(id,money);
						}
						else if (btype==3){
							c=bank.requetLoan(id, money);
						}
						else {
							c=bank.payLoan(id, money);
						}
						out.writeObject(c.clone());
						out.flush();
					}
				} catch (NumberFormatException e) {
					out.writeObject("数据格式不正确");
					out.flush();
				}  catch (BussinessException e) {
					out.writeObject(e.getMessage());
					out.flush();
				}
			}
		} catch (IOException e) {
		} catch (ClassNotFoundException e) {
		}
	}
}

⌨️ 快捷键说明

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