wiki优化

This commit is contained in:
暮光:城中城
2019-03-05 23:15:47 +08:00
parent 7357058694
commit 7d8fa1ff82
20 changed files with 313 additions and 150 deletions

View File

@@ -11,14 +11,17 @@ import com.zyplayer.doc.data.service.manage.WikiPageFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.Date;
/**
@@ -41,30 +44,67 @@ 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) {
fileSuffix = fileName.substring(fileName.lastIndexOf("."));
}
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
File newFile = new File(path);
if (!newFile.exists() && !newFile.mkdir()) {
return DocResponseJson.warn("创建文件夹失败");
}
path += RandomUtil.simpleUUID() + fileSuffix;
newFile = new File(path);
try {
String fileName = file.getOriginalFilename();
String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
File newFile = new File(path);
if (!newFile.exists()) {
newFile.mkdir();
}
path += RandomUtil.simpleUUID() + fileSuffix;
newFile = new File(path);
file.transferTo(newFile);
wikiPageFile.setFileUrl(path);
wikiPageFile.setFileName(fileName);
wikiPageFile.setCreateTime(new Date());
wikiPageFile.setCreateUserId(currentUser.getUserId());
wikiPageFile.setCreateUserName(currentUser.getUsername());
wikiPageFile.setDelFlag(0);
} catch (Exception e) {
e.printStackTrace();
return DocResponseJson.warn("失败");
return DocResponseJson.warn("保存文件失败");
}
wikiPageFile.setFileUrl(path);
wikiPageFile.setFileName(fileName);
wikiPageFile.setCreateTime(new Date());
wikiPageFile.setCreateUserId(currentUser.getUserId());
wikiPageFile.setCreateUserName(currentUser.getUsername());
wikiPageFile.setDelFlag(0);
wikiPageFileService.save(wikiPageFile);
wikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + wikiPageFile.getId());
return DocResponseJson.ok(wikiPageFile);
}
@GetMapping("/file")
public ResponseJson<Object> file(Long fileId, HttpServletResponse response) {
if (fileId == null || fileId <= 0) {
return DocResponseJson.warn("请指定文件ID");
}
WikiPageFile pageFile = wikiPageFileService.getById(fileId);
if (pageFile == null) {
return DocResponseJson.warn("未找到指定文件");
}
try {
String fileName = pageFile.getFileName();
File file = new File(pageFile.getFileUrl());
String contentType = Files.probeContentType(file.toPath());
response.setContentType(contentType);
response.setHeader("Content-disposition", "inline;filename=" + URLEncoder.encode(fileName, "UTF-8"));
// response.setHeader("Content-disposition", "inline;filename=" + fileName);
// response.setHeader("Content-Disposition", "inline; fileName=" + fileName + ";filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8"));
InputStream inputStream = new FileInputStream(file);
OutputStream os = response.getOutputStream();
byte[] b = new byte[2048];
int length;
while ((length = inputStream.read(b)) > 0) {
os.write(b, 0, length);
}
os.close();
inputStream.close();
return null;
} catch (Exception e) {
logger.info("失败:{}", e.getMessage());
}
return DocResponseJson.warn("获取文件失败");
}
}

View File

@@ -8,9 +8,11 @@ import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageContent;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageZan;
import com.zyplayer.doc.data.service.manage.WikiPageContentService;
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
import com.zyplayer.doc.data.service.manage.WikiPageService;
import com.zyplayer.doc.data.service.manage.WikiPageZanService;
import com.zyplayer.doc.wiki.controller.vo.WikiPageContentVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +41,8 @@ public class WikiPageController {
WikiPageContentService wikiPageContentService;
@Resource
WikiPageFileService wikiPageFileService;
@Resource
WikiPageZanService wikiPageZanService;
@PostMapping("/list")
public ResponseJson<List<WikiPage>> list(WikiPage wikiPage) {
@@ -54,21 +58,31 @@ public class WikiPageController {
@PostMapping("/detail")
public ResponseJson<WikiPageContentVo> detail(WikiPage wikiPage) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
WikiPage wikiPageSel = wikiPageService.getById(wikiPage.getId());
UpdateWrapper<WikiPageContent> wrapper = new UpdateWrapper<>();
wrapper.eq("page_id", wikiPage.getId());
WikiPageContent pageContent = wikiPageContentService.getOne(wrapper);
// TODO 检查space是否开放访问
UpdateWrapper<WikiPageFile> wrapperFile = new UpdateWrapper<>();
wrapperFile.eq("page_id", wikiPage.getId());
wrapper.eq("del_flag", 0);
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());
}
UpdateWrapper<WikiPageZan> wrapperZan = new UpdateWrapper<>();
wrapperZan.eq("page_id", wikiPage.getId());
wrapperZan.eq("create_user_id", currentUser.getUserId());
wrapperZan.eq("yn", 1);
WikiPageZan pageZan = wikiPageZanService.getOne(wrapperZan);
WikiPageContentVo vo = new WikiPageContentVo();
vo.setWikiPage(wikiPageSel);
vo.setPageContent(pageContent);
vo.setFileList(pageFiles);
vo.setSelfZan((pageZan != null) ? 1 : 0);
return DocResponseJson.ok(vo);
}

View File

@@ -1,21 +1,12 @@
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.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;
import java.util.List;
/**
* 文档控制器
@@ -31,28 +22,31 @@ public class WikiPageFileController {
@Resource
WikiPageFileService wikiPageFileService;
@PostMapping("/list")
public ResponseJson<List<WikiPageFile>> list(WikiPageFile wikiPageFile) {
// TODO 检查space是否开放访问
UpdateWrapper<WikiPageFile> wrapper = new UpdateWrapper<>();
wrapper.eq("del_flag", 0);
wrapper.eq("page_id", wikiPageFile.getPageId());
List<WikiPageFile> fileList = wikiPageFileService.list(wrapper);
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("/list")
// public ResponseJson<List<WikiPageFile>> list(WikiPageFile wikiPageFile) {
// // TODO 检查space是否开放访问
// UpdateWrapper<WikiPageFile> wrapper = new UpdateWrapper<>();
// wrapper.eq("del_flag", 0);
// 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());
// }
// 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();
// }
}

View File

@@ -1,10 +1,7 @@
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.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageZan;
import com.zyplayer.doc.data.service.manage.WikiPageZanService;
import org.slf4j.Logger;
@@ -14,8 +11,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* 文档控制器
@@ -31,29 +26,18 @@ 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) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
wrapper.eq("create_uid", currentUser.getUserId());
wrapper.eq("page_id", wikiPageZan.getPageId());
wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
WikiPageZan pageZan = wikiPageZanService.getOne(wrapper);
if (pageZan != null) {
return DocResponseJson.warn("您已经赞过了哦~");
}
wikiPageZan.setCreateTime(new Date());
wikiPageZan.setCreateUserId(currentUser.getUserId());
wikiPageZanService.save(wikiPageZan);
wikiPageZanService.zanPage(wikiPageZan);
return DocResponseJson.ok();
}
}

View File

@@ -40,9 +40,9 @@ public class WikiSpaceController {
wrapper.in("type", 1, 2);
} else if(wikiSpace.getType() == 1 || wikiSpace.getType() == 2) {
wrapper.eq(wikiSpace.getType() != null, "type", wikiSpace.getType());
wrapper.eq(Objects.equals(wikiSpace.getType(), 2), "create_uid", wikiSpace.getCreateUserId());
wrapper.eq(Objects.equals(wikiSpace.getType(), 2), "create_user_id", wikiSpace.getCreateUserId());
} else if(wikiSpace.getType() == 3) {
wrapper.eq("create_uid", currentUser.getUserId());
wrapper.eq("create_user_id", currentUser.getUserId());
}
List<WikiSpace> authList = wikiSpaceService.list(wrapper);
return DocResponseJson.ok(authList);

View File

@@ -10,6 +10,7 @@ public class WikiPageContentVo {
private WikiPage wikiPage;
private WikiPageContent pageContent;
private List<WikiPageFile> fileList;
private Integer selfZan;
public WikiPage getWikiPage() {
return wikiPage;
@@ -34,4 +35,12 @@ public class WikiPageContentVo {
public void setFileList(List<WikiPageFile> fileList) {
this.fileList = fileList;
}
public Integer getSelfZan() {
return selfZan;
}
public void setSelfZan(Integer selfZan) {
this.selfZan = selfZan;
}
}

View File

@@ -46,12 +46,14 @@
<!--:before-remove="beforeRemove"-->
<!--:on-exceed="handleExceed"-->
<el-upload
class="upload-demo"
class="upload-page-file"
action="zyplayer-doc-wiki/common/upload"
:on-success="uploadFileSuccess"
name="files"
show-file-list
multiple
:limit="3">
:data="uploadFormData"
:limit="999">
<el-button icon="el-icon-upload">上传附件</el-button>
</el-upload>
</div>
@@ -69,6 +71,25 @@
<div class="wiki-content">
<div v-html="pageContent.content"></div>
</div>
<div style="margin-top: 10px; font-size: 14px;">
<span style="vertical-align: top;" class="is-link">
<img src="webjars/doc-wiki/img/zan.png" style="vertical-align: middle;">
<span v-show="wikiPage.selfZan == 0" v-on:click="zanPage(1)"></span>
<span v-show="wikiPage.selfZan == 1" v-on:click="zanPage(0)"></span>
</span>
<span style="margin-left: 10px;vertical-align: top;">
<span v-if="wikiPage.selfZan == 0 && wikiPage.zanNum <= 0">成为第一个赞同者</span>
<span v-else-if="wikiPage.selfZan == 0 && wikiPage.zanNum > 0"><span class="is-link" v-on:click="showZanPageUser">{{wikiPage.zanNum}}人</span>赞了它</span>
<span v-else-if="wikiPage.selfZan == 1 && wikiPage.zanNum <= 1">我赞了它</span>
<span v-else-if="wikiPage.selfZan == 1 && wikiPage.zanNum > 1"><span class="is-link" v-on:click="showZanPageUser">我和{{wikiPage.zanNum-1}}个其他人</span>赞了它</span>
</span>
</div>
<div style="margin-top: 10px;">
<el-input type="textarea" v-model="commentTextInput" :rows="2" placeholder="请输入评论内容"></el-input>
<div align="right" style="margin-top: 5px;">
<el-button v-on:click="submitPageComment">提交评论</el-button>
</div>
</div>
</el-row>
<el-row type="border-card" v-show="rightContentType == 2">
<div style="margin-bottom: 10px;">
@@ -141,6 +162,9 @@
pageContent: {},
pageFileList: [],
uploadFileList: [],
uploadFormData: {pageId: 0},
// 评论相关
commentTextInput: ""
}
},
watch: {
@@ -151,7 +175,26 @@
this.init();
},
methods: {
editWiki(){
zanPage(yn) {
var param = {yn: yn, pageId: app.wikiPage.id};
ajaxTemp("zyplayer-doc-wiki/page/zan/update", "post", "json", param, function (json) {
if (validateResult(json)) {
app.wikiPage.selfZan = yn;
app.wikiPage.zanNum = app.wikiPage.zanNum + (yn == 1 ? 1 : -1);
}
});
},
showZanPageUser() {
},
submitPageComment() {
Toast.success(app.commentTextInput);
},
uploadFileSuccess(response) {
app.pageFileList.push(response.data);
Toast.success("上传成功!");
},
editWiki() {
this.rightContentType = 2;
this.newPageId = app.wikiPage.id;
this.newPageTitle = app.wikiPage.name;
@@ -183,7 +226,7 @@
ajaxTemp("zyplayer-doc-wiki/page/update", "post", "json", param, function (json) {
if (validateResult(json)) {
Toast.success("保存成功!");
this.loadPageDetail(json.data.id);
app.loadPageDetail(json.data.id);
}
});
},
@@ -201,9 +244,12 @@
var param = {id: pageId};
ajaxTemp("zyplayer-doc-wiki/page/detail", "post", "json", param, function (json) {
if (validateResult(json)) {
app.wikiPage = json.data.wikiPage || {};
var wikiPage = json.data.wikiPage || {};
wikiPage.selfZan = json.data.selfZan || 0;
app.wikiPage = wikiPage;
app.pageContent = json.data.pageContent || {};
app.pageFileList = json.data.fileList || [];
app.uploadFormData = {pageId: app.wikiPage.id};
}
});
},
@@ -278,6 +324,9 @@
.wiki-title{font-size: 20px;}
.wiki-author{font-size: 14px;padding: 10px 0;}
.wiki-content{font-size: 14px;}
.upload-page-file .el-upload-list{display: none;}
.is-link{color: #1e88e5;cursor: pointer;}
</style>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B