Ai-interviewer-system/src/main/java/com/yzdx/AiInterviewer/controller/QuestionController.java

359 lines
13 KiB
Java
Raw Normal View History

package com.yzdx.AiInterviewer.controller;
import com.yzdx.AiInterviewer.comment.R;
2023-11-18 07:47:31 +00:00
import com.yzdx.AiInterviewer.entity.Question;
import com.yzdx.AiInterviewer.entity.QuestionBank;
2023-11-18 07:36:40 +00:00
import com.yzdx.AiInterviewer.entity.SharedQuestionBank;
2023-10-22 01:10:10 +00:00
import com.yzdx.AiInterviewer.entity.dto.QuestionDto;
2023-11-19 05:19:41 +00:00
import com.yzdx.AiInterviewer.entity.dto.SharedQuestionBankDto;
import com.yzdx.AiInterviewer.entity.dto.SharedQuestionDto;
import com.yzdx.AiInterviewer.service.QuestionBankService;
2023-10-22 01:10:10 +00:00
import com.yzdx.AiInterviewer.service.QuestionService;
2023-11-18 07:36:40 +00:00
import com.yzdx.AiInterviewer.service.SharedQuestionBankService;
import com.yzdx.AiInterviewer.service.SharedQuestionService;
2023-11-20 02:38:07 +00:00
import io.swagger.annotations.Api;
2023-10-22 01:10:10 +00:00
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;
2023-10-22 01:10:10 +00:00
@Autowired
private QuestionService questionService;
2023-11-18 07:36:40 +00:00
@Autowired
private SharedQuestionBankService sharedQuestionBankService;
@Autowired
private SharedQuestionService sharedQuestionService;
/**
* 获取题库列表
* @param encoding 公司编码
* @return 返回的该公司下的公司题库
* */
@GetMapping("/get_typeList")
2023-10-22 01:10:10 +00:00
public R getTypeListByEncoding(@RequestParam @ApiParam("传入前端存入的encoding数据") String encoding){
List<QuestionBank> typeList = questionBankService.getTypeList(encoding);
return R.success(typeList);
}
2023-11-18 07:47:31 +00:00
/**
* 搜索题库信息
* @param name 题库名
* @param type 题库类型
* @param encoding 公司编码
* @return R
*/
2023-11-12 06:00:40 +00:00
@GetMapping("/search_typeName")
2023-11-18 07:47:31 +00:00
public R searchTypeList(@ApiParam("传入的值为:(String)name,(String)type,(String)encoding") String name,String type,String encoding){
2023-11-12 06:00:40 +00:00
if(name==null&&encoding==null){
return R.error("搜索失败,请稍后再试");
}
List<QuestionBank> questionBanks = questionBankService.searchTypeList(name,type,encoding);
return R.success(questionBanks);
}
2023-11-18 07:47:31 +00:00
/**
* 获取题库列表
* @param encoding 公司编码
* @param type 题库类型
* @return R
*/
2023-11-04 16:30:50 +00:00
@GetMapping("/get_typeListByType")
2023-11-18 07:47:31 +00:00
public R getTypeListByType(@ApiParam("传入的值为:(String)encoding,(Integer)type") String encoding,Integer type){
2023-11-04 16:30:50 +00:00
if(encoding==null||type==null){
return R.error("数据出错啦,请联系管理员!");
}
List<QuestionBank> typeListByType = questionBankService.getTypeListByType(encoding, type);
return R.success(typeListByType);
}
/**
2023-11-18 07:47:31 +00:00
* 添加题库信息
* @param addInfo typeName,encoding,userId
* @return R
* */
@PostMapping("/add_typeName")
2023-11-18 07:47:31 +00:00
public R addTypeName(@RequestBody @ApiParam("传入的值:{addInfo:(String)typeName,(String)encoding,(Integer)userId}") Map<String ,Object> addInfo){
2023-10-22 01:10:10 +00:00
if(addInfo.size()==0||addInfo.get("typeName")==null){
return R.error("添加失败,请检查输入");
}
String typeName=(String)addInfo.get("typeName");
2023-10-22 01:10:10 +00:00
String encoding= (String)addInfo.get("encoding");
2023-11-04 16:30:50 +00:00
Integer type=(Integer)addInfo.get("type");
String description=(String) addInfo.get("description");
Integer userId=(Integer)addInfo.get("userId");
2023-11-04 16:30:50 +00:00
if (type==null){
return R.error("请选择添加的题库类型");
}
Integer row=questionBankService.addTypeName(typeName,encoding,description,type,userId);
if(row==0){
return R.error("添加失败,请联系管理员");
}
if (row==-2){
2023-11-04 16:30:50 +00:00
return R.error("该题库名称已存在!");
}
return R.success("添加成功");
}
2023-10-22 01:10:10 +00:00
/**
* 根据题库id删除题库
* @param typeId 传入的题库id
2023-11-18 07:47:31 +00:00
* return R
2023-10-22 01:10:10 +00:00
* */
2023-11-20 02:38:07 +00:00
@DeleteMapping("/delete_type")
2023-10-22 01:10:10 +00:00
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 更新题库的信息
2023-11-18 07:47:31 +00:00
* return R
2023-10-22 01:10:10 +00:00
* */
@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");
2023-11-04 16:30:50 +00:00
String description=(String) updateType.get("description");
Integer type=(Integer)updateType.get("type");
2023-10-22 01:10:10 +00:00
Integer userId=(Integer) updateType.get("userId");
2023-11-04 16:30:50 +00:00
if (type==null){
return R.error("请选择题库类型");
}
Integer rows=questionBankService.changeType(typeId,description,type,typeName,userId);
2023-10-22 01:10:10 +00:00
if(rows==-2){
return R.error("修改的题库名已存在!");
}
if(rows==0){
return R.error("修改失败,请稍后再试或联系管理员");
}
return R.success("修改成功");
}
/**
* 根据公司编码查找题目
* @param encoding 公司编码
2023-11-18 07:47:31 +00:00
* return R
2023-10-22 01:10:10 +00:00
* */
@GetMapping("/get_questionList")
2023-11-18 07:47:31 +00:00
public R getQuestionList( @ApiParam("传入的值:(String)encoding") String encoding){
2023-10-22 01:10:10 +00:00
if(encoding==null){
return R.error("出错了!请联系管理员");
}
List<QuestionDto> questionDtoList= questionService.getQuestionList(encoding);
return R.success(questionDtoList);
}
2023-10-24 07:33:01 +00:00
2023-11-12 09:35:39 +00:00
@GetMapping("/search_questionList")
public R searchQuestionList(String name,String type,String encoding){
List<QuestionDto> questionDtos = questionService.searchQuestionList(name, type, encoding);
return R.success(questionDtos);
}
2023-10-24 07:33:01 +00:00
/**
* 添加题目
2023-11-18 07:47:31 +00:00
* @param addQuestionInfo 公司编码,题库类型id,题目详情,题目promote,题目标题,用户id
* return R
2023-10-24 07:33:01 +00:00
* */
@PostMapping("add_question")
2023-11-18 07:47:31 +00:00
public R addQuestion(@RequestBody @ApiParam("传入的值addQuestionInfo:{(String)encoding,(Integer)banId,(String)details,(String)promote,(Integer)userId),(String)title}") Map<String,Object> addQuestionInfo){
2023-10-24 07:33:01 +00:00
String title=(String)addQuestionInfo.get("title");
Integer bankId=(Integer) addQuestionInfo.get("bankId");
String details=(String)addQuestionInfo.get("details");
2023-11-19 05:31:20 +00:00
///
2023-10-24 07:33:01 +00:00
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("添加成功!");
}
/**
* 修改题目
2023-11-18 07:47:31 +00:00
* @param addQuestionInfo 公司编码,题库类型id,题目详情,题目promote,题目标题,用户id题目id
* return R
2023-10-24 07:33:01 +00:00
* */
@PostMapping("update_question")
2023-11-18 07:47:31 +00:00
public R updateQuestion(@RequestBody @ApiParam("传入的值addQuestionInfo:{(Integer)id,(Integer)banId,(String)details,(String)promote,(String)encoding,(Integer)userId),(String)title}") Map<String,Object> addQuestionInfo){
2023-10-24 07:33:01 +00:00
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
2023-11-18 07:47:31 +00:00
* return R
2023-10-24 07:33:01 +00:00
* */
2023-11-20 02:38:07 +00:00
@DeleteMapping("/del_question")
2023-11-18 07:47:31 +00:00
public R deleteQuestion(@ApiParam("传入的值:(Integer)id") Integer id){
2023-10-24 07:33:01 +00:00
Integer rows=questionService.deleteQuestion(id);
if(rows==-2||rows==0){
return R.error("删除失败,请联系管理员");
}
return R.success("删除成功!");
}
2023-11-19 05:19:41 +00:00
@GetMapping("/get_sharedQuestionType")
public R getSharedQuestionBankList(){
List<SharedQuestionBankDto> sharedQuestionBank = sharedQuestionBankService.getSharedQuestionBank();
return R.success(sharedQuestionBank);
}
@PostMapping("/add_sharedQuestionBank")
2023-11-18 07:36:40 +00:00
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");
Integer userId=(Integer) addInfo.get("userId");
2023-11-19 05:19:41 +00:00
String encoding=(String)addInfo.get("encoding");
2023-11-18 07:36:40 +00:00
2023-11-19 05:19:41 +00:00
SharedQuestionBank sharedQuestionBank = sharedQuestionBankService.addSharedQuestionBank(typeName, type, description, userId,encoding);
2023-11-18 07:36:40 +00:00
if(sharedQuestionBank==null){
2023-11-19 05:19:41 +00:00
return R.error("添加失败,贵公司可能创建了相同名称的题库!");
2023-11-18 07:36:40 +00:00
}
return R.success("添加成功",sharedQuestionBank);
}
2023-11-19 05:19:41 +00:00
@GetMapping("/get_sharedQuestion")
public R getSharedQuestionList(){
List<SharedQuestionDto> sharedQuestionList = sharedQuestionService.getSharedQuestionList();
return R.success(sharedQuestionList);
}
2023-11-19 12:32:02 +00:00
@GetMapping("/get_sharedQuestionByBankId")
public R getSharedQuestionListBySharedBankId(Integer sharedBankId){
2023-11-19 05:19:41 +00:00
2023-11-19 12:32:02 +00:00
List<SharedQuestionDto> sharedQuestionList = sharedQuestionService.getSharedQuestionListBySharedBankId(sharedBankId);
return R.success(sharedQuestionList);
}
2023-11-19 05:19:41 +00:00
@PostMapping("/add_sharedQuestion")
2023-11-18 07:36:40 +00:00
public R addSharedQuestion(@RequestBody Map<String,Object> addInfo){
Integer sharedBankId=(Integer) addInfo.get("sharedBankId");
List<Integer> selectQuestionId=(List<Integer>) addInfo.get("selectQuestionId");
Integer userId =(Integer) addInfo.get("userId");
2023-11-19 05:19:41 +00:00
String encoding=(String)addInfo.get("encoding");
2023-10-24 07:33:01 +00:00
2023-11-19 05:19:41 +00:00
String result = sharedQuestionService.addSharedQuestions(sharedBankId, selectQuestionId, userId,encoding);
2023-11-18 07:36:40 +00:00
if(result.equals("已存在添加题库中")){
return R.success("分享成功");
}
return R.error(result);
}
2023-11-20 02:38:57 +00:00
@GetMapping("/search_sharedQuestionType")
public R searchSharedQuestionType(String searchName){
List<SharedQuestionBankDto> sharedQuestionBankDtoList = sharedQuestionBankService.searchSharedQuestionType(searchName);
return R.success(sharedQuestionBankDtoList);
}
@GetMapping("/search_sharedQuestion")
public R searchSharedQuestion(String searchName){
List<SharedQuestionDto> sharedQuestionDtos = sharedQuestionService.searchSharedQuestion(searchName);
return R.success(sharedQuestionDtos);
}
@PostMapping("/add_QuestionBankFromShare")
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);
}
2023-11-20 08:31:29 +00:00
@PostMapping("/add_QuestionFromShare")
public R addQuestionFromShare(@RequestBody Map<String,Object> addInfo){
List<Integer> selectSharedQuestionIds=(List<Integer>) addInfo.get("selectSharedQuestionIds");
Integer bankId=(Integer) addInfo.get("bankId");
Integer userId =(Integer) addInfo.get("userId");
String encoding =(String) addInfo.get("encoding");
String result=sharedQuestionService.addQuestionFromShare(selectSharedQuestionIds,bankId,userId,encoding);
if(result.equals("题目:已添加到题目中")){
return R.success("添加成功");
}
return R.error(result);
}
2023-10-24 07:33:01 +00:00
2023-11-18 07:47:31 +00:00
2023-11-19 07:50:14 +00:00
}
2023-10-22 01:10:10 +00:00
2023-10-24 07:33:01 +00:00