fix:优化

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