Commit dfd34c63 by 李辅翼

v13

parent e936c065
......@@ -3,6 +3,7 @@ package com.hikcreate.drv_photo_pic.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.hikcreate.drv_photo_pic.DrvPhoto;
import com.hikcreate.entity.PicResult;
import com.hikcreate.service.fdfs.service.FileService;
import com.hikcreate.utils.DateUtil;
import com.hikcreate.utils.redis.RedisClientUtil;
......@@ -216,9 +217,11 @@ public class DrvPhotoImpl implements DrvPhoto {
//判断图片是否已经存入fastdfs
colValue = new String[2];
String rowkey = sfzmhm;
boolean flag1=SqlHelp.getFlag(rowkey,driverPhototable,colValue,gxsj);
// logger.info(flag1+"================");
if (flag1) {
PicResult picResult=SqlHelp.getFlag(rowkey,driverPhototable,colValue,gxsj);
if (picResult.getI()!=0) {
if(picResult.getI()==2){
fileService.deleteFile(picResult.getUrl());
}
Put put = new Put(rowkey.getBytes());
put.addColumn("info".getBytes(), "sfzmhm".getBytes(), sfzmhm.getBytes());
byte[] bytes1=SqlHelp.blobToByteZp(zp);
......
package com.hikcreate.drv_photo_pic.impl;
import com.hikcreate.entity.PicResult;
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;
......@@ -10,13 +11,16 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.IOException;
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 {
......@@ -38,35 +42,48 @@ public class SqlHelp {
}
public static boolean getFlag(String rowkey, Table table, String[] colValue, String gxsj) {
boolean flag1 = true;
public static PicResult getFlag(String rowkey, Table table, String[] colValue, String gxsj) {
//1:写入,2:删除原有并写入,0:不写入
int flag1 = 1;
String url = "";
PicResult picResult = new PicResult();
try {
Get get = new Get(rowkey.getBytes());
get.addColumn("info".getBytes(), "picUrl".getBytes());
get.addColumn("info".getBytes(), "gxsj".getBytes());
Result result = table.get(get);
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(result.size()>0){
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(colName)) {
colValue[1] = value;
}
}
if ("gxsj".equals(colName)) {
colValue[1] =value;
if (colValue[0] == null) {
flag1 = 1;
} else if (colValue[0] != null && (gxsj.substring(0, 19).compareTo(colValue[1].substring(0, 19)) < 0)) {
flag1 = 0;
} else {
flag1 = 2;
url = colValue[0];
}
}
if(colValue[0] == null){
flag1=true;
} else if (colValue[0] != null && (gxsj.substring(0, 19).compareTo(colValue[1].substring(0, 19)) < 0 )) {
flag1 = false;
picResult.setI(flag1);
picResult.setUrl(url);
return picResult;
}else {
logger.info(gxsj+"---------------"+colValue[1]);
flag1=true;
picResult.setI(flag1);
picResult.setUrl(url);
return picResult;
}
return flag1;
} catch (IOException e) {
e.printStackTrace();
return false;
picResult.setI(0);
picResult.setUrl(url);
return picResult;
}
}
......
package com.hikcreate.drv_photo_pic.impl;
import com.hikcreate.drv_photo_pic.Vehicle;
import com.hikcreate.entity.PicResult;
import com.hikcreate.service.fdfs.service.FileService;
import com.hikcreate.utils.DateUtil;
import oracle.sql.BLOB;
......@@ -42,11 +43,6 @@ public class VehicleImpl implements Vehicle {
private static String startTime;
private static String endTime;
private static String xh;
private static String hphm;
private static String hpzl;
private static BLOB zp;
private static String gxsj;
private static TableName vehPicTableName;
private static Table vehPicTable;
private static String[] colValue;
......@@ -82,7 +78,6 @@ public class VehicleImpl implements Vehicle {
endTime = lastTime;
resultSet.close();
connection.close();
Thread.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
......@@ -180,15 +175,18 @@ public class VehicleImpl implements Vehicle {
*/
private synchronized void saveToHbase(ResultSet resultSet, FileService fileService) {
try {
xh = resultSet.getString("XH");
hphm = resultSet.getString("HPHM");
hpzl = resultSet.getString("HPZL");
zp = (BLOB) resultSet.getBlob("ZP");
gxsj = resultSet.getString("GXSJ");
String xh = resultSet.getString("XH");
String hphm = resultSet.getString("HPHM");
String hpzl = resultSet.getString("HPZL");
BLOB zp = (BLOB) resultSet.getBlob("ZP");
String gxsj = resultSet.getString("GXSJ");
String rowkey = xh;
colValue = new String[2];
boolean flag = SqlHelp.getFlag(rowkey, vehPicTable, colValue, gxsj);
if (flag) {
PicResult picResult = SqlHelp.getFlag(rowkey, vehPicTable, colValue, gxsj);
if (picResult.getI()!=0) {
if(picResult.getI()==2){
fileService.deleteFile(picResult.getUrl());
}
Put put = new Put(rowkey.getBytes());
put.addColumn("info".getBytes(), "xh".getBytes(), (xh == null ? "null" : xh).getBytes());
put.addColumn("info".getBytes(), "hphm".getBytes(), (hphm == null ? "null" : hphm).getBytes());
......@@ -199,7 +197,7 @@ public class VehicleImpl implements Vehicle {
put.addColumn("info".getBytes(), "picUrl".getBytes(), picUrl.getBytes());
vehPicTable.put(put);
}
} catch (IOException | SQLException e) {
} catch (Exception e) {
e.printStackTrace();
}
......
package com.hikcreate.entity;
import lombok.Data;
import java.io.Serializable;
@Data
public class PicResult implements Serializable {
int i;
String url;
}
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