试卷分类扩展层级不卡控

This commit is contained in:
flower 2018-12-18 22:59:33 +08:00
parent ce5c7314de
commit f08bb2c98d
3 changed files with 144 additions and 165 deletions

View File

@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import com.ruoyi.exam.domain.ExamPaperCategory; import com.ruoyi.exam.domain.ExamPaperCategory;
import com.ruoyi.exam.domain.ExamQuestion;
import com.ruoyi.exam.service.IExamQuestionService;
import com.ruoyi.framework.web.util.ShiroUtils; import com.ruoyi.framework.web.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -33,169 +35,159 @@ import com.ruoyi.common.utils.ExcelUtil;
*/ */
@Controller @Controller
@RequestMapping("/exam/examQuestionCategory") @RequestMapping("/exam/examQuestionCategory")
public class ExamQuestionCategoryController extends BaseController public class ExamQuestionCategoryController extends BaseController {
{ private String prefix = "exam/examQuestionCategory";
private String prefix = "exam/examQuestionCategory";
@Autowired @Autowired
private IExamQuestionCategoryService examQuestionCategoryService; private IExamQuestionCategoryService examQuestionCategoryService;
@RequiresPermissions("exam:examQuestionCategory:view") @Autowired
@GetMapping() private IExamQuestionService examQuestionService;
public String examQuestionCategory()
{ @RequiresPermissions("exam:examQuestionCategory:view")
return prefix + "/examQuestionCategory"; @GetMapping()
} public String examQuestionCategory() {
return prefix + "/examQuestionCategory";
}
/**
* 查询试题分类列表
*/
@RequiresPermissions("exam:examQuestionCategory:list")
@GetMapping("/list")
@ResponseBody
public List<ExamQuestionCategory> list(ExamQuestionCategory examQuestionCategory) {
/** List<ExamQuestionCategory> list = examQuestionCategoryService.selectExamQuestionCategoryList(examQuestionCategory);
* 查询试题分类列表 return list;
*/ }
@RequiresPermissions("exam:examQuestionCategory:list")
@GetMapping("/list")
@ResponseBody
public List<ExamQuestionCategory> list(ExamQuestionCategory examQuestionCategory)
{
List<ExamQuestionCategory> list = examQuestionCategoryService.selectExamQuestionCategoryList(examQuestionCategory);
return list;
}
/** /**
* 导出试题分类列表 * 导出试题分类列表
*/ */
@RequiresPermissions("exam:examQuestionCategory:export") @RequiresPermissions("exam:examQuestionCategory:export")
@PostMapping("/export") @PostMapping("/export")
@ResponseBody @ResponseBody
public AjaxResult export(ExamQuestionCategory examQuestionCategory) public AjaxResult export(ExamQuestionCategory examQuestionCategory) {
{ List<ExamQuestionCategory> list = examQuestionCategoryService.selectExamQuestionCategoryList(examQuestionCategory);
List<ExamQuestionCategory> list = examQuestionCategoryService.selectExamQuestionCategoryList(examQuestionCategory); ExcelUtil<ExamQuestionCategory> util = new ExcelUtil<ExamQuestionCategory>(ExamQuestionCategory.class);
ExcelUtil<ExamQuestionCategory> util = new ExcelUtil<ExamQuestionCategory>(ExamQuestionCategory.class); return util.exportExcel(list, "examQuestionCategory");
return util.exportExcel(list, "examQuestionCategory"); }
}
/** /**
* 新增试题分类 * 新增试题分类
*/ */
@GetMapping("/add/{parentId}") @GetMapping("/add/{parentId}")
public String add(@PathVariable("parentId") String parentId, ModelMap mmap) public String add(@PathVariable("parentId") String parentId, ModelMap mmap) {
{ mmap.put("examQuestionCategory", examQuestionCategoryService.selectExamQuestionCategoryById(parentId));
mmap.put("examQuestionCategory", examQuestionCategoryService.selectExamQuestionCategoryById(parentId)); return prefix + "/add";
return prefix + "/add"; }
}
/** /**
* 新增保存试题分类 * 新增保存试题分类
*/ */
@RequiresPermissions("exam:examQuestionCategory:add") @RequiresPermissions("exam:examQuestionCategory:add")
@Log(title = "试题分类", businessType = BusinessType.INSERT) @Log(title = "试题分类", businessType = BusinessType.INSERT)
@PostMapping("/add") @PostMapping("/add")
@ResponseBody @ResponseBody
public AjaxResult addSave(ExamQuestionCategory examQuestionCategory) public AjaxResult addSave(ExamQuestionCategory examQuestionCategory) {
{ ExamQuestion examQuestion = new ExamQuestion();
examQuestionCategory.setCreateBy(ShiroUtils.getLoginName()); examQuestion.setCategoryId(examQuestionCategory.getParentId().toString());
examQuestionCategory.setCreateDate(new Date()); if (examQuestionService.selectList(examQuestion).size() > 0) {
return toAjax(examQuestionCategoryService.insertExamQuestionCategory(examQuestionCategory)); return error(1, "分类包含试题,不允许扩展分类");
} }
examQuestionCategory.setCreateBy(ShiroUtils.getLoginName());
examQuestionCategory.setCreateDate(new Date());
return toAjax(examQuestionCategoryService.insertExamQuestionCategory(examQuestionCategory));
}
/** /**
* 修改试题分类 * 修改试题分类
*/ */
@GetMapping("/edit/{id}") @GetMapping("/edit/{id}")
public String edit(@PathVariable("id") String id, ModelMap mmap) public String edit(@PathVariable("id") String id, ModelMap mmap) {
{ ExamQuestionCategory examQuestionCategory = examQuestionCategoryService.selectExamQuestionCategoryById(id);
ExamQuestionCategory examQuestionCategory = examQuestionCategoryService.selectExamQuestionCategoryById(id); mmap.put("examQuestionCategory", examQuestionCategory);
mmap.put("examQuestionCategory", examQuestionCategory); return prefix + "/edit";
return prefix + "/edit"; }
}
/** /**
* 修改保存试题分类 * 修改保存试题分类
*/ */
@RequiresPermissions("exam:examQuestionCategory:edit") @RequiresPermissions("exam:examQuestionCategory:edit")
@Log(title = "试题分类", businessType = BusinessType.UPDATE) @Log(title = "试题分类", businessType = BusinessType.UPDATE)
@PostMapping("/edit") @PostMapping("/edit")
@ResponseBody @ResponseBody
public AjaxResult editSave(ExamQuestionCategory examQuestionCategory) public AjaxResult editSave(ExamQuestionCategory examQuestionCategory) {
{ return toAjax(examQuestionCategoryService.updateExamQuestionCategory(examQuestionCategory));
return toAjax(examQuestionCategoryService.updateExamQuestionCategory(examQuestionCategory)); }
}
/** /**
* 删除试题分类 * 删除试题分类
*/ */
@RequiresPermissions("exam:examQuestionCategory:remove") @RequiresPermissions("exam:examQuestionCategory:remove")
@Log(title = "试题分类", businessType = BusinessType.DELETE) @Log(title = "试题分类", businessType = BusinessType.DELETE)
@PostMapping( "/remove") @PostMapping("/remove")
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids) {
{ return toAjax(examQuestionCategoryService.deleteExamQuestionCategoryByIds(ids));
return toAjax(examQuestionCategoryService.deleteExamQuestionCategoryByIds(ids)); }
}
/** /**
* 选择部门树 * 选择部门树
*/ */
@GetMapping("/selectExamQuestionCategoryTree/{examQuestionCategoryId}") @GetMapping("/selectExamQuestionCategoryTree/{examQuestionCategoryId}")
public String selectDeptTree(@PathVariable("examQuestionCategoryId") String examQuestionCategoryId, ModelMap mmap) public String selectDeptTree(@PathVariable("examQuestionCategoryId") String examQuestionCategoryId, ModelMap mmap) {
{ mmap.put("examQuestionCategory", examQuestionCategoryService.selectExamQuestionCategoryById(examQuestionCategoryId));
mmap.put("examQuestionCategory", examQuestionCategoryService.selectExamQuestionCategoryById(examQuestionCategoryId)); return prefix + "/tree";
return prefix + "/tree"; }
}
/** /**
* 加载列表树 * 加载列表树
*/ */
@GetMapping("/treeData") @GetMapping("/treeData")
@ResponseBody @ResponseBody
public List<Map<String, Object>> treeData() public List<Map<String, Object>> treeData() {
{ List<Map<String, Object>> tree = examQuestionCategoryService.selectDeptTree();
List<Map<String, Object>> tree = examQuestionCategoryService.selectDeptTree(); return tree;
return tree; }
}
/** /**
* 选择部门树 * 选择部门树
*/ */
@GetMapping("/treeDataForAdd") @GetMapping("/treeDataForAdd")
@ResponseBody @ResponseBody
public List<Map<String, Object>> treeDataForAdd() public List<Map<String, Object>> treeDataForAdd() {
{ List<Map<String, Object>> tree = examQuestionCategoryService.selectDeptTree();
List<Map<String, Object>> tree = examQuestionCategoryService.selectDeptTree(); return tree;
List<Map<String, Object>> res = new ArrayList<>(); }
for (Map<String, Object> stringObjectMap : tree) {
String pId = stringObjectMap.get("pId").toString();
if(pId.equals("0")||pId.equals("1")){
res.add(stringObjectMap);
}
} /**
* 删除
*/
@Log(title = "试题分类管理", businessType = BusinessType.DELETE)
@RequiresPermissions("system:examQuestionCategory:remove")
@PostMapping("/remove/{id}")
@ResponseBody
public AjaxResult remove(@PathVariable("id") Long id) {
ExamQuestionCategory exam = new ExamQuestionCategory();
exam.setParentId(id);
if (examQuestionCategoryService.selectList(exam).size() > 0) {
return error(1, "存在下级分类,不允许删除");
}
ExamQuestion examQuestion = new ExamQuestion();
examQuestion.setCategoryId(id.toString());
return res; if (examQuestionService.selectList(examQuestion).size() > 0) {
} return error(1, "分类包含试题,不允许删除");
}
/** return toAjax(examQuestionCategoryService.deleteById(id));
* 删除 }
*/
@Log(title = "试题分类管理", businessType = BusinessType.DELETE)
@RequiresPermissions("system:examQuestionCategory:remove")
@PostMapping("/remove/{id}")
@ResponseBody
public AjaxResult remove(@PathVariable("id") Long id)
{
ExamQuestionCategory exam = new ExamQuestionCategory();
exam.setParentId(id);
if (examQuestionCategoryService.selectList(exam).size() > 0)
{
return error(1, "存在下级分类,不允许删除");
}
return toAjax(examQuestionCategoryService.deleteById(id));
}
} }

