diff --git a/src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java b/src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java index bfea1312840c47a4d123aaee096ba80842e777bd..bc879c76374474ba6d990ffe6cfa3b8b3585f955 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java @@ -6,9 +6,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.kwan.springbootkwan.entity.AlgorithmicProblem; import com.kwan.springbootkwan.entity.Result; import com.kwan.springbootkwan.entity.dto.AlgorithmicProblemDTO; +import com.kwan.springbootkwan.entity.query.AlgorithmicProblemQuery; import com.kwan.springbootkwan.service.AlgorithmicProblemService; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -41,6 +45,16 @@ public class AlgorithmicProblemController { return Result.ok(this.algorithmicProblemService.questionType()); } + /** + * 获取面试题的种类的数量 + * + * @return + */ + @GetMapping("/allQuestionType") + public Result allQuestionType() { + return Result.ok(this.algorithmicProblemService.allQuestionType()); + } + /** * 分页查询所有数据 * @@ -76,5 +90,81 @@ public class AlgorithmicProblemController { wrapper.orderByAsc("rand()").last("limit 1"); return Result.ok(AlgorithmicProblemDTO.Converter.INSTANCE.from(this.algorithmicProblemService.getOne(wrapper))); } + + /** + * 新增问题 + * + * @return 所有数据 + */ + @PostMapping("/add") + public Result add(@RequestBody AlgorithmicProblemQuery addInfo) { + final Integer addType = addInfo.getAddType(); + final String questionName = addInfo.getQuestionName(); + if (StringUtils.isEmpty(questionName)) { + return Result.error("问题不能为空"); + } + //批量添加 + if (addType == 1) { + final String[] split = questionName.split("\n"); + for (String str : split) { + str = str.trim().replace("- ", ""); + if (StringUtils.isEmpty(str)) { + continue; + } + AlgorithmicProblem algorithmicProblem = new AlgorithmicProblem(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("question_name", str); + wrapper.eq("is_delete", 0); + final AlgorithmicProblem one = this.algorithmicProblemService.getOne(wrapper); + if (one == null) { + BeanUtils.copyProperties(addInfo, algorithmicProblem); + algorithmicProblem.setQuestionName(str); + this.algorithmicProblemService.save(algorithmicProblem); + } + } + } else { + AlgorithmicProblem algorithmicProblem = new AlgorithmicProblem(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("question_name", questionName); + wrapper.eq("is_delete", 0); + final AlgorithmicProblem one = this.algorithmicProblemService.getOne(wrapper); + if (one == null) { + BeanUtils.copyProperties(addInfo, algorithmicProblem); + this.algorithmicProblemService.save(algorithmicProblem); + return Result.ok(); + } else { + return Result.error("该面试问题已存在"); + } + } + return Result.ok(); + } + + /** + * 更新面试题 + * + * @param query + * @return + */ + @PostMapping("/update") + public Result update(@RequestBody AlgorithmicProblemQuery query) { + AlgorithmicProblem algorithmicProblem = new AlgorithmicProblem(); + BeanUtils.copyProperties(query, algorithmicProblem); + return Result.ok(this.algorithmicProblemService.updateById(algorithmicProblem)); + } + + /** + * 删除面试题 + * + * @param id + * @return + */ + @GetMapping("/delete") + public Result delete(@RequestParam("id") Integer id) { + AlgorithmicProblem algorithmicProblem = new AlgorithmicProblem(); + algorithmicProblem.setIsDelete(1); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("id", id); + return Result.ok(this.algorithmicProblemService.update(algorithmicProblem, wrapper)); + } } diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/AlgorithmicProblemQuery.java b/src/main/java/com/kwan/springbootkwan/entity/query/AlgorithmicProblemQuery.java new file mode 100644 index 0000000000000000000000000000000000000000..6ae112e0d399adab22a85b002fe61a3bbfe98020 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/query/AlgorithmicProblemQuery.java @@ -0,0 +1,16 @@ +package com.kwan.springbootkwan.entity.query; + +import lombok.Data; + +@Data +public class AlgorithmicProblemQuery { + private Integer id; + private Integer addType; + private String questionName; + private Integer questionType; + private Integer degreeOfImportance; + private Integer degreeOfDifficulty; + private Integer difficultyOfScore; + private Integer leetcodeNumber; + private String leetcodeLink; +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/InterviewQuestionAdd.java b/src/main/java/com/kwan/springbootkwan/entity/query/InterviewQuestionAdd.java index f5c3a6b648559b4e7caaed9c82edc3336523360a..85cc653e5c868db3cb6fb7590851d48b57928093 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/query/InterviewQuestionAdd.java +++ b/src/main/java/com/kwan/springbootkwan/entity/query/InterviewQuestionAdd.java @@ -4,8 +4,7 @@ import lombok.Data; @Data public class InterviewQuestionAdd { - + private Integer addType; private String question; private Integer questionType; - private Integer addType; } diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/QueryInfo.java b/src/main/java/com/kwan/springbootkwan/entity/query/QueryInfo.java index 71e71a800dfb7fd31fea34498a5f67310775985c..130582d550998cc65e12ebfff5624610c78bdcb5 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/query/QueryInfo.java +++ b/src/main/java/com/kwan/springbootkwan/entity/query/QueryInfo.java @@ -4,10 +4,8 @@ import lombok.Data; @Data public class QueryInfo { - private String invQtyA; private String invQtyB; private String invQtyC; private String invQtyD; - } diff --git a/src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java b/src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java index 7437d364f995408250e09acf2d1c7721a001337d..99fa356ea745a0aacf8da7d7decfb873285dd6cd 100644 --- a/src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java +++ b/src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java @@ -1,8 +1,11 @@ package com.kwan.springbootkwan.enums; +import com.kwan.springbootkwan.entity.dto.AlgorithmicQuestionTypeDTO; import lombok.Getter; import lombok.ToString; +import java.util.LinkedList; + @Getter @ToString public enum AlgorithmicProblemTypeEnum { @@ -19,55 +22,17 @@ public enum AlgorithmicProblemTypeEnum { */ 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_03(3, "二叉树"), /** - * 反问环节 + * 贪心 */ - type_13(13, "反问环节"), + type_04(4, "贪心"), /** - * 设计模式 + * 动态规划 */ - type_14(14, "设计模式"), + type_05(5, "动态规划"), /** * 其他 */ @@ -96,20 +61,16 @@ public enum AlgorithmicProblemTypeEnum { } /** - * 通过value取枚举 + * 获取所有枚举 * - * @param value * @return */ - public static AlgorithmicProblemTypeEnum getBrandDetailNoByValue(String value) { - if (null == value) { - return null; - } + public static LinkedList getAll() { + LinkedList list = new LinkedList<>(); for (AlgorithmicProblemTypeEnum enums : AlgorithmicProblemTypeEnum.values()) { - if (enums.getCode().equals(value)) { - return enums; - } + AlgorithmicQuestionTypeDTO algorithmicQuestionTypeDTO = new AlgorithmicQuestionTypeDTO(enums.getCode(), enums.getName(), 0); + list.add(algorithmicQuestionTypeDTO); } - return null; + return list; } } diff --git a/src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java b/src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java index 1d6793b10406b0b5d2a9ae8e653f322f8ab8740b..ec145ff1e4f1d5e53c2073bcadb5c4ec5388744e 100644 --- a/src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java +++ b/src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java @@ -14,7 +14,19 @@ import java.util.List; */ public interface AlgorithmicProblemService extends IService { + /** + * 根据已有数据查询类型 + * + * @return + */ List questionType(); + + /** + * 问题类型字典 + * + * @return + */ + List allQuestionType(); } diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java index ca54c9024977e5774fa7c7d3d7fe6c2347436c88..581f46b9fb67a236045356f8bad152b29bbd1d10 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java @@ -35,5 +35,10 @@ public class AlgorithmicProblemServiceImpl extends ServiceImpl allQuestionType() { + return AlgorithmicProblemTypeEnum.getAll(); + } }