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 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 selectQuestionId, Integer userId,String encoding) { String errorQuestion=""; for (int i = 0; i < selectQuestionId.size(); i++) { Integer id = selectQuestionId.get(i); LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper<>(); queryWrapper.eq(Question::getId,id); Question question = questionMapper.selectOne(queryWrapper); if(question==null){ continue; } String findTitle=question.getTitle(); LambdaQueryWrapper 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 getSharedQuestionList() { List sharedQuestions = sharedQuestionMapper.selectList(null); List 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 getSharedQuestionListBySharedBankId(Integer SharedBankId) { LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper<>(); queryWrapper.eq(SharedQuestion::getBankId,SharedBankId); List sharedQuestions = sharedQuestionMapper.selectList(queryWrapper); List 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 searchSharedQuestion(String searchName) { LambdaQueryWrapper sharedQuestionLambdaQueryWrapper =new LambdaQueryWrapper<>(); sharedQuestionLambdaQueryWrapper.like(SharedQuestion::getTitle,searchName); List list = sharedQuestionMapper.selectList(sharedQuestionLambdaQueryWrapper); List 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; } }