View File

@ -36,7 +36,7 @@
<div class="row"> <div class="row">
<div class="col-sm-12 search-collapse"> <div class="col-sm-12 search-collapse">
<form id="formId"> <form id="formId">
<input type="hidden" id="categoryId" name="categoryId"> <input type="hidden" id="categoryId" name="categoryId" >
<div class="select-list"> <div class="select-list">
<ul> <ul>
<li> <li>
@ -97,7 +97,9 @@
$(function () { $(function () {
$('body').layout({west__size: 185}); $('body').layout({west__size: 185});
$("#categoryId").val(0);
queryExamQuestionList(); queryExamQuestionList();
// $.table.search();
queryExamQuestionCategoryTree(); queryExamQuestionCategoryTree();
}); });
@ -188,9 +190,9 @@
$.tree.init(options); $.tree.init(options);
function zOnClick(event, treeId, treeNode) { function zOnClick(event, treeId, treeNode) {
if(treeNode.pId == 1 || treeNode.pId == 0 ||treeNode.pId == null) { // if(treeNode.pId == 1 || treeNode.pId == 0 ||treeNode.pId == null) {
return; // return;
} // }
$("#categoryId").val(treeNode.id); $("#categoryId").val(treeNode.id);
$.table.search(); $.table.search();
} }
@ -220,7 +222,7 @@
} }
function addChoiceQuestion(){ function addChoiceQuestion(){
if($("#categoryId").val() == null||$("#categoryId").val() == ''){ if($("#categoryId").val() == null||$("#categoryId").val() == ''||$("#categoryId").val() == 1 || $("#categoryId").val() == 0 ){
alert("请选择题库!") alert("请选择题库!")
return; return;
} }
@ -229,7 +231,7 @@
} }
function addMoreChoiceQuestion(){ function addMoreChoiceQuestion(){
if($("#categoryId").val() == null||$("#categoryId").val() == ''){ if($("#categoryId").val() == null||$("#categoryId").val() == ''||$("#categoryId").val() == 1 || $("#categoryId").val() == 0 ){
alert("请选择题库!") alert("请选择题库!")
return; return;
} }
@ -238,7 +240,7 @@
} }
function addJudgeQuestion(){ function addJudgeQuestion(){
if($("#categoryId").val() == null||$("#categoryId").val() == ''){ if($("#categoryId").val() == null||$("#categoryId").val() == ''||$("#categoryId").val() == 1 || $("#categoryId").val() == 0 ){
alert("请选择题库!") alert("请选择题库!")
return; return;
} }

View File

@ -73,11 +73,6 @@
field: 'name', field: 'name',
title: '分类', title: '分类',
align: "left" align: "left"
},
{
field: 'orderNum',
title: '排序',
align: "left"
}, },
{ {
field : 'createBy', field : 'createBy',
@ -87,16 +82,6 @@
{ {
field : 'createDate', field : 'createDate',
title : '创建时间', title : '创建时间',
align: "left"
},
{
field : 'updateBy',
title : '更新者',
align: "left"
},
{
field : 'updateDate',
title : '更新时间',
align: "left" align: "left"
}, },
{ {