同一个页面只能一个人编辑

This commit is contained in:
暮光:城中城
2019-06-21 21:05:34 +08:00
parent 89b32304bd
commit fbd6ef5f83
9 changed files with 154 additions and 5 deletions

View File

@@ -49,6 +49,11 @@ public class DocUserDetails {
this.authorities = authorities;
}
public DocUserDetails(Long userId, String username) {
this.userId = userId;
this.username = username;
}
public DocUserDetails(Long userId, String username, String password, boolean enabled) {
super();
this.userId = userId;

View File

@@ -8,7 +8,7 @@ import java.util.Date;
/**
* <p>
*
*
* </p>
*
* @author 暮光:城中城
@@ -99,6 +99,16 @@ public class WikiPage implements Serializable {
*/
private Integer seqNo;
/**
* 当前正在编辑的用户ID
*/
private Integer nowEditUserId;
/**
* 当前正在编辑的用户名
*/
private Integer nowEditUserName;
public Long getId() {
return id;
}
@@ -211,7 +221,23 @@ public class WikiPage implements Serializable {
public void setSeqNo(Integer seqNo) {
this.seqNo = seqNo;
}
public Integer getNowEditUserId() {
return nowEditUserId;
}
public void setNowEditUserId(Integer nowEditUserId) {
this.nowEditUserId = nowEditUserId;
}
public Integer getNowEditUserName() {
return nowEditUserName;
}
public void setNowEditUserName(Integer nowEditUserName) {
this.nowEditUserName = nowEditUserName;
}
@Override
public String toString() {
return "WikiPage{" +

View File

@@ -21,7 +21,17 @@ UPDATE wiki_page SET seq_no=id WHERE del_flag=0;
ALTER TABLE `wiki_page_content` ADD COLUMN `preview` varchar(1024) NULL COMMENT '预览内容';
ALTER TABLE `wiki_page_file` ADD COLUMN `download_num` int NOT NULL DEFAULT 0 COMMENT '下载次数';
CREATE TABLE `wiki_page_history` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
`page_id` bigint(20) DEFAULT NULL COMMENT '页面ID',
`content` mediumtext COMMENT '本次文章内容',
`create_user_id` bigint(20) DEFAULT NULL COMMENT '创建人ID',
`create_user_name` varchar(20) DEFAULT NULL COMMENT '创建人名字',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`del_flag` tinyint(4) NOT NULL DEFAULT '0' COMMENT '删除标记 0=正常 1=已删除',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_page_id` (`page_id`) USING BTREE COMMENT '页面ID索引'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
@@ -308,6 +318,18 @@ CREATE TABLE `zyplayer_storage` (
UNIQUE INDEX `key`(`doc_key`) USING BTREE COMMENT 'key唯一索引'
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '' ROW_FORMAT = Compact;
DROP TABLE IF EXISTS `wiki_page_history`;
CREATE TABLE `wiki_page_history` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`page_id` bigint(20) DEFAULT NULL COMMENT 'ID',
`content` mediumtext COMMENT '',
`create_user_id` bigint(20) DEFAULT NULL COMMENT 'ID',
`create_user_name` varchar(20) DEFAULT NULL COMMENT '',
`create_time` datetime DEFAULT NULL COMMENT '',
`del_flag` tinyint(4) NOT NULL DEFAULT '0' COMMENT ' 0= 1=',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_page_id` (`page_id`) USING BTREE COMMENT 'ID索引'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
-- ----------------------------
-- Records of zyplayer_storage
-- ----------------------------

View File

@@ -9,6 +9,8 @@ var URL = {
pageDetail: '/zyplayer-doc-wiki/page/detail',
pageDelete: '/zyplayer-doc-wiki/page/delete',
pageNews: '/zyplayer-doc-wiki/page/news',
pageLock: '/zyplayer-doc-wiki/page/lock',
pageUnlock: '/zyplayer-doc-wiki/page/unlock',
spaceList: '/zyplayer-doc-wiki/space/list',
updateSpace: '/zyplayer-doc-wiki/space/update',
getPageUserAuthList: '/zyplayer-doc-wiki/page/auth/list',

View File

@@ -52,6 +52,27 @@ export default {
this.validateResult(res);
});
},
postNonCheck: function (url, param, callback) {
param = param || {};
param.accessToken = this.getAccessToken();
global.vue.axios({
method: "post",
url: url,
headers: {'Content-type': 'application/x-www-form-urlencoded'},
data: Qs.stringify(param),
withCredentials: true,
}).then((res) => {
console.log("ok", res);
if (typeof callback == 'function') {
callback(res.data);
}
}).catch((res) => {
console.log("error", res);
if (typeof callback == 'function') {
callback(res.data);
}
});
},
/**
* 返回不为空的字符串为空返回def
*/

View File

@@ -23,6 +23,13 @@
import global from '../../common/config/global'
import WangEditor from 'wangeditor'
window.onunload = function () {
app.unlockPage();
};
window.onbeforeunload = function () {
app.unlockPage();
};
var app;
export default {
data() {
@@ -32,8 +39,12 @@
newPageTitle: "",
parentPath: {},
wikiPage: {},
isUnlock: false,
};
},
destroyed: function () {
this.unlockPage();
},
beforeRouteUpdate(to, from, next) {
this.initQueryParam(to);
next();
@@ -47,12 +58,22 @@
changeToRootPath() {
app.parentPath = {spaceId: this.parentPath.spaceId};
},
unlockPage() {
// 防止各种事件重复调这个接口,只需要调一次就好了
if (this.isUnlock) {
return;
}
this.isUnlock = true;
var param = {pageId: app.parentPath.pageId};
this.common.post(this.apilist1.pageUnlock, param, function (json) {});
},
createWikiCancel() {
this.$confirm('确定要取消编辑吗?您编辑的内容将不会被保存哦~', '提示', {
confirmButtonText: '确定',
cancelButtonText: '继续编辑',
type: 'warning'
}).then(() => {
app.unlockPage();
app.$router.back();
});
},
@@ -114,6 +135,17 @@
} else {
this.cleanPage();
}
var param = {pageId: app.parentPath.pageId};
this.common.postNonCheck(this.apilist1.pageLock, param, function (json) {
if (json.errCode !== 200) {
app.$alert(json.errMsg || '未知错误', '错误', {
confirmButtonText: '确定',
callback: () => {
app.$router.back();
}
});
}
});
},
initEditor() {
this.editor = new WangEditor('#newPageContentDiv');

View File

@@ -183,7 +183,10 @@
},
methods: {
editWiki() {
this.$router.push({path: '/page/edit', query: this.parentPath});
var param = {pageId: app.parentPath.pageId};
this.common.post(this.apilist1.pageLock, param, function (json) {
app.$router.push({path: '/page/edit', query: app.parentPath});
});
},
getSearchUserList(query) {
if (query == '') {
@@ -320,6 +323,10 @@
this.recommentInfo = {};
},
submitPageComment() {
if (app.commentTextInput.length <= 0) {
toast.error("请输入评论内容");
return;
}
var param = {
pageId: app.wikiPage.id, content: app.commentTextInput,
parentId: app.recommentInfo.id
@@ -332,7 +339,7 @@
});
},
uploadFileError(err) {
toast.success("上传失败," + err);
toast.error("上传失败," + err);
},
uploadFileSuccess(response) {
this.common.validateResult({data: response}, function () {

View File

@@ -12,12 +12,14 @@ import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.*;
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageMapper;
import com.zyplayer.doc.data.service.manage.*;
import com.zyplayer.doc.data.utils.CacheUtil;
import com.zyplayer.doc.wiki.controller.param.SpaceNewsParam;
import com.zyplayer.doc.wiki.controller.vo.SpaceNewsVo;
import com.zyplayer.doc.wiki.controller.vo.WikiPageContentVo;
import com.zyplayer.doc.wiki.controller.vo.WikiPageVo;
import com.zyplayer.doc.wiki.framework.consts.SpaceType;
import com.zyplayer.doc.wiki.framework.consts.WikiAuthType;
import com.zyplayer.doc.wiki.framework.consts.WikiCachePrefix;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.dozer.Mapper;
@@ -253,6 +255,33 @@ public class WikiPageController {
return DocResponseJson.ok(wikiPage);
}
@PostMapping("/unlock")
public ResponseJson<Object> unlock(Long pageId) {
String lockKey = WikiCachePrefix.WIKI_LOCK_PAGE + pageId;
DocUserDetails pageLockUser = CacheUtil.get(lockKey);
if (pageLockUser != null) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
if (Objects.equals(pageLockUser.getUserId(), currentUser.getUserId())) {
CacheUtil.remove(lockKey);
}
}
return DocResponseJson.ok();
}
@PostMapping("/lock")
public ResponseJson<Object> editLock(Long pageId) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
String lockKey = WikiCachePrefix.WIKI_LOCK_PAGE + pageId;
DocUserDetails pageLockUser = CacheUtil.get(lockKey);
if (pageLockUser != null) {
if (!Objects.equals(pageLockUser.getUserId(), currentUser.getUserId())) {
return DocResponseJson.warn("当前页面正在被:" + pageLockUser.getUsername() + " 编辑");
}
}
CacheUtil.put(lockKey, new DocUserDetails(currentUser.getUserId(), currentUser.getUsername()));
return DocResponseJson.ok();
}
@PostMapping("/news")
public ResponseJson<Object> news(SpaceNewsParam param) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();

View File

@@ -0,0 +1,5 @@
package com.zyplayer.doc.wiki.framework.consts;
public class WikiCachePrefix {
public static final String WIKI_LOCK_PAGE = "WIKI_LOCK_PAGE_";
}