191 lines
7.3 KiB
Java
191 lines
7.3 KiB
Java
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.*;
|
|
import com.yzdx.AiInterviewer.entity.dto.SharedQuestionDto;
|
|
import com.yzdx.AiInterviewer.mapper.QuestionMapper;
|
|
import com.yzdx.AiInterviewer.mapper.SharedQuestionMapper;
|
|
import com.yzdx.AiInterviewer.service.CompanyService;
|
|
import com.yzdx.AiInterviewer.service.SharedQuestionBankService;
|
|
import com.yzdx.AiInterviewer.service.SharedQuestionService;
|
|
import com.yzdx.AiInterviewer.service.UserService;
|
|
import com.yzdx.AiInterviewer.utiles.TimeUtil;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Service
|
|
public class SharedQuestionServiceImpl extends ServiceImpl<SharedQuestionMapper, SharedQuestion> implements SharedQuestionService {
|
|
|
|
@Autowired
|
|
private QuestionMapper questionMapper;
|
|
|
|
@Autowired
|
|
private SharedQuestionMapper sharedQuestionMapper;
|
|
|
|
@Autowired
|
|
private UserService userService;
|
|
|
|
@Autowired
|
|
private SharedQuestionBankService sharedQuestionBankService;
|
|
|
|
@Autowired
|
|
private CompanyService companyService;
|
|
|
|
@Override
|
|
public String addSharedQuestions(Integer sharedBankId, List<Integer> selectQuestionId, Integer userId,String encoding) {
|
|
|
|
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.setUpdateUser(userId);
|
|
sharedQuestion.setUpdateTime(TimeUtil.getTime());
|
|
sharedQuestion.setBankId(sharedBankId);
|
|
sharedQuestion.setCreateCompany(encoding);
|
|
|
|
sharedQuestionMapper.insert(sharedQuestion);
|
|
}
|
|
errorQuestion=errorQuestion+"已存在添加题库中";
|
|
return errorQuestion;
|
|
}
|
|
|
|
@Override
|
|
public List<SharedQuestionDto> getSharedQuestionList() {
|
|
List<SharedQuestion> sharedQuestions = sharedQuestionMapper.selectList(null);
|
|
|
|
List<SharedQuestionDto> sharedQuestionDtos=sharedQuestions.stream().map(item->{
|
|
SharedQuestionDto sharedQuestionDto=new SharedQuestionDto();
|
|
|
|
BeanUtils.copyProperties(item,sharedQuestionDto);
|
|
|
|
User findCreateUser = userService.getUserById(sharedQuestionDto.getCreateUser());
|
|
|
|
sharedQuestionDto.setCreateUserName(findCreateUser.getUsername());
|
|
|
|
User findUpdateUser = userService.getUserById(sharedQuestionDto.getUpdateUser());
|
|
|
|
sharedQuestionDto.setUpdateUserName(findUpdateUser.getUsername());
|
|
|
|
SharedQuestionBank sharedQuestionBankById = sharedQuestionBankService.getSharedQuestionBankById(sharedQuestionDto.getBankId());
|
|
|
|
sharedQuestionDto.setSharedQuestionBankName(sharedQuestionBankById.getTypeName());
|
|
|
|
Company companyDetail = companyService.getCompanyDetail(sharedQuestionDto.getCreateCompany());
|
|
|
|
sharedQuestionDto.setCreateCompanyName(companyDetail.getCompanyName());
|
|
|
|
return sharedQuestionDto;
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
return sharedQuestionDtos;
|
|
}
|
|
|
|
@Override
|
|
public List<SharedQuestionDto> getSharedQuestionListBySharedBankId(Integer SharedBankId) {
|
|
LambdaQueryWrapper<SharedQuestion> queryWrapper=new LambdaQueryWrapper<>();
|
|
|
|
queryWrapper.eq(SharedQuestion::getBankId,SharedBankId);
|
|
|
|
List<SharedQuestion> sharedQuestions = sharedQuestionMapper.selectList(queryWrapper);
|
|
|
|
List<SharedQuestionDto> sharedQuestionDtos=sharedQuestions.stream().map(item->{
|
|
SharedQuestionDto sharedQuestionDto=new SharedQuestionDto();
|
|
|
|
BeanUtils.copyProperties(item,sharedQuestionDto);
|
|
|
|
User findCreateUser = userService.getUserById(sharedQuestionDto.getCreateUser());
|
|
|
|
sharedQuestionDto.setCreateUserName(findCreateUser.getUsername());
|
|
|
|
User findUpdateUser = userService.getUserById(sharedQuestionDto.getUpdateUser());
|
|
|
|
sharedQuestionDto.setUpdateUserName(findUpdateUser.getUsername());
|
|
|
|
SharedQuestionBank sharedQuestionBankById = sharedQuestionBankService.getSharedQuestionBankById(sharedQuestionDto.getBankId());
|
|
|
|
sharedQuestionDto.setSharedQuestionBankName(sharedQuestionBankById.getTypeName());
|
|
|
|
Company companyDetail = companyService.getCompanyDetail(sharedQuestionDto.getCreateCompany());
|
|
|
|
sharedQuestionDto.setCreateCompanyName(companyDetail.getCompanyName());
|
|
|
|
return sharedQuestionDto;
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
return sharedQuestionDtos;
|
|
}
|
|
|
|
@Override
|
|
public List<SharedQuestionDto> searchSharedQuestion(String searchName) {
|
|
LambdaQueryWrapper<SharedQuestion> sharedQuestionLambdaQueryWrapper =new LambdaQueryWrapper<>();
|
|
sharedQuestionLambdaQueryWrapper.like(SharedQuestion::getTitle,searchName);
|
|
List<SharedQuestion> list = sharedQuestionMapper.selectList(sharedQuestionLambdaQueryWrapper);
|
|
List<SharedQuestionDto> sharedQuestionDtos=list.stream().map(item->{
|
|
SharedQuestionDto sharedQuestionDto=new SharedQuestionDto();
|
|
|
|
BeanUtils.copyProperties(item,sharedQuestionDto);
|
|
|
|
User findCreateUser = userService.getUserById(sharedQuestionDto.getCreateUser());
|
|
|
|
sharedQuestionDto.setCreateUserName(findCreateUser.getUsername());
|
|
|
|
User findUpdateUser = userService.getUserById(sharedQuestionDto.getUpdateUser());
|
|
|
|
sharedQuestionDto.setUpdateUserName(findUpdateUser.getUsername());
|
|
|
|
SharedQuestionBank sharedQuestionBankById = sharedQuestionBankService.getSharedQuestionBankById(sharedQuestionDto.getBankId());
|
|
|
|
sharedQuestionDto.setSharedQuestionBankName(sharedQuestionBankById.getTypeName());
|
|
|
|
Company companyDetail = companyService.getCompanyDetail(sharedQuestionDto.getCreateCompany());
|
|
|
|
sharedQuestionDto.setCreateCompanyName(companyDetail.getCompanyName());
|
|
|
|
return sharedQuestionDto;
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
return sharedQuestionDtos;
|
|
}
|
|
|
|
|
|
|
|
}
|