Commit dfd34c63 by 李辅翼

v13

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