diff --git a/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java b/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java index 0b01e1b162e9b7e4cffea7b44e1d815b7dcf98d7..d4dd50b114d03ca7d1de1461bcce3653363beba9 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/InterviewQuestionController.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.kwan.springbootkwan.entity.InterviewQuestion; import com.kwan.springbootkwan.entity.Result; import com.kwan.springbootkwan.entity.dto.InterviewQuestionDTO; +import com.kwan.springbootkwan.entity.query.InterviewQuestionAddQuery; import com.kwan.springbootkwan.service.InterviewQuestionService; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.DeleteMapping; @@ -48,7 +49,7 @@ public class InterviewQuestionController { } /** - * 分页查询所有数据,本地缓存的使用 + * 分页查询所有数据 * * @return 所有数据 */ @@ -56,14 +57,14 @@ public class InterviewQuestionController { public Result selectAll(@RequestParam Integer page , @RequestParam Integer pageSize , @RequestParam String question - , @RequestParam Integer type) { + , @RequestParam Integer questionType) { Page pageParm = new Page<>(); pageParm.setCurrent(page); pageParm.setSize(pageSize); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.orderByDesc("id"); - if (type != 0) { - wrapper.eq("type", type); + if (questionType != 0) { + wrapper.eq("question_type", questionType); } wrapper.eq("is_delete", 0); if (StringUtils.isNotEmpty(question)) { @@ -73,15 +74,26 @@ public class InterviewQuestionController { } /** - * 分页查询所有数据 + * 新增问题 * - * @param page 分页对象 - * @param interviewQuestion 查询实体 * @return 所有数据 */ - @GetMapping - public Result selectAll(Page page, InterviewQuestion interviewQuestion) { - return Result.ok(this.interviewQuestionService.page(page, new QueryWrapper<>(interviewQuestion))); + @PostMapping("/add") + public Result add(@RequestBody InterviewQuestionAddQuery addInfo) { + InterviewQuestion interviewQuestion = new InterviewQuestion(); + interviewQuestion.setQuestion(addInfo.getQuestion()); + interviewQuestion.setQuestionType(addInfo.getQuestionType()); + return Result.ok(this.interviewQuestionService.save(interviewQuestion)); + } + + /** + * 获取面试题的种类的数量 + * + * @return + */ + @GetMapping("/questionType") + public Result questionType() { + return Result.ok(interviewQuestionService.questionType()); } /** diff --git a/src/main/java/com/kwan/springbootkwan/entity/InterviewQuestion.java b/src/main/java/com/kwan/springbootkwan/entity/InterviewQuestion.java index a8d85bf563e160a671853450de82888597e79a4a..cea90bea33b0bcc80e4e7186f6ba0329afa01f20 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/InterviewQuestion.java +++ b/src/main/java/com/kwan/springbootkwan/entity/InterviewQuestion.java @@ -21,7 +21,7 @@ public class InterviewQuestion extends Model { //问题回答 private String response; //知识类型,先默认0,后面再区分 - private Integer type; + private Integer questionType; //创建时间 private Date createTime; //逻辑删除,0未删除,1已删除 diff --git a/src/main/java/com/kwan/springbootkwan/entity/dto/InterviewQuestionDTO.java b/src/main/java/com/kwan/springbootkwan/entity/dto/InterviewQuestionDTO.java index 605984bfd70b3fdba80a4fa756b8cd487cdb9dfd..7ffe169c644d8f5943e7976935df4f4dc51fcb1f 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/dto/InterviewQuestionDTO.java +++ b/src/main/java/com/kwan/springbootkwan/entity/dto/InterviewQuestionDTO.java @@ -26,7 +26,7 @@ public class InterviewQuestionDTO extends Model { //问题回答 private String response; //知识类型,先默认0,后面再区分 - private Integer type; + private Integer questionType; //创建时间 private Date createTime; //逻辑删除,0未删除,1已删除 diff --git a/src/main/java/com/kwan/springbootkwan/entity/dto/InterviewQuestionTypeDTO.java b/src/main/java/com/kwan/springbootkwan/entity/dto/InterviewQuestionTypeDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..e996d9aa1ffa0b2d629c7df8b7ca84b01e0a0614 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/dto/InterviewQuestionTypeDTO.java @@ -0,0 +1,16 @@ +package com.kwan.springbootkwan.entity.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class InterviewQuestionTypeDTO { + private Integer questionType; + private String name; + private Integer typeSize; +} + diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/InterviewQuestionAddQuery.java b/src/main/java/com/kwan/springbootkwan/entity/query/InterviewQuestionAddQuery.java new file mode 100644 index 0000000000000000000000000000000000000000..1cfffb64da0735432ed87a23f306de23d4edcd74 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/query/InterviewQuestionAddQuery.java @@ -0,0 +1,9 @@ +package com.kwan.springbootkwan.entity.query; + +import lombok.Data; + +@Data +public class InterviewQuestionAddQuery { + private String question; + private Integer questionType; +} diff --git a/src/main/java/com/kwan/springbootkwan/enums/InterviewQuestionTypeEnum.java b/src/main/java/com/kwan/springbootkwan/enums/InterviewQuestionTypeEnum.java new file mode 100644 index 0000000000000000000000000000000000000000..058340feba3a42511a83ec3ad5fcd5e54d9cde17 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/enums/InterviewQuestionTypeEnum.java @@ -0,0 +1,103 @@ +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_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/mapper/InterviewQuestionMapper.java b/src/main/java/com/kwan/springbootkwan/mapper/InterviewQuestionMapper.java index ec80d3d6dcead4f04130e33a0d03ec532e003ada..c710d6928c62c7b12e51922f952bcc715a51c837 100644 --- a/src/main/java/com/kwan/springbootkwan/mapper/InterviewQuestionMapper.java +++ b/src/main/java/com/kwan/springbootkwan/mapper/InterviewQuestionMapper.java @@ -2,6 +2,9 @@ package com.kwan.springbootkwan.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.kwan.springbootkwan.entity.InterviewQuestion; +import com.kwan.springbootkwan.entity.dto.InterviewQuestionTypeDTO; + +import java.util.LinkedList; /** * 面试题(InterviewQuestion)表数据库访问层 @@ -11,5 +14,11 @@ import com.kwan.springbootkwan.entity.InterviewQuestion; */ public interface InterviewQuestionMapper extends BaseMapper { + /** + * 获取面试题的种类 + * + * @return + */ + LinkedList questionType(); } diff --git a/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java b/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java index 7ee7e4ce5f901f66583049ecf90a345c7faee6be..9e94bd2a912944ffc747fc07f7ee15e6bd2a8c07 100644 --- a/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java +++ b/src/main/java/com/kwan/springbootkwan/service/InterviewQuestionService.java @@ -2,6 +2,9 @@ package com.kwan.springbootkwan.service; import com.baomidou.mybatisplus.extension.service.IService; import com.kwan.springbootkwan.entity.InterviewQuestion; +import com.kwan.springbootkwan.entity.dto.InterviewQuestionTypeDTO; + +import java.util.List; /** * 面试题(InterviewQuestion)表服务接口 @@ -10,7 +13,18 @@ import com.kwan.springbootkwan.entity.InterviewQuestion; * @since 2023-09-08 16:31:53 */ public interface InterviewQuestionService extends IService { - + /** + * 上传面试题 + * + * @param path + * @return + */ boolean uploadFile(String path); -} + /** + * 获取面试题的种类 + * + * @return + */ + List questionType(); +} \ 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 d730bf96240c7c33df82cad90bc40dcf948b4750..23bc9d3e2f154299a64f51542094cad39e5f311b 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/InterviewQuestionServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/InterviewQuestionServiceImpl.java @@ -3,6 +3,8 @@ 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.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.InterviewQuestionService; import lombok.extern.slf4j.Slf4j; @@ -13,6 +15,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.LinkedList; import java.util.List; /** @@ -24,6 +27,7 @@ import java.util.List; @Slf4j @Service("interviewQuestionService") public class InterviewQuestionServiceImpl extends ServiceImpl implements InterviewQuestionService { + @Resource private InterviewQuestionMapper interviewQuestionMapper; @@ -53,4 +57,15 @@ public class InterviewQuestionServiceImpl extends ServiceImpl questionType() { + //获取种类,并按数量排序 + LinkedList types = interviewQuestionMapper.questionType(); + types.addFirst(new InterviewQuestionTypeDTO(0, "全部", 0)); + for (InterviewQuestionTypeDTO interviewQuestionTypeDTO : types) { + interviewQuestionTypeDTO.setName(InterviewQuestionTypeEnum.getNameByCode(interviewQuestionTypeDTO.getQuestionType())); + } + return types; + } } \ No newline at end of file diff --git a/src/main/resources/mapper/InterviewQuestionMapper.xml b/src/main/resources/mapper/InterviewQuestionMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..fac26604a8b04a4901feaea53eec2924552b3b47 --- /dev/null +++ b/src/main/resources/mapper/InterviewQuestionMapper.xml @@ -0,0 +1,14 @@ + + + + + +