359 lines
13 KiB
Java
359 lines
13 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.QuestionBankService;
|
||
import com.yzdx.AiInterviewer.service.QuestionService;
|
||
import com.yzdx.AiInterviewer.service.SharedQuestionBankService;
|
||
import com.yzdx.AiInterviewer.service.SharedQuestionService;
|
||
import io.swagger.annotations.Api;
|
||
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;
|
||
|
||
@Autowired
|
||
private SharedQuestionBankService sharedQuestionBankService;
|
||
|
||
@Autowired
|
||
private SharedQuestionService sharedQuestionService;
|
||
/**
|
||
* 获取题库列表
|
||
* @param encoding 公司编码
|
||
* @return 返回的该公司下的公司题库
|
||
* */
|
||
@GetMapping("/get_typeList")
|
||
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")
|
||
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")
|
||
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);
|
||
|
||
}
|
||
|
||
/**
|
||
* 添加题库信息
|
||
* @param addInfo typeName,encoding,userId
|
||
* @return R
|
||
* */
|
||
@PostMapping("/add_typeName")
|
||
public R addTypeName(@RequestBody @ApiParam("传入的值:{addInfo:(String)typeName,(String)encoding,(Integer)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
|
||
* return R
|
||
* */
|
||
@DeleteMapping("/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 更新题库的信息
|
||
* return R
|
||
* */
|
||
@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 公司编码
|
||
* return R
|
||
* */
|
||
@GetMapping("/get_questionList")
|
||
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")
|
||
public R searchQuestionList(String name,String type,String encoding){
|
||
List<QuestionDto> questionDtos = questionService.searchQuestionList(name, type, encoding);
|
||
return R.success(questionDtos);
|
||
}
|
||
/**
|
||
* 添加题目
|
||
* @param addQuestionInfo 公司编码,题库类型id,题目详情,题目promote,题目标题,用户id
|
||
* return R
|
||
* */
|
||
@PostMapping("add_question")
|
||
public R addQuestion(@RequestBody @ApiParam("传入的值:addQuestionInfo:{(String)encoding,(Integer)banId,(String)details,(String)promote,(Integer)userId),(String)title}") 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 公司编码,题库类型id,题目详情,题目promote,题目标题,用户id,题目id
|
||
* return R
|
||
* */
|
||
@PostMapping("update_question")
|
||
public R updateQuestion(@RequestBody @ApiParam("传入的值:addQuestionInfo:{(Integer)id,(Integer)banId,(String)details,(String)promote,(String)encoding,(Integer)userId),(String)title}") 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
|
||
* return R
|
||
* */
|
||
@DeleteMapping("/del_question")
|
||
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")
|
||
public R getSharedQuestionBankList(){
|
||
|
||
List<SharedQuestionBankDto> sharedQuestionBank = sharedQuestionBankService.getSharedQuestionBank();
|
||
return R.success(sharedQuestionBank);
|
||
}
|
||
|
||
|
||
@PostMapping("/add_sharedQuestionBank")
|
||
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");
|
||
String encoding=(String)addInfo.get("encoding");
|
||
|
||
SharedQuestionBank sharedQuestionBank = sharedQuestionBankService.addSharedQuestionBank(typeName, type, description, userId,encoding);
|
||
|
||
if(sharedQuestionBank==null){
|
||
return R.error("添加失败,贵公司可能创建了相同名称的题库!");
|
||
}
|
||
return R.success("添加成功",sharedQuestionBank);
|
||
}
|
||
|
||
@GetMapping("/get_sharedQuestion")
|
||
public R getSharedQuestionList(){
|
||
|
||
List<SharedQuestionDto> sharedQuestionList = sharedQuestionService.getSharedQuestionList();
|
||
|
||
return R.success(sharedQuestionList);
|
||
}
|
||
@GetMapping("/get_sharedQuestionByBankId")
|
||
public R getSharedQuestionListBySharedBankId(Integer sharedBankId){
|
||
|
||
List<SharedQuestionDto> sharedQuestionList = sharedQuestionService.getSharedQuestionListBySharedBankId(sharedBankId);
|
||
|
||
return R.success(sharedQuestionList);
|
||
}
|
||
|
||
@PostMapping("/add_sharedQuestion")
|
||
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");
|
||
String encoding=(String)addInfo.get("encoding");
|
||
|
||
String result = sharedQuestionService.addSharedQuestions(sharedBankId, selectQuestionId, userId,encoding);
|
||
|
||
if(result.equals("已存在添加题库中")){
|
||
return R.success("分享成功");
|
||
}
|
||
return R.error(result);
|
||
}
|
||
@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);
|
||
}
|
||
@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);
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|