试卷题目选择

This commit is contained in:
flower 2018-12-17 02:39:30 +08:00
parent d1ab7c6ec1
commit 8392af7bda
9 changed files with 806 additions and 0 deletions

View File

@ -0,0 +1,154 @@
package com.ruoyi.exam.controller;
import java.util.Date;
import java.util.List;
import com.ruoyi.exam.service.IExamPaperQuestionService;
import com.ruoyi.framework.web.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamPaper;
import com.ruoyi.exam.service.IExamPaperService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.ExcelUtil;
/**
* 试卷 信息操作处理
*
* @author zhujj
* @date 2018-12-16
*/
@Controller
@RequestMapping("/exam/examPaper")
public class ExamPaperController extends BaseController
{
private String prefix = "exam/examPaper";
@Autowired
private IExamPaperService examPaperService;
@Autowired
private IExamPaperQuestionService examPaperQuestionService;
@RequiresPermissions("exam:examPaper:view")
@GetMapping()
public String examPaper()
{
return prefix + "/examPaper";
}
/**
* 查询试卷列表
*/
@RequiresPermissions("exam:examPaper:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(ExamPaper examPaper)
{
List<ExamPaper> list = examPaperService.selectExamPaperPage(examPaper);
return getDataTable(list);
}
/**
* 导出试卷列表
*/
@RequiresPermissions("exam:examPaper:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(ExamPaper examPaper)
{
List<ExamPaper> list = examPaperService.selectExamPaperList(examPaper);
ExcelUtil<ExamPaper> util = new ExcelUtil<ExamPaper>(ExamPaper.class);
return util.exportExcel(list, "examPaper");
}
/**
* 新增试卷
*/
@GetMapping("/add/{id}")
public String add(@PathVariable("id") String id, ModelMap mmap)
{
mmap.put("examPaperCategoryId",id);
return prefix + "/add";
}
/**
* 新增保存试卷
*/
@RequiresPermissions("exam:examPaper:add")
@Log(title = "试卷", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(ExamPaper examPaper)
{
examPaper.setCreateBy(ShiroUtils.getLoginName());
examPaper.setCreateDate(new Date());
examPaper.setDelFlag("0");
return toAjax(examPaperService.insert(examPaper));
}
/**
* 修改试卷
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap mmap)
{
ExamPaper examPaper = examPaperService.selectById(id);
mmap.put("examPaper", examPaper);
return prefix + "/edit";
}
/**
* 修改保存试卷
*/
@RequiresPermissions("exam:examPaper:edit")
@Log(title = "试卷", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(ExamPaper examPaper)
{
examPaper.setUpdateBy(ShiroUtils.getLoginName());
examPaper.setUpdateDate(new Date());
return toAjax(examPaperService.updateSelectiveById(examPaper));
}
/**
* 删除试卷
*/
@RequiresPermissions("exam:examPaper:remove")
@Log(title = "试卷", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(examPaperService.deleteByIds(ids));
}
@GetMapping("/addQuestion/{id}")
public String addQuestion(@PathVariable("id") Integer id, ModelMap mmap)
{
mmap.put("examPaperId", id);
mmap.put("examPaperQuestionIds",examPaperQuestionService.selectQuestionIdsForPaperId(id));
return prefix + "/examQuestion";
}
@RequiresPermissions("exam:examPaper:remove")
@Log(title = "试卷", businessType = BusinessType.DELETE)
@PostMapping( "/saveQuestion")
@ResponseBody
public AjaxResult saveQuestion(@RequestParam(value = "questionId[]" ,required = false) String[] questionId,@RequestParam("paperId")String paperId)
{
return toAjax(examPaperQuestionService.saveQuestion(paperId,questionId));
}
}

View File

@ -0,0 +1,152 @@
package com.ruoyi.exam.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
import java.util.Date;
/**
* 试卷题目表 exam_paper_question
*
* @author zhujj
* @date 2018-12-17
*/
public class ExamPaperQuestion
{
private static final long serialVersionUID = 1L;
/** 试卷题目ID */
@Id
private Integer id;
/** 试卷代码 */
private Integer examPaperId;
/** */
private Integer examQuestionId;
/** 创建者 */
private String createBy;
/** 创建时间 */
private Date createDate;
/** 更新者 */
private String updateBy;
/** 更新时间 */
private Date updateDate;
/** 备注信息 */
private String remarks;
/** 删除标记 */
private String delFlag;
/** 设置试卷题目ID */
public void setId(Integer id)
{
this.id = id;
}
/** 获取试卷题目ID */
public Integer getId()
{
return id;
}
/** 设置试卷代码 */
public void setExamPaperId(Integer examPaperId)
{
this.examPaperId = examPaperId;
}
/** 获取试卷代码 */
public Integer getExamPaperId()
{
return examPaperId;
}
/** 设置 */
public void setExamQuestionId(Integer examQuestionId)
{
this.examQuestionId = examQuestionId;
}
/** 获取 */
public Integer getExamQuestionId()
{
return examQuestionId;
}
/** 设置创建者 */
public void setCreateBy(String createBy)
{
this.createBy = createBy;
}
/** 获取创建者 */
public String getCreateBy()
{
return createBy;
}
/** 设置创建时间 */
public void setCreateDate(Date createDate)
{
this.createDate = createDate;
}
/** 获取创建时间 */
public Date getCreateDate()
{
return createDate;
}
/** 设置更新者 */
public void setUpdateBy(String updateBy)
{
this.updateBy = updateBy;
}
/** 获取更新者 */
public String getUpdateBy()
{
return updateBy;
}
/** 设置更新时间 */
public void setUpdateDate(Date updateDate)
{
this.updateDate = updateDate;
}
/** 获取更新时间 */
public Date getUpdateDate()
{
return updateDate;
}
/** 设置备注信息 */
public void setRemarks(String remarks)
{
this.remarks = remarks;
}
/** 获取备注信息 */
public String getRemarks()
{
return remarks;
}
/** 设置删除标记 */
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
/** 获取删除标记 */
public String getDelFlag()
{
return delFlag;
}
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("examPaperId", getExamPaperId())
.append("examQuestionId", getExamQuestionId())
.append("createBy", getCreateBy())
.append("createDate", getCreateDate())
.append("updateBy", getUpdateBy())
.append("updateDate", getUpdateDate())
.append("remarks", getRemarks())
.append("delFlag", getDelFlag())
.toString();
}
}

View File

@ -0,0 +1,24 @@
package com.ruoyi.exam.mapper;
import com.ruoyi.exam.domain.ExamPaper;
import java.util.List;
import com.ruoyi.framework.web.base.MyMapper;
/**
* 试卷 数据层
*
* @author zhujj
* @date 2018-12-16
*/
public interface ExamPaperMapper extends MyMapper<ExamPaper>
{
/**
* 查询试卷列表
*
* @param examPaper 试卷信息
* @return 试卷集合
*/
public List<ExamPaper> selectExamPaperList(ExamPaper examPaper);
}

View File

@ -0,0 +1,24 @@
package com.ruoyi.exam.mapper;
import com.ruoyi.exam.domain.ExamPaperQuestion;
import java.util.List;
import com.ruoyi.framework.web.base.MyMapper;
/**
* 试卷题目 数据层
*
* @author zhujj
* @date 2018-12-17
*/
public interface ExamPaperQuestionMapper extends MyMapper<ExamPaperQuestion>
{
/**
* 查询试卷题目列表
*
* @param examPaperQuestion 试卷题目信息
* @return 试卷题目集合
*/
public List<ExamPaperQuestion> selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion);
}

View File

@ -0,0 +1,33 @@
package com.ruoyi.exam.service;
import com.ruoyi.exam.domain.ExamPaperQuestion;
import java.util.List;
import com.ruoyi.framework.web.base.AbstractBaseService;
/**
* 试卷题目 服务层
*
* @author zhujj
* @date 2018-12-17
*/
public interface IExamPaperQuestionService extends AbstractBaseService<ExamPaperQuestion>
{
/**
* 查询试卷题目分页列表
*
* @param examPaperQuestion 试卷题目信息
* @return 试卷题目集合
*/
public List<ExamPaperQuestion> selectExamPaperQuestionPage(ExamPaperQuestion examPaperQuestion);
/**
* 查询试卷题目列表
*
* @param examPaperQuestion 试卷题目信息
* @return 试卷题目集合
*/
public List<ExamPaperQuestion> selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion);
int saveQuestion(String paperId, String[] questionId);
List<String> selectQuestionIdsForPaperId(Integer id);
}

View File

@ -0,0 +1,30 @@
package com.ruoyi.exam.service;
import com.ruoyi.exam.domain.ExamPaper;
import java.util.List;
import com.ruoyi.framework.web.base.AbstractBaseService;
/**
* 试卷 服务层
*
* @author zhujj
* @date 2018-12-16
*/
public interface IExamPaperService extends AbstractBaseService<ExamPaper>
{
/**
* 查询试卷分页列表
*
* @param examPaper 试卷信息
* @return 试卷集合
*/
public List<ExamPaper> selectExamPaperPage(ExamPaper examPaper);
/**
* 查询试卷列表
*
* @param examPaper 试卷信息
* @return 试卷集合
*/
public List<ExamPaper> selectExamPaperList(ExamPaper examPaper);
}

View File

@ -0,0 +1,94 @@
package com.ruoyi.exam.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.ruoyi.exam.domain.ExamPaper;
import com.ruoyi.exam.mapper.ExamPaperMapper;
import com.ruoyi.framework.web.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.exam.mapper.ExamPaperQuestionMapper;
import com.ruoyi.exam.domain.ExamPaperQuestion;
import com.ruoyi.exam.service.IExamPaperQuestionService;
import com.ruoyi.common.support.Convert;
import com.ruoyi.framework.web.base.AbstractBaseServiceImpl;
/**
* 试卷题目 服务层实现
*
* @author zhujj
* @date 2018-12-17
*/
@Service
public class ExamPaperQuestionServiceImpl extends AbstractBaseServiceImpl<ExamPaperQuestionMapper,ExamPaperQuestion> implements IExamPaperQuestionService
{
@Autowired
private ExamPaperQuestionMapper examPaperQuestionMapper;
/**
* 查询试卷题目列表
*
* @param examPaperQuestion 试卷题目信息
* @return 试卷题目集合
*/
@Override
public List<ExamPaperQuestion> selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion)
{
return examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion);
}
@Override
public int saveQuestion(String paperId, String[] questionId) {
ExamPaperQuestion ea = new ExamPaperQuestion();
ea.setExamPaperId(Integer.parseInt(paperId));
examPaperQuestionMapper.delete(ea);
List<ExamPaperQuestion> list = new ArrayList();
if(questionId!=null && questionId.length>0){
for (String s : questionId) {
ExamPaperQuestion examPaperQuestion = new ExamPaperQuestion();
examPaperQuestion.setExamPaperId(Integer.parseInt(paperId));
examPaperQuestion.setExamQuestionId(Integer.parseInt(s));
examPaperQuestion.setDelFlag("0");
examPaperQuestion.setCreateBy(ShiroUtils.getLoginName());
examPaperQuestion.setCreateDate(new Date());
list.add(examPaperQuestion);
}
if(list.size()>0){
examPaperQuestionMapper.insertList(list);
}
}
return 1;
}
@Override
public List<String> selectQuestionIdsForPaperId(Integer id) {
ExamPaperQuestion examPaperQuestion = new ExamPaperQuestion();
examPaperQuestion.setExamPaperId(id);
List<ExamPaperQuestion> examPaperQuestions = examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion);
List<String> ids = new ArrayList<>();
for (ExamPaperQuestion paperQuestion : examPaperQuestions) {
ids.add(paperQuestion.getExamQuestionId().toString());
}
return ids;
}
/**
* 查询试卷题目分页列表
*
* @param examPaperQuestion 试卷题目信息
* @return 试卷题目集合
*/
@Override
public List<ExamPaperQuestion> selectExamPaperQuestionPage(ExamPaperQuestion examPaperQuestion)
{
startPage();
return examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion);
}
}

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.exam.mapper.ExamPaperQuestionMapper">
<resultMap type="ExamPaperQuestion" id="ExamPaperQuestionResult">
<result property="id" column="id" />
<result property="examPaperId" column="exam_paper_id" />
<result property="examQuestionId" column="exam_question_id" />
<result property="createBy" column="create_by" />
<result property="createDate" column="create_date" />
<result property="updateBy" column="update_by" />
<result property="updateDate" column="update_date" />
<result property="remarks" column="remarks" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectExamPaperQuestionVo">
id, exam_paper_id, exam_question_id, create_by, create_date, update_by, update_date, remarks, del_flag </sql>
<select id="selectExamPaperQuestionList" parameterType="ExamPaperQuestion" resultMap="ExamPaperQuestionResult">
select
<include refid="selectExamPaperQuestionVo"/>
from exam_paper_question
<where>
<if test="id != null "> and id = #{id}</if>
<if test="examPaperId != null "> and exam_paper_id = #{examPaperId}</if>
<if test="examQuestionId != null "> and exam_question_id = #{examQuestionId}</if>
<if test="createBy != null and createBy != '' "> and create_by = #{createBy}</if>
<if test="createDate != null "> and create_date = #{createDate}</if>
<if test="updateBy != null and updateBy != '' "> and update_by = #{updateBy}</if>
<if test="updateDate != null "> and update_date = #{updateDate}</if>
<if test="remarks != null and remarks != '' "> and remarks = #{remarks}</if>
<if test="delFlag != null and delFlag != '' "> and del_flag = #{delFlag}</if>
</where>
</select>
</mapper>

