试卷分类扩展层级不卡控

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,30 +35,29 @@ 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;
@Autowired
private IExamQuestionService examQuestionService;
@RequiresPermissions("exam:examQuestionCategory:view") @RequiresPermissions("exam:examQuestionCategory:view")
@GetMapping() @GetMapping()
public String examQuestionCategory() public String examQuestionCategory() {
{
return prefix + "/examQuestionCategory"; return prefix + "/examQuestionCategory";
} }
/** /**
* 查询试题分类列表 * 查询试题分类列表
*/ */
@RequiresPermissions("exam:examQuestionCategory:list") @RequiresPermissions("exam:examQuestionCategory:list")
@GetMapping("/list") @GetMapping("/list")
@ResponseBody @ResponseBody
public List<ExamQuestionCategory> list(ExamQuestionCategory examQuestionCategory) public List<ExamQuestionCategory> list(ExamQuestionCategory examQuestionCategory) {
{
List<ExamQuestionCategory> list = examQuestionCategoryService.selectExamQuestionCategoryList(examQuestionCategory); List<ExamQuestionCategory> list = examQuestionCategoryService.selectExamQuestionCategoryList(examQuestionCategory);
return list; return list;
@ -69,8 +70,7 @@ public class ExamQuestionCategoryController extends BaseController
@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");
@ -80,8 +80,7 @@ public class ExamQuestionCategoryController extends BaseController
* 新增试题分类 * 新增试题分类
*/ */
@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";
} }
@ -93,8 +92,12 @@ public class ExamQuestionCategoryController extends BaseController
@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();
examQuestion.setCategoryId(examQuestionCategory.getParentId().toString());
if (examQuestionService.selectList(examQuestion).size() > 0) {
return error(1, "分类包含试题,不允许扩展分类");
}
examQuestionCategory.setCreateBy(ShiroUtils.getLoginName()); examQuestionCategory.setCreateBy(ShiroUtils.getLoginName());
examQuestionCategory.setCreateDate(new Date()); examQuestionCategory.setCreateDate(new Date());
return toAjax(examQuestionCategoryService.insertExamQuestionCategory(examQuestionCategory)); return toAjax(examQuestionCategoryService.insertExamQuestionCategory(examQuestionCategory));
@ -104,8 +107,7 @@ public class ExamQuestionCategoryController extends BaseController
* 修改试题分类 * 修改试题分类
*/ */
@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";
@ -118,8 +120,7 @@ public class ExamQuestionCategoryController extends BaseController
@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));
} }
@ -128,10 +129,9 @@ public class ExamQuestionCategoryController extends BaseController
*/ */
@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));
} }
@ -140,8 +140,7 @@ public class ExamQuestionCategoryController extends BaseController
* 选择部门树 * 选择部门树
*/ */
@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";
} }
@ -152,8 +151,7 @@ public class ExamQuestionCategoryController extends BaseController
*/ */
@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;
} }
@ -164,19 +162,9 @@ public class ExamQuestionCategoryController extends BaseController
*/ */
@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();
List<Map<String, Object>> res = new ArrayList<>(); return tree;
for (Map<String, Object> stringObjectMap : tree) {
String pId = stringObjectMap.get("pId").toString();
if(pId.equals("0")||pId.equals("1")){
res.add(stringObjectMap);
}
}
return res;
} }
/** /**
@ -186,14 +174,18 @@ public class ExamQuestionCategoryController extends BaseController
@RequiresPermissions("system:examQuestionCategory:remove") @RequiresPermissions("system:examQuestionCategory:remove")
@PostMapping("/remove/{id}") @PostMapping("/remove/{id}")
@ResponseBody @ResponseBody
public AjaxResult remove(@PathVariable("id") Long id) public AjaxResult remove(@PathVariable("id") Long id) {
{
ExamQuestionCategory exam = new ExamQuestionCategory(); ExamQuestionCategory exam = new ExamQuestionCategory();
exam.setParentId(id); exam.setParentId(id);
if (examQuestionCategoryService.selectList(exam).size() > 0) if (examQuestionCategoryService.selectList(exam).size() > 0) {
{
return error(1, "存在下级分类,不允许删除"); return error(1, "存在下级分类,不允许删除");
} }
ExamQuestion examQuestion = new ExamQuestion();
examQuestion.setCategoryId(id.toString());
if (examQuestionService.selectList(examQuestion).size() > 0) {
return error(1, "分类包含试题,不允许删除");
}
return toAjax(examQuestionCategoryService.deleteById(id)); 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"
}, },
{ {