| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiProductPoint; |
| | | import cc.mrbird.febs.ai.entity.AiProductPointLink; |
| | | import cc.mrbird.febs.ai.mapper.AiProductPointMapper; |
| | | import cc.mrbird.febs.ai.req.productPoint.ApiProductPointInfoDto; |
| | | import cc.mrbird.febs.ai.res.productPoint.ApiProductPointInfoVo; |
| | | import cc.mrbird.febs.ai.res.productPoint.ApiProductPointVo; |
| | | import cc.mrbird.febs.ai.service.AiProductPointLinkService; |
| | | import cc.mrbird.febs.ai.service.AiProductPointService; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | 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.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * AI产品知识点 Service实现类 |
| | |
| | | public class AiProductPointServiceImpl extends ServiceImpl<AiProductPointMapper, AiProductPoint> implements AiProductPointService { |
| | | |
| | | private final AiProductPointMapper aiProductPointMapper; |
| | | private final AiProductPointLinkService aiProductPointLinkService; |
| | | |
| | | @Override |
| | | public AiProductPoint getById(String id) { |
| | | return this.getById(id); |
| | | return aiProductPointMapper.selectById( id); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductPoint> getByCompanyId(String companyId) { |
| | | LambdaQueryWrapper<AiProductPoint> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductPoint::getCompanyId, companyId); |
| | | queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | public List<AiProductPoint> getListByPointIds(Set<String> collect) { |
| | | return aiProductPointMapper.selectBatchIds( collect); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductPoint> getByIsNormal(Integer isNormal) { |
| | | LambdaQueryWrapper<AiProductPoint> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductPoint::getIsNormal, isNormal); |
| | | queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | public List<ApiProductPointVo> listByProductId(String productId) { |
| | | List<ApiProductPointVo> vos = new ArrayList<>(); |
| | | |
| | | @Override |
| | | public List<AiProductPoint> getByFinderUserName(String finderUserName) { |
| | | LambdaQueryWrapper<AiProductPoint> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductPoint::getFinderUserName, finderUserName); |
| | | queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductPoint> getByTitle(String title) { |
| | | LambdaQueryWrapper<AiProductPoint> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.like(AiProductPoint::getTitle, title); |
| | | queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductPoint> getByCompanyIdAndIsNormal(String companyId, Integer isNormal) { |
| | | LambdaQueryWrapper<AiProductPoint> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductPoint::getCompanyId, companyId); |
| | | queryWrapper.eq(AiProductPoint::getIsNormal, isNormal); |
| | | queryWrapper.orderByDesc(AiProductPoint::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductPoint> searchByKeyword(String keyword) { |
| | | LambdaQueryWrapper<AiProductPoint> 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; |
| | | LambdaQueryWrapper<AiProductPointLink> pointLinkQUery = Wrappers.lambdaQuery(AiProductPointLink.class); |
| | | pointLinkQUery.eq(AiProductPointLink::getProductId, productId); |
| | | List<AiProductPointLink> linkList = aiProductPointLinkService.getListByProductId(pointLinkQUery); |
| | | if (CollUtil.isEmpty(linkList)){ |
| | | return vos; |
| | | } |
| | | |
| | | Set<String> collect = linkList.stream().map(AiProductPointLink::getProductPointId).collect(Collectors.toSet()); |
| | | List<AiProductPoint> list = this.getListByPointIds(collect); |
| | | if (CollUtil.isEmpty(list)){ |
| | | return vos; |
| | | } |
| | | |
| | | for (AiProductPoint point : list){ |
| | | ApiProductPointVo vo = new ApiProductPointVo(); |
| | | vo.setId(point.getId()); |
| | | vo.setTitle(point.getTitle()); |
| | | vos.add(vo); |
| | | } |
| | | return vos; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveBatchProductPoints(List<AiProductPoint> productPoints) { |
| | | try { |
| | | return this.saveBatch(productPoints); |
| | | } catch (Exception e) { |
| | | log.error("批量保存AI产品知识点失败: ", e); |
| | | return false; |
| | | public FebsResponse productPointInfo(ApiProductPointInfoDto dto) { |
| | | ApiProductPointInfoVo apiProductPointInfoVo = new ApiProductPointInfoVo(); |
| | | String id = dto.getId(); |
| | | AiProductPoint entity = this.getById(id); |
| | | if (ObjectUtil.isNotNull( entity)){ |
| | | apiProductPointInfoVo.setIsNormal(entity.getIsNormal()); |
| | | apiProductPointInfoVo.setFinderUserName(entity.getFinderUserName()); |
| | | apiProductPointInfoVo.setFeedId(entity.getFeedId()); |
| | | apiProductPointInfoVo.setTitle(entity.getTitle()); |
| | | apiProductPointInfoVo.setDescription(entity.getDescription()); |
| | | } |
| | | } |
| | | |
| | | @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<AiProductPoint> 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<AiProductPoint> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductPoint::getFeedId, feedId); |
| | | return this.remove(queryWrapper); |
| | | } catch (Exception e) { |
| | | log.error("根据视频号FeedID删除AI产品知识点失败: ", e); |
| | | return false; |
| | | } |
| | | return new FebsResponse().success().data(apiProductPointInfoVo); |
| | | } |
| | | } |