From 5bd6820f5ba5a67a36ffc8a5949a05c363c7e442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sat, 7 Oct 2023 18:19:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=96=B0=E5=A2=9E=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InterviewQuestionController.java | 10 ++ .../enums/InterviewQuestionTypeEnum.java | 115 ------------------ .../service/InterviewQuestionService.java | 6 + .../impl/InterviewQuestionServiceImpl.java | 25 +++- 4 files changed, 39 insertions(+), 117 deletions(-) delete mode 100644 src/main/java/com/kwan/springbootkwan/enums/InterviewQuestionTypeEnum.java diff --git a/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java b/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java index 2b56d06..4b3114b 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 67d3156..0000000 --- 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 9e94bd2..1d2a4eb 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 9de9afb..b3152a2 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 -- GitLab