Commit bc49983b by 李辅翼

v9

parent 75807a9b
......@@ -82,6 +82,16 @@ public class PicController {
vehicle.insertVehPicByCar(hphm,hpzl);
}
/**
* 指定时间段驾驶人头像同步
* @param start
* @param end
*/
@GetMapping("/increDrvPic")
public void increDrvPic(@RequestParam("start") String start,@RequestParam("end") String end){
drvPhoto.increDrvPic(start,end);
}
@GetMapping("/testIncVioPic")
public void testIncVioPic(@RequestParam("start") String start,@RequestParam("end") String end) {
......
......@@ -18,4 +18,5 @@ public interface DrvPhoto {
void insertDrvPhotoById(String sfzmhm);
void increDrvPic(String start, String end);
}
......@@ -184,13 +184,40 @@ public class DrvPhotoImpl implements DrvPhoto {
}
}
@Override
public void increDrvPic(String start, String end) {
hbaseConf = HBaseConfiguration.create();
hbaseConf.set("hbase.zookeeper.property.clientPort", hbaseAddress);
hbaseConf.set("hbase.zookeeper.quorum", hbaseZkQuorum);
try {
hbaseConn = ConnectionFactory.createConnection(hbaseConf);
driverPhotoTablename = TableName.valueOf(driverPhotoTableStr);
driverPhototable = hbaseConn.getTable(driverPhotoTablename);
String sql = "select * from GYJG.DRV_PHOTO where ZP is not null and fzjg is not null and sfzmhm is not null " +
"and to_char(GXSJ,'yyyy-mm-dd')>='" + start + "' and to_char(GXSJ,'yyyy-mm-dd')<'" + end + "'";
Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement pstm = connection.prepareStatement(sql);
ResultSet resultSet = pstm.executeQuery();
while (resultSet.next()) {
saveToHbase(resultSet, fileService);
}
resultSet.close();
pstm.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
closeTable();
}
}
private static void saveToHbase(ResultSet resultSet, FileService fileService) throws Exception {
paramResultSet(resultSet);
//判断图片是否已经存入fastdfs
colValue = new String[2];
String rowkey = sfzmhm;
boolean flag1=SqlHelp.getFlag(rowkey,driverPhototable,colValue,gxsj);
logger.info(flag1+"================");
if (flag1) {
Put put = new Put(rowkey.getBytes());
put.addColumn("info".getBytes(), "sfzmhm".getBytes(), sfzmhm.getBytes());
......
package com.hikcreate.drv_photo_pic.impl;
import oracle.sql.BLOB;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.IOException;
......@@ -12,7 +16,7 @@ import java.io.InputStream;
import java.sql.*;
public class SqlHelp {
private static Logger logger = LoggerFactory.getLogger(SqlHelp.class);
public static String getStartTime(String sql, String url, String username, String password) {
String startTime = null;
try {
......@@ -41,16 +45,24 @@ public class SqlHelp {
get.addColumn("info".getBytes(), "picUrl".getBytes());
get.addColumn("info".getBytes(), "gxsj".getBytes());
Result result = table.get(get);
for (KeyValue value : result.raw()) {
if ("picUrl".equals(new String(value.getQualifierArray()))) {
colValue[0] = new String(value.getValue());
for (Cell cell : result.rawCells()) {
String colName = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
String value = Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
if ("picUrl".equals(colName)) {
colValue[0] = value;
}
if ("gxsj".equals(value.getQualifierArray())) {
colValue[1] = new String(value.getValue());
if ("gxsj".equals(colName)) {
colValue[1] =value;
}
}
if (colValue[0] != null && !(gxsj.substring(0, 19).compareTo(colValue[1].substring(0, 19)) > 0)) {
if(colValue[0] == null){
flag1=true;
} else if (colValue[0] != null && (gxsj.substring(0, 19).compareTo(colValue[1].substring(0, 19)) < 0 ||
gxsj.substring(0, 19).compareTo(colValue[1].substring(0, 19)) == 0)) {
flag1 = false;
}else {
logger.info(gxsj+"---------------"+colValue[1]);
flag1=true;
}
return flag1;
} catch (IOException e) {
......
......@@ -7,11 +7,9 @@ import javafx.scene.control.Tab;
import oracle.sql.BLOB;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,6 +19,7 @@ import redis.clients.jedis.ZParams;
import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
@Service("vehicleImpl")
public class VehicleImpl implements Vehicle {
......@@ -171,6 +170,22 @@ public class VehicleImpl implements Vehicle {
String rowkey = hphm + "#" + hpzl;
colValue = new String[2];
boolean flag = SqlHelp.getFlag(rowkey, vehPicTable, colValue, gxsj);
// boolean flag1 = true;
// Get get = new Get(rowkey.getBytes());
// get.addColumn("info".getBytes(), "picUrl".getBytes());
// get.addColumn("info".getBytes(), "gxsj".getBytes());
// Result result = vehPicTable.get(get);
// for (KeyValue value : result.raw()) {
// if ("picUrl".equals(new String(value.getQualifierArray()))) {
// colValue[0] = new String(value.getValue());
// }
// if ("gxsj".equals(value.getQualifierArray())) {
// colValue[1] = new String(value.getValue());
// }
// }
// if (colValue[0] != null && gxsj.substring(0, 19).compareTo(colValue[1].substring(0, 19)) < 0) {
// flag1 = false;
// }
if (flag) {
Put put = new Put(rowkey.getBytes());
put.addColumn("info".getBytes(), "xh".getBytes(), (xh == null ? "null" : xh).getBytes());
......
......@@ -25,8 +25,9 @@ public class FileServiceImpl implements FileService {
private FastFileStorageClient storageClient;
@Override
public String uploadFile(byte[] file, String fileName) {
public synchronized String uploadFile(byte[] file, String fileName) {
try {
Thread.sleep(200);
//将文件上装到fast文件服务器上,成功则返回文件保存的路径
String path = fastDFSClient.uploadFile(file, fileName);
if (!StringUtils.hasText(path)) {
......
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