|
@@ -77,7 +77,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
}
|
|
|
String startTime = param.getStartTime();
|
|
|
String endTime = param.getEndTime();
|
|
|
- if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime) ) {
|
|
|
+ if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
|
|
|
condition.and().andBetween("createTime", startTime, endTime);
|
|
|
}
|
|
|
Integer status = param.getStatus();
|
|
@@ -108,7 +108,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Integer getQuesitongCount(Long id){
|
|
|
+ private Integer getQuesitongCount(Long id) {
|
|
|
List<QuestionAnswerEntity> answerEntityList = questionAnswerService.findByQuestionGroupId(id);
|
|
|
return answerEntityList.size();
|
|
|
}
|
|
@@ -117,7 +117,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
public Result apply(Long id) {
|
|
|
// 1:审核中
|
|
|
updateStatus(id, 1);
|
|
|
- return Result.success();
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -127,7 +127,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
if (status == 0) {
|
|
|
// 审核不通过
|
|
|
status = 2;
|
|
|
- } else if (status == 1){
|
|
|
+ } else if (status == 1) {
|
|
|
// 审核通过
|
|
|
status = 3;
|
|
|
} else {
|
|
@@ -155,7 +155,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
}
|
|
|
|
|
|
if (display == 1) {
|
|
|
- if (entity.getStatus() != 3){
|
|
|
+ if (entity.getStatus() != 3) {
|
|
|
return Result.failure("只有审核通过的,才允许设置为显示状态");
|
|
|
}
|
|
|
}
|
|
@@ -176,10 +176,11 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
|
|
|
/**
|
|
|
* 解决excel数据并保存数据库
|
|
|
+ *
|
|
|
* @param filePath 相对路径
|
|
|
* @return
|
|
|
*/
|
|
|
- private void parseExcel(String filePath){
|
|
|
+ private void parseExcel(String filePath) {
|
|
|
// 读取excel数据
|
|
|
String excelPath = configConstant.serverBasePath + filePath;
|
|
|
List<List<Object>> read = ExcelUtils.readExcel(excelPath);
|
|
@@ -189,43 +190,53 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
// 题组标题
|
|
|
List<Object> group = read.get(1);
|
|
|
String groupTitle = group.get(1).toString();
|
|
|
- if (StrUtil.isBlank(groupTitle)){
|
|
|
+ if (StrUtil.isBlank(groupTitle)) {
|
|
|
throw new BaseRuntimeException("题组名称不能为空");
|
|
|
}
|
|
|
- log.info("题组名称:{}", groupTitle );
|
|
|
+ checkLengthStr(groupTitle);
|
|
|
+ log.info("题组名称:{}", groupTitle);
|
|
|
|
|
|
// 从第三行读取,直接读取题目跟选项, 使用LinkedHashMap区分顺序
|
|
|
LinkedHashMap<String, TopicDto> topicMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ // 正确答案,校验是否多个检查
|
|
|
+ HashMap<String, Integer> checkCorrectMap = new HashMap<>();
|
|
|
+
|
|
|
String topic = null;
|
|
|
for (int i = 2; i < read.size(); i++) {
|
|
|
List<Object> list = read.get(i);
|
|
|
- String tips = (String)list.get(0);
|
|
|
- if (StrUtil.isBlank(tips)){
|
|
|
+ String tips = (String) list.get(0);
|
|
|
+ if (StrUtil.isBlank(tips)) {
|
|
|
log.warn("提示行为空,默认为结束行");
|
|
|
break;
|
|
|
}
|
|
|
// 题目
|
|
|
- if (tips.contains("题目")){
|
|
|
- topic = (String)list.get(1);
|
|
|
+ if (tips.contains("题目")) {
|
|
|
+ topic = (String) list.get(1);
|
|
|
// 题目为空,结束循环
|
|
|
- if (StrUtil.isBlank(topic)){
|
|
|
+ if (StrUtil.isBlank(topic)) {
|
|
|
log.warn(tips + ": 为空,结束循环");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
// 保存题目
|
|
|
+ checkLengthStr(topic);
|
|
|
TopicDto topicDto = new TopicDto();
|
|
|
topicDto.setTopic(topic);
|
|
|
topicMap.put(topic, topicDto);
|
|
|
+ checkCorrectMap.put(topic, 0);
|
|
|
}
|
|
|
|
|
|
// 选项
|
|
|
- if (tips.contains("选项")){
|
|
|
- String option = (String)list.get(1);
|
|
|
- if (StrUtil.isBlank(option)){
|
|
|
+ if (tips.contains("选项")) {
|
|
|
+ String option = (String) list.get(1);
|
|
|
+ if (StrUtil.isBlank(option)) {
|
|
|
// 选项为空, 执行下一次循环
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
+ // 每一行数据
|
|
|
TopicDto topicDto = topicMap.get(topic);
|
|
|
String random = RandomUtil.randomString(8);
|
|
|
|
|
@@ -236,19 +247,23 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
// }
|
|
|
|
|
|
// 预防单元格没有边框拿不到值
|
|
|
- if (list.size() >2){
|
|
|
- String correct = (String)list.get(2);
|
|
|
- if (StrUtil.isNotBlank(correct)){
|
|
|
+ if (list.size() > 2) {
|
|
|
+ String correct = (String) list.get(2);
|
|
|
+ if (StrUtil.isNotBlank(correct) && StrUtil.equals("√", correct)) {
|
|
|
+ Integer integer = checkCorrectMap.get(topic);
|
|
|
+ // 用于校验多个正确答案
|
|
|
+ checkCorrectMap.put(topic, integer + 1);
|
|
|
topicDto.setCorrect(random);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ // 选项
|
|
|
LinkedHashMap<String, String> options = topicDto.getOptions();
|
|
|
- if (CollectionUtil.isEmpty(options)){
|
|
|
+ if (CollectionUtil.isEmpty(options)) {
|
|
|
options = new LinkedHashMap<>();
|
|
|
}
|
|
|
+ checkLengthStr(option);
|
|
|
options.put(random, option);
|
|
|
|
|
|
topicDto.setOptions(options);
|
|
@@ -259,6 +274,10 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
}
|
|
|
|
|
|
log.info("excel数据封装完成");
|
|
|
+
|
|
|
+ // 校验正确答案
|
|
|
+ checkCorrect(checkCorrectMap);
|
|
|
+
|
|
|
// 题组保存数据库
|
|
|
QuestionGroupEntity groupEntity = new QuestionGroupEntity();
|
|
|
groupEntity.setName(groupTitle);
|
|
@@ -268,7 +287,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
log.info("保存题组完成, 题组id: {}", groupEntityId);
|
|
|
|
|
|
// 题目保存数据库
|
|
|
- for(Map.Entry<String, TopicDto> entry : topicMap.entrySet()){
|
|
|
+ for (Map.Entry<String, TopicDto> entry : topicMap.entrySet()) {
|
|
|
TopicDto value = entry.getValue();
|
|
|
QuestionAnswerEntity answerEntity = new QuestionAnswerEntity();
|
|
|
answerEntity.setQuestionGroupId(groupEntityId);
|
|
@@ -281,20 +300,48 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
log.info("保存题目完成");
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 校验字符串长度
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ */
|
|
|
+ private void checkLengthStr(String str) {
|
|
|
+ if (StringUtils.isNotBlank(str)) {
|
|
|
+ if (str.length() > 100) {
|
|
|
+ throw new BaseRuntimeException(MsgCode.e3006, "标题及选项限长度大于100个字符");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验同一题目出现多个正确答案
|
|
|
+ *
|
|
|
+ * @param options
|
|
|
+ */
|
|
|
+ private void checkCorrect(Map<String, Integer> options) {
|
|
|
+ for (Map.Entry<String, Integer> entry : options.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Integer value = entry.getValue();
|
|
|
+ if (value != 1) {
|
|
|
+ throw new BaseRuntimeException("此题目:" + key + ", 答案选项不正确:" + value);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 解析选项
|
|
|
+ *
|
|
|
* @param options
|
|
|
* @return
|
|
|
*/
|
|
|
- private String parseAnswer(Map<String, String> options){
|
|
|
+ private String parseAnswer(Map<String, String> options) {
|
|
|
JSONArray array = new JSONArray();
|
|
|
- for(Map.Entry<String, String> entry : options.entrySet()){
|
|
|
+ for (Map.Entry<String, String> entry : options.entrySet()) {
|
|
|
String key = entry.getKey();
|
|
|
String value = entry.getValue();
|
|
|
JSONObject obj = new JSONObject();
|
|
@@ -307,7 +354,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void updateStatus(Long id, Integer status){
|
|
|
+ private void updateStatus(Long id, Integer status) {
|
|
|
QuestionGroupEntity entity = this.findById(id);
|
|
|
if (entity == null) {
|
|
|
throw new BaseRuntimeException(MsgCode.e3001, "对象不存在");
|
|
@@ -364,7 +411,7 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
// 相应的答案删除
|
|
|
questionAnswerService.removeByQuestionGroupId(id);
|
|
|
|
|
|
- return Result.success();
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -377,10 +424,8 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
|
|
|
HashMap<Object, Object> result = new HashMap<>();
|
|
|
result.put("entity", entity);
|
|
|
result.put("answer", list);
|
|
|
- return Result.success(result);
|
|
|
+ return Result.success(result);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|