Merge remote-tracking branch 'origin/master'

This commit is contained in:
wangliwen 2022-04-26 15:11:10 +08:00
commit 77faae8e73
2 changed files with 23 additions and 7 deletions

View File

@ -42,7 +42,9 @@ public class DevelopmentGuideController {
@PostMapping("/uploadDevelopmentFile")
@ApiOperation("开发指南文件上传")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "开发指南文件", paramType = "file", dataType = "file", required = true)
@ApiImplicitParam(name = "file", value = "开发指南文件", paramType = "file", dataType = "file", required = true),
@ApiImplicitParam(name = "fileName", value = "文件名称", paramType = "query", dataType = "String", required = true),
@ApiImplicitParam(name = "type", value = "能力类型", paramType = "query", dataType = "String", required = true),
})
public Result uploadDevelopmentFile(@RequestParam("file") MultipartFile uploadFile, HttpServletRequest request) {
try {

View File

@ -27,19 +27,28 @@ public class DevelopmentGuideServiceImpl implements DevelopmentGuideService {
@Override
public void getDevelopmentFile(HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("----------------------------------开始上传开发指南--------------------------------------------------");
String type = request.getParameter("type").toString();
Long resourceId = Long.parseLong(request.getParameter("resourceId"));
logger.info("读取文件类型及能力ID" + type + ";" + resourceId);
String url = devModelFilePath + File.separator + type + File.separator + resourceId + ".md";
String filePath = devModelFilePath + File.separator + type;
File file = new File(url);
//开发指南未保存过获取默认模板文件
if (! file.exists()) {
file = new File(devModelFilePath + File.separator + type + File.separator + type + ".md");
if (new File(filePath).exists()) {
if (! file.exists()) {
file = new File(devModelFilePath + File.separator + type + File.separator + type + ".md");
}
} else {
logger.info("----------------------------------文件路径不存在--------------------------------------");
throw new IOException("文件路径不存在!");
}
response.setContentType("text/html");
try (
FileInputStream fis = new FileInputStream(file);
OutputStream outputStream = response.getOutputStream();
) {
logger.info("----------------------------------开始获取文件--------------------------------------");
//将读取流拷贝到输出流中
IOUtils.copy(fis, outputStream);
//清空缓存的读取流保证数据完整性
@ -52,22 +61,27 @@ public class DevelopmentGuideServiceImpl implements DevelopmentGuideService {
@Override
public void uploadDevelopmentFile(MultipartFile uploadFile, HttpServletRequest request) throws Exception{
logger.info("----------------------------------开始上传开发指南--------------------------------------------------");
String type = request.getParameter("type").toString();
File folder = new File(devModelFilePath + File.pathSeparator + type + File.separator + uploadFile.getName());
File path = new File(devModelFilePath + File.pathSeparator + type);
String fileName = request.getParameter("fileName").toString();
logger.info("读取文件类型及文件名:" + type + ";" + fileName);
File folder = new File(devModelFilePath + File.pathSeparator + type + File.separator + fileName);
File path = new File(devModelFilePath + File.pathSeparator + type + File.separator);
//文件保存过删除后重新保存
if (folder.exists()) {
if (folder.isFile()) {
if (!folder.delete()) {
logger.info("----------------------------------删除已存在文件失败--------------------------------------");
throw new IOException("保存文件失败!");
}
}
}
try {
// 文件保存
logger.info("读取文件名:" + uploadFile.getName());
uploadFile.transferTo(new File(path, uploadFile.getName()));
uploadFile.transferTo(new File(path, fileName));
logger.info("----------------------------------文件上传成功--------------------------------------");
} catch (IOException e) {
logger.info("----------------------------------文件上传失败--------------------------------------");
e.printStackTrace();
}
}