wiki评论点赞

This commit is contained in:
暮光:城中城
2019-03-06 22:17:57 +08:00
parent 7d8fa1ff82
commit 3c29cac2d7
15 changed files with 184 additions and 84 deletions

View File

@@ -2,12 +2,14 @@ package com.zyplayer.doc.wiki.controller;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.data.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -43,7 +45,6 @@ public class WikiCommonController {
@PostMapping("/upload")
public ResponseJson<Object> upload(WikiPageFile wikiPageFile, @RequestParam("files") MultipartFile file) {
//通过CommonsMultipartFile的方法直接写文件注意这个时候
String fileName = file.getOriginalFilename();
String fileSuffix = "";
if (fileName != null && fileName.lastIndexOf(".") >= 0) {
@@ -55,7 +56,8 @@ public class WikiCommonController {
if (!newFile.exists() && !newFile.mkdir()) {
return DocResponseJson.warn("创建文件夹失败");
}
path += RandomUtil.simpleUUID() + fileSuffix;
String simpleUUID = RandomUtil.simpleUUID();
path += simpleUUID + fileSuffix;
newFile = new File(path);
try {
file.transferTo(newFile);
@@ -63,6 +65,7 @@ public class WikiCommonController {
e.printStackTrace();
return DocResponseJson.warn("保存文件失败");
}
wikiPageFile.setUuid(simpleUUID);
wikiPageFile.setFileUrl(path);
wikiPageFile.setFileName(fileName);
wikiPageFile.setCreateTime(new Date());
@@ -70,16 +73,18 @@ public class WikiCommonController {
wikiPageFile.setCreateUserName(currentUser.getUsername());
wikiPageFile.setDelFlag(0);
wikiPageFileService.save(wikiPageFile);
wikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + wikiPageFile.getId());
wikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + wikiPageFile.getUuid());
return DocResponseJson.ok(wikiPageFile);
}
@GetMapping("/file")
public ResponseJson<Object> file(Long fileId, HttpServletResponse response) {
if (fileId == null || fileId <= 0) {
public ResponseJson<Object> file(String uuid, HttpServletResponse response) {
if (StringUtils.isBlank(uuid)) {
return DocResponseJson.warn("请指定文件ID");
}
WikiPageFile pageFile = wikiPageFileService.getById(fileId);
UpdateWrapper<WikiPageFile> wrapperFile = new UpdateWrapper<>();
wrapperFile.eq("uuid", uuid);
WikiPageFile pageFile = wikiPageFileService.getOne(wrapperFile);
if (pageFile == null) {
return DocResponseJson.warn("未找到指定文件");
}

View File

@@ -49,9 +49,10 @@ public class WikiPageCommentController {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
pageComment.setCreateTime(new Date());
pageComment.setCreateUserId(currentUser.getUserId());
pageComment.setCreateUserName(currentUser.getUsername());
wikiPageCommentService.save(pageComment);
}
return DocResponseJson.ok();
return DocResponseJson.ok(pageComment);
}
}

View File

@@ -71,7 +71,7 @@ public class WikiPageController {
wrapperFile.eq("del_flag", 0);
List<WikiPageFile> pageFiles = wikiPageFileService.list(wrapperFile);
for (WikiPageFile pageFile : pageFiles) {
pageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + pageFile.getId());
pageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + pageFile.getUuid());
}
UpdateWrapper<WikiPageZan> wrapperZan = new UpdateWrapper<>();
wrapperZan.eq("page_id", wikiPage.getId());

View File

@@ -1,12 +1,19 @@
package com.zyplayer.doc.wiki.controller;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.data.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
/**
* 文档控制器
@@ -30,23 +37,27 @@ public class WikiPageFileController {
// wrapper.eq("page_id", wikiPageFile.getPageId());
// List<WikiPageFile> fileList = wikiPageFileService.list(wrapper);
// for (WikiPageFile pageFile : fileList) {
// pageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + pageFile.getId());
// pageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + pageFile.getUuid());
// }
// return DocResponseJson.ok(fileList);
// }
//
// @PostMapping("/update")
// public ResponseJson<Object> update(WikiPageFile wikiPageFile) {
// Long id = wikiPageFile.getId();
// if (id != null && id > 0) {
// wikiPageFileService.updateById(wikiPageFile);
// } else {
// DocUserDetails currentUser = DocUserUtil.getCurrentUser();
// wikiPageFile.setCreateTime(new Date());
// wikiPageFile.setCreateUserId(currentUser.getUserId());
// wikiPageFileService.save(wikiPageFile);
// }
// return DocResponseJson.ok();
// }
@PostMapping("/update")
public ResponseJson<Object> update(WikiPageFile wikiPageFile) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
Long id = wikiPageFile.getId();
if (id != null && id > 0) {
wikiPageFile.setUpdateUserId(currentUser.getUserId());
wikiPageFile.setUpdateUserName(currentUser.getUsername());
wikiPageFile.setUpdateTime(new Date());
wikiPageFileService.updateById(wikiPageFile);
} else {
wikiPageFile.setCreateTime(new Date());
wikiPageFile.setCreateUserId(currentUser.getUserId());
wikiPageFile.setCreateUserName(currentUser.getUsername());
wikiPageFileService.save(wikiPageFile);
}
return DocResponseJson.ok();
}
}

View File

@@ -1,5 +1,6 @@
package com.zyplayer.doc.wiki.controller;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageZan;
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* 文档控制器
@@ -26,14 +28,14 @@ public class WikiPageZanController {
@Resource
WikiPageZanService wikiPageZanService;
// @PostMapping("/list")
// public ResponseJson<List<WikiPageZan>> list(WikiPageZan wikiPageZan) {
// UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
// wrapper.eq("page_id", wikiPageZan.getPageId());
// wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
// List<WikiPageZan> zanList = wikiPageZanService.list(wrapper);
// return DocResponseJson.ok(zanList);
// }
@PostMapping("/list")
public ResponseJson<List<WikiPageZan>> list(WikiPageZan wikiPageZan) {
UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
wrapper.eq("page_id", wikiPageZan.getPageId());
wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
List<WikiPageZan> zanList = wikiPageZanService.list(wrapper);
return DocResponseJson.ok(zanList);
}
@PostMapping("/update")
public ResponseJson<Object> update(WikiPageZan wikiPageZan) {