Merge remote-tracking branch 'origin/master'

master
xiaoCJ 8 months ago
commit 7ba5360d85

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

@ -84,6 +84,6 @@ public interface IFileUtil {
*/
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(), "文件不存在");
String originalFilename = file.getOriginalFilename();
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 + "/";
filePath = relativePath + originalFilename;
int i = file.getOriginalFilename().lastIndexOf(".");
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);
return filePath;
return "上传成功!";
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("上传文件失败,FileNotFound错误");
throw new IllegalArgumentException("上传文件失败,FileNotFound错误", e);
} catch (IOException e) {
throw new IllegalArgumentException("上传文件失败,IO错误");
throw new IllegalArgumentException("上传文件失败,IO错误", e);
}
}
}

Loading…
Cancel
Save