main
tamguo 7 years ago
parent 02a27da72f
commit 2715688990

@ -1,9 +1,13 @@
package com.tamguo.modules.tiku.model; package com.tamguo.modules.tiku.model;
import java.io.Serializable; 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.TableField;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
import com.tamguo.config.dao.SuperEntity; import com.tamguo.config.dao.SuperEntity;
import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum;
import java.util.List; import java.util.List;
@ -17,6 +21,7 @@ public class ChapterEntity extends SuperEntity<ChapterEntity> implements Seriali
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String courseId; private String courseId;
private String bookId;
private String name; private String name;
private String parentCode; private String parentCode;
private String parentCodes; private String parentCodes;
@ -24,10 +29,13 @@ public class ChapterEntity extends SuperEntity<ChapterEntity> implements Seriali
private Integer pointNum; private Integer pointNum;
private Integer orders; private Integer orders;
private Boolean treeLeaf; private Boolean treeLeaf;
private String treeLevel; private Integer treeLevel;
@TableField(exist=false) @TableField(exist=false)
private List<ChapterEntity> childChapterList; private List<ChapterEntity> childChapterList;
@JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString)
private ChapterStatusEnum status;
public ChapterEntity() { public ChapterEntity() {
} }
@ -104,12 +112,28 @@ public class ChapterEntity extends SuperEntity<ChapterEntity> implements Seriali
this.treeLeaf = treeLeaf; this.treeLeaf = treeLeaf;
} }
public String getTreeLevel() { public Integer getTreeLevel() {
return treeLevel; return treeLevel;
} }
public void setTreeLevel(String treeLevel) { public void setTreeLevel(Integer treeLevel) {
this.treeLevel = 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;
}
} }

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

@ -2,6 +2,7 @@ package com.tamguo.modules.tiku.service;
import java.util.List; import java.util.List;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.service.IService; import com.baomidou.mybatisplus.service.IService;
import com.tamguo.modules.tiku.model.ChapterEntity; import com.tamguo.modules.tiku.model.ChapterEntity;
import com.tamguo.modules.tiku.model.condition.ChapterCondition; import com.tamguo.modules.tiku.model.condition.ChapterCondition;
@ -14,4 +15,10 @@ public interface IChapterService extends IService<ChapterEntity>{
// 章节列表 // 章节列表
public List<ChapterEntity> listData(ChapterCondition condition); public List<ChapterEntity> listData(ChapterCondition condition);
// 章节树形数据
public JSONArray treeData(String courseId, String excludeId);
// 保存章节
public void save(ChapterEntity chapter);
} }

@ -8,12 +8,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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.mapper.Condition;
import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tamguo.common.utils.SystemConstant; import com.tamguo.common.utils.SystemConstant;
import com.tamguo.modules.tiku.dao.ChapterMapper; import com.tamguo.modules.tiku.dao.ChapterMapper;
import com.tamguo.modules.tiku.model.ChapterEntity; import com.tamguo.modules.tiku.model.ChapterEntity;
import com.tamguo.modules.tiku.model.condition.ChapterCondition; import com.tamguo.modules.tiku.model.condition.ChapterCondition;
import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum;
import com.tamguo.modules.tiku.service.IChapterService; import com.tamguo.modules.tiku.service.IChapterService;
@Service @Service
@ -83,5 +86,49 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
} }
return chapterMapper.selectList(query); return chapterMapper.selectList(query);
} }
@SuppressWarnings("unchecked")
@Override
public JSONArray treeData(String courseId, String excludeId) {
List<ChapterEntity> 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<ChapterEntity> chapterList) {
if(chapterList != null) {
JSONArray nodes = new JSONArray();
for(int i=0 ; i<chapterList.size() ; i++) {
JSONObject node = new JSONObject();
ChapterEntity office = chapterList.get(i);
node.put("name", office.getName());
node.put("id", office.getId());
node.put("pId", office.getParentCode());
node.put("title", office.getName());
nodes.add(node);
}
return nodes;
}
return null;
}
@Transactional(readOnly=false)
@Override
public void save(ChapterEntity chapter) {
ChapterEntity parentChapter = chapterMapper.selectById(chapter.getParentCode());
chapter.setStatus(ChapterStatusEnum.NORMAL);
chapter.setTreeLeaf(true);
chapter.setTreeLevel(parentChapter.getTreeLevel() + 1);
chapter.setBookId(parentChapter.getBookId());
chapterMapper.insert(chapter);
chapter.setParentCodes(parentChapter.getParentCodes() + chapter.getId() + ",");
chapterMapper.updateById(chapter);
}
} }

