题目功能完善
This commit is contained in:
parent
82c6ea2d32
commit
84f6656e7d
|
@ -127,7 +127,78 @@ public class QuestionController {
|
||||||
List<QuestionDto> questionDtoList= questionService.getQuestionList(encoding);
|
List<QuestionDto> questionDtoList= questionService.getQuestionList(encoding);
|
||||||
return R.success(questionDtoList);
|
return R.success(questionDtoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加题目
|
||||||
|
* @param addQuestionInfo 添加题目信息
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
@PostMapping("add_question")
|
||||||
|
public R addQuestion(@RequestBody Map<String,Object> addQuestionInfo){
|
||||||
|
String title=(String)addQuestionInfo.get("title");
|
||||||
|
Integer bankId=(Integer) addQuestionInfo.get("bankId");
|
||||||
|
String details=(String)addQuestionInfo.get("details");
|
||||||
|
String promote=(String)addQuestionInfo.get("promote");
|
||||||
|
String encoding=(String)addQuestionInfo.get("encoding");
|
||||||
|
Integer userId=(Integer) addQuestionInfo.get("userId");
|
||||||
|
|
||||||
|
Integer rows = questionService.addQuestion(title, bankId, details, promote, encoding, userId);
|
||||||
|
|
||||||
|
if(rows==0){
|
||||||
|
return R.error("添加失败,请检查输入!");
|
||||||
|
}
|
||||||
|
if(rows==-2){
|
||||||
|
return R.error("题目标题已存在,请检查是否要添加该题目");
|
||||||
|
}
|
||||||
|
return R.success("添加成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改题目
|
||||||
|
* @param addQuestionInfo 修改题目信息
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
@PostMapping("update_question")
|
||||||
|
public R updateQuestion(@RequestBody Map<String,Object> addQuestionInfo){
|
||||||
|
Integer id=(Integer) addQuestionInfo.get("id");
|
||||||
|
String title=(String)addQuestionInfo.get("title");
|
||||||
|
Integer bankId=(Integer) addQuestionInfo.get("bankId");
|
||||||
|
String details=(String)addQuestionInfo.get("details");
|
||||||
|
String promote=(String)addQuestionInfo.get("promote");
|
||||||
|
String encoding=(String)addQuestionInfo.get("encoding");
|
||||||
|
Integer userId=(Integer) addQuestionInfo.get("userId");
|
||||||
|
|
||||||
|
Integer rows = questionService.updateQuestion(id,title, bankId, details, promote, encoding, userId);
|
||||||
|
|
||||||
|
if(rows==0){
|
||||||
|
return R.error("修改失败,请检查输入!");
|
||||||
|
}
|
||||||
|
if(rows==-2){
|
||||||
|
return R.error("题目标题已存在,请检查是否要修改该题目");
|
||||||
|
}
|
||||||
|
return R.success("修改成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*删除题目
|
||||||
|
* @param id 删除题目的id
|
||||||
|
* */
|
||||||
|
@GetMapping("/del_question")
|
||||||
|
public R deleteQuestion(Integer id){
|
||||||
|
|
||||||
|
Integer rows=questionService.deleteQuestion(id);
|
||||||
|
|
||||||
|
if(rows==-2||rows==0){
|
||||||
|
return R.error("删除失败,请联系管理员");
|
||||||
|
}
|
||||||
|
return R.success("删除成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,35 @@ public interface QuestionService extends IService<Question> {
|
||||||
* @return 题目列表
|
* @return 题目列表
|
||||||
* */
|
* */
|
||||||
List<QuestionDto> getQuestionList(String encoding);
|
List<QuestionDto> getQuestionList(String encoding);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加题目
|
||||||
|
* @param encoding 公司编码
|
||||||
|
* @param bankId 题库类型id
|
||||||
|
* @param details 题目详情
|
||||||
|
* @param promote 题目promote
|
||||||
|
* @param title 题目标题
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 改变的行数
|
||||||
|
* */
|
||||||
|
Integer addQuestion(String title,Integer bankId,String details,String promote,String encoding,Integer userId);
|
||||||
|
/**
|
||||||
|
* 修改题目
|
||||||
|
* @param id 题目ID
|
||||||
|
* @param encoding 公司编码
|
||||||
|
* @param bankId 题库类型id
|
||||||
|
* @param details 题目详情
|
||||||
|
* @param promote 题目promote
|
||||||
|
* @param title 题目标题
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 改变的行数
|
||||||
|
* */
|
||||||
|
Integer updateQuestion(Integer id,String title,Integer bankId,String details,String promote,String encoding,Integer userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除题目
|
||||||
|
* @param id 删除题目的id
|
||||||
|
* @return 改变的行数
|
||||||
|
* */
|
||||||
|
Integer deleteQuestion(Integer id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.yzdx.AiInterviewer.mapper.QuestionBankMapper;
|
||||||
import com.yzdx.AiInterviewer.mapper.QuestionMapper;
|
import com.yzdx.AiInterviewer.mapper.QuestionMapper;
|
||||||
import com.yzdx.AiInterviewer.mapper.UserMapper;
|
import com.yzdx.AiInterviewer.mapper.UserMapper;
|
||||||
import com.yzdx.AiInterviewer.service.QuestionService;
|
import com.yzdx.AiInterviewer.service.QuestionService;
|
||||||
|
import com.yzdx.AiInterviewer.utiles.TimeUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -37,12 +38,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
||||||
|
|
||||||
List<QuestionDto> questionDtoList =new ArrayList<>();
|
List<QuestionDto> questionDtoList =new ArrayList<>();
|
||||||
|
|
||||||
QuestionDto questionDto=new QuestionDto();
|
|
||||||
|
|
||||||
QuestionBank findQuestionBank=new QuestionBank();
|
QuestionBank findQuestionBank=new QuestionBank();
|
||||||
|
|
||||||
|
|
||||||
for (Question question:questionList) {
|
for (Question question:questionList) {
|
||||||
|
QuestionDto questionDto=new QuestionDto();
|
||||||
questionDto.setId(question.getId());
|
questionDto.setId(question.getId());
|
||||||
questionDto.setTitle(question.getTitle());
|
questionDto.setTitle(question.getTitle());
|
||||||
questionDto.setDetails(question.getDetails());
|
questionDto.setDetails(question.getDetails());
|
||||||
|
@ -80,4 +82,79 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
||||||
|
|
||||||
return questionDtoList;
|
return questionDtoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer addQuestion(String title, Integer bankId, String details, String promote, String encoding, Integer userId) {
|
||||||
|
//判断题目标题是否重复
|
||||||
|
Question question=new Question();
|
||||||
|
question.setTitle(title);
|
||||||
|
question.setBankId(bankId);
|
||||||
|
question.setDetails(details);
|
||||||
|
question.setPromote(promote);
|
||||||
|
question.setCompanyEncoding(encoding);
|
||||||
|
question.setCreateUser(userId);
|
||||||
|
question.setCreateTime(TimeUtil.getTime());
|
||||||
|
question.setUpdateTime(TimeUtil.getTime());
|
||||||
|
question.setUpdateUser(userId);
|
||||||
|
|
||||||
|
LambdaQueryWrapper<Question> questionLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
questionLambdaQueryWrapper
|
||||||
|
.eq(Question::getTitle,question.getTitle())
|
||||||
|
.eq(Question::getBankId,question.getBankId())
|
||||||
|
.eq(Question::getCompanyEncoding,question.getCompanyEncoding());
|
||||||
|
|
||||||
|
Question selectQuestion = questionMapper.selectOne(questionLambdaQueryWrapper);
|
||||||
|
|
||||||
|
if(selectQuestion!=null){
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer rows = questionMapper.insert(question);
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer updateQuestion(Integer id,String title, Integer bankId, String details, String promote, String encoding, Integer userId) {
|
||||||
|
//判断题目标题是否重复
|
||||||
|
Question question=new Question();
|
||||||
|
question.setId(id);
|
||||||
|
question.setTitle(title);
|
||||||
|
question.setBankId(bankId);
|
||||||
|
question.setDetails(details);
|
||||||
|
question.setPromote(promote);
|
||||||
|
question.setCompanyEncoding(encoding);
|
||||||
|
question.setUpdateTime(TimeUtil.getTime());
|
||||||
|
question.setUpdateUser(userId);
|
||||||
|
LambdaQueryWrapper<Question> questionLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
||||||
|
questionLambdaQueryWrapper
|
||||||
|
.eq(Question::getTitle,question.getTitle())
|
||||||
|
.eq(Question::getBankId,question.getBankId())
|
||||||
|
.eq(Question::getCompanyEncoding,question.getCompanyEncoding());
|
||||||
|
|
||||||
|
Question selectQuestion = questionMapper.selectOne(questionLambdaQueryWrapper);
|
||||||
|
|
||||||
|
if(selectQuestion!=null){
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
Integer rows = questionMapper.updateById(question);
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deleteQuestion(Integer id) {
|
||||||
|
|
||||||
|
LambdaQueryWrapper<Question> queryWrapper=new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
queryWrapper.eq(Question::getId,id);
|
||||||
|
|
||||||
|
if(questionMapper.selectOne(queryWrapper)==null){
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
Integer rows = questionMapper.delete(queryWrapper);
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue