题目分类
parent
fd2c19e920
commit
dd72d75e2e
|
@ -6,6 +6,8 @@ package com.jwl.driver.server.constant;
|
|||
|
||||
public class Constants {
|
||||
|
||||
public static Integer DEFAULT_CARTYPE_ID = -1;
|
||||
|
||||
//短信验证码redis存储的前缀
|
||||
public static String MESSAGE_CODE_PREFIX = "code_";
|
||||
|
||||
|
@ -39,4 +41,7 @@ public class Constants {
|
|||
//多选题
|
||||
public static String QUESTION_TYPE_THREE = "3";
|
||||
|
||||
//字典表题目分类标识
|
||||
public static String QUESTION_CATEGORY = "QusetionCategory";
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
package com.jwl.driver.server.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jwl.driver.server.constant.Constants;
|
||||
import com.jwl.driver.server.dto.QuestionQueryDto;
|
||||
import com.jwl.driver.server.entity.TdQuestion;
|
||||
import com.jwl.driver.server.entity.TdSysConfigList;
|
||||
import com.jwl.driver.server.mapper.TdQuestionMapper;
|
||||
import com.jwl.driver.server.service.ITdQuestionService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jwl.driver.server.service.ITdSysConfigListService;
|
||||
import com.jwl.driver.server.service.ITdSysConfigService;
|
||||
import com.jwl.driver.server.vo.QusetionCategoryVo;
|
||||
import com.jwl.driver.server.vo.QusetionVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -31,6 +34,9 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
|
|||
@Autowired
|
||||
private ITdSysConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private ITdSysConfigListService configListService;
|
||||
|
||||
@Override
|
||||
public TdQuestion queryQuestionById(QuestionQueryDto queryDto) {
|
||||
return this.getBaseMapper().selectById(queryDto.getQuestionId());
|
||||
|
@ -83,9 +89,40 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
|
|||
@Override
|
||||
public List<QusetionCategoryVo> questionCategory(QuestionQueryDto queryDto) {
|
||||
|
||||
return null;
|
||||
|
||||
List<QusetionCategoryVo> resultList = new ArrayList<>();
|
||||
//获取题目
|
||||
List<TdQuestion> tdQuestions = queryQuestionByIdList(queryDto);
|
||||
if (CollectionUtil.isEmpty(tdQuestions)){
|
||||
return resultList;
|
||||
}
|
||||
//获取分类
|
||||
List<TdSysConfigList> categoryList = configListService.querySysConfigList(Constants.QUESTION_CATEGORY, Constants.DEFAULT_CARTYPE_ID);
|
||||
Map<String, String> categoryMap = categoryList.stream().collect(Collectors.toMap(TdSysConfigList::getConfigItemCode, TdSysConfigList::getConfigItemName, (v1, v2) -> v1));
|
||||
Map<String,Integer> totalMap = new HashMap<>();
|
||||
|
||||
for (TdQuestion tdQuestion : tdQuestions) {
|
||||
String category = tdQuestion.getCategory();
|
||||
if (StrUtil.isBlank(category)){
|
||||
continue;
|
||||
}
|
||||
String[] split = category.split(",");
|
||||
for (String s : split) { //遍历字符串数组
|
||||
if (totalMap.containsKey(s)) { //判断Map集合中是否有该字符
|
||||
Integer value = totalMap.get(s); //通过key找出集合中的value
|
||||
totalMap.put(s, value + 1); //将值的数据加1,然后添加到集合中去
|
||||
} else {
|
||||
totalMap.put(s,1); //此时集合中没有该Key,所以将该字符作为键加入到集合中
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String category : totalMap.keySet()) {
|
||||
QusetionCategoryVo categoryVo = new QusetionCategoryVo()
|
||||
.setCategory(category)
|
||||
.setCategoryName(categoryMap.getOrDefault(category,"其他类型"))
|
||||
.setNum(totalMap.get(category));
|
||||
resultList.add(categoryVo);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue