diff --git a/tamguo-bms/src/main/java/com/tamguo/web/BookController.java b/tamguo-bms/src/main/java/com/tamguo/web/BookController.java index 7de5da4..420eea3 100644 --- a/tamguo-bms/src/main/java/com/tamguo/web/BookController.java +++ b/tamguo-bms/src/main/java/com/tamguo/web/BookController.java @@ -1,26 +1,73 @@ package com.tamguo.web; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.web.servlet.ModelAndView; +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.service.IBookService; +import com.tamguo.modules.book.service.IDocumentService; @Controller public class BookController { + private Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired private IBookService iBookService; + @Autowired + private IDocumentService iDocumentService; - @RequestMapping(value="book/{id}" , method=RequestMethod.GET) + @SuppressWarnings("unchecked") + @RequestMapping(value="book/{id}.html" , method=RequestMethod.GET) public ModelAndView book(@PathVariable String id , ModelAndView model) { BookEntity book = iBookService.selectById(id); model.addObject("book", book); model.setViewName("book/book"); + + // 查询第一章 + List documentList = iDocumentService.selectList(Condition.create().eq("book_id", id).eq("parent_id", "0").orderAsc(Arrays.asList("create_date"))); + if(!CollectionUtils.isEmpty(documentList)) { + model.addObject("document", documentList.get(0)); + } + model.addObject("documentList", iDocumentService.selectList(Condition.create().eq("book_id", id).orderAsc(Arrays.asList("create_date")))); + return model; + } + + @SuppressWarnings("unchecked") + @RequestMapping(value="document/{id}.html" , method=RequestMethod.GET) + public ModelAndView document(@PathVariable String id , ModelAndView model) { + model.setViewName("book/document"); + DocumentEntity document = iDocumentService.selectById(id); + List documentList = iDocumentService.selectList(Condition.create().eq("book_id", document.getBookId()).orderAsc(Arrays.asList("create_date"))); + model.addObject("documentList", documentList); + model.addObject("document", document); + model.addObject("book", iBookService.selectById(document.getBookId())); return model; } + + @RequestMapping(value="document/{id}" , method=RequestMethod.POST) + @ResponseBody + public Result getDocument(@PathVariable String id) { + try { + DocumentEntity document = iDocumentService.selectById(id); + return Result.result(0, document, "查询成功!"); + } catch (Exception e) { + logger.error(e.getMessage() , e); + return Result.result(1, null, "查询失败!"); + } + } } diff --git a/tamguo-bms/src/main/resources/static/js/kancloud.js b/tamguo-bms/src/main/resources/static/js/kancloud.js index c124af1..6bbf95c 100644 --- a/tamguo-bms/src/main/resources/static/js/kancloud.js +++ b/tamguo-bms/src/main/resources/static/js/kancloud.js @@ -75,11 +75,11 @@ function loadDocument($url, $id, $callback) { NProgress.start(); }, success : function (res) { - if (res.errcode === 0) { - var body = res.data.body; - var doc_title = res.data.doc_title; - var title = res.data.title; - var doc_info = res.data.doc_info; + if (res.code === 0) { + var body = res.result.content; + var doc_title = res.result.name; + var title = res.result.name; + var doc_info = res.result.markdown; $body = body; if (typeof $callback === "function" ) { diff --git a/tamguo-bms/src/main/resources/templates/book/book.html b/tamguo-bms/src/main/resources/templates/book/book.html index da3d390..cfd5cae 100644 --- a/tamguo-bms/src/main/resources/templates/book/book.html +++ b/tamguo-bms/src/main/resources/templates/book/book.html @@ -6,7 +6,7 @@ - + @@ -77,22 +77,22 @@
-

测试项目类型

+

测试项目类型

@@ -148,7 +148,7 @@
-
+
@@ -235,7 +235,7 @@ $(function () { $("#searchList").on("click","a",function () { var id = $(this).attr("data-id"); - var url = "[[${domainName}]]" + "/document/[[${book.id}]].html"; + var url = "[[${domainName}]]" + "/document/[[${book.id}]]"; $(this).parent("li").siblings().find("a").removeClass("active"); $(this).addClass("active"); loadDocument(url,id,function (body) { diff --git a/tamguo-bms/src/main/resources/templates/book/document.html b/tamguo-bms/src/main/resources/templates/book/document.html new file mode 100644 index 0000000..97ca209 --- /dev/null +++ b/tamguo-bms/src/main/resources/templates/book/document.html @@ -0,0 +1,251 @@ + + + + 测试项目类型 - 探果网 + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+ 目录 + 搜索 +
+
+ + + + +
+
+
+ + +
+ +
+
+ +
+
+
+
+
+
+
+ +
+
+

测试项目类型

+
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+ +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file