分享题库功能完善
This commit is contained in:
parent
d5d82ee380
commit
a96fd136d0
|
@ -16,6 +16,14 @@ public class R<T>{
|
|||
r.message="成功";
|
||||
return r;
|
||||
}
|
||||
|
||||
public static <T> R<T> success(String message,T object){
|
||||
R r= new R<>();
|
||||
r.code=0;
|
||||
r.data=object;
|
||||
r.message=message;
|
||||
return r;
|
||||
}
|
||||
public static<T> R<T> error(String message){
|
||||
R r=new R<>();
|
||||
|
||||
|
|
|
@ -2,9 +2,12 @@ package com.yzdx.AiInterviewer.controller;
|
|||
|
||||
import com.yzdx.AiInterviewer.comment.R;
|
||||
import com.yzdx.AiInterviewer.entity.QuestionBank;
|
||||
import com.yzdx.AiInterviewer.entity.SharedQuestionBank;
|
||||
import com.yzdx.AiInterviewer.entity.dto.QuestionDto;
|
||||
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.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -22,6 +25,11 @@ public class QuestionController {
|
|||
@Autowired
|
||||
private QuestionService questionService;
|
||||
|
||||
@Autowired
|
||||
private SharedQuestionBankService sharedQuestionBankService;
|
||||
|
||||
@Autowired
|
||||
private SharedQuestionService sharedQuestionService;
|
||||
/**
|
||||
* 获取题库列表
|
||||
* @param encoding 公司编码
|
||||
|
@ -231,7 +239,34 @@ public class QuestionController {
|
|||
return R.success("删除成功!");
|
||||
}
|
||||
|
||||
@PostMapping("/add_question_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");
|
||||
|
||||
SharedQuestionBank sharedQuestionBank = sharedQuestionBankService.addSharedQuestionBank(typeName, type, description, userId);
|
||||
|
||||
if(sharedQuestionBank==null){
|
||||
return R.error("添加失败,您可能创建了相同名称的题库!");
|
||||
}
|
||||
return R.success("添加成功",sharedQuestionBank);
|
||||
}
|
||||
|
||||
@PostMapping("/add_question_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 result = sharedQuestionService.addShardQuestions(sharedBankId, selectQuestionId, userId);
|
||||
|
||||
if(result.equals("已存在添加题库中")){
|
||||
return R.success("分享成功");
|
||||
}
|
||||
return R.error(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,14 +8,8 @@ import com.yzdx.AiInterviewer.entity.dto.JobSettingDto;
|
|||
import com.yzdx.AiInterviewer.service.CompanyService;
|
||||
import com.yzdx.AiInterviewer.service.InterviewSettingService;
|
||||
import com.yzdx.AiInterviewer.service.JobListService;
|
||||
import com.yzdx.AiInterviewer.utiles.MyStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
|
|
@ -5,5 +5,15 @@ import com.yzdx.AiInterviewer.entity.SharedQuestionBank;
|
|||
|
||||
public interface SharedQuestionBankService extends IService<SharedQuestionBank> {
|
||||
|
||||
/**
|
||||
* 添加分享题库
|
||||
* @param typeName 题库名称
|
||||
* @param type 题库类型
|
||||
* @param description 题库描述
|
||||
* @param userId 创建人
|
||||
* @return 创建的SharedQuestionBank对象
|
||||
* */
|
||||
SharedQuestionBank addSharedQuestionBank(String typeName,Integer type,String description,Integer userId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,5 +3,17 @@ package com.yzdx.AiInterviewer.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yzdx.AiInterviewer.entity.SharedQuestion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SharedQuestionService extends IService<SharedQuestion> {
|
||||
|
||||
/**
|
||||
* 增加题目
|
||||
* @param sharedBankId 分享题库id
|
||||
* @param selectQuestionId 分享题目的id
|
||||
* @param userId 分享人
|
||||
* @return 影响的行数
|
||||
*
|
||||
* */
|
||||
String addShardQuestions(Integer sharedBankId, List<Integer> selectQuestionId,Integer userId);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.yzdx.AiInterviewer.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yzdx.AiInterviewer.entity.BaseEntity;
|
||||
import com.yzdx.AiInterviewer.entity.QuestionBank;
|
||||
import com.yzdx.AiInterviewer.entity.SharedQuestionBank;
|
||||
import com.yzdx.AiInterviewer.mapper.SharedQuestionBankMapper;
|
||||
import com.yzdx.AiInterviewer.service.SharedQuestionBankService;
|
||||
import com.yzdx.AiInterviewer.utiles.TimeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -13,5 +17,32 @@ public class SharedQuestionBankServiceImpl extends ServiceImpl<SharedQuestionBan
|
|||
private SharedQuestionBankMapper sharedQuestionBankMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public SharedQuestionBank addSharedQuestionBank(String typeName, Integer type, String description, Integer userId) {
|
||||
LambdaQueryWrapper<SharedQuestionBank> queryWrapper=new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.eq(SharedQuestionBank::getTypeName,typeName).eq(BaseEntity::getCreateUser,userId);
|
||||
|
||||
SharedQuestionBank sharedQuestionBank = sharedQuestionBankMapper.selectOne(queryWrapper);
|
||||
|
||||
if (sharedQuestionBank!=null){
|
||||
return null;
|
||||
}
|
||||
SharedQuestionBank newSharedBank=new SharedQuestionBank();
|
||||
|
||||
newSharedBank.setTypeName(typeName);
|
||||
newSharedBank.setType(type);
|
||||
newSharedBank.setDescription(description);
|
||||
newSharedBank.setCreateUser(userId);
|
||||
newSharedBank.setCreateTime(TimeUtil.getTime());
|
||||
|
||||
sharedQuestionBankMapper.insert(newSharedBank);
|
||||
|
||||
LambdaQueryWrapper<SharedQuestionBank> bankLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
||||
|
||||
bankLambdaQueryWrapper.eq(SharedQuestionBank::getTypeName,typeName).eq(BaseEntity::getCreateUser,userId);
|
||||
|
||||
return sharedQuestionBankMapper.selectOne(bankLambdaQueryWrapper);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,70 @@
|
|||
package com.yzdx.AiInterviewer.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yzdx.AiInterviewer.entity.Question;
|
||||
import com.yzdx.AiInterviewer.entity.SharedQuestion;
|
||||
import com.yzdx.AiInterviewer.mapper.QuestionMapper;
|
||||
import com.yzdx.AiInterviewer.mapper.SharedQuestionBankMapper;
|
||||
import com.yzdx.AiInterviewer.mapper.SharedQuestionMapper;
|
||||
import com.yzdx.AiInterviewer.service.SharedQuestionService;
|
||||
import com.yzdx.AiInterviewer.utiles.TimeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SharedQuestionServiceImpl extends ServiceImpl<SharedQuestionMapper, SharedQuestion> implements SharedQuestionService {
|
||||
|
||||
@Autowired
|
||||
private QuestionMapper questionMapper;
|
||||
|
||||
@Autowired
|
||||
private SharedQuestionMapper sharedQuestionMapper;
|
||||
|
||||
@Override
|
||||
public String addShardQuestions(Integer sharedBankId, List<Integer> selectQuestionId, Integer userId) {
|
||||
|
||||
String errorQuestion="";
|
||||
|
||||
for (int i = 0; i < selectQuestionId.size(); i++) {
|
||||
Integer id = selectQuestionId.get(i);
|
||||
LambdaQueryWrapper<Question> queryWrapper=new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.eq(Question::getId,id);
|
||||
|
||||
Question question = questionMapper.selectOne(queryWrapper);
|
||||
|
||||
if(question==null){
|
||||
continue;
|
||||
}
|
||||
|
||||
String findTitle=question.getTitle();
|
||||
|
||||
LambdaQueryWrapper<SharedQuestion> titleQueryWrapper=new LambdaQueryWrapper<>();
|
||||
|
||||
titleQueryWrapper.eq(SharedQuestion::getTitle,findTitle).eq(SharedQuestion::getBankId,sharedBankId);
|
||||
|
||||
SharedQuestion selectOne = sharedQuestionMapper.selectOne(titleQueryWrapper);
|
||||
|
||||
if(selectOne!=null){
|
||||
errorQuestion=errorQuestion+","+selectOne.getTitle();
|
||||
continue;
|
||||
}
|
||||
|
||||
SharedQuestion sharedQuestion=new SharedQuestion();
|
||||
|
||||
sharedQuestion.setDetails(question.getDetails());
|
||||
sharedQuestion.setTitle(question.getTitle());
|
||||
sharedQuestion.setPromote(question.getPromote());
|
||||
sharedQuestion.setCreateUser(userId);
|
||||
sharedQuestion.setCreateTime(TimeUtil.getTime());
|
||||
sharedQuestion.setBankId(sharedBankId);
|
||||
|
||||
sharedQuestionMapper.insert(sharedQuestion);
|
||||
}
|
||||
errorQuestion=errorQuestion+"已存在添加题库中";
|
||||
return errorQuestion;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue