-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdatePackage.java
More file actions
180 lines (164 loc) · 4.58 KB
/
UpdatePackage.java
File metadata and controls
180 lines (164 loc) · 4.58 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package NewDB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class UpdatePackage {
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://140.127.74.186/410977033";
static final String USER = "410977033";
static final String PASS = "410977033";
public void updatePackageDetails() {
int counta = 0;
ArrayList alist = new ArrayList();
alist.clear();
Connection conn = null;
Statement stmt = null;
try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
String sql = "";
sql = "SELECT info_id,nation,timeliness,size\r\n"
+ "FROM package_info\r\n"
+ "where info_id>10000"
+ " order by info_id";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
alist.add(rs.getInt("info_id"));
alist.add(rs.getString("nation"));
alist.add(rs.getString("timeliness"));
alist.add(rs.getString("size"));
counta += 1;
}
rs.close();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null)
conn.close();
} catch (SQLException se) {
}
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
} // end try
System.out.println("Goodbye!");
for (int i = 0; i < counta; i++) {
ArrayList blist = new ArrayList();
blist.clear();
int price = 0;
if(alist.get(i*4+1).equals("國內"))
price += 30;
else if(alist.get(i*4+1).equals("國外"))
price += 100;
if(alist.get(i*4+2).equals("一般"))
price += 20;
else if(alist.get(i*4+2).equals("快件"))
price += 70;
if(alist.get(i*4+3).equals("平信"))
price += 5;
else if(alist.get(i*4+3).equals("小包"))
price += 20;
else if(alist.get(i*4+3).equals("大盒"))
price += 40;
conn = null;
stmt = null;
try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
String sql = "";
sql = "SELECT update_time\r\n"
+ "FROM delivery_log\r\n"
+ "where package_id="+alist.get(i*4)+" and update_s_id='System';";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
blist.add(rs.getString("update_time"));
}
rs.close();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null)
conn.close();
} catch (SQLException se) {
}
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
} // end try
System.out.println("Goodbye!");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d1 = new Date();
Date d2 = new Date();
try {
d1 = sdf.parse(blist.get(0).toString());
d2 = sdf.parse(blist.get(1).toString());
} catch (Exception e) {
e.printStackTrace();
}
long ontime_time=0;
if (alist.get(i*4+1).equals("國內")) {
if(alist.get(i*4+2).equals("快件"))
ontime_time=42* 60 * 60 * 1000;
else
ontime_time=82* 60 * 60 * 1000;
} else {
if(alist.get(i*4+2).equals("快件"))
ontime_time=68* 60 * 60 * 1000;
else
ontime_time=133* 60 * 60 * 1000;
}
boolean ontime=true;
if((d2.getTime()-d1.getTime())>ontime_time) {
ontime=false;
}
conn = null;
stmt = null;
try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
String sql = "";
sql = "UPDATE package_overall\r\n"
+ "SET price = '"+price+"', arrival_time = '"+blist.get(1)+"',ontime_ornot = '"+ontime+"'\r\n"
+ "WHERE package_id="+alist.get(i*4)+";";
stmt.executeUpdate(sql);
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null)
conn.close();
} catch (SQLException se) {
}
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
} // end try
System.out.println("------------------------------");
}
}
}