From 7db3fcb75439536b74d63c7156321ec2d178b975 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 12:54:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=9A=8F=E6=9C=BA=E4=B8=80=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AlgorithmicProblemController.java | 80 ++++++++++++ .../entity/AlgorithmicProblem.java | 68 +++++++++++ .../entity/dto/AlgorithmicProblemDTO.java | 63 ++++++++++ .../dto/AlgorithmicQuestionTypeDTO.java | 25 ++++ .../enums/AlgorithmicProblemTypeEnum.java | 115 ++++++++++++++++++ .../mapper/AlgorithmicProblemMapper.java | 19 +++ .../service/AlgorithmicProblemService.java | 20 +++ .../impl/AlgorithmicProblemServiceImpl.java | 39 ++++++ .../mapper/AlgorithmicProblemMapper.xml | 14 +++ 9 files changed, 443 insertions(+) create mode 100644 src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/AlgorithmicProblem.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicProblemDTO.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicQuestionTypeDTO.java create mode 100644 src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java create mode 100644 src/main/java/com/kwan/springbootkwan/mapper/AlgorithmicProblemMapper.java create mode 100644 src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java create mode 100644 src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java create mode 100644 src/main/resources/mapper/AlgorithmicProblemMapper.xml diff --git a/src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java b/src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java new file mode 100644 index 0000000..bfea131 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/controller/AlgorithmicProblemController.java @@ -0,0 +1,80 @@ +package com.kwan.springbootkwan.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +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.service.AlgorithmicProblemService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 算法题(AlgorithmicProblem)表控制层 + * + * @author makejava + * @since 2023-10-07 09:15:45 + */ +@RestController +@RequestMapping("algorithmicProblem") +public class AlgorithmicProblemController { + + /** + * 服务对象 + */ + @Resource + private AlgorithmicProblemService algorithmicProblemService; + + /** + * 获取面试题的种类的数量 + * + * @return + */ + @GetMapping("/questionType") + public Result questionType() { + return Result.ok(this.algorithmicProblemService.questionType()); + } + + /** + * 分页查询所有数据 + * + * @return 所有数据 + */ + @GetMapping("/page") + public Result selectAll(@RequestParam Integer page + , @RequestParam Integer pageSize + , @RequestParam String questionName + , @RequestParam Integer questionType) { + Page pageParm = new Page<>(); + pageParm.setCurrent(page); + pageParm.setSize(pageSize); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.orderByDesc("id"); + if (questionType != 0) { + wrapper.eq("question_type", questionType); + } + wrapper.eq("is_delete", 0); + if (StringUtils.isNotEmpty(questionName)) { + wrapper.like("question_name", questionName); + } + return Result.ok(AlgorithmicProblemDTO.Converter.INSTANCE.from(this.algorithmicProblemService.page(pageParm, wrapper))); + } + + /** + * 随机一题 + */ + @GetMapping("/random") + public Result random() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("is_delete", 0); + wrapper.orderByAsc("rand()").last("limit 1"); + return Result.ok(AlgorithmicProblemDTO.Converter.INSTANCE.from(this.algorithmicProblemService.getOne(wrapper))); + } +} + diff --git a/src/main/java/com/kwan/springbootkwan/entity/AlgorithmicProblem.java b/src/main/java/com/kwan/springbootkwan/entity/AlgorithmicProblem.java new file mode 100644 index 0000000..7e36ddb --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/AlgorithmicProblem.java @@ -0,0 +1,68 @@ +package com.kwan.springbootkwan.entity; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.Data; + +import java.util.Date; + +/** + * 算法题(AlgorithmicProblem)表实体类 + * + * @author makejava + * @since 2023-10-07 09:15:47 + */ +@Data +public class AlgorithmicProblem extends Model { + /** + * 主键id + */ + private Integer id; + /** + * 问题名称 + */ + private String questionName; + /** + * 0:'全部'; + * 1: '链表'; + * 2: '数组'; + * 3: 'JVM'; + * 4: '并发编程'; + * 5:'MySql'; + * 6: 'Redis'; + * 7: '中间件'; + * 8: 'Spring'; + * 9: '微服务'; + * 10:'分布式'; + * 11:'项目'; + * 12:'算法'; + * 99: '其他'; + */ + private Integer questionType; + /** + * 1~10的分值 + */ + private Integer degreeOfImportance; + + /** + * 1:简单;2:中等;3:困难 + */ + private Integer degreeOfDifficulty; + /** + * 困难指数 + */ + private Integer difficultyOfScore; + /** + * 力扣的问题号 + */ + private Integer leetcodeNumber; + /** + * 力扣的问题链接 + */ + private String leetcodeLink; + /** + * 创建时间 + */ + private Date createTime; + //逻辑删除,0未删除,1已删除 + private Integer isDelete; +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicProblemDTO.java b/src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicProblemDTO.java new file mode 100644 index 0000000..b6ff7ae --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicProblemDTO.java @@ -0,0 +1,63 @@ +package com.kwan.springbootkwan.entity.dto; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.kwan.springbootkwan.entity.AlgorithmicProblem; +import com.kwan.springbootkwan.mapstruct.FromConverter; +import lombok.Data; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +import java.util.Date; + +/** + * 面试题(InterviewQuestion)表实体类 + * + * @author makejava + * @since 2023-09-08 16:31:53 + */ +@Data +@SuppressWarnings("serial") +public class AlgorithmicProblemDTO extends Model { + /** + * 主键id + */ + private Integer id; + /** + * 面试问题 + */ + private String questionName; + /** + * 类型 + */ + private Integer questionType; + /** + * 1~10的分值 + */ + private Integer degreeOfImportance; + /** + * 1:简单;2:中等;3:困难 + */ + private Integer degreeOfDifficulty; + /** + * 困难指数 + */ + private Integer difficultyOfScore; + /** + * 力扣的问题号 + */ + private Integer leetcodeNumber; + /** + * 力扣的问题链接 + */ + private String leetcodeLink; + /** + * 创建时间 + */ + private Date createTime; + + @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) + public interface Converter extends FromConverter { + AlgorithmicProblemDTO.Converter INSTANCE = Mappers.getMapper(AlgorithmicProblemDTO.Converter.class); + } +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicQuestionTypeDTO.java b/src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicQuestionTypeDTO.java new file mode 100644 index 0000000..1a7df58 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/dto/AlgorithmicQuestionTypeDTO.java @@ -0,0 +1,25 @@ +package com.kwan.springbootkwan.entity.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AlgorithmicQuestionTypeDTO { + /** + * 问题类型编码 + */ + private Integer questionType; + /** + * 问题类型名称 + */ + private String name; + /** + * 问题类型数量 + */ + private Integer typeSize; +} + diff --git a/src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java b/src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java new file mode 100644 index 0000000..7437d36 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/enums/AlgorithmicProblemTypeEnum.java @@ -0,0 +1,115 @@ +package com.kwan.springbootkwan.enums; + +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public enum AlgorithmicProblemTypeEnum { + /** + * 全部 + */ + 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; + + AlgorithmicProblemTypeEnum(Integer code, String name) { + this.code = code; + this.name = name; + } + + /** + * 通过code获取name + * + * @param code + * @return + */ + public static String getNameByCode(Integer code) { + for (AlgorithmicProblemTypeEnum enums : AlgorithmicProblemTypeEnum.values()) { + if (enums.getCode().equals(code)) { + return enums.getName(); + } + } + return null; + } + + /** + * 通过value取枚举 + * + * @param value + * @return + */ + public static AlgorithmicProblemTypeEnum getBrandDetailNoByValue(String value) { + if (null == value) { + return null; + } + for (AlgorithmicProblemTypeEnum enums : AlgorithmicProblemTypeEnum.values()) { + if (enums.getCode().equals(value)) { + return enums; + } + } + return null; + } +} diff --git a/src/main/java/com/kwan/springbootkwan/mapper/AlgorithmicProblemMapper.java b/src/main/java/com/kwan/springbootkwan/mapper/AlgorithmicProblemMapper.java new file mode 100644 index 0000000..8166b81 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/mapper/AlgorithmicProblemMapper.java @@ -0,0 +1,19 @@ +package com.kwan.springbootkwan.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.kwan.springbootkwan.entity.AlgorithmicProblem; +import com.kwan.springbootkwan.entity.dto.AlgorithmicQuestionTypeDTO; + +import java.util.LinkedList; + +/** + * 算法题(AlgorithmicProblem)表数据库访问层 + * + * @author makejava + * @since 2023-10-07 09:15:45 + */ +public interface AlgorithmicProblemMapper extends BaseMapper { + + LinkedList questionType(); +} + diff --git a/src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java b/src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java new file mode 100644 index 0000000..1d6793b --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/service/AlgorithmicProblemService.java @@ -0,0 +1,20 @@ +package com.kwan.springbootkwan.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.kwan.springbootkwan.entity.AlgorithmicProblem; +import com.kwan.springbootkwan.entity.dto.AlgorithmicQuestionTypeDTO; + +import java.util.List; + +/** + * 算法题(AlgorithmicProblem)表服务接口 + * + * @author makejava + * @since 2023-10-07 09:15:47 + */ +public interface AlgorithmicProblemService extends IService { + + List questionType(); + +} + diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java new file mode 100644 index 0000000..ca54c90 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/service/impl/AlgorithmicProblemServiceImpl.java @@ -0,0 +1,39 @@ +package com.kwan.springbootkwan.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.kwan.springbootkwan.entity.AlgorithmicProblem; +import com.kwan.springbootkwan.entity.dto.AlgorithmicQuestionTypeDTO; +import com.kwan.springbootkwan.enums.AlgorithmicProblemTypeEnum; +import com.kwan.springbootkwan.mapper.AlgorithmicProblemMapper; +import com.kwan.springbootkwan.service.AlgorithmicProblemService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 算法题(AlgorithmicProblem)表服务实现类 + * + * @author makejava + * @since 2023-10-07 09:15:47 + */ +@Service("algorithmicProblemService") +public class AlgorithmicProblemServiceImpl extends ServiceImpl implements AlgorithmicProblemService { + + @Autowired + private AlgorithmicProblemMapper interviewQuestionMapper; + + @Override + public List questionType() { + //获取种类,并按数量排序 + LinkedList types = interviewQuestionMapper.questionType(); + types.addFirst(new AlgorithmicQuestionTypeDTO(0, "全部", 0)); + for (AlgorithmicQuestionTypeDTO algorithmicQuestionTypeDTO : types) { + //数据库存的是问题类型的编码 + algorithmicQuestionTypeDTO.setName(AlgorithmicProblemTypeEnum.getNameByCode(algorithmicQuestionTypeDTO.getQuestionType())); + } + return types; + } +} + diff --git a/src/main/resources/mapper/AlgorithmicProblemMapper.xml b/src/main/resources/mapper/AlgorithmicProblemMapper.xml new file mode 100644 index 0000000..8aa9880 --- /dev/null +++ b/src/main/resources/mapper/AlgorithmicProblemMapper.xml @@ -0,0 +1,14 @@ + + + + + + -- GitLab