Commit 2d761682 by 李辅翼

v14

parent 57157a55
......@@ -122,6 +122,17 @@ public class PicController {
}
}
/**
* 删除Hbase机动车表所有数据
* @param table
* @param maxrow
* @param minrow
*/
@GetMapping("/deleteAllVehPic")
public void deleteAllVehPic(@RequestParam("table") String table,@RequestParam("maxrow") String maxrow,@RequestParam("minrow") String minrow){
vehicle.deleteAllVehPic(table,maxrow,minrow);
}
@GetMapping("/drvPhotoHis")
public void getHisDrvPhoto(@RequestParam("time") String time, HttpServletResponse response) {
......
......@@ -10,4 +10,6 @@ public interface Vehicle {
void getVehPicStage(String start, String end);
void insertVehPicByXh(String xh);
void deleteAllVehPic(String table, String maxrow, String minrow);
}
......@@ -9,6 +9,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -18,6 +19,8 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
import java.util.Iterator;
import java.util.Map;
@Service("vehicleImpl")
public class VehicleImpl implements Vehicle {
......@@ -149,6 +152,55 @@ public class VehicleImpl implements Vehicle {
getPic(sql);
}
@Override
public void deleteAllVehPic(String table1, String maxrow, String minrow) {
org.apache.hadoop.hbase.client.Connection connection = null;
Table table = null;
try {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.property.clientPort", hbaseAddress);
conf.set("hbase.zookeeper.quorum", hbaseZkQuorum);
connection = ConnectionFactory.createConnection(conf);
table = connection.getTable(TableName.valueOf(table1));
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes(minrow));
scan.setStopRow(Bytes.toBytes(maxrow));
ResultScanner rs = table.getScanner(scan);
Iterator<Result> it = rs.iterator();
while (it.hasNext()) {
Result r = it.next();
Map<byte[], byte[]> map = r.getFamilyMap(Bytes.toBytes("info"));
String url = Bytes.toString(map.get(Bytes.toBytes("picUrl")));
try {
fileService.deleteFile(url);
} catch (Exception e) {
e.printStackTrace();
} finally {
Delete delete = new Delete(r.getRow());
table.delete(delete);
}
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
if(connection!=null){
try {
connection.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(table!=null){
try {
table.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private void getPic(String sql) {
org.apache.hadoop.hbase.client.Connection hbaseConn = null;
......@@ -211,11 +263,12 @@ public class VehicleImpl implements Vehicle {
if (picResult.getI() == 2) {
try {
fileService.deleteFile(picResult.getUrl());
Delete delete = new Delete(rowkey.getBytes());
vehPicTable.delete(delete);
} catch (Exception e) {
logger.info(xh);
logger.info(xh + "---------------------" + picResult.getUrl());
e.printStackTrace();
} finally {
Delete delete = new Delete(rowkey.getBytes());
vehPicTable.delete(delete);
}
}
Put put = new Put(rowkey.getBytes());
......@@ -224,7 +277,7 @@ public class VehicleImpl implements Vehicle {
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 = uploadFile(bytes, xh + ".jpeg",xh);
String picUrl = uploadFile(bytes, xh + ".jpeg", xh);
put.addColumn("info".getBytes(), "picUrl".getBytes(), picUrl.getBytes());
vehPicTable.put(put);
}
......@@ -235,16 +288,27 @@ public class VehicleImpl implements Vehicle {
}
private String uploadFile(byte[] file, String fileName,String xh) {
private String uploadFile(byte[] file, String fileName, String xh) {
String url;
try {
url = fileService.uploadFile(file, fileName);
} catch (Exception e) {
logger.info("---------------"+xh);
logger.info("---------------" + xh);
e.printStackTrace();
url = uploadFile(file, fileName,xh);
url = uploadFile(file, fileName, xh);
}
return url;
// int count=0;
// while ("false".equals(url)){
// url=fileService.uploadFile(file, fileName);
// count++;
// if(count>10){
// logger.info("---------------" + xh);
// }
// }
}
......
package com.hikcreate.service.fdfs.service;
import java.io.IOException;
/**
* @author 赵东
* @create 2019/3/22 13:39
......@@ -12,7 +14,7 @@ public interface FileService {
* @param fileName
* @return
*/
String uploadFile(byte[] file, String fileName) throws Exception;
String uploadFile(byte[] file, String fileName) throws IOException, InterruptedException;
/**
* 下载文件
......@@ -25,4 +27,5 @@ public interface FileService {
void deleteFile(String path);
}
......@@ -9,6 +9,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import java.io.IOException;
/**
* @author 赵东
......@@ -22,17 +23,26 @@ public class FileServiceImpl implements FileService {
@Override
public synchronized String uploadFile(byte[] file, String fileName) throws Exception {
public synchronized String uploadFile(byte[] file, String fileName) throws IOException, InterruptedException {
Thread.sleep(10);
//将文件上装到fast文件服务器上,成功则返回文件保存的路径
String path = fastDFSClient.uploadFile(file, fileName);
if (!StringUtils.hasText(path)) {
logger.error("Upload Img Error");
}
// logger.info("Upload Img Success. path {}", ("/group" + path.split("group")[1]));
return "/group" + path.split("group")[1];
// try {
// Thread.sleep(10);
// //将文件上装到fast文件服务器上,成功则返回文件保存的路径
// String path = fastDFSClient.uploadFile(file, fileName);
// if (!StringUtils.hasText(path)) {
// logger.error("Upload Img Error");
// }
// return "/group" + path.split("group")[1];
// } catch (Exception e) {
// e.printStackTrace();
// return "false";
// }
}
@Override
......
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