package cc.mrbird.febs.ai.service.impl; import cc.mrbird.febs.ai.entity.AiProductPoint; import cc.mrbird.febs.ai.mapper.AiProductPointMapper; import cc.mrbird.febs.ai.service.AiProductPointService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.List; /** * AI产品知识点 Service实现类 * * @author yourname * @date 2025-07-29 */ @Slf4j @Service @RequiredArgsConstructor public class AiProductPointServiceImpl extends ServiceImpl implements AiProductPointService { private final AiProductPointMapper aiProductPointMapper; @Override public AiProductPoint getById(String id) { return this.getById(id); } @Override public List getByCompanyId(String companyId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AiProductPoint::getCompanyId, companyId); queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); return this.list(queryWrapper); } @Override public List getByIsNormal(Integer isNormal) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AiProductPoint::getIsNormal, isNormal); queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); return this.list(queryWrapper); } @Override public List getByFinderUserName(String finderUserName) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AiProductPoint::getFinderUserName, finderUserName); queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); return this.list(queryWrapper); } @Override public List getByTitle(String title) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.like(AiProductPoint::getTitle, title); queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); return this.list(queryWrapper); } @Override public List getByCompanyIdAndIsNormal(String companyId, Integer isNormal) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AiProductPoint::getCompanyId, companyId); queryWrapper.eq(AiProductPoint::getIsNormal, isNormal); queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); return this.list(queryWrapper); } @Override public List searchByKeyword(String keyword) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.and(wrapper -> wrapper.like(AiProductPoint::getTitle, keyword) .or() .like(AiProductPoint::getDescription, keyword)); queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); return this.list(queryWrapper); } @Override @Transactional(rollbackFor = Exception.class) public boolean saveProductPoint(AiProductPoint aiProductPoint) { try { return this.save(aiProductPoint); } catch (Exception e) { log.error("保存AI产品知识点失败: ", e); return false; } } @Override @Transactional(rollbackFor = Exception.class) public boolean saveBatchProductPoints(List productPoints) { try { return this.saveBatch(productPoints); } catch (Exception e) { log.error("批量保存AI产品知识点失败: ", e); return false; } } @Override @Transactional(rollbackFor = Exception.class) public boolean updateProductPoint(AiProductPoint aiProductPoint) { try { return this.updateById(aiProductPoint); } catch (Exception e) { log.error("更新AI产品知识点失败: ", e); return false; } } @Override @Transactional(rollbackFor = Exception.class) public boolean deleteById(String id) { try { return this.removeById(id); } catch (Exception e) { log.error("删除AI产品知识点失败: ", e); return false; } } @Override @Transactional(rollbackFor = Exception.class) public boolean deleteByCompanyId(String companyId) { try { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AiProductPoint::getCompanyId, companyId); return this.remove(queryWrapper); } catch (Exception e) { log.error("根据公司ID删除AI产品知识点失败: ", e); return false; } } @Override @Transactional(rollbackFor = Exception.class) public boolean deleteByFeedId(String feedId) { try { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AiProductPoint::getFeedId, feedId); return this.remove(queryWrapper); } catch (Exception e) { log.error("根据视频号FeedID删除AI产品知识点失败: ", e); return false; } } }