书籍管理

main
tamguo 7 years ago
parent 52c648ec71
commit ca50eca8af

@ -139,6 +139,12 @@
<artifactId>tamguo-modules-core</artifactId> <artifactId>tamguo-modules-core</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>

@ -1,6 +1,8 @@
package com.tamguo.web.member; package com.tamguo.web.member;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.Condition; import com.baomidou.mybatisplus.mapper.Condition;
import com.tamguo.common.utils.Result; 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.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.IBookService;
import com.tamguo.modules.book.service.IDocumentService; import com.tamguo.modules.book.service.IDocumentService;
@ -26,6 +33,8 @@ public class BookController {
@Autowired @Autowired
IBookService iBookService; IBookService iBookService;
@Autowired @Autowired
IBookCategoryService iBookCategoryService;
@Autowired
IDocumentService iDocumentService; IDocumentService iDocumentService;
@RequestMapping(value = "edit", method = RequestMethod.GET) @RequestMapping(value = "edit", method = RequestMethod.GET)
@ -38,14 +47,37 @@ public class BookController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = "getDocumentList", method = RequestMethod.POST) @RequestMapping(value = "getDocumentList", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result getDocumentList(String bookId) { public Result getDocumentList(String id) {
List<DocumentEntity> documentList = null; Map<String, Object> map = new HashMap<>();
try { try {
documentList = iDocumentService.selectList(Condition.create().eq("book_id", bookId)); BookEntity book = iBookService.selectById(id);
List<DocumentEntity> 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) { } catch (Exception e) {
logger.error(e.getMessage() , e ); logger.error(e.getMessage() , e );
return Result.failResult("查询失败!"); return Result.failResult("查询失败");
}
return Result.successResult(map);
}
private JSONArray processDocumentList(List<DocumentEntity> documentList) {
JSONArray entitys = new JSONArray();
for(int i=0 ; i<documentList.size() ; i ++) {
DocumentEntity doc = documentList.get(i);
JSONObject entity = new JSONObject();
entity.put("id", doc.getId());
entity.put("text", doc.getName());
entity.put("parent", "0".equals(doc.getParentId()) ? "#" : doc.getParentId());
entity.put("identify", doc.getId());
entity.put("version", doc.getCreateDate().getTime());
JSONObject attr = new JSONObject();
attr.put("is_open", "0".equals(doc.getIsOpen()) ? false : true);
entity.put("a_attr", attr);
entitys.add(entity);
} }
return Result.successResult(documentList); return entitys;
} }
} }

@ -1,11 +1,67 @@
package com.tamguo.web.member; package com.tamguo.web.member;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tamguo.common.utils.Result;
import com.tamguo.modules.book.model.DocumentEntity;
import com.tamguo.modules.book.service.IDocumentService; import com.tamguo.modules.book.service.IDocumentService;
@Controller @Controller
@RequestMapping(value="member/document")
public class DocumentController { public class DocumentController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
IDocumentService iDocumentService; IDocumentService iDocumentService;
@RequestMapping(value = "{id}" , method = RequestMethod.GET)
@ResponseBody
public Result getDocument(@PathVariable String id) {
DocumentEntity document = null;
try {
document = iDocumentService.selectById(id);
} catch (Exception e) {
logger.error(e.getMessage() , e );
return Result.failResult("查询失败");
}
return Result.successResult(document);
}
/**
*
*/
@RequestMapping(value = "modify" , method = RequestMethod.POST)
@ResponseBody
public Result modify(DocumentEntity document) {
try {
iDocumentService.modify(document);
} catch (Exception e) {
logger.error(e.getMessage() , e );
return Result.failResult("保存失败");
}
return Result.successResult("保存成功");
}
/**
*
*/
@RequestMapping(value = "create" , method = RequestMethod.POST)
@ResponseBody
public Result create(DocumentEntity document) {
try {
iDocumentService.create(document);
} catch (Exception e) {
logger.error(e.getMessage() , e );
return Result.failResult("保存失败");
}
return Result.successResult(document);
}
} }

