fix:添加面试题

上级 a9f2bf58
...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; ...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kwan.springbootkwan.entity.InterviewQuestion; import com.kwan.springbootkwan.entity.InterviewQuestion;
import com.kwan.springbootkwan.entity.Result; import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.entity.dto.InterviewQuestionDTO; import com.kwan.springbootkwan.entity.dto.InterviewQuestionDTO;
import com.kwan.springbootkwan.entity.query.InterviewQuestionAddQuery;
import com.kwan.springbootkwan.service.InterviewQuestionService; import com.kwan.springbootkwan.service.InterviewQuestionService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
...@@ -48,7 +49,7 @@ public class InterviewQuestionController { ...@@ -48,7 +49,7 @@ public class InterviewQuestionController {
} }
/** /**
* 分页查询所有数据,本地缓存的使用 * 分页查询所有数据
* *
* @return 所有数据 * @return 所有数据
*/ */
...@@ -56,14 +57,14 @@ public class InterviewQuestionController { ...@@ -56,14 +57,14 @@ public class InterviewQuestionController {
public Result selectAll(@RequestParam Integer page public Result selectAll(@RequestParam Integer page
, @RequestParam Integer pageSize , @RequestParam Integer pageSize
, @RequestParam String question , @RequestParam String question
, @RequestParam Integer type) { , @RequestParam Integer questionType) {
Page<InterviewQuestion> pageParm = new Page<>(); Page<InterviewQuestion> pageParm = new Page<>();
pageParm.setCurrent(page); pageParm.setCurrent(page);
pageParm.setSize(pageSize); pageParm.setSize(pageSize);
QueryWrapper<InterviewQuestion> wrapper = new QueryWrapper<>(); QueryWrapper<InterviewQuestion> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("id"); wrapper.orderByDesc("id");
if (type != 0) { if (questionType != 0) {
wrapper.eq("type", type); wrapper.eq("question_type", questionType);
} }
wrapper.eq("is_delete", 0); wrapper.eq("is_delete", 0);
if (StringUtils.isNotEmpty(question)) { if (StringUtils.isNotEmpty(question)) {
...@@ -73,15 +74,26 @@ public class InterviewQuestionController { ...@@ -73,15 +74,26 @@ public class InterviewQuestionController {
} }
/** /**
* 分页查询所有数据 * 新增问题
* *
* @param page 分页对象
* @param interviewQuestion 查询实体
* @return 所有数据 * @return 所有数据
*/ */
@GetMapping @PostMapping("/add")
public Result selectAll(Page<InterviewQuestion> page, InterviewQuestion interviewQuestion) { public Result add(@RequestBody InterviewQuestionAddQuery addInfo) {
return Result.ok(this.interviewQuestionService.page(page, new QueryWrapper<>(interviewQuestion))); 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());
} }
/** /**
......
...@@ -21,7 +21,7 @@ public class InterviewQuestion extends Model<InterviewQuestion> { ...@@ -21,7 +21,7 @@ public class InterviewQuestion extends Model<InterviewQuestion> {
//问题回答 //问题回答
private String response; private String response;
//知识类型,先默认0,后面再区分 //知识类型,先默认0,后面再区分
private Integer type; private Integer questionType;
//创建时间 //创建时间
private Date createTime; private Date createTime;
//逻辑删除,0未删除,1已删除 //逻辑删除,0未删除,1已删除
......
...@@ -26,7 +26,7 @@ public class InterviewQuestionDTO extends Model<InterviewQuestionDTO> { ...@@ -26,7 +26,7 @@ public class InterviewQuestionDTO extends Model<InterviewQuestionDTO> {
//问题回答 //问题回答
private String response; private String response;
//知识类型,先默认0,后面再区分 //知识类型,先默认0,后面再区分
private Integer type; private Integer questionType;
//创建时间 //创建时间
private Date createTime; private Date createTime;
//逻辑删除,0未删除,1已删除 //逻辑删除,0未删除,1已删除
......
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;
}
package com.kwan.springbootkwan.entity.query;
import lombok.Data;
@Data
public class InterviewQuestionAddQuery {
private String question;
private Integer questionType;
}
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;
}
}
...@@ -2,6 +2,9 @@ package com.kwan.springbootkwan.mapper; ...@@ -2,6 +2,9 @@ package com.kwan.springbootkwan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kwan.springbootkwan.entity.InterviewQuestion; import com.kwan.springbootkwan.entity.InterviewQuestion;
import com.kwan.springbootkwan.entity.dto.InterviewQuestionTypeDTO;
import java.util.LinkedList;
/** /**
* 面试题(InterviewQuestion)表数据库访问层 * 面试题(InterviewQuestion)表数据库访问层
...@@ -11,5 +14,11 @@ import com.kwan.springbootkwan.entity.InterviewQuestion; ...@@ -11,5 +14,11 @@ import com.kwan.springbootkwan.entity.InterviewQuestion;
*/ */
public interface InterviewQuestionMapper extends BaseMapper<InterviewQuestion> { public interface InterviewQuestionMapper extends BaseMapper<InterviewQuestion> {
/**
* 获取面试题的种类
*
* @return
*/
LinkedList<InterviewQuestionTypeDTO> questionType();
} }
...@@ -2,6 +2,9 @@ package com.kwan.springbootkwan.service; ...@@ -2,6 +2,9 @@ package com.kwan.springbootkwan.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.kwan.springbootkwan.entity.InterviewQuestion; import com.kwan.springbootkwan.entity.InterviewQuestion;
import com.kwan.springbootkwan.entity.dto.InterviewQuestionTypeDTO;
import java.util.List;
/** /**
* 面试题(InterviewQuestion)表服务接口 * 面试题(InterviewQuestion)表服务接口
...@@ -10,7 +13,18 @@ import com.kwan.springbootkwan.entity.InterviewQuestion; ...@@ -10,7 +13,18 @@ import com.kwan.springbootkwan.entity.InterviewQuestion;
* @since 2023-09-08 16:31:53 * @since 2023-09-08 16:31:53
*/ */
public interface InterviewQuestionService extends IService<InterviewQuestion> { public interface InterviewQuestionService extends IService<InterviewQuestion> {
/**
* 上传面试题
*
* @param path
* @return
*/
boolean uploadFile(String path); boolean uploadFile(String path);
}
/**
* 获取面试题的种类
*
* @return
*/
List<InterviewQuestionTypeDTO> questionType();
}
\ No newline at end of file
...@@ -3,6 +3,8 @@ package com.kwan.springbootkwan.service.impl; ...@@ -3,6 +3,8 @@ package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.InterviewQuestion; 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.mapper.InterviewQuestionMapper;
import com.kwan.springbootkwan.service.InterviewQuestionService; import com.kwan.springbootkwan.service.InterviewQuestionService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -13,6 +15,7 @@ import java.io.IOException; ...@@ -13,6 +15,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List; import java.util.List;
/** /**
...@@ -24,6 +27,7 @@ import java.util.List; ...@@ -24,6 +27,7 @@ import java.util.List;
@Slf4j @Slf4j
@Service("interviewQuestionService") @Service("interviewQuestionService")
public class InterviewQuestionServiceImpl extends ServiceImpl<InterviewQuestionMapper, InterviewQuestion> implements InterviewQuestionService { public class InterviewQuestionServiceImpl extends ServiceImpl<InterviewQuestionMapper, InterviewQuestion> implements InterviewQuestionService {
@Resource @Resource
private InterviewQuestionMapper interviewQuestionMapper; private InterviewQuestionMapper interviewQuestionMapper;
...@@ -53,4 +57,15 @@ public class InterviewQuestionServiceImpl extends ServiceImpl<InterviewQuestionM ...@@ -53,4 +57,15 @@ public class InterviewQuestionServiceImpl extends ServiceImpl<InterviewQuestionM
} }
return true; return true;
} }
@Override
public List<InterviewQuestionTypeDTO> questionType() {
//获取种类,并按数量排序
LinkedList<InterviewQuestionTypeDTO> 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kwan.springbootkwan.mapper.InterviewQuestionMapper">
<select id="questionType" resultType="com.kwan.springbootkwan.entity.dto.InterviewQuestionTypeDTO">
SELECT DISTINCT question_type AS questionType, COUNT(*) AS typeSize
FROM interview_question
WHERE 1 = 1
AND is_delete = 0
AND question_type != 0
GROUP BY question_type
ORDER BY typeSize DESC
</select>
</mapper>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册