From 2715688990933e5c3aa41fa74e7de35b0deac918 Mon Sep 17 00:00:00 2001 From: tamguo Date: Mon, 6 Aug 2018 19:25:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=A0=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/tiku/model/ChapterEntity.java | 30 +++++++- .../tiku/model/enums/ChapterStatusEnum.java | 34 ++++++++ .../modules/tiku/service/IChapterService.java | 7 ++ .../tiku/service/impl/ChapterServiceImpl.java | 47 +++++++++++ .../modules/tiku/web/ChapterController.java | 33 ++++++++ .../templates/modules/tiku/chapter/add.html | 77 +++++++++---------- .../templates/modules/tiku/chapter/list.html | 19 +++-- 7 files changed, 197 insertions(+), 50 deletions(-) create mode 100644 tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/ChapterStatusEnum.java diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java index 11a5b32..476e409 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java @@ -1,9 +1,13 @@ package com.tamguo.modules.tiku.model; import java.io.Serializable; + +import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson.serializer.SerializerFeature; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableName; import com.tamguo.config.dao.SuperEntity; +import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; import java.util.List; @@ -17,6 +21,7 @@ public class ChapterEntity extends SuperEntity implements Seriali private static final long serialVersionUID = 1L; private String courseId; + private String bookId; private String name; private String parentCode; private String parentCodes; @@ -24,10 +29,13 @@ public class ChapterEntity extends SuperEntity implements Seriali private Integer pointNum; private Integer orders; private Boolean treeLeaf; - private String treeLevel; + private Integer treeLevel; @TableField(exist=false) private List childChapterList; + + @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + private ChapterStatusEnum status; public ChapterEntity() { } @@ -104,12 +112,28 @@ public class ChapterEntity extends SuperEntity implements Seriali this.treeLeaf = treeLeaf; } - public String getTreeLevel() { + public Integer getTreeLevel() { return treeLevel; } - public void setTreeLevel(String treeLevel) { + public void setTreeLevel(Integer treeLevel) { this.treeLevel = treeLevel; } + public ChapterStatusEnum getStatus() { + return status; + } + + public void setStatus(ChapterStatusEnum status) { + this.status = status; + } + + public String getBookId() { + return bookId; + } + + public void setBookId(String bookId) { + this.bookId = bookId; + } + } \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/ChapterStatusEnum.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/ChapterStatusEnum.java new file mode 100644 index 0000000..8bcb7a9 --- /dev/null +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/ChapterStatusEnum.java @@ -0,0 +1,34 @@ +package com.tamguo.modules.tiku.model.enums; + +import java.io.Serializable; +import com.baomidou.mybatisplus.enums.IEnum; + +/** + * 类型状态 + */ +public enum ChapterStatusEnum implements IEnum { + NORMAL("normal", "正常"), + DELETE("delete", "删除"), + DISABLED("disabled" , "停用"); + + private String value; + private String desc; + + ChapterStatusEnum(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/tiku/service/IChapterService.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/IChapterService.java index ccf5425..489358b 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/IChapterService.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/IChapterService.java @@ -2,6 +2,7 @@ package com.tamguo.modules.tiku.service; import java.util.List; +import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.service.IService; import com.tamguo.modules.tiku.model.ChapterEntity; import com.tamguo.modules.tiku.model.condition.ChapterCondition; @@ -14,4 +15,10 @@ public interface IChapterService extends IService{ // 章节列表 public List listData(ChapterCondition condition); + // 章节树形数据 + public JSONArray treeData(String courseId, String excludeId); + + // 保存章节 + public void save(ChapterEntity chapter); + } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java index 454ed15..ebdbc67 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java @@ -8,12 +8,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.Condition; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.tamguo.common.utils.SystemConstant; import com.tamguo.modules.tiku.dao.ChapterMapper; import com.tamguo.modules.tiku.model.ChapterEntity; import com.tamguo.modules.tiku.model.condition.ChapterCondition; +import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; import com.tamguo.modules.tiku.service.IChapterService; @Service @@ -83,5 +86,49 @@ public class ChapterServiceImpl extends ServiceImpl chapterList = null; + if(StringUtils.isEmpty(excludeId)) { + chapterList = chapterMapper.selectList(Condition.EMPTY); + } else { + chapterList = chapterMapper.selectList(Condition.create().notLike("parent_codes", excludeId).eq("id", excludeId)); + } + return turnZTreeData(chapterList); + } + private JSONArray turnZTreeData(List chapterList) { + if(chapterList != null) { + JSONArray nodes = new JSONArray(); + for(int i=0 ; i listData(ChapterCondition condition) { return iChapterService.listData(condition); } + + @RequestMapping(path="treeData") + @ResponseBody + public JSONArray treeData(String courseId , String excludeId) { + return iChapterService.treeData(courseId , excludeId); + } + + @RequestMapping(path="save") + @ResponseBody + public Result save(ChapterEntity chapter) { + try { + iChapterService.save(chapter); + return Result.result(0, null, "章节【"+chapter.getName()+"】添加成功!"); + } catch (Exception e) { + return ExceptionSupport.resolverResult("保存章节", this.getClass(), e); + } + } + } diff --git a/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/add.html b/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/add.html index cf76249..7e7d8dc 100644 --- a/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/add.html +++ b/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/add.html @@ -26,14 +26,15 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/> -
+ +
基本信息
+ * 章节名称:
@@ -42,44 +43,33 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
+ * 上级章节:
- -
-
-
-
-
-
-
- -
-
- - + +
-
-
-
-
- -
- +
@@ -173,6 +155,17 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
+
+
+
+ +
+ +
+
+
+
diff --git a/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/list.html b/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/list.html index 0714217..9aa7629 100644 --- a/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/list.html +++ b/tamguo-oms/src/main/resources/templates/modules/tiku/chapter/list.html @@ -86,22 +86,31 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/> $('#dataGrid').dataGrid({ searchForm: $("#searchForm"), columnModel: [ - {header:'章节名称', name:'name', index:'a.office_name', width:250, align:"left", frozen:true, formatter: function(val, obj, row, act){ + {header:'章节名称', name:'name', index:'a.office_name', width:500, align:"left", frozen:true, formatter: function(val, obj, row, act){ return '( '+row.id+' ) '+''+(val||row.id)+''; }}, {header:'问题数量', name:'questionNum', index:'a.question_num', width:100, align:"center"}, {header:'知识点数量', name:'pointNum', index:'a.pointNum', width:100, align:"center"}, - {header:'操作', name:'actions', width:150, sortable:false, title:false, formatter: function(val, obj, row, act){ + {header:'状态', name:'status', index:'b.status', width:80, align:"center", formatter: function(val, obj, row, act){ + if(val == "normal"){ + return '正常'; + }else if(val == "disabled"){ + return '停用'; + }else{ + return '未知'; + } + }}, + {header:'操作', name:'actions', width:100, sortable:false, title:false, formatter: function(val, obj, row, act){ var actions = []; - actions.push(' '); + actions.push(' '); if (row.status == Global.STATUS_NORMAL){ actions.push(' '); } if (row.status == Global.STATUS_DISABLE){ actions.push(' '); } - actions.push(' '); - actions.push(' '); + actions.push(' '); + actions.push(' '); return actions.join(''); }} ],