241 lines
7.5 KiB
Java
241 lines
7.5 KiB
Java
package com.yzdx.AiInterviewer.controller;
|
|
|
|
import com.yzdx.AiInterviewer.comment.R;
|
|
import com.yzdx.AiInterviewer.entity.QuestionBank;
|
|
import com.yzdx.AiInterviewer.entity.dto.QuestionDto;
|
|
import com.yzdx.AiInterviewer.service.QuestionBankService;
|
|
import com.yzdx.AiInterviewer.service.QuestionService;
|
|
import io.swagger.annotations.ApiParam;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/question")
|
|
public class QuestionController {
|
|
|
|
@Autowired
|
|
private QuestionBankService questionBankService;
|
|
|
|
@Autowired
|
|
private QuestionService questionService;
|
|
|
|
/**
|
|
* 获取题库列表
|
|
* @param encoding 公司编码
|
|
* @return 返回的该公司下的公司题库
|
|
* */
|
|
@GetMapping("/get_typeList")
|
|
public R getTypeListByEncoding(@RequestParam @ApiParam("传入前端存入的encoding数据") String encoding){
|
|
|
|
List<QuestionBank> typeList = questionBankService.getTypeList(encoding);
|
|
|
|
return R.success(typeList);
|
|
}
|
|
@GetMapping("/search_typeName")
|
|
public R searchTypeList(String name,String type,String encoding){
|
|
|
|
if(name==null&&encoding==null){
|
|
return R.error("搜索失败,请稍后再试");
|
|
}
|
|
List<QuestionBank> questionBanks = questionBankService.searchTypeList(name,type,encoding);
|
|
return R.success(questionBanks);
|
|
}
|
|
|
|
@GetMapping("/get_typeListByType")
|
|
public R getTypeListByType(String encoding,Integer type){
|
|
|
|
if(encoding==null||type==null){
|
|
return R.error("数据出错啦,请联系管理员!");
|
|
}
|
|
List<QuestionBank> typeListByType = questionBankService.getTypeListByType(encoding, type);
|
|
return R.success(typeListByType);
|
|
|
|
}
|
|
|
|
/**
|
|
* @param addInfo typeName,encoding,userId
|
|
* @return R
|
|
* */
|
|
@PostMapping("/add_typeName")
|
|
public R addTypeName(@RequestBody @ApiParam("addInfo:typeName,encoding,userId") Map<String ,Object> addInfo){
|
|
|
|
if(addInfo.size()==0||addInfo.get("typeName")==null){
|
|
return R.error("添加失败,请检查输入");
|
|
}
|
|
String typeName=(String)addInfo.get("typeName");
|
|
String encoding= (String)addInfo.get("encoding");
|
|
Integer type=(Integer)addInfo.get("type");
|
|
String description=(String) addInfo.get("description");
|
|
Integer userId=(Integer)addInfo.get("userId");
|
|
|
|
if (type==null){
|
|
return R.error("请选择添加的题库类型");
|
|
}
|
|
Integer row=questionBankService.addTypeName(typeName,encoding,description,type,userId);
|
|
|
|
if(row==0){
|
|
return R.error("添加失败,请联系管理员");
|
|
}
|
|
if (row==-2){
|
|
return R.error("该题库名称已存在!");
|
|
}
|
|
return R.success("添加成功");
|
|
}
|
|
|
|
/**
|
|
* 根据题库id删除题库
|
|
* @param typeId 传入的题库id
|
|
*
|
|
* */
|
|
@GetMapping("/delete_type")
|
|
public R deleteTypeName(@RequestParam @ApiParam("typeId:传入的题库id") Integer typeId){
|
|
if(typeId==null){
|
|
return R.error("提交的信息错误,请检查输入");
|
|
}
|
|
Integer row= questionBankService.deleteType(typeId);
|
|
|
|
//判断是否删除成功
|
|
if(row==0){
|
|
return R.error("删除失败,请联系管理员");
|
|
|
|
}
|
|
|
|
return R.success("删除成功");
|
|
}
|
|
/**
|
|
* 根据题库id更新题库
|
|
* @param updateType 更新题库的信息
|
|
*
|
|
* */
|
|
@PostMapping("/change_type")
|
|
public R changeTypeName(@RequestBody @ApiParam("updateType:修改的内容 typeId 修改的题库id typeName 修改的题库名称 userId 修改人的id") Map<String ,Object> updateType){
|
|
|
|
if(updateType.size()==0){
|
|
|
|
return R.error("修改内容格式不正确,请检查输入");
|
|
}
|
|
|
|
Integer typeId= (Integer) updateType.get("typeId");
|
|
|
|
String typeName=(String) updateType.get("typeName");
|
|
|
|
String description=(String) updateType.get("description");
|
|
|
|
Integer type=(Integer)updateType.get("type");
|
|
|
|
Integer userId=(Integer) updateType.get("userId");
|
|
|
|
if (type==null){
|
|
return R.error("请选择题库类型");
|
|
}
|
|
Integer rows=questionBankService.changeType(typeId,description,type,typeName,userId);
|
|
|
|
if(rows==-2){
|
|
return R.error("修改的题库名已存在!");
|
|
}
|
|
|
|
if(rows==0){
|
|
return R.error("修改失败,请稍后再试或联系管理员");
|
|
}
|
|
|
|
return R.success("修改成功");
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 根据公司编码查找题目
|
|
* @param encoding 公司编码
|
|
*
|
|
* */
|
|
@GetMapping("/get_questionList")
|
|
public R getQuestionList(@RequestParam String encoding){
|
|
if(encoding==null){
|
|
return R.error("出错了!请联系管理员");
|
|
}
|
|
List<QuestionDto> questionDtoList= questionService.getQuestionList(encoding);
|
|
return R.success(questionDtoList);
|
|
}
|
|
|
|
@GetMapping("/search_questionList")
|
|
public R searchQuestionList(String name,String type,String encoding){
|
|
List<QuestionDto> questionDtos = questionService.searchQuestionList(name, type, encoding);
|
|
return R.success(questionDtos);
|
|
}
|
|
/**
|
|
* 添加题目
|
|
* @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("删除成功!");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|