|
|
@ -8,6 +8,7 @@ import com.bupt.note.ResponseData.ResponseDataUtil; |
|
|
|
import com.bupt.note.dto.FileForm; |
|
|
|
import com.bupt.note.dto.FileForm; |
|
|
|
import com.bupt.note.dto.QueryContent; |
|
|
|
import com.bupt.note.dto.QueryContent; |
|
|
|
import com.bupt.note.service.FileService; |
|
|
|
import com.bupt.note.service.FileService; |
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -17,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 论文文本管理接口 |
|
|
|
* 论文文本管理接口 |
|
|
@ -64,13 +66,13 @@ public class FileController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("find") |
|
|
|
@GetMapping("find") |
|
|
|
public ResponseData get(QueryContent queryContent,@CookieValue("user") String username) { |
|
|
|
public ResponseData get(QueryContent queryContent,@CookieValue("user") String username) throws IOException { |
|
|
|
if (paperNoteRepository.existsByPaperIdAndUserName(queryContent.getPaperId(),username)) { |
|
|
|
if (paperNoteRepository.existsByPaperIdAndUserName(queryContent.getPaperId(),username)) { |
|
|
|
PaperNote paperNote=paperNoteRepository.findByPaperIdAndUserName(queryContent.getPaperId(),username); |
|
|
|
PaperNote paperNote=paperNoteRepository.findByPaperIdAndUserName(queryContent.getPaperId(),username); |
|
|
|
return ResponseDataUtil.buildSuccess(paperNote.getUrlPath()); |
|
|
|
return ResponseDataUtil.buildSuccess(FileUtils.readFileToString(new File(paperNote.getFilePath()), StandardCharsets.UTF_8)); |
|
|
|
}else if(fileRepository.existsById(queryContent.getFileId())){ |
|
|
|
}else if(fileRepository.existsById(queryContent.getFileId())){ |
|
|
|
com.bupt.note.Model.File file=fileRepository.getOne(queryContent.getFileId()); |
|
|
|
com.bupt.note.Model.File file=fileRepository.getOne(queryContent.getFileId()); |
|
|
|
return ResponseDataUtil.buildSuccess(file.getUrlPath()); |
|
|
|
return ResponseDataUtil.buildSuccess(FileUtils.readFileToString(new File(file.getFilePath()), StandardCharsets.UTF_8)); |
|
|
|
} else{ |
|
|
|
} else{ |
|
|
|
logger.error(String.format("论文文件id=%d不存在", queryContent.getFileId())); |
|
|
|
logger.error(String.format("论文文件id=%d不存在", queryContent.getFileId())); |
|
|
|
return ResponseDataUtil.buildError(); |
|
|
|
return ResponseDataUtil.buildError(); |
|
|
|