Merge branch 'dev' into test

test
wj 2 years ago
commit cf4d754740

@ -48,5 +48,5 @@ public interface IdcService {
boolean batchDownloadFile(String syncIp, String[] files); boolean batchDownloadFile(String syncIp, String[] files);
BaseResponse onceSync(String tableName, boolean isUpload); BaseResponse onceSync(String tableName, boolean isUpload);
boolean signleDownloadFile(String syncIp, String fileName); boolean signleDownloadFile(String syncIp, String fileFullName);
} }

@ -245,8 +245,7 @@ public class IdcServiceImpl implements IdcService {
/*上传失败重新上传*/ /*上传失败重新上传*/
private void asyncFailTask(String host) { private void asyncFailTask(String host) {
try try {
{
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/"; String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/";
String sql = "select * from basic_export_status where status='1' and receiveStatus='0' where updateTime<date_sub(now(),interval 6 minute) order by updateTime"; String sql = "select * from basic_export_status where status='1' and receiveStatus='0' where updateTime<date_sub(now(),interval 6 minute) order by updateTime";
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
@ -630,7 +629,8 @@ public class IdcServiceImpl implements IdcService {
public void downloadFile(String fileName, HttpServletResponse response) { public void downloadFile(String fileName, HttpServletResponse response) {
OutputStream os; OutputStream os;
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : fileName.substring(0, 1).equals("/") ? "" : "/"; String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : fileName.substring(0, 1).equals("/") ? "" : "/";
String sourceFileName = filePath + filePathSlash + imagePath + fileName; // String sourceFileName = filePath + filePathSlash + imagePath + fileName;
String sourceFileName = fileName;
try { try {
if (FileUtils.isFileExist(sourceFileName)) { if (FileUtils.isFileExist(sourceFileName)) {
byte[] bytes = FileUtils.readFileByBytes(sourceFileName); byte[] bytes = FileUtils.readFileByBytes(sourceFileName);
@ -1163,17 +1163,76 @@ public class IdcServiceImpl implements IdcService {
return success; return success;
} }
// @Override
// public boolean signleDownloadFile(String syncIp, String fileName) {
// String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/";
// if (!FileUtils.makeDirectory(filePath + filePathSlash + imagePath))
// IDCUtils.createDirectory(filePath + filePathSlash + imagePath);
// OkHttpClient client = new OkHttpClient().newBuilder()
// .build();
// ;
// MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
//
// RequestBody body = RequestBody.create(mediaType, "fileName=" + fileName);
//
// Request request = new Request.Builder()
// .url(syncIp + "/spssync/common/downloadFile")
// .post(body)
// .addHeader("Content-Type", "application/x-www-form-urlencoded")
// .build();
// int total = 0;
// try {
// Response result = client.newCall(request).execute();
// String msg = result != null ? result.message().length() > 200 ? result.message().substring(0, 200) : result.message() : "";
//
// if (result != null && result.isSuccessful() && MediaType.parse("application/force-download").equals(result.body().contentType())) {
// try (InputStream inputStream = result.body().byteStream()) {
// fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
//
// FileOutputStream outputStream = new FileOutputStream(filePath + filePathSlash + imagePath + fileName);
//
// byte b[] = new byte[1024];
//
// int len = 0;
// while ((len = inputStream.read(b)) != -1) {
// total += len;
// outputStream.write(b, 0, len);
//
// }
//
// outputStream.flush();
// outputStream.close();
// if (!(total > 0)) {
// new File(filePath + filePathSlash + imagePath + fileName).delete();
// executeSql("delete from idc_file where filePath='" + fileName + "'");
// }
//
// } catch (Exception e) {
// e.printStackTrace();
// log.error("", e);
// }
// }
// if (!(total > 0)) {
// String sql = "replace idc_file (filePath,createTime,msg) values ('" + fileName + "',now(),'" + msg + "')";
// executeSql(sql);
// }
//
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// return (total > 0);
// }
@Override @Override
public boolean signleDownloadFile(String syncIp, String fileName) { public boolean signleDownloadFile(String syncIp, String fileFullName) {
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/";
if (!FileUtils.makeDirectory(filePath + filePathSlash + imagePath))
IDCUtils.createDirectory(filePath + filePathSlash + imagePath);
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.build(); .build();
; ;
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "fileName=" + fileName); RequestBody body = RequestBody.create(mediaType, "fileName=" + fileFullName);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(syncIp + "/spssync/common/downloadFile") .url(syncIp + "/spssync/common/downloadFile")
@ -1188,8 +1247,12 @@ public class IdcServiceImpl implements IdcService {
if (result!=null&&result.isSuccessful()&&MediaType.parse("application/force-download").equals(result.body().contentType())) { if (result!=null&&result.isSuccessful()&&MediaType.parse("application/force-download").equals(result.body().contentType())) {
try (InputStream inputStream = result.body().byteStream()) { try (InputStream inputStream = result.body().byteStream()) {
String path = fileFullName.substring(0,fileFullName.lastIndexOf("/"));
if(!FileUtils.makeDirectory(path))
IDCUtils.createDirectory(path);
FileOutputStream outputStream = new FileOutputStream(filePath + filePathSlash + imagePath + fileName); FileOutputStream outputStream = new FileOutputStream(fileFullName);
byte b[] = new byte[1024]; byte b[] = new byte[1024];
@ -1203,8 +1266,8 @@ public class IdcServiceImpl implements IdcService {
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
if(!(total>0)) { if(!(total>0)) {
new File(filePath + filePathSlash + imagePath + fileName).delete(); new File(fileFullName).delete();
executeSql("delete from idc_file where filePath='" + fileName + "'"); executeSql("delete from idc_file where filePath='"+fileFullName+"'");
} }
} catch (Exception e) { } catch (Exception e) {
@ -1213,7 +1276,7 @@ public class IdcServiceImpl implements IdcService {
} }
} }
if(!(total>0)) { if(!(total>0)) {
String sql = "replace idc_file (filePath,createTime,msg) values ('" + fileName + "',now(),'" + msg + "')"; String sql = "replace idc_file (filePath,createTime,msg) values ('"+fileFullName+"',now(),'"+msg+"')";
executeSql(sql); executeSql(sql);
} }
@ -1221,7 +1284,6 @@ public class IdcServiceImpl implements IdcService {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
return (total>0); return (total>0);
} }

@ -194,7 +194,7 @@ public class DlAllDataService {
String taskId = syncOrderResponse.getString("taskId"); String taskId = syncOrderResponse.getString("taskId");
myEntity.setId(taskId); myEntity.setId(taskId);
JSONArray fileJson = syncOrderResponse.getJSONArray("files"); JSONArray fileJson = syncOrderResponse.getJSONArray("syncFiles");
if (fileJson != null) { if (fileJson != null) {
List<String> syncFiles = fileJson.toJavaList(String.class); List<String> syncFiles = fileJson.toJavaList(String.class);
if (CollUtil.isNotEmpty(syncFiles)) { if (CollUtil.isNotEmpty(syncFiles)) {

Loading…
Cancel
Save