diff --git a/doc/db_table.md b/doc/db_table.md
index fe17700..e583820 100644
--- a/doc/db_table.md
+++ b/doc/db_table.md
@@ -1,55 +1,32 @@
-# 用户表 User
+# 用户表 sys_user
| 列名 | 数据类型 | 约束条件 | 含义 |
| ---- | -------- | -------- | ---- |
-| id | bigint | primary key; identity | 用户编号 |
+| id | bigint | primary key; identity | 用户id |
| user_name | varchar | not null | 用户名 |
| password | varchar | not null | 密码 |
-| | | | |
-
-# 论文 Paper
-
-| 列名 | 数据类型 | 约束条件 | 含义 |
-| ---- | -------- | -------- | ---- |
-| Pid | int | primary key; identity | 文章编号 |
-| Ptitle | varchar | not null | 文章标题 |
-| Ptime | date | | 发表时间 |
-
-
-# 作者 Author
-
-| 列名 | 数据类型 | 约束条件 | 含义 |
-| ---- | -------- | -------- | ---- |
-| Aid | int | primary key; identity | 作者编号 |
-| Aname | varchar | not null | 作者姓名 |
-
-
-# 论文作者关系 PaperAuthor
-
-| 列名 | 数据类型 | 约束条件 | 含义 |
-| ---- | -------- | -------- | ---- |
-| PAid | int | primary key; identity | 编号 |
-| Aid | int | foreign key | 作者编号 |
-| Pid | int | foreign key | 文章编号 |
-
-
-# 标签 Tag
+# 论文文件表 sys_file
| 列名 | 数据类型 | 约束条件 | 含义 |
| ---- | -------- | -------- | ---- |
-| Tid | int | primary key; identity | 标签编号 |
-| Tname | varchar | not null | 标签描述 |
-
+| id | bigint | primary key; identity | 文件id |
+| file_path | varchar | not null | 文件路径 |
-# 论文标签 PaperTag
+# 论文 sys_paper
| 列名 | 数据类型 | 约束条件 | 含义 |
| ---- | -------- | -------- | ---- |
-| PTid | int | primary key; identity | 编号 |
-| Pid | int | foreign key | 文章编号 |
-| Tid | int | foreign key | 标签编号 |
-
+| id | int | primary key; identity | 论文id |
+| type | varchar | not null | 论文类型 |
+| author | varchar | not null | 论文作者 |
+| profession | varchar | not null | 学科专业 |
+| school | varchar | not null | 学校 |
+| year | int | not null | 学位年度 |
+| summary | varchar | not null | 摘要 |
+| tag | varchar | not null | 论文标签 |
+| file_id | bigint | not null | 正文文件id |
+| user_name | varchar | not null | 上传用户 |
# 笔记 Note
diff --git a/pom.xml b/pom.xml
index 3c2071f..74acc4f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,13 +56,12 @@
1.2.12
-
- commons-io
- commons-io
- 2.6
+ org.apache.commons
+ commons-lang3
+
@@ -74,6 +73,14 @@
false
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 10
+
+
diff --git a/src/main/java/com/bupt/note/Controller/FileController.java b/src/main/java/com/bupt/note/Controller/FileController.java
new file mode 100644
index 0000000..129cc94
--- /dev/null
+++ b/src/main/java/com/bupt/note/Controller/FileController.java
@@ -0,0 +1,93 @@
+package com.bupt.note.Controller;
+
+import com.bupt.note.Repository.FileRepository;
+import com.bupt.note.ResponseData.ResponseData;
+import com.bupt.note.ResponseData.ResponseDataUtil;
+import com.bupt.note.dto.FileForm;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.MediaType;
+import org.springframework.util.ResourceUtils;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+import java.util.UUID;
+
+/**
+ * 论文文本管理接口
+ */
+@RestController
+@RequestMapping(value = "/v1/api/file")
+public class FileController {
+
+ @Value("${spring.resources.static-locations}")
+ private String txtPath;
+
+ private static Logger logger = LoggerFactory.getLogger(FileController.class);
+
+ @Autowired
+ private FileRepository fileRepository;
+
+ //上传论文文本
+ @PostMapping("upload")
+ public ResponseData upload(FileForm fileForm){
+ MultipartFile file=fileForm.getFile();
+ if(file!=null&& MediaType.TEXT_PLAIN_VALUE.equals(file.getContentType())){
+
+ File txtFile;
+ File txtDir;
+ try {
+ txtDir=new File(URLDecoder.decode(ResourceUtils.getURL("classpath:").getPath(), StandardCharsets.UTF_8) + txtPath.replace("classpath:/", ""));
+
+ if(!txtDir.exists()&&txtDir.mkdirs()){
+ logger.info("成功初始化上传论文目录:"+txtDir.getAbsolutePath());
+ }
+ txtFile=new File(txtDir, UUID.randomUUID()+".txt");
+ logger.debug("论文保存到"+txtFile.getAbsolutePath());
+ file.transferTo(txtFile);
+ com.bupt.note.Model.File f=new com.bupt.note.Model.File();
+ f.setFilePath(txtFile.getAbsolutePath());
+ fileRepository.save(f);
+ return ResponseDataUtil.buildSuccess(f.getId());
+ } catch (IOException e) {
+ logger.error(String.valueOf(e));
+ e.printStackTrace();
+ return ResponseDataUtil.buildError();
+ }
+ }else{
+ return ResponseDataUtil.buildError();
+ }
+ }
+
+ /**
+ * 删除论文文本文件
+ * @param id 文件id
+ * @return
+ */
+ @DeleteMapping("remove/{id}")
+ public ResponseData remove(@PathVariable Long id){
+ if(fileRepository.existsById(id)){
+ Optional f=fileRepository.findById(id);
+ if(f.isPresent()){
+ File txtFile=new File(f.get().getFilePath());
+ if(txtFile.exists()&&txtFile.delete()) {
+ fileRepository.deleteById(id);
+ return ResponseDataUtil.buildSuccess();
+ }else{
+ return ResponseDataUtil.buildError();
+ }
+ }else {
+ return ResponseDataUtil.buildError();
+ }
+ }else{
+ return ResponseDataUtil.buildError();
+ }
+ }
+}
diff --git a/src/main/java/com/bupt/note/Controller/PaperController.java b/src/main/java/com/bupt/note/Controller/PaperController.java
new file mode 100644
index 0000000..c1f2832
--- /dev/null
+++ b/src/main/java/com/bupt/note/Controller/PaperController.java
@@ -0,0 +1,40 @@
+package com.bupt.note.Controller;
+
+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.UploadPaper;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 论文管理接口
+ */
+@RestController
+@RequestMapping(value = "/v1/api/paper")
+public class PaperController {
+
+ @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(),
+ uploadPaper.getAuthor(), uploadPaper.getProfession(), uploadPaper.getSchool(), uploadPaper.getSummary(),uploadPaper.getTag())){
+ Paper paper = uploadPaper.toPaper();
+ paper.setUserName(username);
+ papaerRepository.save(paper);
+ if(papaerRepository.existsById(paper.getId())){
+ return ResponseDataUtil.buildSuccess();
+ }else{
+ return ResponseDataUtil.buildError();
+ }
+ }else{
+ return ResponseDataUtil.buildError();
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/bupt/note/Controller/SignUpController.java b/src/main/java/com/bupt/note/Controller/SignUpController.java
deleted file mode 100644
index b971ab2..0000000
--- a/src/main/java/com/bupt/note/Controller/SignUpController.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.bupt.note.Controller;
-
-import com.bupt.note.Model.User;
-import com.bupt.note.Repository.UserRepository;
-import com.bupt.note.ResponseData.ResponseData;
-import com.bupt.note.ResponseData.ResponseDataUtil;
-import com.bupt.note.ResponseData.ResultEnums;
-import com.bupt.note.dto.UserForm;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-@RequestMapping(value = "/v1/api")
-public class SignUpController {
-
- @Autowired
- UserRepository userRepository;
-
- @RequestMapping("/sign_up")
- public ResponseData signUp(@RequestBody UserForm user) {
- // 用来创建User(即注册)
- User exist = userRepository.findByUserName(user.getUserName());
- if (exist == null) {
- userRepository.save(user.getUser());
- User u = userRepository.findByUserName(user.getUserName());
- return ResponseDataUtil.buildSuccess(u);
- }
- return ResponseDataUtil.buildError(ResultEnums.ErrUserNameConflict);
- }
-}
diff --git a/src/main/java/com/bupt/note/Controller/UserController.java b/src/main/java/com/bupt/note/Controller/UserController.java
index e4519d4..e683b08 100644
--- a/src/main/java/com/bupt/note/Controller/UserController.java
+++ b/src/main/java/com/bupt/note/Controller/UserController.java
@@ -5,11 +5,16 @@ import com.bupt.note.Repository.UserRepository;
import com.bupt.note.ResponseData.ResponseData;
import com.bupt.note.ResponseData.ResponseDataUtil;
import com.bupt.note.ResponseData.ResultEnums;
+import com.bupt.note.dto.UserForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
-import java.util.*;
+import java.util.List;
+import java.util.Optional;
+/**
+ * 用户接口
+ */
@RestController
@RequestMapping(value = "/v1/api/users")
public class UserController {
@@ -17,6 +22,37 @@ public class UserController {
@Autowired
UserRepository userRepository;
+ /**
+ * 注册用户
+ * @param user 用户信息
+ * @return
+ */
+ @PostMapping("/sign_up")
+ public ResponseData signUp(@RequestBody UserForm user) {
+ User exist = userRepository.findByUserName(user.getUserName());
+ if (exist == null) {
+ userRepository.save(user.getUser());
+ User u = userRepository.findByUserName(user.getUserName());
+ return ResponseDataUtil.buildSuccess(u);
+ }
+ return ResponseDataUtil.buildError(ResultEnums.ErrUserNameConflict);
+ }
+
+ /**
+ * 登录用户
+ * @param user 用户信息
+ * @return
+ */
+ @PostMapping("/sign_in")
+ public ResponseData signIn(@RequestBody UserForm user){
+ User exist = userRepository.findByUserName(user.getUserName());
+ if(exist==null||!exist.getPassword().equals(user.getPassword())){
+ return ResponseDataUtil.buildError(ResultEnums.ERROR);
+ }else {
+ return ResponseDataUtil.buildSuccess(ResultEnums.SUCCESS);
+ }
+ }
+
@RequestMapping(method=RequestMethod.GET)
public ResponseData> getUserList() {
// 处理"/users/"的GET请求,用来获取用户列表
diff --git a/src/main/java/com/bupt/note/Model/File.java b/src/main/java/com/bupt/note/Model/File.java
index b8f244c..25c6dc5 100644
--- a/src/main/java/com/bupt/note/Model/File.java
+++ b/src/main/java/com/bupt/note/Model/File.java
@@ -2,26 +2,17 @@ package com.bupt.note.Model;
import javax.persistence.*;
+/**
+ * 论文文本实体
+ */
@Entity
@Table(name = "sys_file")
public class File {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long Id;
- @Column(nullable = false)
- private Long ownerId;
- @Column(nullable = false)
- private String fileName;
-
- public File() {
- super();
- }
- public File(Long ownerId, String fileName) {
- this.ownerId = ownerId;
- this.fileName = fileName;
- }
+ private Long Id;
+ private String filePath;
+ @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return Id;
@@ -31,19 +22,13 @@ public class File {
Id = id;
}
- public Long getOwnerId() {
- return ownerId;
- }
-
- public void setOwnerId(Long ownerId) {
- this.ownerId = ownerId;
+ @Column(nullable = false)
+ public String getFilePath() {
+ return filePath;
}
- public String getFileName() {
- return fileName;
+ public void setFilePath(String filePath) {
+ this.filePath = filePath;
}
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
}
diff --git a/src/main/java/com/bupt/note/Model/Paper.java b/src/main/java/com/bupt/note/Model/Paper.java
new file mode 100644
index 0000000..1a2fc53
--- /dev/null
+++ b/src/main/java/com/bupt/note/Model/Paper.java
@@ -0,0 +1,114 @@
+package com.bupt.note.Model;
+
+import javax.persistence.*;
+
+/**
+ * 论文实体
+ */
+@Entity
+@Table(name = "sys_paper")
+public class Paper {
+
+ private Long id;
+ private String type;
+ private String author;
+ private String profession;
+ private String school;
+ private Integer year;
+ private String summary;
+ private String tag;
+ private Long fileId;
+ 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 String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @Column(nullable = false)
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ @Column(nullable = false)
+ public String getProfession() {
+ return profession;
+ }
+
+ public void setProfession(String profession) {
+ this.profession = profession;
+ }
+
+ @Column(nullable = false)
+ public String getSchool() {
+ return school;
+ }
+
+ public void setSchool(String school) {
+ this.school = school;
+ }
+
+ @Column(nullable = false)
+ public Integer getYear() {
+ return year;
+ }
+
+ public void setYear(Integer year) {
+ this.year = year;
+ }
+
+ @Column(nullable = false)
+ public String getSummary() {
+ return summary;
+ }
+
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+
+ @Column(nullable = false)
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ @Column(nullable = false)
+ public Long getFileId() {
+ return fileId;
+ }
+
+ public void setFileId(Long fileId) {
+ this.fileId = fileId;
+ }
+
+ @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/Model/User.java b/src/main/java/com/bupt/note/Model/User.java
index 9812243..24e6daa 100644
--- a/src/main/java/com/bupt/note/Model/User.java
+++ b/src/main/java/com/bupt/note/Model/User.java
@@ -3,6 +3,9 @@ package com.bupt.note.Model;
import javax.persistence.*;
import java.io.Serializable;
+/*
+用户实体
+ */
@Entity
@Table(name = "sys_user")
public class User implements Serializable {
diff --git a/src/main/java/com/bupt/note/Repository/FileRepository.java b/src/main/java/com/bupt/note/Repository/FileRepository.java
index 96baefa..23ce4ad 100644
--- a/src/main/java/com/bupt/note/Repository/FileRepository.java
+++ b/src/main/java/com/bupt/note/Repository/FileRepository.java
@@ -3,11 +3,6 @@ package com.bupt.note.Repository;
import com.bupt.note.Model.File;
import org.springframework.data.jpa.repository.JpaRepository;
-import java.util.Optional;
-
public interface FileRepository extends JpaRepository {
- @Override
- Optional findById(Long id);
- void deleteById(Long id);
}
diff --git a/src/main/java/com/bupt/note/Repository/PapaerRepository.java b/src/main/java/com/bupt/note/Repository/PapaerRepository.java
new file mode 100644
index 0000000..98b252b
--- /dev/null
+++ b/src/main/java/com/bupt/note/Repository/PapaerRepository.java
@@ -0,0 +1,7 @@
+package com.bupt.note.Repository;
+
+import com.bupt.note.Model.Paper;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface PapaerRepository extends JpaRepository {
+}
diff --git a/src/main/java/com/bupt/note/Repository/UserRepository.java b/src/main/java/com/bupt/note/Repository/UserRepository.java
index 98ab6f2..bbe21cc 100644
--- a/src/main/java/com/bupt/note/Repository/UserRepository.java
+++ b/src/main/java/com/bupt/note/Repository/UserRepository.java
@@ -3,15 +3,7 @@ package com.bupt.note.Repository;
import com.bupt.note.Model.User;
import org.springframework.data.jpa.repository.JpaRepository;
-import java.util.List;
-import java.util.Optional;
-
public interface UserRepository extends JpaRepository {
User findByUserName(String userName);
void deleteByUserName(String userName);
-
- @Override
- Optional findById(Long integer);
-
- List findAll();
}
diff --git a/src/main/java/com/bupt/note/dto/FileForm.java b/src/main/java/com/bupt/note/dto/FileForm.java
new file mode 100644
index 0000000..26b375e
--- /dev/null
+++ b/src/main/java/com/bupt/note/dto/FileForm.java
@@ -0,0 +1,18 @@
+package com.bupt.note.dto;
+
+import org.springframework.web.multipart.MultipartFile;
+
+public class FileForm {
+
+
+ private MultipartFile file;
+
+ public MultipartFile getFile() {
+ return file;
+ }
+
+ public void setFile(MultipartFile file) {
+ this.file = file;
+ }
+
+}
diff --git a/src/main/java/com/bupt/note/dto/UploadPaper.java b/src/main/java/com/bupt/note/dto/UploadPaper.java
new file mode 100644
index 0000000..cb248b9
--- /dev/null
+++ b/src/main/java/com/bupt/note/dto/UploadPaper.java
@@ -0,0 +1,91 @@
+package com.bupt.note.dto;
+
+import com.bupt.note.Model.Paper;
+
+public class UploadPaper {
+ private String type;
+ private String author;
+ private String profession;
+ private String school;
+ private Integer year;
+ private String summary;
+ private String tag;
+ private Long fileId;
+
+ 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 getSchool() {
+ return school;
+ }
+
+ public void setSchool(String school) {
+ this.school = school;
+ }
+
+ public Integer getYear() {
+ return year;
+ }
+
+ public void setYear(Integer year) {
+ this.year = year;
+ }
+
+ public String getSummary() {
+ return summary;
+ }
+
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ public Long getFileId() {
+ return fileId;
+ }
+
+ public void setFileId(Long fileId) {
+ this.fileId = fileId;
+ }
+
+ public Paper toPaper(){
+ Paper paper=new Paper();
+ paper.setType(this.type);
+ paper.setAuthor(this.author);
+ paper.setProfession(this.profession);
+ paper.setSchool(this.school);
+ paper.setYear(this.year);
+ paper.setSummary(this.summary);
+ paper.setTag(this.tag);
+ paper.setFileId(this.fileId);
+ return paper;
+ }
+}
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index b61021a..18fab79 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -7,11 +7,10 @@ spring:
hibernate:
ddl-auto: update
show-sql: true
- servlet:
- multipart:
- max-file-size: 100MB
- max-request-size: 200MB
- enabled: true
- file-size-threshold: 2KB
+ #静态资源目录
+ mvc:
+ static-path-pattern: /txt/**
+ resources:
+ static-locations: classpath:/resources/static/txt
file:
upload-dir: note_file/
\ No newline at end of file