增加论文笔记增删接口

pdf
pan 4 years ago
parent 4bb495d8f9
commit dd4fd1f080
  1. 23
      doc/db_table.md
  2. 82
      src/main/java/com/bupt/note/Controller/FileController.java
  3. 183
      src/main/java/com/bupt/note/Controller/NoteController.java
  4. 5
      src/main/java/com/bupt/note/Controller/PaperController.java
  5. 56
      src/main/java/com/bupt/note/Controller/UserController.java
  6. 83
      src/main/java/com/bupt/note/Model/Note.java
  7. 69
      src/main/java/com/bupt/note/Model/PaperNote.java
  8. 12
      src/main/java/com/bupt/note/Repository/NoteRepository.java
  9. 9
      src/main/java/com/bupt/note/Repository/PaperNoteRepository.java
  10. 31
      src/main/java/com/bupt/note/dto/DeleteNote.java
  11. 72
      src/main/java/com/bupt/note/dto/NoteForm.java
  12. 11
      src/main/java/com/bupt/note/dto/QueryContent.java
  13. 13
      src/main/java/com/bupt/note/dto/QueryNote.java
  14. 31
      src/main/java/com/bupt/note/service/FileService.java
  15. 10
      src/test/java/com/bupt/note/MyTest.java
  16. 3
      src/test/java/com/bupt/note/NoteApplicationTests.java

@ -14,6 +14,17 @@
| file_path | varchar | not null | 文件路径 |
| url_path | varchar | not null | 访问路径 |
# 论文笔记表 sys_paper_note
| 列名 | 数据类型 | 约束条件 | 含义 |
| ---- | -------- | -------- | ---- |
| id | bigint | primary key; identity | 文件id |
| paper_id | bigint | not null | 论文id |
| file_id | bigint | not null | 原文件id |
| file_path | varchar | not null | 文件路径 |
| url_path | varchar | not null | 访问路径 |
| user_name | varchar | not null | 修改用户 |
# 论文 sys_paper
| 列名 | 数据类型 | 约束条件 | 含义 |
@ -40,12 +51,12 @@
| paper_id | bigint | not null | 论文id |
| user_name | varchar | not null | 评价用户 |
# 笔记 Note
# 笔记 sys_note
| 列名 | 数据类型 | 约束条件 | 含义 |
| ---- | -------- | -------- | ---- |
| Nid | int | primary key; identity | 编号 |
| Pid | int | foreign key | 文章编号 |
| Uid | int | foreign key | 用户编号 |
| Ntype | int | | 笔记分类 |
| Ncontent | varchar | | 笔记内容 |
| note_id | varchar | primary key | 笔记id |
| note_title | varchar | not null | 笔记标题 |
| note_content | varchar | not null | 笔记内容 |
| paper_id | bigint | not null | 论文id |
| user_name | varchar | not null | 笔记用户 |

