|
|
@ -1,9 +1,11 @@ |
|
|
|
package com.bupt.note.Controller; |
|
|
|
package com.bupt.note.Controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.bupt.note.Model.Note; |
|
|
|
import com.bupt.note.Model.Note; |
|
|
|
|
|
|
|
import com.bupt.note.Model.Paper; |
|
|
|
import com.bupt.note.Model.PaperNote; |
|
|
|
import com.bupt.note.Model.PaperNote; |
|
|
|
import com.bupt.note.Repository.NoteRepository; |
|
|
|
import com.bupt.note.Repository.NoteRepository; |
|
|
|
import com.bupt.note.Repository.PaperNoteRepository; |
|
|
|
import com.bupt.note.Repository.PaperNoteRepository; |
|
|
|
|
|
|
|
import com.bupt.note.Repository.PaperRepository; |
|
|
|
import com.bupt.note.ResponseData.ResponseData; |
|
|
|
import com.bupt.note.ResponseData.ResponseData; |
|
|
|
import com.bupt.note.ResponseData.ResponseDataUtil; |
|
|
|
import com.bupt.note.ResponseData.ResponseDataUtil; |
|
|
|
import com.bupt.note.dto.DeleteNote; |
|
|
|
import com.bupt.note.dto.DeleteNote; |
|
|
@ -23,6 +25,7 @@ import java.io.IOException; |
|
|
|
import java.io.Writer; |
|
|
|
import java.io.Writer; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
@RestController |
|
|
|
@RestController |
|
|
|
@RequestMapping(value = "/v1/api/notes") |
|
|
|
@RequestMapping(value = "/v1/api/notes") |
|
|
@ -34,6 +37,9 @@ public class NoteController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private PaperNoteRepository paperNoteRepository; |
|
|
|
private PaperNoteRepository paperNoteRepository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private PaperRepository paperRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private FileService fileService; |
|
|
|
private FileService fileService; |
|
|
|
|
|
|
|
|
|
|
@ -107,8 +113,8 @@ public class NoteController { |
|
|
|
* @param username |
|
|
|
* @param username |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@GetMapping("list/{id}") |
|
|
|
@GetMapping({"list/{id}","list"}) |
|
|
|
public ResponseData list(@PathVariable("id") Long paperId,@CookieValue("user") String username) { |
|
|
|
public ResponseData list(@PathVariable(value = "id",required = false) Long paperId,NoteForm noteForm,@CookieValue("user") String username) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Page<Note> list = new Page<>(); |
|
|
|
Page<Note> list = new Page<>(); |
|
|
|
list.setTotal(noteRepository.count()); |
|
|
|
list.setTotal(noteRepository.count()); |
|
|
@ -117,9 +123,21 @@ public class NoteController { |
|
|
|
if (StringUtils.isNotEmpty(username)) { |
|
|
|
if (StringUtils.isNotEmpty(username)) { |
|
|
|
predicates.add(criteriaBuilder.equal(root.get("userName"), username)); |
|
|
|
predicates.add(criteriaBuilder.equal(root.get("userName"), username)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(noteForm.getNoteTitle())){ |
|
|
|
|
|
|
|
predicates.add(criteriaBuilder.like(root.get("noteTitle"),"%"+noteForm.getNoteTitle()+"%")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(noteForm.getNoteContent())){ |
|
|
|
|
|
|
|
predicates.add(criteriaBuilder.like(root.get("noteContent"),"%"+noteForm.getNoteContent()+"%")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(paperId!=null) { |
|
|
|
predicates.add(criteriaBuilder.equal(root.get("paperId"), paperId)); |
|
|
|
predicates.add(criteriaBuilder.equal(root.get("paperId"), paperId)); |
|
|
|
|
|
|
|
} |
|
|
|
return criteriaQuery.where(predicates.toArray(new Predicate[0])).getRestriction(); |
|
|
|
return criteriaQuery.where(predicates.toArray(new Predicate[0])).getRestriction(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
noteList.forEach(note -> { |
|
|
|
|
|
|
|
Optional<Paper> paper=paperRepository.findById(note.getPaperId()); |
|
|
|
|
|
|
|
paper.ifPresent(note::setPaper); |
|
|
|
|
|
|
|
}); |
|
|
|
list.setData(noteList); |
|
|
|
list.setData(noteList); |
|
|
|
return ResponseDataUtil.buildSuccess(list); |
|
|
|
return ResponseDataUtil.buildSuccess(list); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|