From 923a6e49e89003c32548b6025297bcd7e19eabab Mon Sep 17 00:00:00 2001 From: flower Date: Fri, 21 Dec 2018 00:00:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7=E5=88=86?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E8=AF=95=E9=A2=98=E5=88=86=E7=B1=BB=E5=8D=A1?= =?UTF-8?q?=E6=8E=A7=EF=BC=8C=E8=AF=95=E5=8D=B7=E9=80=92=E5=BD=92=E5=91=A2?= =?UTF-8?q?=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExamPaperCategoryController.java | 48 ++++++++++++++----- .../exam/controller/ExamPaperController.java | 32 ++++++++++++- .../ExamQuestionCategoryController.java | 14 ++++++ .../ruoyi/exam/domain/ExamPaperCategory.java | 6 ++- .../exam/domain/ExamQuestionCategory.java | 2 + .../templates/exam/examPaper/examPaper.html | 7 +-- .../exam/examPaperCategory/edit.html | 27 +++++++++++ .../examPaperCategory/examPaperCategory.html | 2 +- .../exam/examQuestionCategory/edit.html | 24 ++++++++++ 9 files changed, 142 insertions(+), 20 deletions(-) diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperCategoryController.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperCategoryController.java index b7d59c7ac..cba0e5433 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperCategoryController.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperCategoryController.java @@ -5,6 +5,8 @@ import java.util.Date; import java.util.List; import java.util.Map; +import com.ruoyi.exam.domain.ExamPaper; +import com.ruoyi.exam.service.IExamPaperService; import com.ruoyi.framework.web.util.ShiroUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +40,9 @@ public class ExamPaperCategoryController extends BaseController @Autowired private IExamPaperCategoryService examPaperCategoryService; + + @Autowired + private IExamPaperService examPaperService; @RequiresPermissions("exam:examPaperCategory:view") @GetMapping() @@ -57,8 +62,8 @@ public class ExamPaperCategoryController extends BaseController List list = examPaperCategoryService.selectExamPaperCategoryPage(examPaperCategory); return list; } - - + + /** * 导出试卷分类列表 */ @@ -91,6 +96,11 @@ public class ExamPaperCategoryController extends BaseController @ResponseBody public AjaxResult addSave(ExamPaperCategory examPaperCategory) { + ExamPaper examPaper = new ExamPaper(); + examPaper.setExamPaperCategoryId(examPaperCategory.getParentId()); + if(examPaperService.selectList(examPaper).size()>0){ + return error(1, "分类包含试卷,不允许扩展分类"); + } examPaperCategory.setCreateBy(ShiroUtils.getLoginName()); examPaperCategory.setCreateDate(new Date()); examPaperCategory.setDelFlag("0"); @@ -104,7 +114,9 @@ public class ExamPaperCategoryController extends BaseController public String edit(@PathVariable("id") Integer id, ModelMap mmap) { ExamPaperCategory examPaperCategory = examPaperCategoryService.selectById(id); + ExamPaperCategory parent = examPaperCategoryService.selectById(examPaperCategory.getParentId()); mmap.put("examPaperCategory", examPaperCategory); + mmap.put("parentName", parent.getName()); return prefix + "/edit"; } @@ -119,7 +131,21 @@ public class ExamPaperCategoryController extends BaseController { examPaperCategory.setUpdateBy(ShiroUtils.getLoginName()); examPaperCategory.setUpdateDate(new Date()); - return toAjax(examPaperCategoryService.updateSelectiveById(examPaperCategory)); + + ExamPaper examPaper = new ExamPaper(); + examPaper.setExamPaperCategoryId(examPaperCategory.getParentId()); + if(examPaperService.selectList(examPaper).size()>0){ + return error(1,"父级分类下面包含试卷,无法移动"); + } + + ExamPaperCategory exam = new ExamPaperCategory(); + exam.setParentId(examPaperCategory.getId()); + if (examPaperCategoryService.selectList(exam).size() > 0) + { + return error(1, "此分类存在下级分类,无法移动"); + } + + return toAjax(examPaperCategoryService.updateSelectiveById(examPaperCategory)); } /** @@ -151,16 +177,8 @@ public class ExamPaperCategoryController extends BaseController public List> treeDataForAdd() { List> tree = examPaperCategoryService.selectDeptTree(); - List> res = new ArrayList<>(); - for (Map stringObjectMap : tree) { - String pId = stringObjectMap.get("pId").toString(); - if(pId.equals("0")||pId.equals("1")){ - res.add(stringObjectMap); - } - } - - return res; + return tree; } /** @@ -178,6 +196,12 @@ public class ExamPaperCategoryController extends BaseController { return error(1, "存在下级分类,不允许删除"); } + ExamPaper examPaper = new ExamPaper(); + examPaper.setExamPaperCategoryId(id); + if(examPaperService.selectList(examPaper).size()>0){ + return error(1, "分类包含试卷,不允许删除分类"); + } + return toAjax(examPaperCategoryService.deleteById(id)); } diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java index 38cc0b578..c09ac2fcf 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java @@ -1,8 +1,13 @@ package com.ruoyi.exam.controller; +import java.util.ArrayList; import java.util.Date; import java.util.List; +import com.ruoyi.exam.domain.ExamPaperCategory; +import com.ruoyi.exam.domain.ExamQuestion; +import com.ruoyi.exam.domain.ExamQuestionCategory; +import com.ruoyi.exam.service.IExamPaperCategoryService; import com.ruoyi.exam.service.IExamPaperQuestionService; import com.ruoyi.framework.web.util.ShiroUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -34,6 +39,9 @@ public class ExamPaperController extends BaseController @Autowired private IExamPaperService examPaperService; + @Autowired + private IExamPaperCategoryService examPaperCategoryService; + @Autowired private IExamPaperQuestionService examPaperQuestionService; @@ -52,8 +60,28 @@ public class ExamPaperController extends BaseController @ResponseBody public TableDataInfo list(ExamPaper examPaper) { - List list = examPaperService.selectExamPaperPage(examPaper); - return getDataTable(list); + List list = new ArrayList<>(); + List listByIds = getListByIds(list, examPaper); + return getDataTable(listByIds); + } + + /** + * 递归找到所有下级的试卷 + * @param list + * @param examPaper + * @return + */ + private List getListByIds(List list,ExamPaper examPaper){ + list.addAll(examPaperService.selectExamPaperList(examPaper)); + String categoryId = examPaper.getExamPaperCategoryId().toString(); + ExamPaperCategory examPaperCategory = new ExamPaperCategory(); + examPaperCategory.setParentId(Integer.parseInt(categoryId)); + List examPaperCategorys = examPaperCategoryService.selectList(examPaperCategory); + for (ExamPaperCategory questionCategory : examPaperCategorys) { + examPaper.setExamPaperCategoryId(questionCategory.getId()); + getListByIds(list,examPaper); + } + return list; } diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamQuestionCategoryController.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamQuestionCategoryController.java index 60fae6d07..cfc881fb4 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamQuestionCategoryController.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamQuestionCategoryController.java @@ -109,7 +109,9 @@ public class ExamQuestionCategoryController extends BaseController { @GetMapping("/edit/{id}") public String edit(@PathVariable("id") String id, ModelMap mmap) { ExamQuestionCategory examQuestionCategory = examQuestionCategoryService.selectExamQuestionCategoryById(id); + ExamQuestionCategory parent = examQuestionCategoryService.selectExamQuestionCategoryById(examQuestionCategory.getParentId().toString()); mmap.put("examQuestionCategory", examQuestionCategory); + mmap.put("parentName", parent.getName()); return prefix + "/edit"; } @@ -121,6 +123,18 @@ public class ExamQuestionCategoryController extends BaseController { @PostMapping("/edit") @ResponseBody public AjaxResult editSave(ExamQuestionCategory examQuestionCategory) { + ExamQuestion examQuestion = new ExamQuestion(); + examQuestion.setCategoryId(examQuestionCategory.getParentId().toString()); + + if (examQuestionService.selectList(examQuestion).size() > 0) { + return error(1, "父级分类下包含试题,无法移动"); + } + + ExamQuestionCategory exam = new ExamQuestionCategory(); + exam.setParentId(exam.getId()); + if (examQuestionCategoryService.selectList(exam).size() > 0) { + return error(1, "此分类存在下级分类,无法移动"); + } return toAjax(examQuestionCategoryService.updateExamQuestionCategory(examQuestionCategory)); } diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperCategory.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperCategory.java index 0dd323825..a42752113 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperCategory.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperCategory.java @@ -41,8 +41,10 @@ private static final long serialVersionUID = 1L; private String remarks; /** 删除标记 */ private String delFlag; - - /** 设置试卷分类 */ + + + + /** 设置试卷分类 */ public void setId(Integer id) { this.id = id; diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamQuestionCategory.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamQuestionCategory.java index 3913564ac..32b529112 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamQuestionCategory.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamQuestionCategory.java @@ -41,6 +41,8 @@ public class ExamQuestionCategory private String orderNum; + + public String getOrderNum() { return orderNum; } diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html b/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html index 4d2c39089..174c12ac3 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html @@ -93,6 +93,8 @@ $(function () { $('body').layout({west__size: 185}); queryExamPaperList(); + $("#examPaperCategoryId").val(1); + $.table.search(); queryExamPaperCategoryTree(); }); @@ -206,9 +208,8 @@ function add(){ - if($("#examPaperCategoryId").val() == null||$("#examPaperCategoryId").val() == ''){ - alert("请选分类库!") - return; + if(!$.tree.notAllowParents($._tree)){ + return ; } var url = prefix + "/add/"+$("#examPaperCategoryId").val(); $.operate.jumpModeltoUrl("添加试卷",url); diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/edit.html b/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/edit.html index c0530385e..2bfa671e6 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/edit.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/edit.html @@ -4,9 +4,19 @@
+
+
+ +
+ +
+
+ +
+
@@ -46,6 +56,23 @@ $.operate.save(prefix + "/edit", $('#form-examPaperCategory-edit').serialize()); } } + + function selectExamPaperCategoryTree() { + var options = { + title: '分类选择', + width: "380", + url: prefix + "/selectExamPaperCategoryTree/" + $("#treeId").val(), + callBack: doSubmit + }; + $.modal.openOptions(options); + } + + function doSubmit(index, layero){ + var body = layer.getChildFrame('body', index); + $("#treeId").val(body.find('#treeId').val()); + $("#treeName").val(body.find('#treeName').val()); + layer.close(index); + } diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/examPaperCategory.html b/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/examPaperCategory.html index ec3075c8b..51bc271e2 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/examPaperCategory.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaperCategory/examPaperCategory.html @@ -84,7 +84,7 @@ }, { title: '操作', - align: 'center', + align: 'left', formatter: function(value, row, index) { if(row.id == 1){ return ''; diff --git a/ruoyi-exam/src/main/resources/templates/exam/examQuestionCategory/edit.html b/ruoyi-exam/src/main/resources/templates/exam/examQuestionCategory/edit.html index 2c5869902..a2ac7836c 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examQuestionCategory/edit.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examQuestionCategory/edit.html @@ -6,6 +6,13 @@
+ +
+ +
+ +
+
@@ -78,6 +85,23 @@ $.operate.save(prefix + "/edit", $('#form-examQuestionCategory-edit').serialize()); } } + + function selectExamQuestionCategoryTree() { + var options = { + title: '分类选择', + width: "380", + url: prefix + "/selectExamQuestionCategoryTree/" + $("#treeId").val(), + callBack: doSubmit + }; + $.modal.openOptions(options); + } + + function doSubmit(index, layero){ + var body = layer.getChildFrame('body', index); + $("#treeId").val(body.find('#treeId').val()); + $("#treeName").val(body.find('#treeName').val()); + layer.close(index); + }