@ -1,24 +1,22 @@
package com.bupt.note.Controller;
import com.bupt.note.Model.PaperNote;
import com.bupt.note.Repository.FileRepository;
import com.bupt.note.Repository.PaperNoteRepository;
import com.bupt.note.ResponseData.ResponseData;
import com.bupt.note.ResponseData.ResponseDataUtil;
import com.bupt.note.dto.FileForm;
import com.bupt.note.dto.QueryContent;
import com.bupt.note.service.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.UUID;
/**
* 论文文本管理接口
@ -27,34 +25,31 @@ import java.util.UUID;
@RequestMapping(value = "/v1/api/file")
public class FileController {
@Value("${spring.resources.static-locations}")
private String txtPath;
private static Logger logger = LoggerFactory.getLogger(FileController.class);
@Autowired
private FileRepository fileRepository;
@Autowired
private PaperNoteRepository paperNoteRepository;
@Autowired
private FileService fileService;
//上传论文文本
@PostMapping("upload")
public ResponseData upload(FileForm fileForm){
MultipartFile file=fileForm.getFile();
if(file!=null&& MediaType.TEXT_PLAIN_VALUE.equals(file.getContentType())){
public ResponseData upload(FileForm fileForm) {
MultipartFile file = fileForm.getFile();
if (file != null && MediaType.TEXT_PLAIN_VALUE.equals(file.getContentType())) {
File txtFile;
File txtDir;
try {
txtDir=new File(URLDecoder.decode(ResourceUtils.getURL("classpath:").getPath(), StandardCharsets.UTF_8) + txtPath.replace("classpath:/", ""));
if(!txtDir.exists()&&txtDir.mkdirs()){
logger.info("成功初始化上传论文目录:"+txtDir.getAbsolutePath());
}
txtFile=new File(txtDir, UUID.randomUUID()+".txt");
logger.debug("论文保存到"+txtFile.getAbsolutePath());
File txtFile = fileService.newFile();
logger.debug("论文保存到" + txtFile.getAbsolutePath());
file.transferTo(txtFile);
com.bupt.note.Model.File f=new com.bupt.note.Model.File();
com.bupt.note.Model.File f = new com.bupt.note.Model.File();
f.setFilePath(txtFile.getAbsolutePath());
f.setUrlPath("/txt/"+txtFile.getName());
f.setUrlPath("/txt/" + txtFile.getName());
fileRepository.save(f);
return ResponseDataUtil.buildSuccess(f.getId());
} catch (IOException e) {
@ -62,42 +57,47 @@ public class FileController {
e.printStackTrace();
return ResponseDataUtil.buildError();
}
}else{
} else {
logger.error("上传论文表单校验失败");
return ResponseDataUtil.buildError();
}
}
@GetMapping("find/{id}")
public ResponseData get(@PathVariable Long id){
if(fileRepository.existsById(id)){
com.bupt.note.Model.File file= fileRepository.getOne(id);
@GetMapping("find")
public ResponseData get(QueryContent queryContent,@CookieValue("user") String username) {
if (paperNoteRepository.existsByPaperIdAndUserName(queryContent.getPaperId(),username)) {
PaperNote paperNote=paperNoteRepository.findByPaperIdAndUserName(queryContent.getPaperId(),username);
return ResponseDataUtil.buildSuccess(paperNote.getUrlPath());
}else if(fileRepository.existsById(queryContent.getFileId())){
com.bupt.note.Model.File file=fileRepository.getOne(queryContent.getFileId());
return ResponseDataUtil.buildSuccess(file.getUrlPath());
}else{
} else{
logger.error(String.format("论文文件id=%d不存在", queryContent.getFileId()));
return ResponseDataUtil.buildError();
}
}
/**
* 删除论文文本文件
*
* @param id 文件id
* @return
*/
@DeleteMapping("remove/{id}")
public ResponseData remove(@PathVariable Long id){
if(fileRepository.existsById(id)){
Optional<com.bupt.note.Model.File> f=fileRepository.findById(id);
if(f.isPresent()){
File txtFile=new File(f.get().getFilePath());
if(txtFile.exists()&&txtFile.delete()) {
fileRepository.deleteById(id);
return ResponseDataUtil.buildSuccess();
}else{
return ResponseDataUtil.buildError();
}
}else {
public ResponseData remove(@PathVariable Long id) {
if (fileRepository.existsById(id)) {
com.bupt.note.Model.File txtFile = fileRepository.getOne(id);
File f = new File(txtFile.getFilePath());
if (f.exists() && f.delete()) {
fileRepository.deleteById(id);
return ResponseDataUtil.buildSuccess();
} else {
logger.error(String.format("删除论文id=%d失败",id));
return ResponseDataUtil.buildError();
}
}else{
} else {
logger.error(String.format("论文id=%d不存在",id));
return ResponseDataUtil.buildError();
}
}

@ -1,69 +1,166 @@
package com.bupt.note.Controller;
import com.bupt.note.Model.Note;
import com.bupt.note.Model.PaperNote;
import com.bupt.note.Repository.NoteRepository;
import com.bupt.note.Repository.PaperNoteRepository;
import com.bupt.note.ResponseData.ResponseData;
import com.bupt.note.ResponseData.ResponseDataUtil;
import com.bupt.note.ResponseData.ResultEnums;
import com.bupt.note.dto.DeleteNote;
import com.bupt.note.dto.NoteForm;
import com.bupt.note.dto.Page;
import com.bupt.note.service.FileService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import javax.persistence.criteria.Predicate;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping(value = "/v1/api/notes")
public class NoteController {
@Autowired
NoteRepository noteRepository;
private NoteRepository noteRepository;
@RequestMapping(value="/{docId}", method=RequestMethod.POST, produces = "application/json")
public ResponseData postNote(@PathVariable long docId, @RequestBody Note note) {
// 处理"/notes/[doc_id]"的POST请求,用来创建Note
Note newNote;
note.setDocId(docId);
try {
newNote = noteRepository.save(note);
} catch (Exception e) {
return ResponseDataUtil.buildError(ResultEnums.ErrNoteSaveFailed);
}
return ResponseDataUtil.buildSuccess(newNote);
}
@Autowired
private PaperNoteRepository paperNoteRepository;
@RequestMapping(value="/{docId}/{noteId}", method=RequestMethod.DELETE, produces = "application/json")
public ResponseData deleteNote(@PathVariable long docId, @PathVariable long noteId) {
// 处理"/notes/[doc_id]/[note_id]"的DELETE请求,用来删除Note
Optional<Note> optionalNote = noteRepository.findById(noteId);
if (!optionalNote.isPresent()) {
return ResponseDataUtil.buildError(ResultEnums.ErrNoteDeleteFailed);
@Autowired
private FileService fileService;
private Logger logger = LoggerFactory.getLogger(NoteController.class);
/**
* 添加笔记
*
* @param noteForm
* @param username
* @return
*/
@PostMapping("add")
public ResponseData addNote(@RequestBody NoteForm noteForm, @CookieValue("user") String username) {
if (noteForm.getPaperId() != null && StringUtils.isNoneBlank(noteForm.getNoteId(),
noteForm.getNoteTitle(), noteForm.getNoteContent(), noteForm.getContent())) {
Note note = noteForm.toNote();
note.setUserName(username);
noteRepository.save(note);
if (noteRepository.existsById(note.getNoteId())) {
Writer wr = null;
try {
PaperNote paperNote;
File f;
if (paperNoteRepository.existsByPaperIdAndUserName(noteForm.getPaperId(), username)) {
paperNote = paperNoteRepository.findByPaperIdAndUserName(note.getPaperId(), username);
f = new File(paperNote.getFilePath());
} else {
f = fileService.newFile();
paperNote = new PaperNote();
paperNote.setFileId(noteForm.getFileId());
paperNote.setPaperId(noteForm.getPaperId());
paperNote.setFilePath(f.getAbsolutePath());
paperNote.setUrlPath("/txt/" + f.getName());
paperNote.setUserName(username);
paperNoteRepository.save(paperNote);
}
wr = new FileWriter(f);
wr.write(noteForm.getContent());
return ResponseDataUtil.buildSuccess(note);
} catch (IOException e) {
e.printStackTrace();
logger.error(String.valueOf(e));
} finally {
if (wr != null) {
try {
wr.close();
} catch (IOException e) {
e.printStackTrace();
logger.error(String.valueOf(e));
}
}
}
logger.error(String.format("更新论文id=%d失败", noteForm.getPaperId()));
return ResponseDataUtil.buildError();
} else {
logger.error("保存笔记失败");
return ResponseDataUtil.buildError();
}
} else {
logger.error("表单校验失败");
return ResponseDataUtil.buildError();
}
Note note = optionalNote.get();
noteRepository.delete(note);
return ResponseDataUtil.buildSuccess("success");
}
@RequestMapping(value="/{docId}/{noteId}", method=RequestMethod.PATCH, produces = "application/json")
public ResponseData updateNote(@PathVariable long docId, @PathVariable long noteId,
@RequestParam String type, @RequestParam String text) {
// 处理"/notes/[doc_id]/[note_id]"的PATCH请求,用来更新Note
Optional<Note> optionalNote = noteRepository.findById(noteId);
if (!optionalNote.isPresent()) {
return ResponseDataUtil.buildError(ResultEnums.ErrNoteIdNotExist);
/**
* 查找笔记
*
* @param username
* @return
*/
@GetMapping("list/{id}")
public ResponseData list(@PathVariable("id") Long paperId,@CookieValue("user") String username) {
try {
Page<Note> list = new Page<>();
list.setTotal(noteRepository.count());
List<Note> noteList = noteRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.isNotEmpty(username)) {
predicates.add(criteriaBuilder.equal(root.get("userName"), username));
}
predicates.add(criteriaBuilder.equal(root.get("paperId"),paperId));
return criteriaQuery.where(predicates.toArray(new Predicate[0])).getRestriction();
});
list.setData(noteList);
return ResponseDataUtil.buildSuccess(list);
} catch (Exception e) {
e.printStackTrace();
logger.error(String.valueOf(e));
return ResponseDataUtil.buildError();
}
Note note = optionalNote.get();
note.setText(text);
note.setType(type);
noteRepository.save(note);
return ResponseDataUtil.buildSuccess("success");
}
@RequestMapping(value="/{docId}", method=RequestMethod.GET, produces = "application/json")
public ResponseData getNote(@PathVariable long docId) {
// 处理"/[doc_id]"的GET请求,用来获取某个doc的笔记列表
List<Note> noteList = noteRepository.findByDocId(docId);
if (noteList.isEmpty()) {
return ResponseDataUtil.buildError(ResultEnums.ErrDocIdNotExist);
/**
* 删除笔记
* @return
*/
@DeleteMapping("remove")
public ResponseData remove(@RequestBody DeleteNote deleteNote,@CookieValue("user") String username){
if(deleteNote.getNoteId()!=null&&deleteNote.getPaperId()!=null&&StringUtils.isNotEmpty(deleteNote.getContent())&&
paperNoteRepository.existsByPaperIdAndUserName(deleteNote.getPaperId(),username)){
noteRepository.deleteById(deleteNote.getNoteId());
PaperNote paperNote = paperNoteRepository.findByPaperIdAndUserName(deleteNote.getPaperId(), username);
File f = new File(paperNote.getFilePath());
Writer wr = null;
try {
wr = new FileWriter(f);
wr.write(deleteNote.getContent());
return ResponseDataUtil.buildSuccess();
} catch (IOException e) {
e.printStackTrace();
logger.error(String.valueOf(e));
} finally {
if (wr != null) {
try {
wr.close();
} catch (IOException e) {
e.printStackTrace();
logger.error(String.valueOf(e));
}
}
}
logger.error("删除笔记失败");
}else{
logger.error("删除笔记表单校验失败");
}
return ResponseDataUtil.buildSuccess(noteList);
return ResponseDataUtil.buildError();
}
}

@ -42,9 +42,11 @@ public class PaperController {
if(papaerRepository.existsById(paper.getId())){
return ResponseDataUtil.buildSuccess();
}else{
logger.error("论文上传失败");
return ResponseDataUtil.buildError();
}
}else{
logger.error("论文表单校验失败");
return ResponseDataUtil.buildError();
}
}
@ -97,9 +99,11 @@ public class PaperController {
if(ratingRepository.existsById(rating.getId())){
return ResponseDataUtil.buildSuccess(rating);
}else{
logger.warn("论文保存失败");
return ResponseDataUtil.buildSuccess();
}
}else{
logger.error("论文表单校验失败");
return ResponseDataUtil.buildError();
}
}
@ -110,6 +114,7 @@ public class PaperController {
Rating rating=ratingRepository.findByPaperIdAndUserName(paperId,userName);
return ResponseDataUtil.buildSuccess(rating);
}else{
logger.error("论文评价表单校验失败");
return ResponseDataUtil.buildError();
}
}

@ -7,10 +7,10 @@ import com.bupt.note.ResponseData.ResponseDataUtil;
import com.bupt.note.ResponseData.ResultEnums;
import com.bupt.note.dto.UserForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 用户接口
@ -52,52 +52,4 @@ public class UserController {
return ResponseDataUtil.buildSuccess(ResultEnums.SUCCESS);
}
}
@RequestMapping(method=RequestMethod.GET)
public ResponseData<List<User>> getUserList() {
// 处理"/users/"的GET请求,用来获取用户列表
List<User> userList = userRepository.findAll();
return ResponseDataUtil.buildSuccess(userList);
}
@RequestMapping(value="/{id}", method=RequestMethod.GET)
public ResponseData getUser(@PathVariable Long id) {
// 处理"/users/{id}"的GET请求,用来获取url中id值的User信息
Optional<User> optionalUser = userRepository.findById(id);
if (!optionalUser.isPresent()) {
return ResponseDataUtil.buildError(ResultEnums.ErrUserIdNotExist);
}
User u = optionalUser.get();
return ResponseDataUtil.buildSuccess(u);
}
@RequestMapping(value="/{id}", method=RequestMethod.PUT)
public ResponseData putUser(@PathVariable Long id, @ModelAttribute User user) {
// 处理"/users/{id}"的PUT请求,用来更新User信息
Optional<User> optionalUser = userRepository.findById(id);
if (!optionalUser.isPresent()) {
return ResponseDataUtil.buildError(ResultEnums.ErrUserIdNotExist);
}
User u = optionalUser.get();
u.setUserName(user.getUserName());
u.setPassword(user.getPassword());
userRepository.save(u);
return ResponseDataUtil.buildSuccess("success");
}
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
public ResponseData deleteUser(@PathVariable Long id) {
// 处理"/users/{id}"的DELETE请求,用来删除User
Optional<User> optionalUser = userRepository.findById(id);
if (!optionalUser.isPresent()) {
return ResponseDataUtil.buildError(ResultEnums.ErrUserIdNotExist);
}
User u = optionalUser.get();
userRepository.delete(u);
return ResponseDataUtil.buildSuccess("success");
}
}

@ -1,78 +1,63 @@
package com.bupt.note.Model;
import com.fasterxml.jackson.annotation.JsonProperty;
import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Entity
@Table(name = "sys_note")
public class Note implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long Id;
@Column(nullable = false)
@JsonProperty(value = "docId")
private Long docId;
@Column(nullable = false)
@JsonProperty(value = "userId")
private Long userId;
@Column(nullable = false)
private String type;
@Column(nullable = false)
private String text;
public Note() {
super();
}
private String noteId;
private String noteTitle;
private String noteContent;
private Long paperId;
private String userName;
public Note(long docId, long userId, String type, String text) {
super();
this.docId = docId;
this.userId = userId;
this.type = type;
this.text = text;
}
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return Id;
@Id
public String getNoteId() {
return noteId;
}
public void setId(Long id) {
Id = id;
public void setNoteId(String noteId) {
this.noteId = noteId;
}
public Long getDocId() {
return docId;
@Column(nullable = false)
public String getNoteTitle() {
return noteTitle;
}
public void setDocId(Long docId) {
this.docId = docId;
public void setNoteTitle(String noteTitle) {
this.noteTitle = noteTitle;
}
public Long getUserId() {
return userId;
@Column(nullable = false)
public String getNoteContent() {
return noteContent;
}
public void setUserId(Long userId) {
this.userId = userId;
public void setNoteContent(String noteContent) {
this.noteContent = noteContent;
}
public String getType() {
return type;
@Column(nullable = false)
public Long getPaperId() {
return paperId;
}
public void setType(String type) {
this.type = type;
public void setPaperId(Long paperId) {
this.paperId = paperId;
}
public String getText() {
return text;
@Column(nullable = false)
public String getUserName() {
return userName;
}
public void setText(String text) {
this.text = text;
public void setUserName(String userName) {
this.userName = userName;
}
}

@ -0,0 +1,69 @@
package com.bupt.note.Model;
import javax.persistence.*;
@Entity
@Table(name = "sys_paper_note")
public class PaperNote {
private Long id;
private Long fileId;
private Long paperId;
private String filePath;
private String urlPath;
private String userName;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(nullable = false)
public Long getFileId() {
return fileId;
}
public void setFileId(Long fileId) {
this.fileId = fileId;
}
@Column(nullable = false)
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
@Column(nullable = false)
public String getUrlPath() {
return urlPath;
}
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}
@Column(nullable = false)
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Column(nullable = false)
public Long getPaperId() {
return paperId;
}
public void setPaperId(Long paperId) {
this.paperId = paperId;
}
}

@ -1,15 +1,9 @@
package com.bupt.note.Repository;
import com.bupt.note.Model.Note;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface NoteRepository extends CrudRepository<Note, Long> {
@Override
Optional<Note> findById(Long id);
public interface NoteRepository extends JpaRepository<Note, String>, JpaSpecificationExecutor<Note> {
List<Note> findByDocId(Long id);
int countByDocId(Long id);
void deleteById(Long id);
}

@ -0,0 +1,9 @@
package com.bupt.note.Repository;
import com.bupt.note.Model.PaperNote;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PaperNoteRepository extends JpaRepository<PaperNote, Long> {
boolean existsByPaperIdAndUserName(Long paperId, String userName);
PaperNote findByPaperIdAndUserName(Long paperId, String userName);
}

@ -0,0 +1,31 @@
package com.bupt.note.dto;
public class DeleteNote {
private String noteId;
private Long paperId;
private String content;
public String getNoteId() {
return noteId;
}
public void setNoteId(String noteId) {
this.noteId = noteId;
}
public Long getPaperId() {
return paperId;
}
public void setPaperId(Long paperId) {
this.paperId = paperId;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

@ -0,0 +1,72 @@
package com.bupt.note.dto;
import com.bupt.note.Model.Note;
/**
* 笔记表单
*/
public class NoteForm {
private String noteId;
private String noteTitle;
private String noteContent;
private Long paperId;
private Long fileId;
private String content;
public String getNoteId() {
return noteId;
}
public void setNoteId(String noteId) {
this.noteId = noteId;
}
public String getNoteTitle() {
return noteTitle;
}
public void setNoteTitle(String noteTitle) {
this.noteTitle = noteTitle;
}
public String getNoteContent() {
return noteContent;
}
public void setNoteContent(String noteContent) {
this.noteContent = noteContent;
}
public Long getPaperId() {
return paperId;
}
public void setPaperId(Long paperId) {
this.paperId = paperId;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Long getFileId() {
return fileId;
}
public void setFileId(Long fileId) {
this.fileId = fileId;
}
public Note toNote(){
Note note=new Note();
note.setPaperId(this.paperId);
note.setNoteContent(this.noteContent);
note.setNoteTitle(this.noteTitle);
note.setNoteId(this.noteId);
return note;
}
}

@ -1,7 +1,8 @@
package com.bupt.note.dto;
public class QueryRating {
public class QueryContent {
private Long paperId;
private Long fileId;
public Long getPaperId() {
return paperId;
@ -10,4 +11,12 @@ public class QueryRating {
public void setPaperId(Long paperId) {
this.paperId = paperId;
}
public Long getFileId() {
return fileId;
}
public void setFileId(Long fileId) {
this.fileId = fileId;
}
}

@ -0,0 +1,13 @@
package com.bupt.note.dto;
public class QueryNote {
private Long currentPage;
public Long getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Long currentPage) {
this.currentPage = currentPage;
}
}

@ -0,0 +1,31 @@
package com.bupt.note.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
@Service
public class FileService {
@Value("${spring.resources.static-locations}")
private String txtPath;
private Logger logger = LoggerFactory.getLogger(FileService.class);
public File newFile() throws FileNotFoundException {
File txtDir = new File(URLDecoder.decode(ResourceUtils.getURL("classpath:").getPath(), StandardCharsets.UTF_8) + txtPath.replace("classpath:/", ""));
if (!txtDir.exists() && txtDir.mkdirs()) {
logger.info("成功初始化上传论文目录:" + txtDir.getAbsolutePath());
}
return new File(txtDir, UUID.randomUUID() + ".txt");
}
}

@ -0,0 +1,10 @@
package com.bupt.note;
import org.junit.jupiter.api.Test;
public class MyTest {
@Test
public void test1(){
System.out.println(String.format("%d=%d",1,1L));
}
}

@ -33,4 +33,7 @@ class NoteApplicationTests {
.contentType(MediaType.APPLICATION_JSON);
mvc.perform(builder).andDo(MockMvcResultHandlers.print());
}
}

Loading…
Cancel
Save