From 4bb495d8f95f08960c452034b90d47f07494b705 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Fri, 31 Jul 2020 15:47:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BA=E6=96=87=E8=AF=84?= =?UTF-8?q?=E4=BB=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/db_table.md | 12 +++- .../bupt/note/Controller/PaperController.java | 35 ++++++++- src/main/java/com/bupt/note/Model/Rating.java | 72 +++++++++++++++++++ .../note/Repository/RatingRepository.java | 8 +++ .../java/com/bupt/note/dto/QueryRating.java | 13 ++++ .../java/com/bupt/note/dto/RatingForm.java | 51 +++++++++++++ 6 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/bupt/note/Model/Rating.java create mode 100644 src/main/java/com/bupt/note/Repository/RatingRepository.java create mode 100644 src/main/java/com/bupt/note/dto/QueryRating.java create mode 100644 src/main/java/com/bupt/note/dto/RatingForm.java diff --git a/doc/db_table.md b/doc/db_table.md index 8653414..8d034bc 100644 --- a/doc/db_table.md +++ b/doc/db_table.md @@ -18,7 +18,7 @@ | 列名 | 数据类型 | 约束条件 | 含义 | | ---- | -------- | -------- | ---- | -| id | int | primary key; identity | 论文id | +| id | bigint | primary key; identity | 论文id | | title | varchar | not null | 论文标题 | | type | varchar | not null | 论文类型 | | author | varchar | not null | 论文作者 | @@ -30,6 +30,16 @@ | file_id | bigint | not null | 正文文件id | | user_name | varchar | not null | 上传用户 | +# 论文评价 sys_paper_rating +| 列名 | 数据类型 | 约束条件 | 含义 | +| ---- | -------- | -------- | ---- | +| id | bigint | primary key; identity | 评价id | +| score1 | int | not null | 帮助分 | +| score2 | int | not null | 严谨分 | +| score3 | int | not null | 推荐分 | +| paper_id | bigint | not null | 论文id | +| user_name | varchar | not null | 评价用户 | + # 笔记 Note | 列名 | 数据类型 | 约束条件 | 含义 | diff --git a/src/main/java/com/bupt/note/Controller/PaperController.java b/src/main/java/com/bupt/note/Controller/PaperController.java index b5ac721..ca2e201 100644 --- a/src/main/java/com/bupt/note/Controller/PaperController.java +++ b/src/main/java/com/bupt/note/Controller/PaperController.java @@ -1,12 +1,12 @@ package com.bupt.note.Controller; import com.bupt.note.Model.Paper; +import com.bupt.note.Model.Rating; import com.bupt.note.Repository.PapaerRepository; +import com.bupt.note.Repository.RatingRepository; 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 com.bupt.note.dto.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +29,9 @@ public class PaperController { @Autowired private PapaerRepository papaerRepository; + @Autowired + private RatingRepository ratingRepository; + @PostMapping("upload") public ResponseData upload(@RequestBody UploadPaper uploadPaper, @CookieValue("user") String username) { if (uploadPaper.getFileId() != null && uploadPaper.getYear() != null && StringUtils.isNoneEmpty(uploadPaper.getTitle(),uploadPaper.getType(), @@ -84,4 +87,30 @@ public class PaperController { } } + + @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){ + Rating rating=ratingForm.toRating(); + rating.setUserName(userName); + ratingRepository.save(rating); + if(ratingRepository.existsById(rating.getId())){ + return ResponseDataUtil.buildSuccess(rating); + }else{ + return ResponseDataUtil.buildSuccess(); + } + }else{ + return ResponseDataUtil.buildError(); + } + } + + @GetMapping("findRating") + public ResponseData findRating(Long paperId,@CookieValue("user") String userName){ + if(paperId!=null&&StringUtils.isNotEmpty(userName)){ + Rating rating=ratingRepository.findByPaperIdAndUserName(paperId,userName); + return ResponseDataUtil.buildSuccess(rating); + }else{ + return ResponseDataUtil.buildError(); + } + } } diff --git a/src/main/java/com/bupt/note/Model/Rating.java b/src/main/java/com/bupt/note/Model/Rating.java new file mode 100644 index 0000000..c3a5112 --- /dev/null +++ b/src/main/java/com/bupt/note/Model/Rating.java @@ -0,0 +1,72 @@ +package com.bupt.note.Model; + +import javax.persistence.*; + +/** + * 评价实体 + */ +@Entity +@Table(name = "sys_paper_rating") +public class Rating { + private Long id; + private Integer score1; + private Integer score2; + private Integer score3; + private Long paperId; + 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 Integer getScore1() { + return score1; + } + + public void setScore1(Integer score1) { + this.score1 = score1; + } + + @Column(nullable = false) + public Integer getScore2() { + return score2; + } + + public void setScore2(Integer score2) { + this.score2 = score2; + } + + @Column(nullable = false) + public Integer getScore3() { + return score3; + } + + public void setScore3(Integer score3) { + this.score3 = score3; + } + + @Column(nullable = false) + public Long getPaperId() { + return paperId; + } + + public void setPaperId(Long paperId) { + this.paperId = paperId; + } + + @Column(nullable = false) + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } +} diff --git a/src/main/java/com/bupt/note/Repository/RatingRepository.java b/src/main/java/com/bupt/note/Repository/RatingRepository.java new file mode 100644 index 0000000..58d76bd --- /dev/null +++ b/src/main/java/com/bupt/note/Repository/RatingRepository.java @@ -0,0 +1,8 @@ +package com.bupt.note.Repository; + +import com.bupt.note.Model.Rating; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RatingRepository extends JpaRepository { + Rating findByPaperIdAndUserName(Long paperId, String userName); +} diff --git a/src/main/java/com/bupt/note/dto/QueryRating.java b/src/main/java/com/bupt/note/dto/QueryRating.java new file mode 100644 index 0000000..b53ec56 --- /dev/null +++ b/src/main/java/com/bupt/note/dto/QueryRating.java @@ -0,0 +1,13 @@ +package com.bupt.note.dto; + +public class QueryRating { + private Long paperId; + + public Long getPaperId() { + return paperId; + } + + public void setPaperId(Long paperId) { + this.paperId = paperId; + } +} diff --git a/src/main/java/com/bupt/note/dto/RatingForm.java b/src/main/java/com/bupt/note/dto/RatingForm.java new file mode 100644 index 0000000..9e000d7 --- /dev/null +++ b/src/main/java/com/bupt/note/dto/RatingForm.java @@ -0,0 +1,51 @@ +package com.bupt.note.dto; + +import com.bupt.note.Model.Rating; + +public class RatingForm { + private Integer score1; + private Integer score2; + private Integer score3; + private Long paperId; + + public Integer getScore1() { + return score1; + } + + public void setScore1(Integer score1) { + this.score1 = score1; + } + + public Integer getScore2() { + return score2; + } + + public void setScore2(Integer score2) { + this.score2 = score2; + } + + public Integer getScore3() { + return score3; + } + + public void setScore3(Integer score3) { + this.score3 = score3; + } + + public Long getPaperId() { + return paperId; + } + + public void setPaperId(Long paperId) { + this.paperId = paperId; + } + + public Rating toRating(){ + Rating rating=new Rating(); + rating.setPaperId(this.paperId); + rating.setScore1(this.score1); + rating.setScore2(this.score2); + rating.setScore3(this.score3); + return rating; + } +}