增加论文查询接口

pdf
pan 4 years ago
parent a2458e3871
commit 493605c56c
  1. 1
      doc/db_table.md
  2. 49
      src/main/java/com/bupt/note/Controller/PaperController.java
  3. 10
      src/main/java/com/bupt/note/Model/Paper.java
  4. 5
      src/main/java/com/bupt/note/NoteApplication.java
  5. 17
      src/main/java/com/bupt/note/Properties/FileProperties.java
  6. 3
      src/main/java/com/bupt/note/Repository/PapaerRepository.java
  7. 25
      src/main/java/com/bupt/note/dto/Page.java
  8. 70
      src/main/java/com/bupt/note/dto/QueryPaper.java
  9. 10
      src/main/java/com/bupt/note/dto/UploadPaper.java

@ -18,6 +18,7 @@
| 列名 | 数据类型 | 约束条件 | 含义 |
| ---- | -------- | -------- | ---- |
| id | int | primary key; identity | 论文id |
| title | varchar | not null | 论文标题 |
| type | varchar | not null | 论文类型 |
| author | varchar | not null | 论文作者 |
| profession | varchar | not null | 学科专业 |

@ -4,11 +4,19 @@ import com.bupt.note.Model.Paper;
import com.bupt.note.Repository.PapaerRepository;
import com.bupt.note.ResponseData.ResponseData;
import com.bupt.note.ResponseData.ResponseDataUtil;
import com.bupt.note.dto.Page;
import com.bupt.note.dto.QueryPaper;
import com.bupt.note.dto.UploadPaper;
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 javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
/**
* 论文管理接口
*/
@ -16,12 +24,14 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping(value = "/v1/api/paper")
public class PaperController {
private Logger logger= LoggerFactory.getLogger(PaperController.class);
@Autowired
private PapaerRepository papaerRepository;
@PostMapping("upload")
public ResponseData upload(@RequestBody UploadPaper uploadPaper, @CookieValue("user") String username) {
if (uploadPaper.getFileId() != null && uploadPaper.getYear() != null && StringUtils.isNoneEmpty(uploadPaper.getType(),
if (uploadPaper.getFileId() != null && uploadPaper.getYear() != null && StringUtils.isNoneEmpty(uploadPaper.getTitle(),uploadPaper.getType(),
uploadPaper.getAuthor(), uploadPaper.getProfession(), uploadPaper.getSchool(), uploadPaper.getSummary(),uploadPaper.getTag())){
Paper paper = uploadPaper.toPaper();
paper.setUserName(username);
@ -36,5 +46,42 @@ public class PaperController {
}
}
@GetMapping("list")
public ResponseData list(QueryPaper queryPaper){
try {
Page<Paper> list=new Page<>();
list.setTotal(papaerRepository.count());
List<Paper> papers = papaerRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
if(StringUtils.isNotEmpty(queryPaper.getTitle())){
predicates.add(criteriaBuilder.like(root.get("title"),"%"+queryPaper.getTitle()+"%"));
}
if(StringUtils.isNotEmpty(queryPaper.getAuthor())){
predicates.add(criteriaBuilder.like(root.get("author"),"%"+queryPaper.getAuthor()+"%"));
}
if(StringUtils.isNotEmpty(queryPaper.getTag())){
predicates.add(criteriaBuilder.like(root.get("tag"),"%"+queryPaper.getTag()+"%"));
}
if(StringUtils.isNotEmpty(queryPaper.getProfession())){
predicates.add(criteriaBuilder.like(root.get("profession"),"%"+queryPaper.getTag()+"%"));
}
if(queryPaper.getStartYear()!=null&&queryPaper.getEndYear()==null){
predicates.add(criteriaBuilder.ge(root.get("year"),queryPaper.getStartYear()));
}else if(queryPaper.getStartYear()==null&&queryPaper.getEndYear()!=null){
predicates.add(criteriaBuilder.le(root.get("year"),queryPaper.getEndYear()));
}else if(queryPaper.getStartYear()!=null&&queryPaper.getEndYear()!=null){
predicates.add(criteriaBuilder.between(root.get("year"),queryPaper.getStartYear(),queryPaper.getEndYear()));
}
return criteriaQuery.where(predicates.toArray(new Predicate[0])).getRestriction();
});
list.setData(papers);
return ResponseDataUtil.buildSuccess(list);
} catch (Exception e) {
e.printStackTrace();
logger.error(String.valueOf(e));
return ResponseDataUtil.buildError();
}
}
}

@ -10,6 +10,7 @@ import javax.persistence.*;
public class Paper {
private Long id;
private String title;
private String type;
private String author;
private String profession;
@ -30,6 +31,15 @@ public class Paper {
this.id = id;
}
@Column(nullable = false)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Column(nullable = false)
public String getType() {
return type;

@ -1,14 +1,9 @@
package com.bupt.note;
import com.bupt.note.Properties.FileProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties({
FileProperties.class
})
public class NoteApplication {
public static void main(String[] args) {

@ -1,17 +0,0 @@
package com.bupt.note.Properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "file")
public class FileProperties {
private String uploadDir;
public String getUploadDir() {
return uploadDir;
}
public void setUploadDir(String uploadDir) {
this.uploadDir = uploadDir;
}
}

@ -2,6 +2,7 @@ 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;
public interface PapaerRepository extends JpaRepository<Paper, Long> {
public interface PapaerRepository extends JpaRepository<Paper, Long>, JpaSpecificationExecutor<Paper> {
}

@ -0,0 +1,25 @@
package com.bupt.note.dto;
import java.util.List;
public class Page<T> {
private List<T> data;
private Long total;
public List<T> getData() {
return data;
}
public void setData(List<T> data) {
this.data = data;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
}

@ -0,0 +1,70 @@
package com.bupt.note.dto;
/**
* 论文查询
*/
public class QueryPaper {
private String title;
private String type;
private String author;
private String profession;
private String tag;
private Integer startYear;
private Integer endYear;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public Integer getStartYear() {
return startYear;
}
public void setStartYear(Integer startYear) {
this.startYear = startYear;
}
public Integer getEndYear() {
return endYear;
}
public void setEndYear(Integer endYear) {
this.endYear = endYear;
}
}

@ -3,6 +3,7 @@ package com.bupt.note.dto;
import com.bupt.note.Model.Paper;
public class UploadPaper {
private String title;
private String type;
private String author;
private String profession;
@ -12,6 +13,14 @@ public class UploadPaper {
private String tag;
private Long fileId;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getType() {
return type;
}
@ -78,6 +87,7 @@ public class UploadPaper {
public Paper toPaper(){
Paper paper=new Paper();
paper.setTitle(this.title);
paper.setType(this.type);
paper.setAuthor(this.author);
paper.setProfession(this.profession);

Loading…
Cancel
Save