@ -6,6 +6,11 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; 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 com.alibaba.fastjson.JSONArray;
import com.tamguo.common.utils.ExceptionSupport;
import com.tamguo.common.utils.Result;
import com.tamguo.modules.tiku.model.ChapterEntity; import com.tamguo.modules.tiku.model.ChapterEntity;
import com.tamguo.modules.tiku.model.condition.ChapterCondition; import com.tamguo.modules.tiku.model.condition.ChapterCondition;
import com.tamguo.modules.tiku.service.IChapterService; import com.tamguo.modules.tiku.service.IChapterService;
@ -14,12 +19,40 @@ import com.tamguo.modules.tiku.service.IChapterService;
@RequestMapping(path="tiku/chapter") @RequestMapping(path="tiku/chapter")
public class ChapterController { public class ChapterController {
private final String ADD_CHAPTER_PAGE = "modules/tiku/chapter/add";
@Autowired @Autowired
private IChapterService iChapterService; private IChapterService iChapterService;
@RequestMapping(path="add",method=RequestMethod.GET)
public ModelAndView add(String parentChapterId , ModelAndView model) {
ChapterEntity parentChapter = iChapterService.selectById(parentChapterId);
model.addObject("parentChapter", parentChapter);
model.setViewName(ADD_CHAPTER_PAGE);
return model;
}
@RequestMapping(path="listData",method=RequestMethod.POST) @RequestMapping(path="listData",method=RequestMethod.POST)
@ResponseBody @ResponseBody
public List<ChapterEntity> listData(ChapterCondition condition) { public List<ChapterEntity> listData(ChapterCondition condition) {
return iChapterService.listData(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);
}
}
} }

