-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAdminThread.java
86 lines (75 loc) · 2.52 KB
/
AdminThread.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package finalServer;
import java.io.*;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
public class AdminThread extends Thread {
Socket client;
BufferedReader br;
static public PrintWriter pw;
AdminThread(Socket s){
this.client=s;
try {
br = new BufferedReader(new InputStreamReader(client.getInputStream()));
pw = new PrintWriter(client.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sendAllInfoToAdmin(); //发送更新信息给管理员
}
public void run(){
String info;
try {
while(true){
info=br.readLine();
System.out.println("服务器从管理员收到的信息:"+info);
analysis(info); //分析数据
}
} catch (IOException e) {
//与客户端连接失败
e.printStackTrace();
//break;
}
}
//info=operate-name,newName,account,price
private void analysis(String info) {
if(info.equals("")){
return ;
}
if(info==null){
return;
}
String string[]=info.split(",");
switch(string[0]){
case "changeMedicineInfo":SQLOperate.changeMedicineInfo(string[1], string[2], string[3],string[4]);/*Server.sendMedicineInfoToDoctor();*/break;
case "addMedicineInfo":SQLOperate.addMedicineInfo(string[1], string[2], string[3]);/*Server.sendMedicineInfoToDoctor();*/break;
case "deleteMedicineInfo":SQLOperate.deleteMedicineInfo(string[1]);/*Server.sendMedicineInfoToDoctor();*/break;
case "changeDoctorInfo":SQLOperate.changeDoctorInfo(string[1], string[2], string[3], string[4], string[5], string[6]);break;
case "addDoctorInfo":SQLOperate.addDoctorInfo(string[1], string[2], string[3], string[4], string[5], string[6]);break;
case "deleteDoctorInfo":SQLOperate.deleteDoctorInfo(string[1]);break;
}
}
static void sendDoctorInfo(){
String message="account-";
message+=SQLOperate.sendDoctorInfoToAdmin();
pw.println(message);
System.out.println("发送医生信息给管理员:"+message);
pw.flush();
}
static void sendMedicneInfo(){
String message="medicine-";
message+=SQLOperate.sendMedicineInfoToAdmin();
pw.println(message);
System.out.println("发送药品信息给管理员:"+message);
pw.flush();
}
static void sendAllInfoToAdmin(){
sendMedicneInfo();//在构造函数里发药品信息给管理员客户端
sendDoctorInfo();// 医生信息
}
}