fix:算法页面

上级 7db3fcb7
......@@ -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<AlgorithmicProblem> 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<AlgorithmicProblem> 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<AlgorithmicProblem> wrapper = new QueryWrapper<>();
wrapper.eq("id", id);
return Result.ok(this.algorithmicProblemService.update(algorithmicProblem, wrapper));
}
}
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
......@@ -4,8 +4,7 @@ import lombok.Data;
@Data
public class InterviewQuestionAdd {
private Integer addType;
private String question;
private Integer questionType;
private Integer addType;
}
......@@ -4,10 +4,8 @@ import lombok.Data;
@Data
public class QueryInfo {
private String invQtyA;
private String invQtyB;
private String invQtyC;
private String invQtyD;
}
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<AlgorithmicQuestionTypeDTO> getAll() {
LinkedList<AlgorithmicQuestionTypeDTO> 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;
}
}
......@@ -14,7 +14,19 @@ import java.util.List;
*/
public interface AlgorithmicProblemService extends IService<AlgorithmicProblem> {
/**
* 根据已有数据查询类型
*
* @return
*/
List<AlgorithmicQuestionTypeDTO> questionType();
/**
* 问题类型字典
*
* @return
*/
List<AlgorithmicQuestionTypeDTO> allQuestionType();
}
......@@ -35,5 +35,10 @@ public class AlgorithmicProblemServiceImpl extends ServiceImpl<AlgorithmicProble
}
return types;
}
@Override
public List<AlgorithmicQuestionTypeDTO> allQuestionType() {
return AlgorithmicProblemTypeEnum.getAll();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册