diff --git a/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java b/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java index 2b56d06236d20f58b32670112b6bfb865cf8e4e9..4b3114b613c2d10d9aab781da7050b09b9d50df1 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java @@ -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()); + } + /** * 分页查询所有数据 * diff --git a/src/main/java/com/kwan/springbootkwan/enums/InterviewQuestionTypeEnum.java b/src/main/java/com/kwan/springbootkwan/enums/InterviewQuestionTypeEnum.java deleted file mode 100644 index 67d3156ea9813fca5c684ebd43473a11787088ed..0000000000000000000000000000000000000000 --- a/src/main/java/com/kwan/springbootkwan/enums/InterviewQuestionTypeEnum.java +++ /dev/null @@ -1,115 +0,0 @@ -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; - } -} diff --git a/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java b/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java index 9e94bd2a912944ffc747fc07f7ee15e6bd2a8c07..1d2a4eb1cdb330b54000f5288a7f4c74fe3a0bc1 100644 --- a/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java +++ b/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java @@ -27,4 +27,10 @@ public interface InterviewQuestionService extends IService { * @return */ List questionType(); + /** + * 获取所有的类型 + * + * @return + */ + List allQuestionType(); } \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/InterviewQuestionServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/InterviewQuestionServiceImpl.java index 9de9afb1ff2238711be2fb590cbd853ff99ff0b3..b3152a24db4d941ad4739f7ebc370928c8097081 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/InterviewQuestionServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/InterviewQuestionServiceImpl.java @@ -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 questionType() { + final List interviewQuestionTypeDTOS = this.allQuestionType(); //获取种类,并按数量排序 LinkedList 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 allQuestionType() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("dict_type", 1); + wrapper.eq("is_delete", 0); + final List 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