问题页面,根父节点不能选,递归显示所有下级节点问题

This commit is contained in:
flower 2018-12-19 00:13:34 +08:00
parent f08bb2c98d
commit c7ccd80b24
2 changed files with 39 additions and 38 deletions

View File

@ -1,7 +1,11 @@
package com.ruoyi.exam.controller; package com.ruoyi.exam.controller;
import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import com.ruoyi.exam.domain.ExamQuestionCategory;
import com.ruoyi.exam.service.IExamQuestionCategoryService;
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;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -32,6 +36,9 @@ public class ExamQuestionController extends BaseController
@Autowired @Autowired
private IExamQuestionService examQuestionService; private IExamQuestionService examQuestionService;
@Autowired
private IExamQuestionCategoryService examQuestionCategoryService;
@RequiresPermissions("exam:examQuestion:view") @RequiresPermissions("exam:examQuestion:view")
@GetMapping() @GetMapping()
public String examQuestion() public String examQuestion()
@ -71,8 +78,28 @@ public class ExamQuestionController extends BaseController
@ResponseBody @ResponseBody
public TableDataInfo list(ExamQuestion examQuestion) public TableDataInfo list(ExamQuestion examQuestion)
{ {
List<ExamQuestion> list = examQuestionService.selectExamQuestionList(examQuestion); ArrayList<ExamQuestion> objects = new ArrayList<>();
return getDataTable(list); List<ExamQuestion> listByIds = getListByIds(objects, examQuestion);
return getDataTable(listByIds);
}
/**
* 递归找到所有下级的题目
* @param list
* @param examQuestion
* @return
*/
private List<ExamQuestion> getListByIds(List<ExamQuestion> list,ExamQuestion examQuestion){
list.addAll(examQuestionService.selectExamQuestionList(examQuestion));
String categoryId = examQuestion.getCategoryId();
ExamQuestionCategory examQuestionCategory = new ExamQuestionCategory();
examQuestionCategory.setParentId(Long.parseLong(categoryId));
List<ExamQuestionCategory> examQuestionCategories = examQuestionCategoryService.selectList(examQuestionCategory);
for (ExamQuestionCategory questionCategory : examQuestionCategories) {
examQuestion.setCategoryId(questionCategory.getId().toString());
getListByIds(list,examQuestion);
}
return list;
} }

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" value="1">
<div class="select-list"> <div class="select-list">
<ul> <ul>
<li> <li>
@ -97,9 +97,9 @@
$(function () { $(function () {
$('body').layout({west__size: 185}); $('body').layout({west__size: 185});
$("#categoryId").val(0);
queryExamQuestionList(); queryExamQuestionList();
// $.table.search(); $("#categoryId").val(1);
$.table.search();
queryExamQuestionCategoryTree(); queryExamQuestionCategoryTree();
}); });
@ -116,21 +116,11 @@
columns: [{ columns: [{
checkbox: true checkbox: true
}, },
{
field: 'id',
title: 'ID',
sortable: true
},
{ {
field: 'title', field: 'title',
title: '问题标题', title: '问题标题',
sortable: true sortable: true
}, },
{
field: 'answer',
title: '问题答案',
sortable: true
},
{ {
field: 'type', field: 'type',
title: '问题类型', title: '问题类型',
@ -151,19 +141,9 @@
title: '创建时间', title: '创建时间',
sortable: true sortable: true
}, },
{
field: 'updateBy',
title: '更新者',
sortable: true
},
{
field: 'updateDate',
title: '更新时间',
sortable: true
},
{ {
field: 'remarks', field: 'remarks',
title: '备注信息', title: '答案解析',
sortable: true sortable: true
}, },
{ {
@ -190,9 +170,6 @@
$.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) {
// return;
// }
$("#categoryId").val(treeNode.id); $("#categoryId").val(treeNode.id);
$.table.search(); $.table.search();
} }
@ -222,27 +199,24 @@
} }
function addChoiceQuestion(){ function addChoiceQuestion(){
if($("#categoryId").val() == null||$("#categoryId").val() == ''||$("#categoryId").val() == 1 || $("#categoryId").val() == 0 ){ if(!$.tree.notAllowParents($._tree)){
alert("请选择题库!") return ;
return;
} }
var url = prefix + "/choiceadd/"+$("#categoryId").val(); var url = prefix + "/choiceadd/"+$("#categoryId").val();
$.operate.jumpModeltoUrl("添加单选题",url); $.operate.jumpModeltoUrl("添加单选题",url);
} }
function addMoreChoiceQuestion(){ function addMoreChoiceQuestion(){
if($("#categoryId").val() == null||$("#categoryId").val() == ''||$("#categoryId").val() == 1 || $("#categoryId").val() == 0 ){ if(!$.tree.notAllowParents($._tree)){
alert("请选择题库!") return ;
return;
} }
var url = prefix + "/morechoiceadd/"+$("#categoryId").val(); var url = prefix + "/morechoiceadd/"+$("#categoryId").val();
$.operate.jumpModeltoUrl("添加多选题",url); $.operate.jumpModeltoUrl("添加多选题",url);
} }
function addJudgeQuestion(){ function addJudgeQuestion(){
if($("#categoryId").val() == null||$("#categoryId").val() == ''||$("#categoryId").val() == 1 || $("#categoryId").val() == 0 ){ if(!$.tree.notAllowParents($._tree)){
alert("请选择题库!") return ;
return;
} }
var url = prefix + "/judgeadd/"+$("#categoryId").val(); var url = prefix + "/judgeadd/"+$("#categoryId").val();
$.operate.jumpModeltoUrl("添加多选题",url); $.operate.jumpModeltoUrl("添加多选题",url);