增加论文评价接口

pdf
pan 4 years ago
parent 51a3439939
commit 4bb495d8f9
  1. 12
      doc/db_table.md
  2. 35
      src/main/java/com/bupt/note/Controller/PaperController.java
  3. 72
      src/main/java/com/bupt/note/Model/Rating.java
  4. 8
      src/main/java/com/bupt/note/Repository/RatingRepository.java
  5. 13
      src/main/java/com/bupt/note/dto/QueryRating.java
  6. 51
      src/main/java/com/bupt/note/dto/RatingForm.java

@ -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
| 列名 | 数据类型 | 约束条件 | 含义 |

@ -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();
}
}
}

@ -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;
}
}

@ -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, Long> {
Rating findByPaperIdAndUserName(Long paperId, String userName);
}

@ -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;
}
}

@ -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;
}
}
Loading…
Cancel
Save