518 lines
21 KiB
Java
518 lines
21 KiB
Java
package com.yzdx.AiInterviewer.controller;
|
||
|
||
import com.yzdx.AiInterviewer.comment.R;
|
||
import com.yzdx.AiInterviewer.entity.Question;
|
||
import com.yzdx.AiInterviewer.entity.QuestionBank;
|
||
import com.yzdx.AiInterviewer.entity.SharedQuestionBank;
|
||
import com.yzdx.AiInterviewer.entity.dto.QuestionDto;
|
||
import com.yzdx.AiInterviewer.entity.dto.SharedQuestionBankDto;
|
||
import com.yzdx.AiInterviewer.entity.dto.SharedQuestionDto;
|
||
import com.yzdx.AiInterviewer.service.*;
|
||
import io.swagger.annotations.*;
|
||
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;
|
||
|
||
@Autowired
|
||
private SharedQuestionBankService sharedQuestionBankService;
|
||
|
||
@Autowired
|
||
private SharedQuestionService sharedQuestionService;
|
||
|
||
/**
|
||
* 获取题库列表
|
||
* @param encoding 公司编码
|
||
* @return 返回的该公司下的公司题库
|
||
* */
|
||
@GetMapping("/get_typeList")
|
||
@ApiOperation(value = "根据编码获取题库列表",notes = "")
|
||
public R getTypeListByEncoding(@RequestParam @ApiParam("传入前端存入的encoding数据") String encoding){
|
||
|
||
List<QuestionBank> typeList = questionBankService.getTypeList(encoding);
|
||
|
||
return R.success(typeList);
|
||
}
|
||
|
||
/**
|
||
* 搜索题库信息
|
||
* @param name 题库名
|
||
* @param type 题库类型
|
||
* @param encoding 公司编码
|
||
* @return R
|
||
*/
|
||
@GetMapping("/search_typeName")
|
||
@ApiOperation(value = "根据题库名称搜索题库",notes = "")
|
||
public R searchTypeList(@ApiParam("传入的值为:(String)name,(String)type,(String)encoding") 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);
|
||
}
|
||
|
||
/**
|
||
* 获取题库列表
|
||
* @param encoding 公司编码
|
||
* @param type 题库类型
|
||
* @return R
|
||
*/
|
||
@GetMapping("/get_typeListByType")
|
||
@ApiOperation(value = "根据题库类型获取题库列表",notes = "")
|
||
public R getTypeListByType(@ApiParam("传入的值为:(String)encoding,(Integer)type") String encoding,Integer type){
|
||
|
||
if(encoding==null||type==null){
|
||
return R.error("数据出错啦,请联系管理员!");
|
||
}
|
||
List<QuestionBank> typeListByType = questionBankService.getTypeListByType(encoding, type);
|
||
return R.success(typeListByType);
|
||
|
||
}
|
||
|
||
/**
|
||
* 添加题库信息
|
||
* */
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "typeName",required = true),
|
||
@ApiImplicitParam(name = "encoding",required = true),
|
||
@ApiImplicitParam(name = "type",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "description",required = true),
|
||
})
|
||
@PostMapping("/add_typeName")
|
||
@ApiOperation(value = "根据编码获取logo图片列表",notes = "")
|
||
public R addTypeName(@RequestBody Map<String,Object> addInfo) {
|
||
|
||
String typeName=(String) addInfo.get("typeName");
|
||
String encoding=(String) addInfo.get("encoding");
|
||
String description=(String) addInfo.get("description");
|
||
Integer type=(Integer) addInfo.get("type");
|
||
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
|
||
* return R
|
||
* */
|
||
@DeleteMapping("/delete_type")
|
||
@ApiOperation(value = "根据id删除题库信息",notes = "")
|
||
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更新题库
|
||
* */
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "typeName",required = true),
|
||
@ApiImplicitParam(name = "typeId",required = true),
|
||
@ApiImplicitParam(name = "type",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "description",required = true),
|
||
})
|
||
@PostMapping("/change_type")
|
||
@ApiOperation(value = "根据编码获取logo图片列表",notes = "")
|
||
public R changeTypeName(@RequestBody Map<String,Object> updateInfo){
|
||
|
||
String typeName=(String) updateInfo.get("typeName");
|
||
Integer typeId=(Integer) updateInfo.get("typeId");
|
||
String description=(String) updateInfo.get("description");
|
||
Integer type=(Integer) updateInfo.get("type");
|
||
Integer userId=(Integer) updateInfo.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("修改成功");
|
||
|
||
|
||
}
|
||
@GetMapping("/get_typeById")
|
||
@ApiOperation(value = "根据题库ID获取题库信息",notes = "")
|
||
public R getTypeById(Integer id){
|
||
|
||
QuestionBank bankById = questionBankService.getBankById(id);
|
||
|
||
if(bankById==null){
|
||
return R.error("查找失败,请稍后再试");
|
||
}
|
||
return R.success(bankById);
|
||
}
|
||
|
||
/**
|
||
* 根据公司编码查找题目
|
||
* @param encoding 公司编码
|
||
* return R
|
||
* */
|
||
@GetMapping("/get_questionList")
|
||
@ApiOperation(value = "根据编码获取题目列表",notes = "")
|
||
public R getQuestionList( @ApiParam("传入的值:(String)encoding") String encoding){
|
||
if(encoding==null){
|
||
return R.error("出错了!请联系管理员");
|
||
}
|
||
List<QuestionDto> questionDtoList= questionService.getQuestionList(encoding);
|
||
return R.success(questionDtoList);
|
||
}
|
||
|
||
@GetMapping("/search_questionList")
|
||
@ApiOperation(value = "搜索题目",notes = "")
|
||
public R searchQuestionList(@ApiParam("传入的值:String name,String type,String encoding 注释:name和type字段名可选一个填写,encoding是必填字段") String name,String type,String encoding){
|
||
List<QuestionDto> questionDtos = questionService.searchQuestionList(name, type, encoding);
|
||
return R.success(questionDtos);
|
||
}
|
||
/**
|
||
* 添加题目
|
||
* */
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "title",required = true),
|
||
@ApiImplicitParam(name = "bankId",required = true),
|
||
@ApiImplicitParam(name = "promote",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "details",required = true),
|
||
@ApiImplicitParam(name = "encoding",required = true),
|
||
})
|
||
@PostMapping("add_question")
|
||
@ApiOperation(value = "添加题目",notes = "")
|
||
public R addQuestion(@RequestBody Map<String,Object> addInfo){
|
||
String title=(String) addInfo.get("title");
|
||
Integer bankId=(Integer) addInfo.get("bankId");
|
||
String details=(String) addInfo.get("details");
|
||
String promote=(String) addInfo.get("promote");
|
||
String encoding=(String) addInfo.get("encoding");
|
||
Integer userId=(Integer) addInfo.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("添加成功!");
|
||
}
|
||
|
||
/**
|
||
* 修改题目
|
||
* */
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "title",required = true),
|
||
@ApiImplicitParam(name = "id",required = true),
|
||
@ApiImplicitParam(name = "bankId",required = true),
|
||
@ApiImplicitParam(name = "promote",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "details",required = true),
|
||
@ApiImplicitParam(name = "encoding",required = true),
|
||
})
|
||
@PostMapping("update_question")
|
||
@ApiOperation(value = "更新题目",notes = "")
|
||
|
||
public R updateQuestion(@RequestBody Map<String,Object> updateInfo){
|
||
String title=(String) updateInfo.get("title");
|
||
Integer bankId=(Integer) updateInfo.get("bankId");
|
||
String details=(String) updateInfo.get("details");
|
||
String promote=(String) updateInfo.get("promote");
|
||
String encoding=(String) updateInfo.get("encoding");
|
||
Integer userId=(Integer) updateInfo.get("userId");
|
||
Integer id=(Integer) updateInfo.get("id");
|
||
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
|
||
* return R
|
||
* */
|
||
@DeleteMapping("/del_question")
|
||
@ApiOperation(value = "根据题目ID删除题目",notes = "")
|
||
public R deleteQuestion(@ApiParam("传入的值:(Integer)id") Integer id){
|
||
|
||
Integer rows=questionService.deleteQuestion(id);
|
||
|
||
if(rows==-2||rows==0){
|
||
return R.error("删除失败,请联系管理员");
|
||
}
|
||
return R.success("删除成功!");
|
||
}
|
||
|
||
@GetMapping("/get_sharedQuestionType")
|
||
@ApiOperation(value = "题库广场",notes = "不需要参数")
|
||
public R getSharedQuestionBankList(){
|
||
|
||
List<SharedQuestionBankDto> sharedQuestionBank = sharedQuestionBankService.getSharedQuestionBank();
|
||
return R.success(sharedQuestionBank);
|
||
}
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "typeName",required = true),
|
||
@ApiImplicitParam(name = "type",required = true),
|
||
@ApiImplicitParam(name = "description",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "encoding",required = true),
|
||
})
|
||
@PostMapping("/add_sharedQuestionBank")
|
||
@ApiOperation(value = "添加分享题目",notes = "")
|
||
public R addSharedQuestionType(@RequestBody Map<String,Object> addInfo){
|
||
String typeName=(String) addInfo.get("typeName");
|
||
Integer type=(Integer) addInfo.get("type");
|
||
String description=(String) addInfo.get("description");
|
||
String encoding=(String) addInfo.get("encoding");
|
||
Integer userId=(Integer) addInfo.get("userId");
|
||
SharedQuestionBank sharedQuestionBank = sharedQuestionBankService.addSharedQuestionBank(typeName, type, description, userId,encoding);
|
||
|
||
if(sharedQuestionBank==null){
|
||
return R.error("添加失败,贵公司可能创建了相同名称的题库!");
|
||
}
|
||
return R.success("添加成功",sharedQuestionBank);
|
||
}
|
||
|
||
@GetMapping("/get_sharedQuestion")
|
||
@ApiOperation(value = "题目广场",notes = "不需要参数")
|
||
public R getSharedQuestionList(){
|
||
|
||
List<SharedQuestionDto> sharedQuestionList = sharedQuestionService.getSharedQuestionList();
|
||
|
||
return R.success(sharedQuestionList);
|
||
}
|
||
@GetMapping("/get_sharedQuestionByBankId")
|
||
@ApiOperation(value = "获取分享题库下的题目列表",notes = "")
|
||
public R getSharedQuestionListBySharedBankId( @ApiParam("Integer sharedBankId")Integer sharedBankId){
|
||
|
||
List<SharedQuestionDto> sharedQuestionList = sharedQuestionService.getSharedQuestionListBySharedBankId(sharedBankId);
|
||
|
||
return R.success(sharedQuestionList);
|
||
}
|
||
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "sharedBankId",required = true),
|
||
@ApiImplicitParam(name = "selectQuestionId",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "encoding",required = true),
|
||
})
|
||
@PostMapping("/add_sharedQuestion")
|
||
@ApiOperation(value = "添加分享的题目",notes = "")
|
||
public R addSharedQuestion(@RequestBody Map<String,Object> addInfo){
|
||
Integer sharedBankId=(Integer) addInfo.get("sharedBankId");
|
||
List<Integer> selectQuestionId=(List<Integer>) addInfo.get("selectQuestionId");
|
||
String encoding=(String) addInfo.get("encoding");
|
||
Integer userId=(Integer) addInfo.get("userId");
|
||
String result = sharedQuestionService.addSharedQuestions(sharedBankId, selectQuestionId, userId,encoding);
|
||
|
||
if(result.equals("已存在添加题库中")){
|
||
return R.success("分享成功");
|
||
}
|
||
return R.error(result);
|
||
}
|
||
@GetMapping("/search_sharedQuestionType")
|
||
@ApiOperation(value = "搜索分享题库",notes = "")
|
||
public R searchSharedQuestionType(@ApiParam("String searchName") String searchName){
|
||
List<SharedQuestionBankDto> sharedQuestionBankDtoList = sharedQuestionBankService.searchSharedQuestionType(searchName);
|
||
return R.success(sharedQuestionBankDtoList);
|
||
}
|
||
@GetMapping("/search_sharedQuestion")
|
||
@ApiOperation(value = "搜索分享题目",notes = "")
|
||
public R searchSharedQuestion(@ApiParam("String searchName")String searchName){
|
||
List<SharedQuestionDto> sharedQuestionDtos = sharedQuestionService.searchSharedQuestion(searchName);
|
||
return R.success(sharedQuestionDtos);
|
||
|
||
}
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "sharedBankIds",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "encoding",required = true),
|
||
})
|
||
@PostMapping("/add_QuestionBankFromShare")
|
||
@ApiOperation(value = "从题库广场中导入到本地",notes = "")
|
||
public R addQuestionBankFromShare(@RequestBody Map<String,Object> addInfo){
|
||
List<Integer>sharedBankIds =(List<Integer>)addInfo.get("sharedBankIds");
|
||
Integer userId=(Integer)addInfo.get("userId");
|
||
String encoding=(String) addInfo.get("encoding");
|
||
|
||
String result=sharedQuestionBankService.addQuestionTypeFromShare(sharedBankIds,userId,encoding);
|
||
|
||
if(result.equals("题库:/n题目:已存在添加题库中")){
|
||
return R.success("添加成功");
|
||
}
|
||
return R.error(result);
|
||
}
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "selectSharedQuestionIds",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "bankId",required = true),
|
||
@ApiImplicitParam(name = "encoding",required = true),
|
||
})
|
||
@PostMapping("/add_QuestionFromShare")
|
||
@ApiOperation(value = "从题目广场中导入到本地",notes = "")
|
||
public R addQuestionFromShare(@RequestBody Map<String,Object> addInfo){
|
||
List<Integer>selectSharedQuestionIds =(List<Integer>)addInfo.get("selectSharedQuestionIds");
|
||
Integer userId=(Integer)addInfo.get("userId");
|
||
String encoding=(String) addInfo.get("encoding");
|
||
Integer bankId=(Integer) addInfo.get("bankId");
|
||
|
||
String result=sharedQuestionService.addQuestionFromShare(selectSharedQuestionIds,bankId,userId,encoding);
|
||
if(result.equals("题目:已添加到题目中")){
|
||
return R.success("添加成功");
|
||
}
|
||
return R.error(result);
|
||
}
|
||
@GetMapping("/get_OurQuestionTypeList")
|
||
@ApiOperation(value = "我的分享题库",notes = "")
|
||
public R getOurSharedQuestionTypeList(@ApiParam("String encoding") String encoding){
|
||
List<SharedQuestionBankDto> ourQuestionTypeList = sharedQuestionBankService.getOurQuestionTypeList(encoding);
|
||
return R.success(ourQuestionTypeList);
|
||
}
|
||
@GetMapping("/search_OurSharedQuestionType")
|
||
@ApiOperation(value = "搜索我的分享题库",notes = "")
|
||
public R searchOurSharedQuestionType(@ApiParam("(String) encoding,(String) searchName")String encoding,String searchName){
|
||
List<SharedQuestionBankDto> sharedQuestionBankDtoList = sharedQuestionBankService.searchOurSharedQuestionType(encoding, searchName);
|
||
return R.success(sharedQuestionBankDtoList);
|
||
}
|
||
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "id",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
@ApiImplicitParam(name = "typeName",required = true),
|
||
@ApiImplicitParam(name = "description",required = true),
|
||
@ApiImplicitParam(name = "type",required = true),
|
||
})
|
||
@PostMapping("/edit_OurSharedQuestionType")
|
||
@ApiOperation(value = "修改我的分享题库",notes = "")
|
||
public R editOurSharedQuestionType(@RequestBody Map<String,Object> updateInfo) {
|
||
Integer userId=(Integer)updateInfo.get("userId");
|
||
String typeName=(String) updateInfo.get("typeName");
|
||
Integer type=(Integer) updateInfo.get("type");
|
||
Integer id=(Integer) updateInfo.get("id");
|
||
String description=(String) updateInfo.get("description");
|
||
Integer rows = sharedQuestionBankService.editOurSharedQuestionType(id, typeName, description, type, userId);
|
||
if (rows != 1) {
|
||
return R.error("修改失败");
|
||
}
|
||
return R.success("修改成功");
|
||
|
||
}
|
||
@DeleteMapping("/delete_OurSharedQuestionType")
|
||
@ApiOperation(value = "删除我的分享题库",notes = "")
|
||
public R deleteOurSharedQuestionType(@ApiParam("Integer id") Integer id){
|
||
|
||
sharedQuestionBankService.deleteOurSharedQuestionType(id);
|
||
return R.success("删除成功");
|
||
}
|
||
|
||
@GetMapping("/get_OurQuestionList")
|
||
@ApiOperation(value = "获取我的分享题目",notes = "")
|
||
public R getOurSharedQuestionList(@ApiParam("String encoding") String encoding){
|
||
List<SharedQuestionDto> ourQuestionList = sharedQuestionService.getOurQuestionList(encoding);
|
||
return R.success(ourQuestionList);
|
||
}
|
||
@GetMapping("/search_OurSharedQuestion")
|
||
@ApiOperation(value = "搜索我的分享题目",notes = "")
|
||
public R searchOurSharedQuestion(@ApiParam("(String) encoding,(String) searchName ")String encoding,String searchName){
|
||
List<SharedQuestionDto> sharedQuestionDtoList = sharedQuestionService.searchOurSharedQuestion(encoding, searchName);
|
||
return R.success(sharedQuestionDtoList);
|
||
}
|
||
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "sharedQuestionId",required = true),
|
||
|
||
})
|
||
@PostMapping("/delete_OurSharedQuestion")
|
||
@ApiOperation(value = "删除我的分享题目",notes = "")
|
||
public R deleteOurSharedQuestion(@RequestBody Map<String,Object> deleteInfo) {
|
||
List<Integer> sharedQuestionId=(List<Integer>) deleteInfo.get("sharedQuestionId");
|
||
|
||
Integer rows= sharedQuestionService.deleteOurSharedQuestion(sharedQuestionId);
|
||
return R.success("删除成功,删除"+rows+"分享题目");
|
||
}
|
||
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "id",required = true),
|
||
@ApiImplicitParam(name = "title",required = true),
|
||
@ApiImplicitParam(name = "details",required = true),
|
||
@ApiImplicitParam(name = "promote",required = true),
|
||
@ApiImplicitParam(name = "bankId",required = true),
|
||
@ApiImplicitParam(name = "userId",required = true),
|
||
})
|
||
@PostMapping("/update_OurSharedQuestion")
|
||
@ApiOperation(value = "更新我的分享题目",notes = "")
|
||
public R updateOurSharedQuestion(@RequestBody Map<String,Object> updateInfo){
|
||
Integer userId=(Integer)updateInfo.get("userId");
|
||
String promote=(String) updateInfo.get("promote");
|
||
Integer bankId=(Integer) updateInfo.get("bankId");
|
||
Integer id=(Integer) updateInfo.get("id");
|
||
String details=(String) updateInfo.get("details");
|
||
String title=(String) updateInfo.get("title");
|
||
Integer rows=sharedQuestionService.updateOurSharedQuestion(id, title, details , promote, bankId , userId);
|
||
|
||
if(rows==1){
|
||
return R.success("修改成功");
|
||
}
|
||
return R.error("修改失败");
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|