Merge remote-tracking branch 'origin/master'

master
xiaoCJ 8 months ago
commit 7ba5360d85

@ -381,67 +381,33 @@ public class StuJupyterController {
//文件查询 ,判断有无文件 //文件查询 ,判断有无文件
@ApiOperation("文件上传") @ApiOperation("Html文件上传")
@PostMapping("/importIpynb") @PostMapping("/importHtml")
@AnonymousAccess @AnonymousAccess
public ResultEntity importIpynb(@ApiParam("案例名") String caseName,@RequestPart MultipartFile file ) { public ResultEntity importHtml(@ApiParam("案例名") String caseName,@RequestPart MultipartFile file) {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
int i = originalFilename.lastIndexOf("."); int i = originalFilename.lastIndexOf(".");
String substring = originalFilename.substring(i); String substring = originalFilename.substring(i);
if ("html".equals(substring)|| "md".equals(substring)) if ("html".equals(substring)) {
{
// 上传到不同文件夹
if (!(caseName+".md").equals(file.getOriginalFilename()))
{
return new ResultEntity<>(HttpStatus.ACCEPTED,"请上传和案例名相同的文件!");
}
String upload = localFileUtil.uploadByRelativePath(file,"/usr/local/tianzeProject/jupyter/tch");
if (upload!=null) String htmlPath = "/usr/local/tianzeProject/jupyter/md/html";
{
return new ResultEntity<>(HttpStatus.OK,"上传成功!");
}else {
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"上传失败!");
}
} String upload = localFileUtil.uploadByRelativePath(file, htmlPath,caseName);
if ("ipynb".equals(substring))
{
// 上传到不同文件夹
if (!(caseName+".ipynb").equals(file.getOriginalFilename()))
{
return new ResultEntity<>(HttpStatus.ACCEPTED,"请上传和案例名相同的文件!");
}
String upload = localFileUtil.uploadByRelativePath(file,"/usr/local/tianzeProject/jupyter/tch");
if (upload!=null) if (upload != null) {
{ return new ResultEntity<>(HttpStatus.OK, "上传成功!");
return new ResultEntity<>(HttpStatus.OK,"上传成功!"); } else {
}else { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "上传失败!");
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"上传失败!");
} }
} }
//转换出md文件
return new ResultEntity<>("上传成功!"); return new ResultEntity<>("上传成功!");
} }
// 导入ipynb文件 // 导入ipynb文件

@ -84,6 +84,6 @@ public interface IFileUtil {
*/ */
String getDiskRelativePath(String fileName, String suffix); String getDiskRelativePath(String fileName, String suffix);
String uploadByRelativePath(MultipartFile file, String relativePath); String uploadByRelativePath(MultipartFile file, String relativePath,String caseName);
} }

@ -176,24 +176,29 @@ public class LocalFileUtil implements IFileUtil{
} }
public String uploadByRelativePath(MultipartFile file, String relativePath) { public String uploadByRelativePath(MultipartFile file, String relativePath,String caseName) {
Assert.isTrue(!file.isEmpty(), "文件不存在"); Assert.isTrue(!file.isEmpty(), "文件不存在");
String originalFilename = file.getOriginalFilename();
try { try {
String filePath; // 创建目录如果不存在
File directory = new File(relativePath);
if (!directory.exists()) {
directory.mkdirs();
}
// 设置目标文件路径
String result = caseName == null ? file.getOriginalFilename() : caseName;
relativePath = relativePath.endsWith("/") ? relativePath : relativePath + "/"; int i = file.getOriginalFilename().lastIndexOf(".");
filePath = relativePath + originalFilename; String substring = file.getOriginalFilename().substring(i);
File destFile = new File(relativePath + File.separator + result+substring);
File destFile = new File(getFullPath(filePath));
destFile.getParentFile().mkdirs();
file.transferTo(destFile); file.transferTo(destFile);
return filePath; return "上传成功!";
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new IllegalArgumentException("上传文件失败,FileNotFound错误"); throw new IllegalArgumentException("上传文件失败,FileNotFound错误", e);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalArgumentException("上传文件失败,IO错误"); throw new IllegalArgumentException("上传文件失败,IO错误", e);
} }
} }
} }

Loading…
Cancel
Save