@ -26,14 +26,15 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button> <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div> </div>
</div> </div>
<form id="inputForm" th:action="${setting.domain + 'tiku/book/save'}" method="post" class="form-horizontal"> <form id="inputForm" th:action="${setting.domain + 'tiku/chapter/save'}" method="post" class="form-horizontal">
<input type="hidden" id="courseId" name="courseId" th:value="${parentChapter.courseId}"/>
<div class="box-body"> <div class="box-body">
<div class="form-unit">基本信息</div> <div class="form-unit">基本信息</div>
<div class="row"> <div class="row">
<div class="col-xs-6"> <div class="col-xs-6">
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-4" title=""> <label class="control-label col-sm-4" title="">
<span class="required ">*</span> 书籍名称:<i class="fa icon-question hide"></i></label> <span class="required ">*</span> 章节名称:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="text" id="name" name="name" value="" maxlength="100" class="form-control required "/> <input type="text" id="name" name="name" value="" maxlength="100" class="form-control required "/>
</div> </div>
@ -42,44 +43,33 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
<div class="col-xs-6"> <div class="col-xs-6">
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-4" title=""> <label class="control-label col-sm-4" title="">
<span class="required ">*</span> 出版社<i class="fa icon-question hide"></i></label> <span class="required">*</span> 上级章节<i class="fa icon-question hide"></i></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="text" id="publishingHouse" name="publishingHouse" value="" maxlength="64" class="form-control required"/> <div class="input-group treeselect" id="chapterDiv" data-url="tiku/chapter/treeData?">
</div> <input id="parentCode" type="hidden" name="parentCode" th:value="${parentChapter.id}" class="isReset"/>
</div> <input id="parentName" type="text" name="parentName" th:value="${parentChapter.name}"
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required">*</span> 归属科目:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<div class="input-group treeselect" id="companyDiv" data-url="tiku/course/treeData?">
<input id="courseId" type="hidden" name="courseId" value="" class="isReset"/>
<input id="courseName" type="text" name="courseName" value=""
class="form-control " readonly="readonly" class="form-control " readonly="readonly"
/><span class="input-group-btn"><a id="companyButton" href="javascript:" /><span class="input-group-btn"><a id="chapterButton" href="javascript:"
class="btn btn-default "><i class="fa fa-search"></i></a> class="btn btn-default "><i class="fa fa-search"></i></a>
</span> </span>
</div> </div>
<script> <script>
$("#companyButton,#courseName").click(function(){ $("#chapterButton,#parentName").click(function(){
if ($("#companyButton").hasClass("disabled")){ if ($("#chapterButton").hasClass("disabled")){
return true; return true;
} }
var options = { var options = {
type: 2, type: 2,
maxmin: true, maxmin: true,
shadeClose: true, shadeClose: true,
title: '公司选择', title: '章节选择',
area: ['300px', '400px'], area: ['300px', '400px'],
content: 'sys/treeselect', content: 'sys/treeselect',
contentFormData: { contentFormData: {
url: $('#companyDiv').attr('data-url'), url: $('#chapterDiv').attr('data-url'),
checkbox: 'false', checkbox: 'false',
expandLevel: '-1', expandLevel: '-1',
selectCodes: $("#courseId").val(), selectCodes: $("#parentCode").val(),
isReturnValue: 'false' isReturnValue: 'false'
}, },
success: function(layero, index){ success: function(layero, index){
@ -98,14 +88,14 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
nodes = win.tree.getSelectedNodes(); nodes = win.tree.getSelectedNodes();
} }
for(var i=0; i<nodes.length; i++) { for(var i=0; i<nodes.length; i++) {
if (nodes[i].level == 0 && nodes[i].isParent){ /* if (nodes[i].level == 0 && nodes[i].isParent){
js.showMessage("不能选择根节点("+nodes[i].name+")请重新选择。"); js.showMessage("不能选择根节点("+nodes[i].name+")请重新选择。");
return false; return false;
} }
if (nodes[i].isParent){ if (nodes[i].isParent){
js.showMessage("不能选择父节点("+nodes[i].name+")请重新选择。"); js.showMessage("不能选择父节点("+nodes[i].name+")请重新选择。");
return false; return false;
} } */
var code = nodes[i]['false'=='true'?'value':'id'], name = nodes[i]['name']; var code = nodes[i]['false'=='true'?'value':'id'], name = nodes[i]['name'];
codes.push(code.replace(/^u_/g,'')); codes.push(code.replace(/^u_/g,''));
names.push(name.replace(/\([0-9]*\)/g,'')); names.push(name.replace(/\([0-9]*\)/g,''));
@ -116,39 +106,31 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
return false; return false;
} }
} }
$("#courseId").val(codes.join(',')).change(); $("#parentCode").val(codes.join(',')).change();
$("#courseName").val(names.join(',')).change(); $("#parentName").val(names.join(',')).change();
try { $('#courseId,#courseName').valid(); }catch(e){} try { $('#parentCode,#parentName').valid(); }catch(e){}
if(typeof treeselectCallback == 'function'){ if(typeof treeselectCallback == 'function'){
treeselectCallback('course', 'ok', index, layero, nodes); treeselectCallback('chapter', 'ok', index, layero, nodes);
} }
} }
}; };
options.btn.push('<i class="fa fa-eraser"></i> 清除'); options.btn.push('<i class="fa fa-eraser"></i> 清除');
options['btn'+options.btn.length] = function(index, layero){ options['btn'+options.btn.length] = function(index, layero){
$("#courseId").val('').change(); $("#parentCode").val('').change();
$("#courseName").val('').change(); $("#parentName").val('').change();
if(typeof treeselectCallback == 'function'){ if(typeof treeselectCallback == 'function'){
treeselectCallback('course', 'clear', index, layero); treeselectCallback('chapter', 'clear', index, layero);
} }
}; };
options.btn.push('<i class="fa fa-close"></i> 关闭'); options.btn.push('<i class="fa fa-close"></i> 关闭');
options['btn'+options.btn.length] = function(index, layero){ options['btn'+options.btn.length] = function(index, layero){
if(typeof treeselectCallback == 'function'){ if(typeof treeselectCallback == 'function'){
treeselectCallback('course', 'cancel', index, layero); treeselectCallback('chapter', 'cancel', index, layero);
} }
}; };
js.layer.open(options); js.layer.open(options);
}); });
</script> </div> </script>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required hide">*</span> 排序号:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<input type="text" id="sort" name="sort" value="" maxlength="10" class="form-control digits"/>
</div> </div>
</div> </div>
</div> </div>
@ -173,6 +155,17 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required hide">*</span> 排序:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<input type="text" id="orders" name="orders" value="" maxlength="64" class="form-control required"/>
</div>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="form-group"> <div class="form-group">

