Commit 4a56114c by 李辅翼

v14

parent 240b7ef8
...@@ -43,12 +43,8 @@ public class VehicleImpl implements Vehicle { ...@@ -43,12 +43,8 @@ public class VehicleImpl implements Vehicle {
private static String startTime; private static String startTime;
private static String endTime; private static String endTime;
private static TableName vehPicTableName;
private static Table vehPicTable;
private static String[] colValue; private static String[] colValue;
private static Configuration hbaseConf;
private static org.apache.hadoop.hbase.client.Connection hbaseConn;
/** /**
* 全量车辆图片 * 全量车辆图片
...@@ -57,8 +53,15 @@ public class VehicleImpl implements Vehicle { ...@@ -57,8 +53,15 @@ public class VehicleImpl implements Vehicle {
*/ */
@Override @Override
public void getHisVehPic(String time) { public void getHisVehPic(String time) {
getHbaseVioPicTable(); org.apache.hadoop.hbase.client.Connection hbaseConn = null;
Table vehPicTable = null;
try { try {
Configuration hbaseConf = HBaseConfiguration.create();
hbaseConf.set("hbase.zookeeper.property.clientPort", hbaseAddress);
hbaseConf.set("hbase.zookeeper.quorum", hbaseZkQuorum);
hbaseConn = ConnectionFactory.createConnection(hbaseConf);
TableName vehPicTableName = TableName.valueOf(vehPicTableStr);
vehPicTable = hbaseConn.getTable(vehPicTableName);
endTime = time; endTime = time;
startTime = SqlHelp.getStartTime("select min(GXSJ) mtime from GYJG.VEH_PICTURE", url, username, password); startTime = SqlHelp.getStartTime("select min(GXSJ) mtime from GYJG.VEH_PICTURE", url, username, password);
String lastTime; String lastTime;
...@@ -73,7 +76,7 @@ public class VehicleImpl implements Vehicle { ...@@ -73,7 +76,7 @@ public class VehicleImpl implements Vehicle {
pstm.setString(2, endTime); pstm.setString(2, endTime);
ResultSet resultSet = pstm.executeQuery(); ResultSet resultSet = pstm.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
saveToHbase(resultSet, fileService); saveToHbase(resultSet, fileService, vehPicTable);
} }
endTime = lastTime; endTime = lastTime;
resultSet.close(); resultSet.close();
...@@ -82,7 +85,20 @@ public class VehicleImpl implements Vehicle { ...@@ -82,7 +85,20 @@ public class VehicleImpl implements Vehicle {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
closeHbase(); if (hbaseConn != null) {
try {
hbaseConn.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (vehPicTable != null) {
try {
vehPicTable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
} }
...@@ -91,94 +107,98 @@ public class VehicleImpl implements Vehicle { ...@@ -91,94 +107,98 @@ public class VehicleImpl implements Vehicle {
*/ */
@Override @Override
public void getIncrementVehPic() { public void getIncrementVehPic() {
String sql="select * from GYJG.VEH_PICTURE where GXSJ between sysdate-10 and sysdate and ZP is not null and XH is not null"; String sql = "select * from GYJG.VEH_PICTURE where GXSJ between sysdate-10 and sysdate and ZP is not null and XH is not null";
getPic(sql); getPic(sql);
} }
/** /**
* 根据车牌号获取图片 * 根据车牌号获取图片
*
* @param hphm * @param hphm
* @param hpzl * @param hpzl
*/ */
@Override @Override
public void insertVehPicByCar(String hphm, String hpzl) { public void insertVehPicByCar(String hphm, String hpzl) {
String sql = "select b.XH xh,b.HPHM hphm,b.HPZL hpzl,b.ZP zp,b.GXSJ gxsj from ZCKJ.VM_VEHICLE_GY a inner join GYJG.VEH_PICTURE b " + String sql = "select b.XH xh,b.HPHM hphm,b.HPZL hpzl,b.ZP zp,b.GXSJ gxsj from ZCKJ.VM_VEHICLE_GY a inner join GYJG.VEH_PICTURE b " +
"on a.XH=b.XH where a.HPHM='"+hphm+"' and a.HPZL='"+hpzl+"'"; "on a.XH=b.XH where a.HPHM='" + hphm + "' and a.HPZL='" + hpzl + "'";
getPic(sql); getPic(sql);
} }
/** /**
* 同步指定时间段的增量图片 * 同步指定时间段的增量图片
*
* @param start * @param start
* @param end * @param end
*/ */
@Override @Override
public void getVehPicStage(String start, String end) { public void getVehPicStage(String start, String end) {
String sql="select * from GYJG.VEH_PICTURE where " + String sql = "select * from GYJG.VEH_PICTURE where " +
"to_char(GXSJ,'yyyy-mm-dd')>'"+start+"' and to_char(GXSJ,'yyyy-mm-dd')<='"+end+"' and ZP is not null and XH is not null"; "to_char(GXSJ,'yyyy-mm-dd')>'" + start + "' and to_char(GXSJ,'yyyy-mm-dd')<='" + end + "' and ZP is not null and XH is not null";
getPic(sql); getPic(sql);
} }
/** /**
* 根据序号插入图片 * 根据序号插入图片
*
* @param xh * @param xh
*/ */
@Override @Override
public void insertVehPicByXh(String xh) { public void insertVehPicByXh(String xh) {
String sql = "select * from GYJG.VEH_PICTURE where XH='"+xh+"'"; String sql = "select * from GYJG.VEH_PICTURE where XH='" + xh + "'";
getPic(sql); getPic(sql);
} }
private void getPic(String sql) { private void getPic(String sql) {
getHbaseVioPicTable(); org.apache.hadoop.hbase.client.Connection hbaseConn = null;
Table vehPicTable = null;
try { try {
Configuration hbaseConf = HBaseConfiguration.create();
hbaseConf.set("hbase.zookeeper.property.clientPort", hbaseAddress);
hbaseConf.set("hbase.zookeeper.quorum", hbaseZkQuorum);
hbaseConn = ConnectionFactory.createConnection(hbaseConf);
TableName vehPicTableName = TableName.valueOf(vehPicTableStr);
vehPicTable = hbaseConn.getTable(vehPicTableName);
Class.forName("oracle.jdbc.OracleDriver"); Class.forName("oracle.jdbc.OracleDriver");
Connection connection = DriverManager.getConnection(url, username, password); Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement pstm = connection.prepareStatement(sql); PreparedStatement pstm = connection.prepareStatement(sql);
ResultSet resultSet=pstm.executeQuery(); ResultSet resultSet = pstm.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
saveToHbase(resultSet, fileService); saveToHbase(resultSet, fileService, vehPicTable);
} }
resultSet.close(); resultSet.close();
pstm.close(); pstm.close();
connection.close(); connection.close();
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
closeHbase(); if (hbaseConn != null) {
} try {
} hbaseConn.close();
} catch (IOException e) {
e.printStackTrace();
/** }
* 关闭hbase
*/
private void closeHbase() {
if (hbaseConn != null) {
try {
hbaseConn.close();
} catch (IOException e) {
e.printStackTrace();
} }
} if (vehPicTable != null) {
if (vehPicTable != null) { try {
try { vehPicTable.close();
vehPicTable.close(); } catch (IOException e) {
} catch (IOException e) { e.printStackTrace();
e.printStackTrace(); }
} }
} }
} }
/** /**
* 存储图片 * 存储图片
* *
* @param resultSet * @param resultSet
* @param fileService * @param fileService
* @param vehPicTable
*/ */
private synchronized void saveToHbase(ResultSet resultSet, FileService fileService) { private synchronized void saveToHbase(ResultSet resultSet, FileService fileService, Table vehPicTable) {
try { try {
String xh = resultSet.getString("XH"); String xh = resultSet.getString("XH");
String hphm = resultSet.getString("HPHM"); String hphm = resultSet.getString("HPHM");
...@@ -188,8 +208,8 @@ public class VehicleImpl implements Vehicle { ...@@ -188,8 +208,8 @@ public class VehicleImpl implements Vehicle {
String rowkey = xh; String rowkey = xh;
colValue = new String[2]; colValue = new String[2];
PicResult picResult = SqlHelp.getFlag(rowkey, vehPicTable, colValue, gxsj); PicResult picResult = SqlHelp.getFlag(rowkey, vehPicTable, colValue, gxsj);
if (picResult.getI()!=0) { if (picResult.getI() != 0) {
if(picResult.getI()==2){ if (picResult.getI() == 2) {
fileService.deleteFile(picResult.getUrl()); fileService.deleteFile(picResult.getUrl());
} }
Put put = new Put(rowkey.getBytes()); Put put = new Put(rowkey.getBytes());
...@@ -208,30 +228,18 @@ public class VehicleImpl implements Vehicle { ...@@ -208,30 +228,18 @@ public class VehicleImpl implements Vehicle {
} }
private String uploadFile(byte[] file, String fileName){
private String uploadFile(byte[] file, String fileName) {
String url; String url;
try { try {
url=fileService.uploadFile(file, fileName); url = fileService.uploadFile(file, fileName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
url=uploadFile(file,fileName); url = uploadFile(file, fileName);
} }
return url; return url;
} }
private void getHbaseVioPicTable() {
hbaseConf = HBaseConfiguration.create();
hbaseConf.set("hbase.zookeeper.property.clientPort", hbaseAddress);
hbaseConf.set("hbase.zookeeper.quorum", hbaseZkQuorum);
try {
hbaseConn = ConnectionFactory.createConnection(hbaseConf);
vehPicTableName = TableName.valueOf(vehPicTableStr);
vehPicTable = hbaseConn.getTable(vehPicTableName);
} catch (IOException e) {
e.printStackTrace();
}
}
} }
...@@ -6,6 +6,6 @@ import java.io.Serializable; ...@@ -6,6 +6,6 @@ import java.io.Serializable;
@Data @Data
public class PicResult implements Serializable { public class PicResult implements Serializable {
int i; public int i;
String url; public String url;
} }
...@@ -29,7 +29,7 @@ public class PicSchedule { ...@@ -29,7 +29,7 @@ public class PicSchedule {
/** /**
* 每天早上10点同步驾驶人头像增量数据 * 每天早上10点同步驾驶人头像增量数据
*/ */
// @Scheduled(cron = "0 0 10 * * *") @Scheduled(cron = "0 0 10 * * *")
public void getIncrementDrvPhoto(){ public void getIncrementDrvPhoto(){
drvPhoto.getIncrementDrvPhoto(); drvPhoto.getIncrementDrvPhoto();
} }
......
...@@ -46,7 +46,7 @@ public class FileServiceImpl implements FileService { ...@@ -46,7 +46,7 @@ public class FileServiceImpl implements FileService {
logger.info("删除图片:" + path); logger.info("删除图片:" + path);
fastDFSClient.deleteFile(path); fastDFSClient.deleteFile(path);
} catch (Exception e) { } catch (Exception e) {
logger.info(e.toString()); deleteFile(path);
} }
} }
......
...@@ -20,7 +20,7 @@ fdfs.tracker-list[1] = 172.16.25.26:22122 ...@@ -20,7 +20,7 @@ fdfs.tracker-list[1] = 172.16.25.26:22122
fdfs.pool.max-total = 153 fdfs.pool.max-total = 153
fdfs.pool.max-wait-millis = 102 fdfs.pool.max-wait-millis = 102
#˿ #˿
server.port=8092 server.port=8084
hbase.zookeeper.property.clientPort=2181 hbase.zookeeper.property.clientPort=2181
hbase.zookeeper.quorum=172.16.25.25,172.16.25.28,172.16.25.24,172.16.25.26,172.16.25.27 hbase.zookeeper.quorum=172.16.25.25,172.16.25.28,172.16.25.24,172.16.25.26,172.16.25.27
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment