文件上传修改,路径修改

master
anthonywj 2 years ago
parent 4f7b490d88
commit 164c76858c

@ -16,9 +16,6 @@ import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.idc.service.FileService;
/**
*
*/
@ -31,30 +28,28 @@ public class FileController {
@RequestMapping(value = "/spssync/file/upload")
@ResponseBody
public BaseResponse upload(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return fileService.fileUpload(request,params);
return fileService.fileUpload(request, params);
}
@RequestMapping(value = "/spssync/file/download")
@ResponseBody
public BaseResponse download(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return fileService.fileDownload(request,params);
return fileService.fileDownload(request, params);
}
@RequestMapping(value = "/spssync/file/downloadFile")
@ResponseBody
public BaseResponse downloadFile(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return fileService.downloadFile(request,params);
return fileService.downloadFile(request, params);
}
@RequestMapping(value = "/spssync/file/uploadFile")
public BaseResponse uploadFile(HttpServletRequest request,
@RequestParam(value = "content" , required = false) String content,
@RequestParam(value = "files", required = false) MultipartFile[] files) {
@RequestParam(value = "content", required = false) String content,
@RequestParam(value = "files", required = false) MultipartFile[] files) {
//
return fileService.receiveFile(request, content, files);
}
}

@ -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,152 +48,155 @@ 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) {
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/";
if (StringUtils.isEmpty(host))
return ResultVOUtils.error(9999, "上传地址未配置,请至同步设置中进行设置");
if (list != null) {
ArrayList<String> files = new ArrayList<>();
boolean isExists = true;
List<String> noExitsList = new ArrayList<>();
for(String strs:list) {
String[] str = strs.split(",");
for(String s:str) {
if (!StringUtils.isEmpty(s) && FileUtils.isFileExist(filePath + filePathSlash + imagePath + s)) {
files.add(filePath + filePathSlash + imagePath + s);
} else {
isExists = false;
noExitsList.add(s);
}
for (String strs : list) {
if (!StringUtils.isEmpty(strs) && FileUtils.isFileExist(strs)) {
files.add(strs);
} else {
isExists = false;
noExitsList.add(strs);
}
}
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) {
}
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 +207,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 +247,7 @@ public class FileServiceImpl implements FileService {
}
}
}
RequestBody body = builder.build();
Request req = new Request.Builder()
@ -270,34 +273,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);
}
}
}

@ -1023,7 +1023,27 @@ public class HeartService {
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
dataResponse.setType(BasicExportTypeEnum.SYS_SET_DATA.getRemark());
if (CollUtil.isNotEmpty(dataResponse.getSystemPDFTemplateEntities())) {
// List<Map<String, String>> list = new ArrayList<>(spsSyncSysSettingResponse.getSystemPDFTemplateEntities().size() * 2);
List<String> list = new ArrayList<>();
dataResponse.getSystemPDFTemplateEntities().forEach(systemPDFTemplateEntity -> {
list.add(systemPDFTemplateEntity.getPath());
});
BaseResponse<String> response = spGetHttp.postTemplateFile(list);
if (response.getCode() == 20000) {
log.info("模板文件列表上传成功");
// uploadFileLog = "\n模板文件列表上传成功";
} else {
log.info("模板文件上传失败,响应信息:{}", response.getMessage());
// uploadFileLog = "\n模板文件列表上传失败错误信息" + response.getMessage();
}
}
}
return dataResponse;
}

Loading…
Cancel
Save