fix:新增枚举类

上级 1cf2bc72
......@@ -54,6 +54,16 @@ public class InterviewQuestionController {
return Result.ok(this.interviewQuestionService.questionType());
}
/**
* 获取所有的面试题的种类的数量
*
* @return
*/
@GetMapping("/allQuestionType")
public Result allQuestionType() {
return Result.ok(this.interviewQuestionService.allQuestionType());
}
/**
* 分页查询所有数据
*
......
package com.kwan.springbootkwan.enums;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
public enum InterviewQuestionTypeEnum {
/**
* 全部
*/
type_00(0, "全部"),
/**
* 基础知识
*/
type_01(1, "基础知识"),
/**
* 集合
*/
type_02(2, "集合"),
/**
* JVM
*/
type_03(3, "JVM"),
/**
* 并发编程
*/
type_04(4, "并发编程"),
/**
* MySql
*/
type_05(5, "MySql"),
/**
* Redis
*/
type_06(6, "Redis"),
/**
* 中间件
*/
type_07(7, "中间件"),
/**
* Spring
*/
type_08(8, "Spring"),
/**
* 微服务
*/
type_09(9, "微服务"),
/**
* 分布式
*/
type_10(10, "分布式"),
/**
* 项目
*/
type_11(11, "项目"),
/**
* 算法
*/
type_12(12, "算法"),
/**
* 反问环节
*/
type_13(13, "反问环节"),
/**
* 设计模式
*/
type_14(14, "设计模式"),
/**
* 其他
*/
type_99(99, "其他");
private Integer code;
private String name;
InterviewQuestionTypeEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
/**
* 通过code获取name
*
* @param code
* @return
*/
public static String getNameByCode(Integer code) {
for (InterviewQuestionTypeEnum enums : InterviewQuestionTypeEnum.values()) {
if (enums.getCode().equals(code)) {
return enums.getName();
}
}
return null;
}
/**
* 通过value取枚举
*
* @param value
* @return
*/
public static InterviewQuestionTypeEnum getBrandDetailNoByValue(String value) {
if (null == value) {
return null;
}
for (InterviewQuestionTypeEnum enums : InterviewQuestionTypeEnum.values()) {
if (enums.getCode().equals(value)) {
return enums;
}
}
return null;
}
}
......@@ -27,4 +27,10 @@ public interface InterviewQuestionService extends IService<InterviewQuestion> {
* @return
*/
List<InterviewQuestionTypeDTO> questionType();
/**
* 获取所有的类型
*
* @return
*/
List<InterviewQuestionTypeDTO> allQuestionType();
}
\ No newline at end of file
......@@ -2,10 +2,11 @@ package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.DictionaryManagement;
import com.kwan.springbootkwan.entity.InterviewQuestion;
import com.kwan.springbootkwan.entity.dto.InterviewQuestionTypeDTO;
import com.kwan.springbootkwan.enums.InterviewQuestionTypeEnum;
import com.kwan.springbootkwan.mapper.InterviewQuestionMapper;
import com.kwan.springbootkwan.service.DictionaryManagementService;
import com.kwan.springbootkwan.service.InterviewQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
......@@ -17,6 +18,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 面试题(InterviewQuestion)表服务实现类
......@@ -30,6 +32,8 @@ public class InterviewQuestionServiceImpl extends ServiceImpl<InterviewQuestionM
@Resource
private InterviewQuestionMapper interviewQuestionMapper;
@Resource
private DictionaryManagementService dictionaryManagementService;
@Override
public boolean uploadFile(String path) {
......@@ -60,13 +64,30 @@ public class InterviewQuestionServiceImpl extends ServiceImpl<InterviewQuestionM
@Override
public List<InterviewQuestionTypeDTO> questionType() {
final List<InterviewQuestionTypeDTO> interviewQuestionTypeDTOS = this.allQuestionType();
//获取种类,并按数量排序
LinkedList<InterviewQuestionTypeDTO> types = interviewQuestionMapper.questionType();
types.addFirst(new InterviewQuestionTypeDTO(0, "全部", 0));
for (InterviewQuestionTypeDTO interviewQuestionTypeDTO : types) {
//数据库存的是问题类型的编码
interviewQuestionTypeDTO.setName(InterviewQuestionTypeEnum.getNameByCode(interviewQuestionTypeDTO.getQuestionType()));
final InterviewQuestionTypeDTO item = interviewQuestionTypeDTOS.stream().filter(x -> x.getQuestionType().equals(interviewQuestionTypeDTO.getQuestionType())).findFirst().get();
interviewQuestionTypeDTO.setName(item.getName());
}
return types;
}
@Override
public List<InterviewQuestionTypeDTO> allQuestionType() {
QueryWrapper<DictionaryManagement> wrapper = new QueryWrapper<>();
wrapper.eq("dict_type", 1);
wrapper.eq("is_delete", 0);
final List<DictionaryManagement> list = dictionaryManagementService.list(wrapper);
return list.stream()
.map(item -> {
InterviewQuestionTypeDTO interviewQuestionTypeDTO = new InterviewQuestionTypeDTO();
interviewQuestionTypeDTO.setQuestionType(item.getCode());
interviewQuestionTypeDTO.setName(item.getName());
return interviewQuestionTypeDTO;
}).collect(Collectors.toList());
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册