Commit 4a56114c by 李辅翼

v14

parent 240b7ef8
......@@ -43,12 +43,8 @@ public class VehicleImpl implements Vehicle {
private static String startTime;
private static String endTime;
private static TableName vehPicTableName;
private static Table vehPicTable;
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 {
*/
@Override
public void getHisVehPic(String time) {
getHbaseVioPicTable();
org.apache.hadoop.hbase.client.Connection hbaseConn = null;
Table vehPicTable = null;
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;
startTime = SqlHelp.getStartTime("select min(GXSJ) mtime from GYJG.VEH_PICTURE", url, username, password);
String lastTime;
......@@ -73,7 +76,7 @@ public class VehicleImpl implements Vehicle {
pstm.setString(2, endTime);
ResultSet resultSet = pstm.executeQuery();
while (resultSet.next()) {
saveToHbase(resultSet, fileService);
saveToHbase(resultSet, fileService, vehPicTable);
}
endTime = lastTime;
resultSet.close();
......@@ -82,7 +85,20 @@ public class VehicleImpl implements Vehicle {
} catch (Exception e) {
e.printStackTrace();
} 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,71 +107,72 @@ public class VehicleImpl implements Vehicle {
*/
@Override
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);
}
/**
* 根据车牌号获取图片
*
* @param hphm
* @param hpzl
*/
@Override
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 " +
"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);
}
/**
* 同步指定时间段的增量图片
*
* @param start
* @param end
*/
@Override
public void getVehPicStage(String start, String end) {
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";
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";
getPic(sql);
}
/**
* 根据序号插入图片
*
* @param xh
*/
@Override
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);
}
private void getPic(String sql) {
getHbaseVioPicTable();
org.apache.hadoop.hbase.client.Connection hbaseConn = null;
Table vehPicTable = null;
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");
Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement pstm = connection.prepareStatement(sql);
ResultSet resultSet=pstm.executeQuery();
ResultSet resultSet = pstm.executeQuery();
while (resultSet.next()) {
saveToHbase(resultSet, fileService);
saveToHbase(resultSet, fileService, vehPicTable);
}
resultSet.close();
pstm.close();
connection.close();
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
} finally {
closeHbase();
}
}
/**
* 关闭hbase
*/
private void closeHbase() {
if (hbaseConn != null) {
try {
hbaseConn.close();
......@@ -171,14 +188,17 @@ public class VehicleImpl implements Vehicle {
}
}
}
}
/**
* 存储图片
*
* @param resultSet
* @param fileService
* @param vehPicTable
*/
private synchronized void saveToHbase(ResultSet resultSet, FileService fileService) {
private synchronized void saveToHbase(ResultSet resultSet, FileService fileService, Table vehPicTable) {
try {
String xh = resultSet.getString("XH");
String hphm = resultSet.getString("HPHM");
......@@ -188,8 +208,8 @@ public class VehicleImpl implements Vehicle {
String rowkey = xh;
colValue = new String[2];
PicResult picResult = SqlHelp.getFlag(rowkey, vehPicTable, colValue, gxsj);
if (picResult.getI()!=0) {
if(picResult.getI()==2){
if (picResult.getI() != 0) {
if (picResult.getI() == 2) {
fileService.deleteFile(picResult.getUrl());
}
Put put = new Put(rowkey.getBytes());
......@@ -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;
try {
url=fileService.uploadFile(file, fileName);
url = fileService.uploadFile(file, fileName);
} catch (Exception e) {
e.printStackTrace();
url=uploadFile(file,fileName);
url = uploadFile(file, fileName);
}
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;
@Data
public class PicResult implements Serializable {
int i;
String url;
public int i;
public String url;
}
......@@ -29,7 +29,7 @@ public class PicSchedule {
/**
* 每天早上10点同步驾驶人头像增量数据
*/
// @Scheduled(cron = "0 0 10 * * *")
@Scheduled(cron = "0 0 10 * * *")
public void getIncrementDrvPhoto(){
drvPhoto.getIncrementDrvPhoto();
}
......
......@@ -46,7 +46,7 @@ public class FileServiceImpl implements FileService {
logger.info("删除图片:" + path);
fastDFSClient.deleteFile(path);
} catch (Exception e) {
logger.info(e.toString());
deleteFile(path);
}
}
......
......@@ -20,7 +20,7 @@ fdfs.tracker-list[1] = 172.16.25.26:22122
fdfs.pool.max-total = 153
fdfs.pool.max-wait-millis = 102
#˿
server.port=8092
server.port=8084
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
......
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