@ -184,9 +184,9 @@ function openEditCatalogDialog($node) {
// $then.find("input[name='doc_name']").val(text); // $then.find("input[name='doc_name']").val(text);
if($node.a_attr && $node.a_attr.is_open){ if($node.a_attr && $node.a_attr.is_open){
$then.find("input[name='is_open'][value='1']").prop("checked","checked"); $then.find("input[name='isOpen'][value='1']").prop("checked","checked");
}else{ }else{
$then.find("input[name='is_open'][value='0']").prop("checked","checked"); $then.find("input[name='isOpen'][value='0']").prop("checked","checked");
} }
for (var index in window.documentCategory){ for (var index in window.documentCategory){

@ -151,7 +151,7 @@ $(function () {
}catch(e){ }catch(e){
console.log(e); console.log(e);
} }
var node = { "id": res.result.id, 'parent': res.result.parent_id === 0 ? '#' : res.result.parent_id, "text": res.result.name, "identify": res.result.id}; var node = { "id": res.result.id, 'parent': res.result.parentId === "0" ? '#' : res.result.parentId, "text": res.result.name, "identify": res.result.id};
pushDocumentCategory(node); pushDocumentCategory(node);
window.selectNode = node; window.selectNode = node;
pushVueLists(null); pushVueLists(null);
@ -196,7 +196,7 @@ $(function () {
index = layer.load(1, { shade: [0.1, '#fff'] }); index = layer.load(1, { shade: [0.1, '#fff'] });
window.saveing = true; window.saveing = true;
}, },
url: window.editURL, url: window.editURL + "modify",
data: { "id": doc_id, "markdown": content, "content": html, "cover": $is_cover ? "yes" : "no"}, data: { "id": doc_id, "markdown": content, "content": html, "cover": $is_cover ? "yes" : "no"},
type: "post", type: "post",
timeout : 30000, timeout : 30000,
@ -277,9 +277,9 @@ $(function () {
'parent': res.result.parentId, 'parent': res.result.parentId,
"text": res.result.name, "text": res.result.name,
"identify": res.result.id, "identify": res.result.id,
"version": res.result.version , "version": res.result.createDate ,
state: { opened: res.result.is_open == 1}, state: { opened: res.result.isOpen == 1},
a_attr: { is_open: res.result.is_open == 1} a_attr: { is_open: res.result.isOpen == 1}
}; };
var node = window.treeCatalog.get_node(data.id); var node = window.treeCatalog.get_node(data.id);

@ -17,7 +17,7 @@
window.fileUploadURL = "[[${domainName}]]" + "member/document/uploadFile"; window.fileUploadURL = "[[${domainName}]]" + "member/document/uploadFile";
window.selectNode = null; window.selectNode = null;
window.deleteURL = "[[${domainName}]]" + "member/document/delete"; window.deleteURL = "[[${domainName}]]" + "member/document/delete";
window.editURL = "[[${domainName}]]" + "member/document"; window.editURL = "[[${domainName}]]" + "member/document/";
window.releaseURL = "[[${domainName}]]" + "/book/xingzheng/release"; window.releaseURL = "[[${domainName}]]" + "/book/xingzheng/release";
window.sortURL = "[[${domainName}]]" + "/book/xingzheng/sort"; window.sortURL = "[[${domainName}]]" + "/book/xingzheng/sort";
window.historyURL = "[[${domainName}]]" + "/history/get"; window.historyURL = "[[${domainName}]]" + "/history/get";
@ -35,7 +35,7 @@
async: false, async: false,
success: function (res) { success: function (res) {
if (res.code === 0) { if (res.code === 0) {
window.documentCategory = res.result.documentCategoryList; window.documentCategory = res.result.documentList;
window.book = res.result.book; window.book = res.result.book;
} }
} }
@ -173,7 +173,7 @@
</div> </div>
<div class="col-lg-6"> <div class="col-lg-6">
<label> <label>
<input type="radio" name="is_open" value="0" checked> 关闭<span class="text">(在阅读时会关闭节点)</span> <input type="radio" name="isOpen" value="0" checked> 关闭<span class="text">(在阅读时会关闭节点)</span>
</label> </label>
</div> </div>

@ -1,17 +1,21 @@
package com.tamguo.modules.book.model; package com.tamguo.modules.book.model;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
@TableName(value="b_book_category") @TableName(value="b_book_category")
public class BookCategoryEntity { public class BookCategoryEntity extends Model<BookCategoryEntity>{
private static final long serialVersionUID = 1L;
@TableId @TableId
private String id; private String id;
private String parentCode; private String parentId;
private String parentCodes; private String parentIds;
private String treeSort; private String treeSort;
private String treeSorts; private String treeSorts;
private String treeLeaf; private String treeLeaf;
@ -30,18 +34,6 @@ public class BookCategoryEntity {
public void setId(String id) { public void setId(String id) {
this.id = 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() { public String getTreeSort() {
return treeSort; return treeSort;
} }
@ -108,5 +100,21 @@ public class BookCategoryEntity {
public void setUpdateDate(Date updateDate) { public void setUpdateDate(Date updateDate) {
this.updateDate = 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();
}
} }

@ -1,12 +1,16 @@
package com.tamguo.modules.book.model; package com.tamguo.modules.book.model;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
@TableName(value="b_book") @TableName(value="b_book")
public class BookEntity { public class BookEntity extends Model<BookEntity>{
private static final long serialVersionUID = 1L;
@TableId @TableId
private String id; private String id;
@ -80,5 +84,9 @@ public class BookEntity {
public void setBookImage(String bookImage) { public void setBookImage(String bookImage) {
this.bookImage = bookImage; this.bookImage = bookImage;
} }
@Override
protected Serializable pkVal() {
return getId();
}
} }

@ -1,22 +1,49 @@
package com.tamguo.modules.book.model; package com.tamguo.modules.book.model;
import java.io.Serializable;
import java.util.Date; 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.TableId;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
import com.tamguo.modules.book.model.enums.DocumentStatusEnum;
@TableName(value="b_document") @TableName(value="b_document")
public class DocumentEntity { public class DocumentEntity extends Model<DocumentEntity>{
private static final long serialVersionUID = 1L;
@TableId @TableId
private String id; private String id;
private String parentId;
private String bookId; private String bookId;
private String owner; private String owner;
private String name; 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 createDate;
private Date updateDate; 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<DocumentEntity> children;
@TableField(exist=false)
private String cover;
public String getId() { public String getId() {
return id; return id;
} }
@ -41,12 +68,6 @@ public class DocumentEntity {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Date getCreateDate() { public Date getCreateDate() {
return createDate; return createDate;
} }
@ -59,5 +80,69 @@ public class DocumentEntity {
public void setUpdateDate(Date updateDate) { public void setUpdateDate(Date updateDate) {
this.updateDate = 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<DocumentEntity> getChildren() {
return children;
}
public void setChildren(List<DocumentEntity> 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;
}
} }

@ -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;
}
}

@ -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<BookCategoryEntity>{
}

@ -5,4 +5,10 @@ import com.tamguo.modules.book.model.DocumentEntity;
public interface IDocumentService extends IService<DocumentEntity>{ public interface IDocumentService extends IService<DocumentEntity>{
/** 编辑文档*/
void modify(DocumentEntity document);
/** 创建文档 */
void create(DocumentEntity document);
} }

@ -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<BookCategoryMapper, BookCategoryEntity> implements IBookCategoryService{
}

@ -1,13 +1,63 @@
package com.tamguo.modules.book.service.impl; package com.tamguo.modules.book.service.impl;
import java.util.Date;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tamguo.modules.book.dao.DocumentMapper; import com.tamguo.modules.book.dao.DocumentMapper;
import com.tamguo.modules.book.model.DocumentEntity; import com.tamguo.modules.book.model.DocumentEntity;
import com.tamguo.modules.book.model.enums.DocumentStatusEnum;
import com.tamguo.modules.book.service.IDocumentService; import com.tamguo.modules.book.service.IDocumentService;
@Service @Service
public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, DocumentEntity> implements IDocumentService{ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, DocumentEntity> 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);
}
} }

Loading…
Cancel
Save