Commit 75807a9b by 李辅翼

v8

parent 7d00db21
......@@ -2,6 +2,7 @@ package com.hikcreate.controller;
import com.alibaba.fastjson.JSONObject;
import com.hikcreate.drv_photo_pic.DrvPhoto;
import com.hikcreate.drv_photo_pic.Vehicle;
import com.hikcreate.drv_photo_pic.VioPic;
import com.hikcreate.entity.PicByte;
import com.hikcreate.service.fdfs.service.FileService;
......@@ -42,6 +43,52 @@ public class PicController {
@Value("${ftpUrl}")
private String ftpUrl;
@Value("${httpUrl}")
private String httpUrl;
@Autowired
private Vehicle vehicle;
/**
* 插入指定贵阳驾驶人头像
*/
@GetMapping("/insertDrvPhotoById")
public void insertDrvPhotoById(@RequestParam("sfzmhm") String sfzmhm){
drvPhoto.insertDrvPhotoById(sfzmhm);
}
/**
* 车辆历史图片
* @param time
*/
@GetMapping("/getHisVehPic")
public void getHisVehPic(@RequestParam("time") String time){
vehicle.getHisVehPic(time);
}
/**
* 车辆增量图片
*/
@GetMapping("/getIncrementVehPic")
public void getIncrementVehPic(){
vehicle.getIncrementVehPic();
}
/**
* 根据车牌号和车牌类型插入图片
*/
@GetMapping("/insertVehPicByCar")
public void insertVehPicByCar(@RequestParam("hphm") String hphm,@RequestParam("hpzl") String hpzl){
vehicle.insertVehPicByCar(hphm,hpzl);
}
@GetMapping("/testIncVioPic")
public void testIncVioPic(@RequestParam("start") String start,@RequestParam("end") String end) {
vioPic.getIncrementVioPic(start,end);
}
@GetMapping("/drvPhotoHis")
public void getHisDrvPhoto(@RequestParam("time") String time, HttpServletResponse response) {
......@@ -56,6 +103,37 @@ public class PicController {
}
}
/**
* app端通过此接口获取违法图片
* @param url
* @return
*/
@GetMapping("/getVioPic")
public synchronized PicByte getVioPicByUrl(@RequestParam("url") String url){
PicByte picByte = new PicByte();
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("urls", url);
HttpHeaders headers = new HttpHeaders();
HttpMethod method = HttpMethod.POST;
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
Map<String, byte[]> map;
if(url.startsWith("ftp")){
ResponseEntity<PicByte> resp = restTemplate.exchange(ftpUrl, method, requestEntity, PicByte.class);
map =resp.getBody().getMap();
}else if(url.startsWith("http")){
ResponseEntity<PicByte> resp = restTemplate.exchange(httpUrl, method, requestEntity, PicByte.class);
map =resp.getBody().getMap();
}else {
return null;
}
picByte.setMap(map);
return picByte;
}
@GetMapping("/testHttp")
public void testHttp(@RequestParam("param") String param, HttpServletResponse response) {
try {
......@@ -94,11 +172,7 @@ public class PicController {
vioPic.getIncrementVioPic(DateUtil.formatDate(DateUtil.getPastDate(new Date(),-past)),date);
}
@GetMapping("/testIncVioPic")
public void testIncVioPic(@RequestParam("start") String start,@RequestParam("end") String end) {
String date = DateUtil.getDate();
vioPic.getIncrementVioPic(start,end);
}
@GetMapping("/delAllVioPic")
......
......@@ -14,4 +14,8 @@ public interface DrvPhoto {
boolean getHisDrvPhoto(String time);
void getIncrementDrvPhoto();
void insertDrvPhotoById(String sfzmhm);
}
package com.hikcreate.drv_photo_pic;
public interface Vehicle {
void getHisVehPic(String time);
void getIncrementVehPic();
void insertVehPicByCar(String hphm, String hpzl);
}
......@@ -4,4 +4,6 @@ public interface VioPic {
void getIncrementVioPic(String startDay,String endDay);
void delAllVioPic();
}
package com.hikcreate.drv_photo_pic.impl;
import oracle.sql.BLOB;
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 java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
public class SqlHelp {
public static String getStartTime(String sql, String url, String username, String password) {
String startTime = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
Connection connection1 = DriverManager.getConnection(url, username, password);
PreparedStatement pstm1 = connection1.prepareStatement(sql);
ResultSet resultSet1 = pstm1.executeQuery();
while (resultSet1.next()) {
startTime = resultSet1.getString("MTIME").substring(0, 10);
}
resultSet1.close();
pstm1.close();
connection1.close();
return startTime;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static boolean getFlag(String rowkey, Table table, String[] colValue, String gxsj) {
boolean flag1 = true;
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 (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;
}
return flag1;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static byte[] blobToByteZp(BLOB zp) {
try {
long length = zp.length();
byte[] bytes = new byte[(int) length];
InputStream input = zp.getBinaryStream();
input.read(bytes, 0, (int) length);
byte[] bytes1 = blobToBytes(zp);
return bytes1;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static byte[] blobToBytes(Blob blob) {
BufferedInputStream is = null;
try {
is = new BufferedInputStream(blob.getBinaryStream());
byte[] bytes = new byte[(int) blob.length()];
int len = bytes.length;
int offset = 0;
int read = 0;
while (offset < len
&& (read = is.read(bytes, offset, len - offset)) >= 0) {
offset += read;
}
return bytes;
} catch (Exception e) {
return null;
} finally {
try {
is.close();
is = null;
} catch (IOException e) {
return null;
}
}
}
}
package com.hikcreate.drv_photo_pic.impl;
import com.hikcreate.drv_photo_pic.Vehicle;
import com.hikcreate.service.fdfs.service.FileService;
import com.hikcreate.utils.DateUtil;
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.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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import redis.clients.jedis.ZParams;
import java.io.IOException;
import java.sql.*;
@Service("vehicleImpl")
public class VehicleImpl implements Vehicle {
private static Logger logger = LoggerFactory.getLogger(VehicleImpl.class);
@Autowired
private FileService fileService;
@Value("${hbase.veh_pic.table}")
private String vehPicTableStr;
@Value("${hbase.zookeeper.property.clientPort}")
private String hbaseAddress;
@Value("${hbase.zookeeper.quorum}")
private String hbaseZkQuorum;
@Value("${url}")
private String url;
@Value("${username}")
private String username;
@Value("${password}")
private String password;
@Value("${roundDay}")
private int roundDay;
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;
private static Configuration hbaseConf;
private static org.apache.hadoop.hbase.client.Connection hbaseConn;
/**
* 全量车辆图片
*
* @param time
*/
@Override
public void getHisVehPic(String time) {
getHbaseVioPicTable();
try {
endTime = time;
startTime = SqlHelp.getStartTime("select min(GXSJ) mtime from GYJG.VEH_PICTURE", url, username, password);
String lastTime;
String sql;
while (endTime.compareTo(startTime) > 0 || endTime.compareTo(startTime) == 0) {
Connection connection = DriverManager.getConnection(url, username, password);
lastTime = DateUtil.formatDate(DateUtil.getPastDate(DateUtil.parseDate(endTime), roundDay));
sql = "select * from GYJG.VEH_PICTURE where to_char(GXSJ,'yyyy-mm-dd')>=? and to_char(GXSJ,'yyyy-mm-dd')<? " +
" and ZP is not null and HPHM is not null and HPZL is not null";
PreparedStatement pstm = connection.prepareStatement(sql);
pstm.setString(1, lastTime);
pstm.setString(2, endTime);
ResultSet resultSet = pstm.executeQuery();
while (resultSet.next()) {
saveToHbase(resultSet, fileService);
}
endTime = lastTime;
resultSet.close();
connection.close();
Thread.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
closeHbase();
}
}
/**
* 增量车辆图片
*/
@Override
public void getIncrementVehPic() {
String sql="select * from GYJG.VEH_PICTURE where GXSJ between sysdate-3 and sysdate and ZP is not null and fzjg is not null and sfzmhm is not null";
getPic(sql);
}
/**
* 根据车牌号获取图片
* @param hphm
* @param hpzl
*/
@Override
public void insertVehPicByCar(String hphm, String hpzl) {
String sql = "select * from GYJG.VEH_PICTURE where HPHM='"+hphm+"' and HPZL='"+hpzl+"'";
getPic(sql);
}
private void getPic(String sql) {
getHbaseVioPicTable();
try {
Class.forName("oracle.jdbc.OracleDriver");
Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement pstm = connection.prepareStatement(sql);
ResultSet resultSet=pstm.executeQuery();
while (resultSet.next()) {
saveToHbase(resultSet, fileService);
}
}catch (Exception e) {
e.printStackTrace();
} finally {
closeHbase();
}
}
/**
* 关闭hbase
*/
private void closeHbase() {
if (hbaseConn != null) {
try {
hbaseConn.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (vehPicTable != null) {
try {
vehPicTable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 存储图片
*
* @param resultSet
* @param fileService
*/
private 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 rowkey = hphm + "#" + hpzl;
colValue = new String[2];
boolean flag = SqlHelp.getFlag(rowkey, vehPicTable, colValue, gxsj);
if (flag) {
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());
put.addColumn("info".getBytes(), "hpzl".getBytes(), (hpzl == null ? "null" : hpzl).getBytes());
put.addColumn("info".getBytes(), "gxsj".getBytes(), (gxsj == null ? "null" : gxsj).getBytes());
byte[] bytes = SqlHelp.blobToByteZp(zp);
String picUrl = fileService.uploadFile(bytes, xh + ".jpeg");
put.addColumn("info".getBytes(), "picUrl".getBytes(), picUrl.getBytes());
vehPicTable.put(put);
}
} catch (Exception e) {
e.printStackTrace();
}
}
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();
}
}
}
......@@ -54,7 +54,8 @@ public class VioPicImpl implements VioPic {
private String ftpUrl;
@Value("${httpUrl}")
private String httpUrl;
@Value("${vio.pic.sql.byrow}")
private String sqlByRow;
@Autowired
private FileService fileService;
......@@ -97,7 +98,6 @@ public class VioPicImpl implements VioPic {
hbaseConf = HBaseConfiguration.create();
hbaseConf.set("hbase.zookeeper.property.clientPort", hbaseAddress);
hbaseConf.set("hbase.zookeeper.quorum", hbaseZkQuorum);
// hbaseConf.set("hbase.master", hbaseMaster);
hbaseConn = ConnectionFactory.createConnection(hbaseConf);
vioTableName = TableName.valueOf(vioTableStr);
vioTable = hbaseConn.getTable(vioTableName);
......@@ -117,15 +117,18 @@ public class VioPicImpl implements VioPic {
url1 = resultSet.getString("url1");
url2 = resultSet.getString("url2");
url3 = resultSet.getString("url3");
rowkey = hphm + "#" + hpzl + "#" + wfsj+"#"+wfxw;
rowkey = hphm == null ? "null" : hphm + "#" +
hpzl == null ? "null" : hpzl + "#" +
wfsj == null ? "null" : wfsj.substring(0, 19) + "#" +
wfxw == null ? "wfxw" : wfxw;
Get get = new Get(rowkey.getBytes());
put = new Put(rowkey.getBytes());
get.addColumn(Bytes.toBytes("useful"), Bytes.toBytes("ftpUrl1"));
get.addColumn(Bytes.toBytes("useful"), Bytes.toBytes("ftpUrl2"));
get.addColumn(Bytes.toBytes("useful"), Bytes.toBytes("ftpUrl3"));
get.addColumn(Bytes.toBytes("useful"), Bytes.toBytes("ftpUrl4"));
get.addColumn(Bytes.toBytes("useful"), Bytes.toBytes("ftpUrl5"));
get.addColumn(Bytes.toBytes("useful"), Bytes.toBytes("ftpUrl6"));
get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("ftpUrl1"));
get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("ftpUrl2"));
get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("ftpUrl3"));
get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("ftpUrl4"));
get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("ftpUrl5"));
get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("ftpUrl6"));
Result result = vioTable.get(get);
colValue = new String[6];
for (Cell cell : result.rawCells()) {
......@@ -233,9 +236,6 @@ public class VioPicImpl implements VioPic {
logger.info("执行完毕:---------------------");
} catch (Exception e) {
e.printStackTrace();
Writer writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
logger.error("打印错误:" + writer.toString());
} finally {
if (vioTable != null) {
try {
......@@ -267,21 +267,19 @@ public class VioPicImpl implements VioPic {
vioTableName = TableName.valueOf(vioTableStr);
vioTable = hbaseConn.getTable(vioTableName);
Scan scan = new Scan();
scan.addColumn("useful".getBytes(),"fastDfsUrl1".getBytes());
scan.addColumn("useful".getBytes(),"fastDfsUrl2".getBytes());
scan.addColumn("useful".getBytes(),"fastDfsUrl3".getBytes());
scan.addColumn("useful".getBytes(),"fastDfsUrl4".getBytes());
scan.addColumn("useful".getBytes(),"fastDfsUrl5".getBytes());
scan.addColumn("useful".getBytes(),"fastDfsUrl6".getBytes());
scan.addColumn("info".getBytes(), "fastDfsUrl1".getBytes());
scan.addColumn("info".getBytes(), "fastDfsUrl2".getBytes());
scan.addColumn("info".getBytes(), "fastDfsUrl3".getBytes());
scan.addColumn("info".getBytes(), "fastDfsUrl4".getBytes());
scan.addColumn("info".getBytes(), "fastDfsUrl5".getBytes());
scan.addColumn("info".getBytes(), "fastDfsUrl6".getBytes());
ResultScanner scanner = vioTable.getScanner(scan);
for(Result result:scanner){
for(KeyValue value:result.raw()){
try {
fileService.deleteFile(new String(value.getValue()));
}catch (Exception e){
logger.info(e.toString());
}
logger.info("删除图片+++++++"+new String(value.getValue())+"----------"+new String(value.getQualifier()));
for (Result result : scanner) {
for (KeyValue value : result.raw()) {
fileService.deleteFile(new String(value.getValue()));
logger.info("删除图片+++++++" + new String(value.getValue()) + "----------" + new String(value.getQualifier()));
}
}
} catch (IOException e) {
......@@ -291,6 +289,8 @@ public class VioPicImpl implements VioPic {
}
private static void putData(String hbaseFtpCol, String hbaseFastCol, String url, String ftpUrl, FileService fileService) {
//存fastDfs
params = new LinkedMultiValueMap<String, String>();
......@@ -304,8 +304,8 @@ public class VioPicImpl implements VioPic {
String[] arr = url.split("/");
// logger.info("_-------------" + url);
String fastDfsUrl = fileService.uploadFile(entry.getValue(), arr[arr.length - 1].split("jpg")[0] + "jpg");
put.addColumn("useful".getBytes(), hbaseFastCol.getBytes(), fastDfsUrl.getBytes());
put.addColumn("useful".getBytes(), hbaseFtpCol.getBytes(), url.getBytes());
put.addColumn("info".getBytes(), hbaseFastCol.getBytes(), fastDfsUrl.getBytes());
put.addColumn("info".getBytes(), hbaseFtpCol.getBytes(), url.getBytes());
isPut = true;
} else {
logger.info("图片其他存储方式:" + url);
......
package com.hikcreate.schedul;
import com.hikcreate.drv_photo_pic.DrvPhoto;
import com.hikcreate.drv_photo_pic.Vehicle;
import com.hikcreate.drv_photo_pic.VioPic;
import com.hikcreate.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,6 +18,9 @@ public class PicSchedule {
private DrvPhoto drvPhoto;
@Autowired
private VioPic vioPic;
@Autowired
private Vehicle vehicle;
@Value("${pastDay}")
private int pastDay;
......@@ -34,10 +38,14 @@ public class PicSchedule {
/**
* 每天早上10点同步违法增量数据
*/
@Scheduled(cron = "0 0 11 * * *")
// @Scheduled(cron = "0 0 11 * * *")
public void getIncrementVioPic(){
String date = DateUtil.getDate();
vioPic.getIncrementVioPic(DateUtil.formatDate(DateUtil.getPastDate(new Date(),-pastDay)),date);
}
@Scheduled(cron = "0 0 10 * * *")
public void getIncrementVehPic(){
vehicle.getIncrementVehPic();
}
}
......@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
/**
......@@ -36,7 +37,7 @@ public class FileServiceImpl implements FileService {
return "/group" + path.split("group")[1];
} catch (Exception e) {
e.printStackTrace();
logger.error("Upload Img Error, msg ={}", e);
logger.error("Upload Img Error, msg ={}", e);
throw new RuntimeException("上传图片失败");
}
}
......@@ -48,6 +49,10 @@ public class FileServiceImpl implements FileService {
@Override
public void deleteFile(String path) {
fastDFSClient.deleteFile(path);
try {
fastDFSClient.deleteFile(path);
} catch (Exception e) {
logger.info(e.toString());
}
}
}
......@@ -25,12 +25,16 @@ 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
hbase.master=172.16.25.25:60000
hbase.drv_photo.table=drv:drv_photo
hbase.driverlicense.table=drv:drivinglicense
hbase.vio.table=vio:vio_violation
hbase.drv_photo.table=pic:drv_photo
hbase.vio.table=pic:vio_violation
hbase.veh_pic.table=pic:veh_pic
#hive----sql
increment.vio.pic.sql=SELECT a.ccarnumber hphm,a.clicensetype hpzl,b.wfsj wfsj,b.wfxw wfxw,a.cpic1path url1,a.cpic2path url2,a.cpic3path url3 from (SELECT * from kakou.vio_violation_pic_his_ods WHERE substr(export_time,0,10)<=? and substr(export_time,0,10)>?) a INNER JOIN (SELECT * from default.vio_surveil_all WHERE clbj='0') b WHERE a.ccarnumber=b.hphm and a.clicensetype=b.hpzl and substr(a.dillegaldate,0,16)=substr(b.wfsj,0,16) and a.coffense=b.wfxw
vio.pic.sql.byrow=select cpic1path url1,cpic2path url2,cpic3path url3 from kakou.vio_violation_pic_his_ods where ccarnumber=? and clicensetype=? and substr(dillegaldate,0,19)=? and coffense=?
pastDay=10
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