15 changed files with 488 additions and 149 deletions
@ -1,38 +1,125 @@ |
|||||
<!DOCTYPE html> |
<!DOCTYPE html> |
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org" > |
<html lang="zh" xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
<head> |
||||
<th:block th:include="include :: header('场景题目绑定')" /> |
<th:block th:include="zdxtInclude :: header('场景题目绑定')"/> |
||||
</head> |
</head> |
||||
<body class="white-bg"> |
<body class="white-bg"> |
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> |
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> |
||||
<form class="form-horizontal m" id="form-question-detail" th:object="${sceneQuestion}"> |
<form class="form-horizontal m" id="form-question-bind" th:object="${sceneQuestion}"> |
||||
<h2 th:value="*{name}"></h2> |
<h2 th:text="*{name}" style="margin-bottom: 30px;"></h2> |
||||
<input name="id" th:field="*{id}" type="hidden"> |
<input name="id" th:field="*{id}" type="hidden"> |
||||
<div class="form-group"> |
<div class="form-group"> |
||||
<div class="col-sm-8"> |
<div class="col-sm-6"> |
||||
<input name="name" class="form-control" type="text" placeholder="A:..."> |
<input name="answer" class="form-control" type="text" placeholder="A..."> |
||||
</div> |
</div> |
||||
</div> |
<div class="col-sm-2" style="width: 12%"> |
||||
<div class="form-group"> |
<input type="checkbox" name="check" onclick="inputCheck(this)"> |
||||
<div class="col-sm-8"> |
<span>正确</span> |
||||
<input name="groupId" class="form-control" type="text" placeholder="B:..."> |
</div> |
||||
</div> |
<div class="col-sm-4" style="display: none"> |
||||
</div> |
<select th:each="li:${list}" class="form-control"> |
||||
<div class="form-group"> |
<option th:value="${li.id}" th:text="${li.name}"></option> |
||||
<div class="col-sm-8"> |
</select> |
||||
<input name="roleId" class="form-control" type="text" placeholder="C:..."> |
</div> |
||||
</div> |
</div> |
||||
</div> |
<div class="form-group"> |
||||
<div class="form-group"> |
<div class="col-sm-6"> |
||||
<div class="col-sm-8"> |
<input name="answer" class="form-control" type="text" placeholder="B..."> |
||||
<input name="roleId" class="form-control" type="text" placeholder="D:..."> |
</div> |
||||
</div> |
<div class="col-sm-2" style="width: 12%"> |
||||
</div> |
<input type="checkbox" name="check" onclick="inputCheck(this)"> |
||||
</form> |
<span>正确</span> |
||||
</div> |
</div> |
||||
<th:block th:include="include :: footer" /> |
<div class="col-sm-4" style="display: none"> |
||||
<script type="text/javascript"> |
<select th:each="li:${list}" class="form-control"> |
||||
|
<option th:value="${li.id}" th:text="${li.name}"></option> |
||||
|
</select> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="form-group"> |
||||
|
<div class="col-sm-6"> |
||||
|
<input name="answer" class="form-control" type="text" placeholder="C..."> |
||||
|
</div> |
||||
|
<div class="col-sm-2" style="width: 12%"> |
||||
|
<input type="checkbox" name="check" onclick="inputCheck(this)"> |
||||
|
<span>正确</span> |
||||
|
</div> |
||||
|
<div class="col-sm-4" style="display: none"> |
||||
|
<select th:each="li:${list}" class="form-control"> |
||||
|
<option th:value="${li.id}" th:text="${li.name}"></option> |
||||
|
</select> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="form-group"> |
||||
|
<div class="col-sm-6"> |
||||
|
<input name="answer" class="form-control" type="text" placeholder="D..."> |
||||
|
</div> |
||||
|
<div class="col-sm-2" style="width: 12%"> |
||||
|
<input type="checkbox" name="check" onclick="inputCheck(this)"> |
||||
|
<span>正确</span> |
||||
|
</div> |
||||
|
<div class="col-sm-4" style="display: none"> |
||||
|
<select th:each="li:${list}" class="form-control"> |
||||
|
<option th:value="${li.id}" th:text="${li.name}"></option> |
||||
|
</select> |
||||
|
</div> |
||||
|
</div> |
||||
|
</form> |
||||
|
</div> |
||||
|
<th:block th:include="zdxtInclude :: footer"/> |
||||
|
<script th:inline="javascript"> |
||||
|
var prefix = ctx + "project/question" |
||||
|
$("#form-question-add").validate({ |
||||
|
focusCleanup: true |
||||
|
}); |
||||
|
|
||||
|
function inputCheck(obj) { |
||||
|
if ($(obj).prop('checked')) { |
||||
|
// 还原之前样式 |
||||
|
$("[name='check']").prop('checked', false); |
||||
|
// $("[name='select']").val(""); |
||||
|
$(".col-sm-4").hide(); |
||||
|
//选中当前样式 |
||||
|
$(obj).prop('checked', true) |
||||
|
$(obj).parent().next().show(); |
||||
|
} else { |
||||
|
$(obj).parent().next().hide(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
</script> |
function submitHandler() { |
||||
|
if ($.validate.form()) { |
||||
|
var reqData = {}; |
||||
|
var nextQuestionId; |
||||
|
var reqList = new Array(); |
||||
|
var checkFlag = false; |
||||
|
var elements = document.getElementsByName("answer"); |
||||
|
for (let i = 0; i < document.getElementsByName("answer").length; i++) { |
||||
|
if (elements[i].value === "") { |
||||
|
$.modal.alertWarning("请将选项填写完整"); |
||||
|
return; |
||||
|
} |
||||
|
var req = {}; |
||||
|
req.answer = elements[i].value; |
||||
|
req.check = elements[i].parentElement.nextElementSibling.firstElementChild.checked; |
||||
|
checkFlag = checkFlag === true ? true : req.check; |
||||
|
reqList.push(req); |
||||
|
debugger |
||||
|
if (req.check) { |
||||
|
let divData = elements[i].parentElement.nextElementSibling.nextElementSibling; |
||||
|
nextQuestionId = $(divData).find("select").val(); |
||||
|
} |
||||
|
} |
||||
|
if (!checkFlag) { |
||||
|
$.modal.alertWarning("请勾选一个正确选项"); |
||||
|
return; |
||||
|
} |
||||
|
reqData.id = $("[name = 'id']").val(); |
||||
|
reqData.nextQuestionId = nextQuestionId; |
||||
|
reqData.answer = JSON.stringify(reqList); |
||||
|
$.operate.save(prefix + "/bindAnswer", reqData); |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
</body> |
</body> |
||||
</html> |
</html> |
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.zdxt.knowledge.domain; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 场景题目对象 scene_question |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
* @date 2023-12-26 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class SceneQuestionBindRequest implements Serializable { |
||||
|
|
||||
|
/** |
||||
|
* 主键 |
||||
|
*/ |
||||
|
private Long id; |
||||
|
|
||||
|
/** |
||||
|
* 答案 |
||||
|
*/ |
||||
|
private List<QuestionAnswer> answerList; |
||||
|
|
||||
|
/** |
||||
|
* 下一个答案 |
||||
|
*/ |
||||
|
private Long nextQuestionId; |
||||
|
|
||||
|
@Data |
||||
|
public static class QuestionAnswer { |
||||
|
public String answerEle; |
||||
|
public boolean checkFlag; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -1,98 +1,138 @@ |
|||||
package com.zdxt.knowledge.service.impl; |
package com.zdxt.knowledge.service.impl; |
||||
|
|
||||
|
import com.zdxt.auth.dto.RoleBean; |
||||
|
import com.zdxt.auth.dto.UserBean; |
||||
|
import com.zdxt.auth.feign.RoleApi; |
||||
|
import com.zdxt.auth.feign.UserApi; |
||||
import com.zdxt.common.util.Convert; |
import com.zdxt.common.util.Convert; |
||||
import com.zdxt.common.util.DateUtils; |
import com.zdxt.common.util.DateUtils; |
||||
import com.zdxt.knowledge.domain.SceneQuestion; |
import com.zdxt.knowledge.domain.SceneQuestion; |
||||
import com.zdxt.knowledge.mapper.SceneQuestionMapper; |
import com.zdxt.knowledge.mapper.SceneQuestionMapper; |
||||
import com.zdxt.knowledge.service.ISceneQuestionService; |
import com.zdxt.knowledge.service.ISceneQuestionService; |
||||
|
import org.apache.commons.collections.CollectionUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
||||
|
|
||||
import java.util.List; |
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.Objects; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
/** |
/** |
||||
* 场景题目Service业务层处理 |
* 场景题目Service业务层处理 |
||||
* |
* |
||||
* @author ruoyi |
* @author ruoyi |
||||
* @date 2023-12-26 |
* @date 2023-12-26 |
||||
*/ |
*/ |
||||
@Service |
@Service |
||||
public class SceneQuestionServiceImpl implements ISceneQuestionService |
public class SceneQuestionServiceImpl implements ISceneQuestionService { |
||||
{ |
|
||||
@Autowired |
@Autowired |
||||
private SceneQuestionMapper sceneQuestionMapper; |
private SceneQuestionMapper sceneQuestionMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private UserApi userApi; |
||||
|
|
||||
|
@Autowired |
||||
|
private RoleApi roleApi; |
||||
|
|
||||
/** |
/** |
||||
* 查询场景题目 |
* 查询场景题目 |
||||
* |
* |
||||
* @param id 场景题目ID |
* @param id 场景题目ID |
||||
* @return 场景题目 |
* @return 场景题目 |
||||
*/ |
*/ |
||||
@Override |
@Override |
||||
public SceneQuestion selectSceneQuestionById(Long id) |
public SceneQuestion selectSceneQuestionById(Long id) { |
||||
{ |
|
||||
return sceneQuestionMapper.selectSceneQuestionById(id); |
return sceneQuestionMapper.selectSceneQuestionById(id); |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 查询场景题目列表 |
* 查询场景题目列表 |
||||
* |
* |
||||
* @param sceneQuestion 场景题目 |
* @param sceneQuestion 场景题目 |
||||
* @return 场景题目 |
* @return 场景题目 |
||||
*/ |
*/ |
||||
@Override |
@Override |
||||
public List<SceneQuestion> selectSceneQuestionList(SceneQuestion sceneQuestion) |
public List<SceneQuestion> selectSceneQuestionList(SceneQuestion sceneQuestion) { |
||||
{ |
List<RoleBean> rolesAll = roleApi.getRolesAll(); |
||||
return sceneQuestionMapper.selectSceneQuestionList(sceneQuestion); |
if (Objects.nonNull(sceneQuestion.getCreateTime())) { |
||||
|
sceneQuestion.setCreateTimeEnd(DateUtils.addDays(sceneQuestion.getCreateTime(), 1)); |
||||
|
} |
||||
|
List<SceneQuestion> questionList = sceneQuestionMapper.selectSceneQuestionList(sceneQuestion); |
||||
|
if (CollectionUtils.isNotEmpty(questionList) && CollectionUtils.isNotEmpty(rolesAll)) { |
||||
|
Map<Long, String> roleMap = rolesAll.stream() |
||||
|
.collect(Collectors.toMap(RoleBean::getRoleId, RoleBean::getRoleName)); |
||||
|
questionList = questionList.stream() |
||||
|
.filter(item -> Objects.nonNull(item.getRoleId())) |
||||
|
.peek(item -> { |
||||
|
item.setRoleIdStr(item.getRoleId()); |
||||
|
String[] ids = item.getRoleIdStr().split(","); |
||||
|
for (int i = 0; i < ids.length; i++) { |
||||
|
item.setRoleIdStr(item.getRoleIdStr().replace(ids[i], roleMap.get(Long.valueOf(ids[i])))); |
||||
|
} |
||||
|
}).collect(Collectors.toList()); |
||||
|
} |
||||
|
return questionList; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 新增场景题目 |
* 新增场景题目 |
||||
* |
* |
||||
* @param sceneQuestion 场景题目 |
* @param sceneQuestion 场景题目 |
||||
* @return 结果 |
* @return 结果 |
||||
*/ |
*/ |
||||
@Override |
@Override |
||||
public int insertSceneQuestion(SceneQuestion sceneQuestion) |
public int insertSceneQuestion(SceneQuestion sceneQuestion) { |
||||
{ |
UserBean userBean = userApi.getCurrentUser(); |
||||
sceneQuestion.setCreateTime(DateUtils.getNowDate()); |
if (Objects.nonNull(userBean)) { |
||||
|
sceneQuestion.setCreator(userBean.getUserName()); |
||||
|
sceneQuestion.setCreateTime(DateUtils.getNowDate()); |
||||
|
} |
||||
return sceneQuestionMapper.insertSceneQuestion(sceneQuestion); |
return sceneQuestionMapper.insertSceneQuestion(sceneQuestion); |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 修改场景题目 |
* 修改场景题目 |
||||
* |
* |
||||
* @param sceneQuestion 场景题目 |
* @param sceneQuestion 场景题目 |
||||
* @return 结果 |
* @return 结果 |
||||
*/ |
*/ |
||||
@Override |
@Override |
||||
public int updateSceneQuestion(SceneQuestion sceneQuestion) |
public int updateSceneQuestion(SceneQuestion sceneQuestion) { |
||||
{ |
|
||||
sceneQuestion.setUpdateTime(DateUtils.getNowDate()); |
sceneQuestion.setUpdateTime(DateUtils.getNowDate()); |
||||
return sceneQuestionMapper.updateSceneQuestion(sceneQuestion); |
return sceneQuestionMapper.updateSceneQuestion(sceneQuestion); |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 删除场景题目对象 |
* 删除场景题目对象 |
||||
* |
* |
||||
* @param ids 需要删除的数据ID |
* @param ids 需要删除的数据ID |
||||
* @return 结果 |
* @return 结果 |
||||
*/ |
*/ |
||||
@Override |
@Override |
||||
public int deleteSceneQuestionByIds(String ids) |
public int deleteSceneQuestionByIds(String ids) { |
||||
{ |
|
||||
return sceneQuestionMapper.deleteSceneQuestionByIds(Convert.toStrArray(ids)); |
return sceneQuestionMapper.deleteSceneQuestionByIds(Convert.toStrArray(ids)); |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 删除场景题目信息 |
* 删除场景题目信息 |
||||
* |
* |
||||
* @param id 场景题目ID |
* @param id 场景题目ID |
||||
* @return 结果 |
* @return 结果 |
||||
*/ |
*/ |
||||
@Override |
@Override |
||||
public int deleteSceneQuestionById(Long id) |
public int deleteSceneQuestionById(Long id) { |
||||
{ |
|
||||
return sceneQuestionMapper.deleteSceneQuestionById(id); |
return sceneQuestionMapper.deleteSceneQuestionById(id); |
||||
} |
} |
||||
|
|
||||
|
/** |
||||
|
* 绑定场景题目信息 |
||||
|
* |
||||
|
* @param sceneQuestion |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
@Override |
||||
|
public int bindAnswer(SceneQuestion sceneQuestion) { |
||||
|
return sceneQuestionMapper.bindAnswer(sceneQuestion); |
||||
|
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue