文件下载

version1
admin 2 years ago
parent 51fa5d8624
commit 70810a7b81

@ -3,6 +3,7 @@ package com.glxp.sale.admin.idc.service.impl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@ -274,9 +275,9 @@ public class IdcServiceImpl implements IdcService {
if(isLastLevel()) {
if(json.get("code")!=null) {
success = analyToDB(json.getJSONObject("data"),files);
success = analyToDB(json.getJSONObject("data"),files,false);
} else {
success = analyToDB(json,files);
success = analyToDB(json,files,false);
}
if(!success)
logger.info("fetchData-->解析失败");
@ -375,7 +376,7 @@ public class IdcServiceImpl implements IdcService {
syncAddTaskStatus(json,true,true);
/*解析入库*/
if(isLastLevel()) {
if(!analyToDB(json,files))
if(!analyToDB(json,files,true))
return ResultVOUtils.error(9000, "解析失败");
} else {
//需要转发
@ -411,7 +412,18 @@ public class IdcServiceImpl implements IdcService {
@Override
public void downloadFile(String fileName,HttpServletResponse response) {
OutputStream os;
String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : fileName.substring(0,1).equals("/") ? "" : "/";
try {
byte[] bytes = FileUtils.readFileByBytes(filePath+filePathSlash+fileName);
os = response.getOutputStream();
os.write(bytes);
os.flush();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void saveUploadStatus(Map<String,Object> params) {
@ -616,25 +628,28 @@ public class IdcServiceImpl implements IdcService {
/*解析到数据库*/
private boolean analyToDB(JSONObject jsonObject,MultipartFile[] files) {
private boolean analyToDB(JSONObject jsonObject,MultipartFile[] files,boolean isUpload) {
if(jsonObject.get("data")!=null) {
String tableName = "";
String uniqueColumn = "";
String filePathColumn = "";
Object object = jsonObject.get("data");
List<Map<String,Object>> list = new ArrayList<>();
if(object instanceof List<?>) {
list = jsonObject.getObject("data", List.class);
tableName = jsonObject.getString("tableName");
uniqueColumn = jsonObject.getString("uniqueColumn");
filePathColumn = jsonObject.getString("filePathColumn");
} else {
JSONObject obj = jsonObject.getJSONObject("data");
list = obj.getObject("data", List.class);
tableName = obj.getString("tableName");
uniqueColumn = obj.getString("uniqueColumn");
filePathColumn = obj.getString("filePathColumn");
}
if(!StringUtils.isEmpty(tableName)) {
return analyData(tableName,uniqueColumn,list);
return analyData(tableName,uniqueColumn,filePathColumn,list,isUpload);
} else {
logger.error("数据格式错误:无数据标记");
}
@ -644,7 +659,7 @@ public class IdcServiceImpl implements IdcService {
}
/*按表名解析数据到数据库,子表暂未处理*/
private boolean analyData(String tableName,String uniqueColumn,List<Map<String,Object>> list) {
private boolean analyData(String tableName,String uniqueColumn,String filePathColumn,List<Map<String,Object>> list,boolean isUpload) {
String tName = DBAUtils.tableRealName(tableName);
String sql="replace "+tName +"(";
@ -680,10 +695,15 @@ public class IdcServiceImpl implements IdcService {
if(list!=null&&list.size()>0) {
int n = 0;
int d = 0;
String[] files = new String[list.size()];
for(int i=0;i<list.size();i++) {
String operateMode = list.get(i).get("operateMode") !=null ? list.get(i).get("operateMode").toString() : "A";
String updateWhere ="";
String updateSet = "";
if(!StringUtils.isEmpty(filePathColumn)) {
files[i] = list.get(i).get(filePathColumn) !=null ? list.get(i).get(filePathColumn).toString() : "";
}
if("A,D,U".contains(operateMode)) {
for(int z=0;z<keyColumn.length;z++ ) {
if(list.get(i).get(keyColumn[z])!=null&&!StringUtils.isEmpty(list.get(i).get(keyColumn[z]).toString())) {
@ -750,7 +770,7 @@ public class IdcServiceImpl implements IdcService {
for (Object o : (List<?>) obj) {
chList.add((Map<String,Object>)o);
}
analyData(list.get(i).get("tableName"+m).toString(),"",chList);
analyData(list.get(i).get("tableName"+m).toString(),"","",chList,isUpload);
} else {
break;
}
@ -821,6 +841,22 @@ public class IdcServiceImpl implements IdcService {
return result;
}
/*下载文件*/
private boolean batchDownloadFile(String[] files) {
boolean success = true;
for(String fileName:files) {
if(!StringUtils.isEmpty(fileName)) {
if(!signleDownloadFile(fileName))
success = false;
}
}
return success;
}
private boolean signleDownloadFile(String fileName) {
return true;
}
/*获取转发服务地址当前值允许单向只使用参数upper_server_ip*/
private String getNextHost() {
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("upper_server_ip");
@ -887,7 +923,6 @@ public class IdcServiceImpl implements IdcService {
systemParamConfigEntity.setParamType(0);
systemParamConfigService.insert(systemParamConfigEntity);
}
System.out.print(JSON.toJSONString(systemParamConfigEntity)+"\n");
return systemParamConfigEntity;
}
private void writeFile(byte[] file, String filePath, String fileName) throws Exception {

Loading…
Cancel
Save