View File

@ -0,0 +1,255 @@
<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<body class="gray-bg">
<div class="ui-layout-west">
<div class="main-content">
<div class="box box-main">
<div class="box-header">
<div class="box-title">
<i class="fa icon-grid"></i> 题库
</div>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
class="fa fa-chevron-up"></i></button>
<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
class="fa fa-chevron-down"></i></button>
<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新题库"><i
class="fa fa-refresh"></i></button>
</div>
</div>
<div class="ui-layout-content">
<div id="tree" class="ztree"></div>
</div>
</div>
</div>
</div>
<div class="container-div ui-layout-center">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<input type="hidden" id="categoryId" name="categoryId">
<input type="hidden" id="examPaperId" name="examPaperId" th:value="${examPaperId}">
<div class="select-list">
<ul>
<li>
问题标题:<input type="text" name="title"/>
</li>
<li>
问题类型:<select name="type" th:with="type=${@dict.getType('exam_question_type')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
th:value="${dict.dictValue}"></option>
</select>
</li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
<!--<a class="btn btn-success" onclick="addChoiceQuestion()" shiro:hasPermission="exam:examQuestion:add">-->
<!--<i class="fa fa-plus"></i> 添加单选题-->
<!--</a>-->
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table" data-mobile-responsive="true"></table>
</div>
</div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('exam:examQuestion:edit')}]];
var removeFlag = [[${@permission.hasPermi('exam:examQuestion:remove')}]];
var prefix = ctx + "exam/examQuestion";
var overAllIds = new Array();
$(function () {
$('body').layout({west__size: 150});
queryExamQuestionList();
queryExamQuestionCategoryTree();
debugger;
overAllIds = [[${examPaperQuestionIds}]];
});
function queryExamQuestionList() {
var options = {
url: prefix + "/list",
createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "问题",
search: false,
showExport: true,
columns: [{
checkbox: true,
formatter: function (i, row) { // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
if ($.inArray(row.id,
overAllIds) != -1) {// 因为 判断数组里有没有这个 id
return {
checked: true
// 存在则选中
}
}
}
},
{
field: 'id',
title: 'ID',
sortable: true
},
{
field: 'title',
title: '问题标题',
sortable: true
},
{
field: 'answer',
title: '问题答案',
sortable: true
},
{
field: 'type',
title: '问题类型',
sortable: true
},
{
field: 'createBy',
title: '创建者',
sortable: true
},
{
field: 'remarks',
title: '备注信息',
sortable: true
}]
// {
// title: '操作',
// align: 'center',
// formatter: function (value, row, index) {
// var actions = [];
// actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
// actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
// return actions.join('');
// }
// }]
};
$.table.init(options);
};
function queryExamQuestionCategoryTree() {
var url = ctx + "exam/examQuestionCategory/treeData";
var options = {
url: url,
expandLevel: 2,
onClick: zOnClick
};
$.tree.init(options);
function zOnClick(event, treeId, treeNode) {
if (treeNode.pId == 1 || treeNode.pId == 0 || treeNode.pId == null) {
return;
}
$("#categoryId").val(treeNode.id);
$.table.search();
}
}
$('#btnExpand').click(function () {
$._tree.expandAll(true);
$(this).hide();
$('#btnCollapse').show();
});
$('#btnCollapse').click(function () {
$._tree.expandAll(false);
$(this).hide();
$('#btnExpand').show();
});
$('#btnRefresh').click(function () {
queryExamQuestionCategoryTree();
});
/*用户管理-部门*/
function examQuestionCategory() {
var url = ctx + "exam/examQuestionCategory";
createMenuItem(url, "题库管理");
}
function addChoiceQuestion() {
if ($("#categoryId").val() == null || $("#categoryId").val() == '') {
alert("请选择题库!")
return;
}
var url = prefix + "/choiceadd/" + $("#categoryId").val();
$.operate.jumpModeltoUrl("添加单选题", url);
}
function addMoreChoiceQuestion() {
if ($("#categoryId").val() == null || $("#categoryId").val() == '') {
alert("请选择题库!")
return;
}
var url = prefix + "/morechoiceadd/" + $("#categoryId").val();
$.operate.jumpModeltoUrl("添加多选题", url);
}
function addJudgeQuestion() {
if ($("#categoryId").val() == null || $("#categoryId").val() == '') {
alert("请选择题库!")
return;
}
var url = prefix + "/judgeadd/" + $("#categoryId").val();
$.operate.jumpModeltoUrl("添加多选题", url);
}
var overAllIds = new Array(); //全局数组
function getSelectCheck() {
return overAllIds;
}
function examine(type, datas) {
if (type.indexOf('uncheck') == -1) {
$.each(datas,
function (i, v) {
// 添加时,判断一行或多行的 id 是否已经在数组里 不存则添加 
overAllIds.indexOf(v.id) == -1 ? overAllIds
.push(v.id) : -1;
});
} else {
$.each(datas, function (i, v) {
overAllIds.splice(overAllIds.indexOf(v.id), 1); //删除取消选中行
});
}
}
$('#bootstrap-table').on(
'uncheck.bs.table check.bs.table check-all.bs.table uncheck-all.bs.table',
function (e, rows) {
debugger
var datas = $.isArray(rows) ? rows : [rows]; // 点击时获取选中的行或取消选中的行
examine(e.type, datas); // 保存到全局 Array() 里
});
function submitHandler() {
debugger
$.operate.save(ctx + "exam/examPaper"+ "/saveQuestion",$.param({questionId:overAllIds,paperId:$("#examPaperId").val()}));
}
</script>
</body>
</html>