| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiMemberRole; |
| | | import cc.mrbird.febs.ai.entity.AiProductPoint; |
| | | import cc.mrbird.febs.ai.entity.AiProductQuestion; |
| | | import cc.mrbird.febs.ai.mapper.AiProductQuestionMapper; |
| | | import cc.mrbird.febs.ai.service.AiProductQuestionService; |
| | | import cc.mrbird.febs.ai.util.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | public AiProductQuestion getById(String id) { |
| | | return this.getById(id); |
| | | |
| | | return aiProductQuestionMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByCompanyId(String companyId) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getCompanyId, companyId); |
| | | queryWrapper.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | public IPage<AiProductQuestion> listInPage(AiProductQuestion dto, QueryRequest request) { |
| | | Page<AiProductQuestion> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | LambdaQueryWrapper<AiProductQuestion> query = Wrappers.lambdaQuery(AiProductQuestion.class); |
| | | Page<AiProductQuestion> pages = aiProductQuestionMapper.selectPage(page, query); |
| | | return pages; |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByProductCategoryId(String productCategoryId) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getProductCategoryId, productCategoryId); |
| | | queryWrapper.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByTitle(String title) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.like(AiProductQuestion::getTitle, title); |
| | | queryWrapper.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByParentId(String parentId) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getParentId, parentId); |
| | | queryWrapper.orderByAsc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByDifficulty(Integer difficulty) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getDifficulty, difficulty); |
| | | queryWrapper.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByState(Integer state) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getState, state); |
| | | queryWrapper.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByCorrectAnswer(Integer correctAnswer) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getCorrectAnswer, correctAnswer); |
| | | queryWrapper.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByCompanyIdAndState(String companyId, Integer state) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getCompanyId, companyId); |
| | | queryWrapper.eq(AiProductQuestion::getState, state); |
| | | queryWrapper.orderByDesc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductQuestion> getByParentIdAndState(String parentId, Integer state) { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getParentId, parentId); |
| | | queryWrapper.eq(AiProductQuestion::getState, state); |
| | | queryWrapper.orderByAsc(AiProductQuestion::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveProductQuestion(AiProductQuestion aiProductQuestion) { |
| | | try { |
| | | return this.save(aiProductQuestion); |
| | | } catch (Exception e) { |
| | | log.error("保存AI产品题目失败: ", e); |
| | | return false; |
| | | public FebsResponse changeState(String id, Integer state) { |
| | | AiProductQuestion entity = this.getById(id); |
| | | if(ObjectUtil.isNotEmpty(entity)){ |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiProductQuestion.class) |
| | | .set(AiProductQuestion::getState, state) |
| | | .set(AiProductQuestion::getUpdatedTime, new Date()) |
| | | .eq(AiProductQuestion::getId, id)); |
| | | } |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveBatchProductQuestions(List<AiProductQuestion> productQuestions) { |
| | | try { |
| | | return this.saveBatch(productQuestions); |
| | | } catch (Exception e) { |
| | | log.error("批量保存AI产品题目失败: ", e); |
| | | return false; |
| | | } |
| | | public FebsResponse add(AiProductQuestion dto) { |
| | | |
| | | AiProductQuestion entity = new AiProductQuestion(); |
| | | entity.setId(UUID.getSimpleUUIDString()); |
| | | entity.setCompanyId(dto.getCompanyId()); |
| | | entity.setProductCategoryId(dto.getProductCategoryId()); |
| | | entity.setTitle(dto.getTitle()); |
| | | entity.setDifficulty(dto.getDifficulty()); |
| | | entity.setCreatedTime(new Date()); |
| | | this.save(entity); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateProductQuestion(AiProductQuestion aiProductQuestion) { |
| | | try { |
| | | return this.updateById(aiProductQuestion); |
| | | } catch (Exception e) { |
| | | log.error("更新AI产品题目失败: ", e); |
| | | return false; |
| | | public FebsResponse update(AiProductQuestion dto) { |
| | | String id = dto.getId(); |
| | | AiProductQuestion entity = this.getById(id); |
| | | if (ObjectUtil.isNotNull( entity)){ |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiProductQuestion.class) |
| | | .set(AiProductQuestion::getCompanyId, dto.getCompanyId()) |
| | | .set(AiProductQuestion::getProductCategoryId, dto.getProductCategoryId()) |
| | | .set(AiProductQuestion::getTitle, dto.getTitle()) |
| | | .set(AiProductQuestion::getDifficulty, dto.getDifficulty()) |
| | | .set(AiProductQuestion::getUpdatedTime, new Date()) |
| | | .eq(AiProductQuestion::getId, id) |
| | | ); |
| | | } |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteById(String id) { |
| | | try { |
| | | return this.removeById(id); |
| | | } catch (Exception e) { |
| | | log.error("删除AI产品题目失败: ", e); |
| | | return false; |
| | | public FebsResponse delete(String id) { |
| | | AiProductQuestion entity = this.getById(id); |
| | | if(ObjectUtil.isNotNull( entity)){ |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiProductQuestion.class) |
| | | .set(AiProductQuestion::getState, 2) |
| | | .set(AiProductQuestion::getUpdatedTime, new Date()) |
| | | .eq(AiProductQuestion::getId, id)); |
| | | |
| | | } |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteByParentId(String parentId) { |
| | | try { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getParentId, parentId); |
| | | return this.remove(queryWrapper); |
| | | } catch (Exception e) { |
| | | log.error("根据父ID删除AI产品题目失败: ", e); |
| | | return false; |
| | | } |
| | | public List<AiProductQuestion> questionTree() { |
| | | |
| | | return aiProductQuestionMapper.selectList(null); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteByCompanyId(String companyId) { |
| | | try { |
| | | LambdaQueryWrapper<AiProductQuestion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductQuestion::getCompanyId, companyId); |
| | | return this.remove(queryWrapper); |
| | | } catch (Exception e) { |
| | | log.error("根据公司ID删除AI产品题目失败: ", e); |
| | | return false; |
| | | } |
| | | } |
| | | } |