fix:优化

上级 e4b3b1e3
......@@ -6,22 +6,18 @@ 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.entity.query.InterviewQuestionAdd;
import com.kwan.springbootkwan.entity.query.InterviewQuestionUpdate;
import com.kwan.springbootkwan.service.InterviewQuestionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
/**
* 面试题(InterviewQuestion)表控制层
......@@ -48,6 +44,16 @@ public class InterviewQuestionController {
return Result.ok(this.interviewQuestionService.uploadFile(path));
}
/**
* 获取面试题的种类的数量
*
* @return
*/
@GetMapping("/questionType")
public Result questionType() {
return Result.ok(this.interviewQuestionService.questionType());
}
/**
* 分页查询所有数据
*
......@@ -79,65 +85,78 @@ public class InterviewQuestionController {
* @return 所有数据
*/
@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));
public Result add(@RequestBody InterviewQuestionAdd addInfo) {
final Integer addType = addInfo.getAddType();
final String question = addInfo.getQuestion();
if (StringUtils.isEmpty(question)) {
return Result.error("问题不能为空");
}
//批量添加
if (addType == 1) {
final String[] split = question.split("\n");
for (String str : split) {
str = str.trim().replace("- ", "");
if (StringUtils.isEmpty(str)) {
continue;
}
InterviewQuestion interviewQuestion = new InterviewQuestion();
QueryWrapper<InterviewQuestion> wrapper = new QueryWrapper<>();
wrapper.eq("question", str);
wrapper.eq("is_delete", 0);
final InterviewQuestion one = this.interviewQuestionService.getOne(wrapper);
if (one == null) {
interviewQuestion.setQuestion(str);
interviewQuestion.setQuestionType(addInfo.getQuestionType());
this.interviewQuestionService.save(interviewQuestion);
}
}
} else {
InterviewQuestion interviewQuestion = new InterviewQuestion();
QueryWrapper<InterviewQuestion> wrapper = new QueryWrapper<>();
wrapper.eq("question", question);
wrapper.eq("is_delete", 0);
final InterviewQuestion one = this.interviewQuestionService.getOne(wrapper);
if (one == null) {
interviewQuestion.setQuestion(question);
interviewQuestion.setQuestionType(addInfo.getQuestionType());
this.interviewQuestionService.save(interviewQuestion);
return Result.ok();
} else {
return Result.error("该面试问题已存在");
}
}
return Result.ok();
}
/**
* 获取面试题的种类的数量
* 更新面试题
*
* @param addInfo
* @return
*/
@GetMapping("/questionType")
public Result questionType() {
return Result.ok(interviewQuestionService.questionType());
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("{id}")
public Result selectOne(@PathVariable Serializable id) {
return Result.ok(this.interviewQuestionService.getById(id));
}
/**
* 新增数据
*
* @param interviewQuestion 实体对象
* @return 新增结果
*/
@PostMapping
public Result insert(@RequestBody InterviewQuestion interviewQuestion) {
return Result.ok(this.interviewQuestionService.save(interviewQuestion));
}
/**
* 修改数据
*
* @param interviewQuestion 实体对象
* @return 修改结果
*/
@PutMapping
public Result update(@RequestBody InterviewQuestion interviewQuestion) {
@PostMapping("/update")
public Result update(@RequestBody InterviewQuestionUpdate addInfo) {
InterviewQuestion interviewQuestion = new InterviewQuestion();
interviewQuestion.setId(addInfo.getId());
interviewQuestion.setQuestion(addInfo.getQuestion());
interviewQuestion.setQuestionType(addInfo.getQuestionType());
return Result.ok(this.interviewQuestionService.updateById(interviewQuestion));
}
/**
* 删除数据
* 删除面试题
*
* @param idList 主键结合
* @return 删除结果
* @param id
* @return
*/
@DeleteMapping
public Result delete(@RequestParam("idList") List<Long> idList) {
return Result.ok(this.interviewQuestionService.removeByIds(idList));
@GetMapping("/delete")
public Result delete(@RequestParam("id") Integer id) {
InterviewQuestion interviewQuestion = new InterviewQuestion();
interviewQuestion.setIsDelete(1);
QueryWrapper<InterviewQuestion> wrapper = new QueryWrapper<>();
wrapper.eq("id", id);
return Result.ok(this.interviewQuestionService.update(interviewQuestion, wrapper));
}
}
package com.kwan.springbootkwan.entity.query;
import lombok.Data;
@Data
public class InterviewQuestionAdd {
private String question;
private Integer questionType;
private Integer addType;
}
......@@ -3,7 +3,9 @@ package com.kwan.springbootkwan.entity.query;
import lombok.Data;
@Data
public class InterviewQuestionAddQuery {
public class InterviewQuestionUpdate {
private Integer id;
private String question;
private Integer questionType;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册