From ca50eca8af5602c7f6504e49fc984e1b76d290cd Mon Sep 17 00:00:00 2001 From: tamguo Date: Wed, 14 Nov 2018 15:26:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=A6=E7=B1=8D=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tamguo-bms/pom.xml | 6 ++ .../com/tamguo/web/member/BookController.java | 42 +++++++- .../tamguo/web/member/DocumentController.java | 56 ++++++++++ .../src/main/resources/static/js/editor.js | 4 +- .../src/main/resources/static/js/markdown.js | 10 +- .../resources/templates/member/book/edit.html | 6 +- .../book/model/BookCategoryEntity.java | 38 ++++--- .../tamguo/modules/book/model/BookEntity.java | 10 +- .../modules/book/model/DocumentEntity.java | 101 ++++++++++++++++-- .../book/model/enums/DocumentStatusEnum.java | 33 ++++++ .../book/service/IBookCategoryService.java | 8 ++ .../book/service/IDocumentService.java | 6 ++ .../service/impl/BookCategoryServiceImpl.java | 13 +++ .../service/impl/DocumentServiceImpl.java | 50 +++++++++ 14 files changed, 344 insertions(+), 39 deletions(-) create mode 100644 tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java create mode 100644 tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IBookCategoryService.java create mode 100644 tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookCategoryServiceImpl.java diff --git a/tamguo-bms/pom.xml b/tamguo-bms/pom.xml index 01e4712..d93c16c 100644 --- a/tamguo-bms/pom.xml +++ b/tamguo-bms/pom.xml @@ -139,6 +139,12 @@ tamguo-modules-core 1.0.0 + + + commons-collections + commons-collections + 3.2.1 + diff --git a/tamguo-bms/src/main/java/com/tamguo/web/member/BookController.java b/tamguo-bms/src/main/java/com/tamguo/web/member/BookController.java index afee0f8..2c5f757 100644 --- a/tamguo-bms/src/main/java/com/tamguo/web/member/BookController.java +++ b/tamguo-bms/src/main/java/com/tamguo/web/member/BookController.java @@ -1,6 +1,8 @@ package com.tamguo.web.member; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,9 +13,14 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.Condition; import com.tamguo.common.utils.Result; +import com.tamguo.modules.book.model.BookEntity; import com.tamguo.modules.book.model.DocumentEntity; +import com.tamguo.modules.book.model.enums.DocumentStatusEnum; +import com.tamguo.modules.book.service.IBookCategoryService; import com.tamguo.modules.book.service.IBookService; import com.tamguo.modules.book.service.IDocumentService; @@ -26,6 +33,8 @@ public class BookController { @Autowired IBookService iBookService; @Autowired + IBookCategoryService iBookCategoryService; + @Autowired IDocumentService iDocumentService; @RequestMapping(value = "edit", method = RequestMethod.GET) @@ -38,14 +47,37 @@ public class BookController { @SuppressWarnings("unchecked") @RequestMapping(value = "getDocumentList", method = RequestMethod.POST) @ResponseBody - public Result getDocumentList(String bookId) { - List documentList = null; + public Result getDocumentList(String id) { + Map map = new HashMap<>(); try { - documentList = iDocumentService.selectList(Condition.create().eq("book_id", bookId)); + BookEntity book = iBookService.selectById(id); + List documentList = iDocumentService.selectList(Condition.create().eq("book_id", id).eq("status", DocumentStatusEnum.NORMAL.getValue())); + + map.put("documentList", this.processDocumentList(documentList)); + map.put("book", book); } catch (Exception e) { logger.error(e.getMessage() , e ); - return Result.failResult("查询失败!"); + return Result.failResult("查询失败"); + } + return Result.successResult(map); + } + + private JSONArray processDocumentList(List documentList) { + JSONArray entitys = new JSONArray(); + for(int i=0 ; i
diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java index 0fe793a..9b0270e 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java @@ -1,17 +1,21 @@ package com.tamguo.modules.book.model; +import java.io.Serializable; import java.util.Date; +import com.baomidou.mybatisplus.activerecord.Model; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; @TableName(value="b_book_category") -public class BookCategoryEntity { +public class BookCategoryEntity extends Model{ + private static final long serialVersionUID = 1L; + @TableId private String id; - private String parentCode; - private String parentCodes; + private String parentId; + private String parentIds; private String treeSort; private String treeSorts; private String treeLeaf; @@ -30,18 +34,6 @@ public class BookCategoryEntity { public void setId(String id) { this.id = id; } - public String getParentCode() { - return parentCode; - } - public void setParentCode(String parentCode) { - this.parentCode = parentCode; - } - public String getParentCodes() { - return parentCodes; - } - public void setParentCodes(String parentCodes) { - this.parentCodes = parentCodes; - } public String getTreeSort() { return treeSort; } @@ -108,5 +100,21 @@ public class BookCategoryEntity { public void setUpdateDate(Date updateDate) { this.updateDate = updateDate; } + public String getParentId() { + return parentId; + } + public void setParentId(String parentId) { + this.parentId = parentId; + } + public String getParentIds() { + return parentIds; + } + public void setParentIds(String parentIds) { + this.parentIds = parentIds; + } + @Override + protected Serializable pkVal() { + return getId(); + } } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java index 840a120..2e953a1 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java @@ -1,13 +1,17 @@ package com.tamguo.modules.book.model; +import java.io.Serializable; import java.util.Date; +import com.baomidou.mybatisplus.activerecord.Model; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; @TableName(value="b_book") -public class BookEntity { +public class BookEntity extends Model{ + private static final long serialVersionUID = 1L; + @TableId private String id; private String categoryId; @@ -80,5 +84,9 @@ public class BookEntity { public void setBookImage(String bookImage) { this.bookImage = bookImage; } + @Override + protected Serializable pkVal() { + return getId(); + } } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java index db6a518..b0fa44e 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java @@ -1,22 +1,49 @@ package com.tamguo.modules.book.model; +import java.io.Serializable; import java.util.Date; +import java.util.List; +import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; +import com.tamguo.modules.book.model.enums.DocumentStatusEnum; @TableName(value="b_document") -public class DocumentEntity { +public class DocumentEntity extends Model{ + private static final long serialVersionUID = 1L; + @TableId private String id; + private String parentId; private String bookId; private String owner; private String name; - private String status; + @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + private DocumentStatusEnum status; + @TableField(value="is_open") + private String isOpen; private Date createDate; private Date updateDate; + private String content; + private String markdown; + + @TableField(exist=false) + private Integer level; + @TableField(exist=false) + private String rootId; + @TableField(exist=false) + private boolean leaf; + @TableField(exist=false) + private List children; + @TableField(exist=false) + private String cover; + public String getId() { return id; } @@ -41,12 +68,6 @@ public class DocumentEntity { public void setName(String name) { this.name = name; } - public String getStatus() { - return status; - } - public void setStatus(String status) { - this.status = status; - } public Date getCreateDate() { return createDate; } @@ -59,5 +80,69 @@ public class DocumentEntity { public void setUpdateDate(Date updateDate) { this.updateDate = updateDate; } + public String getContent() { + return content; + } + public void setContent(String content) { + this.content = content; + } + public String getMarkdown() { + return markdown; + } + public void setMarkdown(String markdown) { + this.markdown = markdown; + } + public String getParentId() { + return parentId; + } + public void setParentId(String parentId) { + this.parentId = parentId; + } + public Integer getLevel() { + return level; + } + public void setLevel(Integer level) { + this.level = level; + } + public String getRootId() { + return rootId; + } + public void setRootId(String rootId) { + this.rootId = rootId; + } + public boolean isLeaf() { + return leaf; + } + public void setLeaf(boolean leaf) { + this.leaf = leaf; + } + public String getIsOpen() { + return isOpen; + } + public void setIsOpen(String isOpen) { + this.isOpen = isOpen; + } + public List getChildren() { + return children; + } + public void setChildren(List children) { + this.children = children; + } + @Override + protected Serializable pkVal() { + return getId(); + } + public String getCover() { + return cover; + } + public void setCover(String cover) { + this.cover = cover; + } + public DocumentStatusEnum getStatus() { + return status; + } + public void setStatus(DocumentStatusEnum status) { + this.status = status; + } } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java new file mode 100644 index 0000000..582e08b --- /dev/null +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java @@ -0,0 +1,33 @@ +package com.tamguo.modules.book.model.enums; + +import java.io.Serializable; +import com.baomidou.mybatisplus.enums.IEnum; + +/** + * 用户状态 + */ +public enum DocumentStatusEnum implements IEnum { + NORMAL("normal", "正常"), + HISTORY("history", "历史版本"); + + private String value; + private String desc; + + DocumentStatusEnum(final String value, final String desc) { + this.value = value; + this.desc = desc; + } + + public Serializable getValue() { + return this.value; + } + + public String getDesc(){ + return this.desc; + } + + @Override + public String toString() { + return this.value; + } +} diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IBookCategoryService.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IBookCategoryService.java new file mode 100644 index 0000000..ee42fc6 --- /dev/null +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IBookCategoryService.java @@ -0,0 +1,8 @@ +package com.tamguo.modules.book.service; + +import com.baomidou.mybatisplus.service.IService; +import com.tamguo.modules.book.model.BookCategoryEntity; + +public interface IBookCategoryService extends IService{ + +} diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IDocumentService.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IDocumentService.java index 40d4991..97cfaab 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IDocumentService.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/IDocumentService.java @@ -5,4 +5,10 @@ import com.tamguo.modules.book.model.DocumentEntity; public interface IDocumentService extends IService{ + /** 编辑文档*/ + void modify(DocumentEntity document); + + /** 创建文档 */ + void create(DocumentEntity document); + } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookCategoryServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookCategoryServiceImpl.java new file mode 100644 index 0000000..df21115 --- /dev/null +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookCategoryServiceImpl.java @@ -0,0 +1,13 @@ +package com.tamguo.modules.book.service.impl; + +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.tamguo.modules.book.dao.BookCategoryMapper; +import com.tamguo.modules.book.model.BookCategoryEntity; +import com.tamguo.modules.book.service.IBookCategoryService; + +@Service +public class BookCategoryServiceImpl extends ServiceImpl implements IBookCategoryService{ + +} diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java index 1bb1ffa..82a6ec2 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java @@ -1,13 +1,63 @@ package com.tamguo.modules.book.service.impl; +import java.util.Date; + import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.tamguo.modules.book.dao.DocumentMapper; import com.tamguo.modules.book.model.DocumentEntity; +import com.tamguo.modules.book.model.enums.DocumentStatusEnum; import com.tamguo.modules.book.service.IDocumentService; @Service public class DocumentServiceImpl extends ServiceImpl implements IDocumentService{ + @Transactional(readOnly=false) + @Override + public void modify(DocumentEntity document) { + DocumentEntity entity = this.selectById(document.getId()); + if("yes".equals(document.getCover())) { + // 覆盖修改 + entity.setContent(document.getContent()); + entity.setMarkdown(document.getMarkdown()); + entity.setStatus(DocumentStatusEnum.NORMAL); + this.updateById(entity); + } else { + String content = entity.getContent(); + String markdown = entity.getMarkdown(); + + // 更新内容 + entity.setContent(document.getContent()); + entity.setMarkdown(document.getMarkdown()); + this.updateById(entity); + + // 新增历史 + document.setId(null); + document.setContent(content); + document.setMarkdown(markdown); + document.setBookId(entity.getBookId()); + document.setCreateDate(new Date()); + document.setIsOpen(entity.getIsOpen()); + document.setName(entity.getName()); + document.setOwner(entity.getOwner()); + document.setParentId(entity.getParentId()); + document.setUpdateDate(new Date()); + document.setStatus(DocumentStatusEnum.HISTORY); + this.insert(document); + + } + } + + @Transactional(readOnly=false) + @Override + public void create(DocumentEntity document) { + document.setStatus(DocumentStatusEnum.NORMAL); + document.setCreateDate(new Date()); + document.setUpdateDate(new Date()); + document.setOwner("system"); + this.insert(document); + } + }