@ -86,22 +86,31 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
$('#dataGrid').dataGrid({ $('#dataGrid').dataGrid({
searchForm: $("#searchForm"), searchForm: $("#searchForm"),
columnModel: [ 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+' ) '+'<a href="sys/office/update?officeCode='+row.officeCode+'" class="btnList" data-title="编辑机构">'+(val||row.id)+'</a>'; return '( '+row.id+' ) '+'<a href="sys/office/update?officeCode='+row.officeCode+'" class="btnList" data-title="编辑机构">'+(val||row.id)+'</a>';
}}, }},
{header:'问题数量', name:'questionNum', index:'a.question_num', width:100, align:"center"}, {header:'问题数量', name:'questionNum', index:'a.question_num', width:100, align:"center"},
{header:'知识点数量', name:'pointNum', index:'a.pointNum', 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 '<span style="color:red;">停用</span>';
}else{
return '<span style="color:red;">未知</span>';
}
}},
{header:'操作', name:'actions', width:100, sortable:false, title:false, formatter: function(val, obj, row, act){
var actions = []; var actions = [];
actions.push('<a href="sys/chapter/update?officeCode='+row.officeCode+'" class="btnList" title="编辑机构"><i class="fa fa-pencil"></i></a>&nbsp;'); actions.push('<a href="tiku/chapter/update?officeCode='+row.officeCode+'" class="btnList" title="编辑机构"><i class="fa fa-pencil"></i></a>&nbsp;');
if (row.status == Global.STATUS_NORMAL){ if (row.status == Global.STATUS_NORMAL){
actions.push('<a href="sys/chapter/disable?officeCode='+row.officeCode+'" class="btnList" title="停用机构" data-confirm="确认要停用该机构吗?"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;'); actions.push('<a href="sys/chapter/disable?officeCode='+row.officeCode+'" class="btnList" title="停用机构" data-confirm="确认要停用该机构吗?"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
} }
if (row.status == Global.STATUS_DISABLE){ if (row.status == Global.STATUS_DISABLE){
actions.push('<a href="sys/chapter/enable?officeCode='+row.officeCode+'" class="btnList" title="启用机构" data-confirm="确认要启用该机构吗?"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;'); actions.push('<a href="sys/chapter/enable?officeCode='+row.officeCode+'" class="btnList" title="启用机构" data-confirm="确认要启用该机构吗?"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
} }
actions.push('<a href="sys/chapter/delete?officeCode='+row.officeCode+'" class="btnList" title="删除机构" data-confirm="确认要删除该机构及所有子机构吗?" data-deltreenode="'+row.id+'"><i class="fa fa-trash-o"></i></a>&nbsp;'); actions.push('<a href="tiku/chapter/delete?officeCode='+row.officeCode+'" class="btnList" title="删除机构" data-confirm="确认要删除该机构及所有子机构吗?" data-deltreenode="'+row.id+'"><i class="fa fa-trash-o"></i></a>&nbsp;');
actions.push('<a href="sys/chapter/add?parentCode='+row.id+'" class="btnList" title="新增下级机构"><i class="fa fa-plus-square"></i></a>&nbsp;'); actions.push('<a href="tiku/chapter/add?parentChapterId='+row.id+'" class="btnList" title="新增下级章节"><i class="fa fa-plus-square"></i></a>&nbsp;');
return actions.join(''); return actions.join('');
}} }}
], ],

Loading…
Cancel
Save