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.Company; import com.yzdx.AiInterviewer.entity.SharedQuestionBank; import com.yzdx.AiInterviewer.entity.User; import com.yzdx.AiInterviewer.entity.dto.SharedQuestionBankDto; import com.yzdx.AiInterviewer.mapper.SharedQuestionBankMapper; import com.yzdx.AiInterviewer.service.CompanyService; import com.yzdx.AiInterviewer.service.SharedQuestionBankService; 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 SharedQuestionBankServiceImpl extends ServiceImpl implements SharedQuestionBankService{ @Autowired private SharedQuestionBankMapper sharedQuestionBankMapper; @Autowired private CompanyService companyService; @Autowired private UserService userService; @Override public SharedQuestionBank addSharedQuestionBank(String typeName, Integer type, String description, Integer userId,String encoding) { LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper<>(); queryWrapper.eq(SharedQuestionBank::getTypeName,typeName).eq(SharedQuestionBank::getCreateCompany,encoding); 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.setUpdateUser(userId); newSharedBank.setUpdateTime(TimeUtil.getTime()); newSharedBank.setCreateTime(TimeUtil.getTime()); newSharedBank.setCreateCompany(encoding); sharedQuestionBankMapper.insert(newSharedBank); LambdaQueryWrapper bankLambdaQueryWrapper=new LambdaQueryWrapper<>(); bankLambdaQueryWrapper.eq(SharedQuestionBank::getTypeName,typeName).eq(BaseEntity::getCreateUser,userId); return sharedQuestionBankMapper.selectOne(bankLambdaQueryWrapper); } @Override public List getSharedQuestionBank() { List sharedQuestionBanks = sharedQuestionBankMapper.selectList(null); List sharedQuestionBankDtos=sharedQuestionBanks.stream().map(item->{ SharedQuestionBankDto sharedQuestionBankDto=new SharedQuestionBankDto(); BeanUtils.copyProperties(item,sharedQuestionBankDto); Company companyDetail = companyService.getCompanyDetail(sharedQuestionBankDto.getCreateCompany()); sharedQuestionBankDto.setCreateCompany(null); sharedQuestionBankDto.setCreateCompanyName(companyDetail.getCompanyName()); User createUser = userService.getUserById(sharedQuestionBankDto.getCreateUser()); sharedQuestionBankDto.setCreateUserName(createUser.getUsername()); User updateUser = userService.getUserById(sharedQuestionBankDto.getUpdateUser()); sharedQuestionBankDto.setUpdateUserName(updateUser.getUsername()); return sharedQuestionBankDto; }).collect(Collectors.toList()); return sharedQuestionBankDtos; } @Override public SharedQuestionBank getSharedQuestionBankById(Integer bankId) { LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper<>(); queryWrapper.eq(SharedQuestionBank::getId,bankId); SharedQuestionBank sharedQuestionBank = sharedQuestionBankMapper.selectOne(queryWrapper); return sharedQuestionBank; } }