GpsBgnEnd.java
2.77 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
package com.glsx.bzi.logistmap;
import com.glsx.conf.ConfigurationManager;
import com.glsx.connection.MysqlMutiConn;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
/**
* 设备GPS上点的对应的起止时间,本程序定期调度一次
*/
public class GpsBgnEnd {
public static void main(String[] args) {
MysqlMutiConn.addConnection("pap_dev", ConfigurationManager.getProperty("mysql_pap"));
MysqlMutiConn.addConnection("device_mapping", ConfigurationManager.getProperty("mysql_prd_login"));
Connection pap_dev = MysqlMutiConn.getConnection("pap_dev");
Connection device_mapping = MysqlMutiConn.getConnection("device_mapping");
Map<String, String> papMap = getPap(pap_dev);
Map<String, String> deviceMap = getDevice(device_mapping);
String tmpSql = "replace into t_pap_end_info(sn,bgnTime,endTime) values";
String values = "";
int index = 0;
int sumNotFit = 0;
for(Map.Entry<String, String> entry : deviceMap.entrySet()) {
String fakeSn = papMap.get(entry.getKey());
if (fakeSn == null) {
sumNotFit++;
continue;
}
String value = entry.getValue();
values += "('" + fakeSn + ",'" + value + "'),";
if (++index %1000 == 0) {
tmpSql += values.substring(0, values.length()-1);
// MysqlMutiConn.executeUpdate(pap_dev, tmpSql);
tmpSql = "replace into t_pap_end_info(sn,bgnTime,endTime) values";
values = "";
}
}
System.out.println("total=" + index + ",sumNotFit=" + sumNotFit);
}
private static Map<String, String> getDevice(Connection device_mapping) {
Map<String, String> deviceMap = new HashMap<String, String>();
MysqlMutiConn.executeQuery(device_mapping, "select realSn,fakeSn from device_mapping", new MysqlMutiConn.QueryCallback() {
@Override
public void process(ResultSet rs) throws Exception {
while (rs.next()) {
deviceMap.put(rs.getString(1), rs.getString(2));
}
}
});
return deviceMap;
}
private static Map<String, String> getPap(Connection pap_dev) {
Map<String, String> papMap = new HashMap<String, String>();
MysqlMutiConn.executeQuery(pap_dev, "select sn,firstGpsTime,todayGpsTime from t_pap_dev", new MysqlMutiConn.QueryCallback() {
@Override
public void process(ResultSet rs) throws Exception {
while (rs.next()) {
papMap.put(rs.getString(1), rs.getString(2) + "," + rs.getString(3));
}
}
});
return papMap;
}
}