增加推荐接口

pdf
pan 4 years ago
parent febe235802
commit e0163cb0c2
  1. 10
      src/main/java/com/bupt/note/Controller/PaperController.java
  2. 15
      src/main/java/com/bupt/note/Repository/PaperRepository.java
  3. 12
      src/test/java/com/bupt/note/NoteApplicationTests.java

@ -106,6 +106,16 @@ public class PaperController {
}
/**
* 论文推荐
* @return
*/
@GetMapping("recommend")
public ResponseData recommend(){
List<Paper> papers=paperRepository.recommend();
return ResponseDataUtil.buildSuccess(papers);
}
@PostMapping("rating")
public ResponseData rating(@RequestBody RatingForm ratingForm,@CookieValue("user") String userName) {
if(ratingForm.getPaperId()!=null&&ratingForm.getScore1()!=null&&ratingForm.getScore2()!=null&&ratingForm.getScore3()!=null){

@ -3,7 +3,20 @@ package com.bupt.note.Repository;
import com.bupt.note.Model.Paper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
public interface PaperRepository extends JpaRepository<Paper, Long>, JpaSpecificationExecutor<Paper> {
import java.util.List;
public interface PaperRepository extends JpaRepository<Paper, Long>, JpaSpecificationExecutor<Paper> {
@Query(value = "select *\n" +
"from sys_paper\n" +
"where id in (select a.id\n" +
" from (select p.id, sum(r.score1 + r.score2 + r.score3) as score\n" +
" from sys_paper p,\n" +
" sys_paper_rating r\n" +
" where p.id = r.paper_id\n" +
" group by p.id\n" +
" order by score desc\n" +
" limit 10) a)",nativeQuery = true)
List<Paper> recommend();
}

@ -1,5 +1,7 @@
package com.bupt.note;
import com.bupt.note.Model.Paper;
import com.bupt.note.Repository.PaperRepository;
import com.bupt.note.service.FileService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -14,6 +16,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.io.IOException;
import java.util.List;
@SpringBootTest
class NoteApplicationTests {
@ -26,6 +29,9 @@ class NoteApplicationTests {
@Autowired
private FileService fileService;
@Autowired
private PaperRepository paperRepository;
@BeforeEach
public void setUp() {
mvc = MockMvcBuilders.webAppContextSetup(context).build();
@ -45,4 +51,10 @@ class NoteApplicationTests {
public void testRead() throws IOException {
String a= fileService.getContent("E:\\JetBrains\\IdeaProjects\\back-end code\\target\\classes\\resources\\static\\txt\\1aee7062-58a7-46e0-ba4d-84a9a14f4205.txt");
}
@Test
public void testPaper(){
List<Paper> papers=paperRepository.recommend();
System.out.println(papers.size());
}
}

Loading…
Cancel
Save