|
|
|
@ -38,7 +38,7 @@ import okhttp3.RequestBody;
|
|
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*文件服务*/
|
|
|
|
|
/*文件服务*/
|
|
|
|
|
@Service
|
|
|
|
|
public class FileServiceImpl implements FileService {
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FileServiceImpl.class);
|
|
|
|
@ -48,62 +48,64 @@ public class FileServiceImpl implements FileService {
|
|
|
|
|
private String apiKey;
|
|
|
|
|
@Value("${API_SECRET}")
|
|
|
|
|
private String apiSecret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private DbDao dbDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private IdcService idcService;
|
|
|
|
|
private String imagePath = "register/file/image2/";
|
|
|
|
|
|
|
|
|
|
String pdfPath = "pdf/template/";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse upload(List<String> list) {
|
|
|
|
|
return fileToUpload(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse download(List<String> list) {
|
|
|
|
|
return fileToDownload(list);
|
|
|
|
|
return fileToDownload(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse fileUpload(HttpServletRequest request,Map<String,Object> params) {
|
|
|
|
|
public BaseResponse fileUpload(HttpServletRequest request, Map<String, Object> params) {
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
String[] strs = params.get("fileName").toString().split(",");
|
|
|
|
|
for(String str:strs) {
|
|
|
|
|
for (String str : strs) {
|
|
|
|
|
list.add(str);
|
|
|
|
|
}
|
|
|
|
|
return fileToUpload(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BaseResponse fileToUpload(List<String> list) {
|
|
|
|
|
String host="";
|
|
|
|
|
String host = "";
|
|
|
|
|
try {
|
|
|
|
|
Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1");
|
|
|
|
|
if(map!=null&&map.get("syncIp")!=null)
|
|
|
|
|
if (map != null && map.get("syncIp") != null)
|
|
|
|
|
host = map.get("syncIp").toString();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isEmpty(host)) {
|
|
|
|
|
if (StringUtils.isEmpty(host)) {
|
|
|
|
|
try {
|
|
|
|
|
Map<String,Object> config =dbDao.get("select paramValue from system_param_config where paramKey='upper_server_ip'");
|
|
|
|
|
if(config!=null&&config.get("paramValue")!=null)
|
|
|
|
|
Map<String, Object> config = dbDao.get("select paramValue from system_param_config where paramKey='upper_server_ip'");
|
|
|
|
|
if (config != null && config.get("paramValue") != null)
|
|
|
|
|
host = config.get("paramValue").toString();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isEmpty(host))
|
|
|
|
|
return ResultVOUtils.error(9999,"上传地址未配置,请至同步设置中进行设置");
|
|
|
|
|
if(list!=null) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(host))
|
|
|
|
|
return ResultVOUtils.error(9999, "上传地址未配置,请至同步设置中进行设置");
|
|
|
|
|
if (list != null) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/";
|
|
|
|
|
ArrayList<String> files = new ArrayList<>();
|
|
|
|
|
boolean isExists = true;
|
|
|
|
|
List<String> noExitsList = new ArrayList<>();
|
|
|
|
|
for(String strs:list) {
|
|
|
|
|
for (String strs : list) {
|
|
|
|
|
String[] str = strs.split(",");
|
|
|
|
|
for(String s:str) {
|
|
|
|
|
for (String s : str) {
|
|
|
|
|
if (!StringUtils.isEmpty(s) && FileUtils.isFileExist(filePath + filePathSlash + imagePath + s)) {
|
|
|
|
|
files.add(filePath + filePathSlash + imagePath + s);
|
|
|
|
|
} else {
|
|
|
|
@ -112,88 +114,93 @@ public class FileServiceImpl implements FileService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!isExists)
|
|
|
|
|
return ResultVOUtils.error(9999,"以下文件不存在:\n"+JSON.toJSONString(noExitsList));
|
|
|
|
|
String result = relayFile(files,host);
|
|
|
|
|
if (!isExists)
|
|
|
|
|
return ResultVOUtils.error(9999, "以下文件不存在:\n" + JSON.toJSONString(noExitsList));
|
|
|
|
|
String result = relayFile(files, host);
|
|
|
|
|
if (IDCUtils.isJson(result)) {
|
|
|
|
|
BaseResponse baseResponse = JSON.parseObject(result,BaseResponse.class);
|
|
|
|
|
BaseResponse baseResponse = JSON.parseObject(result, BaseResponse.class);
|
|
|
|
|
return baseResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.error(9999,"失败");
|
|
|
|
|
return ResultVOUtils.error(9999, "失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse fileDownload(HttpServletRequest request,Map<String,Object> params) {
|
|
|
|
|
public BaseResponse fileDownload(HttpServletRequest request, Map<String, Object> params) {
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
String[] strs = params.get("fileName").toString().split(",");
|
|
|
|
|
for(String str:strs) {
|
|
|
|
|
for (String str : strs) {
|
|
|
|
|
list.add(str);
|
|
|
|
|
}
|
|
|
|
|
return fileToDownload(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BaseResponse fileToDownload(List<String> list) {
|
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
String fileName = "";
|
|
|
|
|
for(String str:list) {
|
|
|
|
|
fileName +=fileName.length()>0 ? ","+str : str;
|
|
|
|
|
for (String str : list) {
|
|
|
|
|
fileName += fileName.length() > 0 ? "," + str : str;
|
|
|
|
|
}
|
|
|
|
|
params.put("fileName", fileName);
|
|
|
|
|
Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1");
|
|
|
|
|
if(map!=null&&map.get("syncIp")!=null) {
|
|
|
|
|
|
|
|
|
|
String result = IDCUtils.post(map.get("syncIp").toString()+"/spssync/file/downloadFile", params);
|
|
|
|
|
if (map != null && map.get("syncIp") != null) {
|
|
|
|
|
|
|
|
|
|
String result = IDCUtils.post(map.get("syncIp").toString() + "/spssync/file/downloadFile", params);
|
|
|
|
|
boolean success = false;
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
|
if (IDCUtils.isJson(result)) {
|
|
|
|
|
JSONObject object = JSON.parseObject(result);
|
|
|
|
|
|
|
|
|
|
if(object.getInteger("code")==20000) {
|
|
|
|
|
|
|
|
|
|
if (object.getInteger("code") == 20000) {
|
|
|
|
|
String[] files = params.get("fileName").toString().split(",");
|
|
|
|
|
success = true;
|
|
|
|
|
for(String str:files) {
|
|
|
|
|
if(!idcService.signleDownloadFile(map.get("syncIp").toString(), str))
|
|
|
|
|
for (String str : files) {
|
|
|
|
|
if (!idcService.signleDownloadFile(map.get("syncIp").toString(), str))
|
|
|
|
|
success = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!success)
|
|
|
|
|
return ResultVOUtils.error(9999,"失败");
|
|
|
|
|
if (!success)
|
|
|
|
|
return ResultVOUtils.error(9999, "失败");
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(9999,"中继服务地址未配置,请至同步设置中进行配置");
|
|
|
|
|
return ResultVOUtils.error(9999, "中继服务地址未配置,请至同步设置中进行配置");
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse receiveFile(HttpServletRequest request,String content,MultipartFile[] files) {
|
|
|
|
|
public BaseResponse receiveFile(HttpServletRequest request, String content, MultipartFile[] files) {
|
|
|
|
|
boolean isRelay = false;
|
|
|
|
|
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/";
|
|
|
|
|
String host = "";
|
|
|
|
|
try {
|
|
|
|
|
Map<String,Object> config =dbDao.get("select paramValue from system_param_config where paramKey='upper_server_ip'");
|
|
|
|
|
if(config!=null&&config.get("paramValue")!=null) {
|
|
|
|
|
Map<String, Object> config = dbDao.get("select paramValue from system_param_config where paramKey='upper_server_ip'");
|
|
|
|
|
if (config != null && config.get("paramValue") != null) {
|
|
|
|
|
isRelay = true;
|
|
|
|
|
host = config.get("paramValue").toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
ArrayList<String> saveFiles = new ArrayList<>();
|
|
|
|
|
Date startTime = new Date();
|
|
|
|
|
if (files != null) {
|
|
|
|
|
if(!FileUtils.makeDirectory(filePath + filePathSlash + imagePath))
|
|
|
|
|
if (!FileUtils.makeDirectory(filePath + filePathSlash + imagePath))
|
|
|
|
|
IDCUtils.createDirectory(filePath + filePathSlash + imagePath);
|
|
|
|
|
try {
|
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
|
String imageName = filePath + filePathSlash + imagePath + file.getOriginalFilename();
|
|
|
|
|
String flodPath;
|
|
|
|
|
if (file.getName().contains(".jrxml") || file.getName().contains(".jasper")) {
|
|
|
|
|
flodPath = pdfPath;
|
|
|
|
|
} else {
|
|
|
|
|
flodPath = imagePath;
|
|
|
|
|
}
|
|
|
|
|
String imageName = filePath + filePathSlash + flodPath + file.getOriginalFilename();
|
|
|
|
|
saveFiles.add(imageName);
|
|
|
|
|
IDCUtils.writeFile(file.getBytes(), filePath + filePathSlash + imagePath, file.getOriginalFilename());
|
|
|
|
|
}
|
|
|
|
|
IDCUtils.writeFile(file.getBytes(), filePath + filePathSlash + flodPath, file.getOriginalFilename());
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -204,24 +211,24 @@ public class FileServiceImpl implements FileService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(isRelay) {
|
|
|
|
|
String result = relayFile(saveFiles,host);
|
|
|
|
|
if (isRelay) {
|
|
|
|
|
String result = relayFile(saveFiles, host);
|
|
|
|
|
logger.info(result);
|
|
|
|
|
if (IDCUtils.isJson(result)&&!result.contains("<html")) {
|
|
|
|
|
BaseResponse baseResponse = JSON.parseObject(result,BaseResponse.class);
|
|
|
|
|
if (IDCUtils.isJson(result) && !result.contains("<html")) {
|
|
|
|
|
BaseResponse baseResponse = JSON.parseObject(result, BaseResponse.class);
|
|
|
|
|
return baseResponse;
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(9999,"上传失败");
|
|
|
|
|
return ResultVOUtils.error(9999, "上传失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*转发图片*/
|
|
|
|
|
private String relayFile(ArrayList<String> files, String ip) {
|
|
|
|
|
String host = ip;
|
|
|
|
|
String result = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(host)) {
|
|
|
|
|
host += "/spssync/file/uploadFile";
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
@ -244,7 +251,7 @@ public class FileServiceImpl implements FileService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody body = builder.build();
|
|
|
|
|
|
|
|
|
|
Request req = new Request.Builder()
|
|
|
|
@ -270,34 +277,34 @@ public class FileServiceImpl implements FileService {
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse downloadFile(HttpServletRequest request,Map<String,Object> params) {
|
|
|
|
|
public BaseResponse downloadFile(HttpServletRequest request, Map<String, Object> params) {
|
|
|
|
|
String host = "";
|
|
|
|
|
try {
|
|
|
|
|
Map<String,Object> config =dbDao.get("select paramValue from system_param_config where paramKey='upper_server_ip'");
|
|
|
|
|
if(config!=null&&config.get("paramValue")!=null)
|
|
|
|
|
Map<String, Object> config = dbDao.get("select paramValue from system_param_config where paramKey='upper_server_ip'");
|
|
|
|
|
if (config != null && config.get("paramValue") != null)
|
|
|
|
|
host = config.get("paramValue").toString();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
|
String result = IDCUtils.post(host+"/spssync/file/downloadFile", params);
|
|
|
|
|
if (!StringUtils.isEmpty(host)) {
|
|
|
|
|
String result = IDCUtils.post(host + "/spssync/file/downloadFile", params);
|
|
|
|
|
JSONObject object = JSON.parseObject(result);
|
|
|
|
|
boolean success = false;
|
|
|
|
|
if(object.getInteger("code")==20000) {
|
|
|
|
|
if (object.getInteger("code") == 20000) {
|
|
|
|
|
String[] files = params.get("fileName").toString().split(",");
|
|
|
|
|
success = true;
|
|
|
|
|
for(String str:files) {
|
|
|
|
|
if(!idcService.signleDownloadFile(host, str))
|
|
|
|
|
for (String str : files) {
|
|
|
|
|
if (!idcService.signleDownloadFile(host, str))
|
|
|
|
|
success = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!success)
|
|
|
|
|
ResultVOUtils.error(9999,"失败");
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
ResultVOUtils.error(9999, "失败");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success(null);
|
|
|
|
|
return ResultVOUtils.success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|