| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiProductPoint; |
| | | import cc.mrbird.febs.ai.entity.*; |
| | | import cc.mrbird.febs.ai.mapper.AiProductPointMapper; |
| | | import cc.mrbird.febs.ai.service.AiProductPointService; |
| | | import cc.mrbird.febs.ai.req.productPoint.ApiProductPointInfoDto; |
| | | import cc.mrbird.febs.ai.req.productPoint.ApiProductPointPageDto; |
| | | import cc.mrbird.febs.ai.req.productPoint.ApiProductPointRecommendDto; |
| | | import cc.mrbird.febs.ai.res.productPoint.ApiProductPointInfoVo; |
| | | import cc.mrbird.febs.ai.res.productPoint.ApiProductPointListVo; |
| | | import cc.mrbird.febs.ai.res.productPoint.ApiProductPointRecommendVo; |
| | | import cc.mrbird.febs.ai.res.productPoint.ApiProductPointVo; |
| | | import cc.mrbird.febs.ai.service.*; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.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; |
| | | private final AiProductCategoryService aiProductCategoryService; |
| | | private final AiMemberRoleService aiMemberRoleService; |
| | | private final AiMemberTalkService aiMemberTalkService; |
| | | |
| | | @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 productPointList(ApiProductPointPageDto dto) { |
| | | |
| | | if(StrUtil.isEmpty(dto.getMemberRoleId())){ |
| | | String memberRoleId = aiMemberRoleService.getDefaultMemberRoleId(); |
| | | dto.setMemberRoleId(memberRoleId); |
| | | } |
| | | |
| | | if(StrUtil.isEmpty(dto.getCategoryId())){ |
| | | String categoryId = aiProductCategoryService.getDefaultProductCategoryId(); |
| | | dto.setCategoryId(categoryId); |
| | | } |
| | | // 创建分页对象,传入当前页和每页大小 |
| | | Page<ApiProductPointListVo> page = new Page<>(dto.getPageNow(), dto.getPageSize()); |
| | | Page<ApiProductPointListVo> pageListByQuery = aiProductPointMapper.selectPageListByQuery(page, dto); |
| | | return new FebsResponse().success().data(pageListByQuery); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateProductPoint(AiProductPoint aiProductPoint) { |
| | | try { |
| | | return this.updateById(aiProductPoint); |
| | | } 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.setFeedImg(entity.getFeedImg()); |
| | | apiProductPointInfoVo.setTitle(entity.getTitle()); |
| | | apiProductPointInfoVo.setDescription(entity.getDescription()); |
| | | } |
| | | return new FebsResponse().success().data(apiProductPointInfoVo); |
| | | } |
| | | |
| | | @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 recommend(ApiProductPointRecommendDto dto) { |
| | | |
| | | @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; |
| | | } |
| | | } |
| | | List<ApiProductPointRecommendVo> vos = new ArrayList<>(); |
| | | |
| | | @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; |
| | | String memberTalkId = dto.getMemberTalkId(); |
| | | AiMemberTalk aiMemberTalk = aiMemberTalkService.getById(memberTalkId); |
| | | if (ObjectUtil.isNotNull(aiMemberTalk)){ |
| | | return new FebsResponse().success().data(vos); |
| | | } |
| | | String productId = aiMemberTalk.getProductId(); |
| | | List<AiProductPointLink> aiProductPointLinkList = aiProductPointLinkService.getListByProductId( |
| | | Wrappers.lambdaQuery(AiProductPointLink.class) |
| | | .eq(AiProductPointLink::getProductId, productId) |
| | | ); |
| | | if (CollUtil.isEmpty(aiProductPointLinkList)){ |
| | | return new FebsResponse().success().data(vos); |
| | | } |
| | | |
| | | //stream流操作aiProductPointLinkList,返回一个Set<productPointId>的set集合 |
| | | Set<String> productPointIdSet = aiProductPointLinkList.stream().map(AiProductPointLink::getProductPointId).collect(Collectors.toSet()); |
| | | |
| | | List<AiProductPoint> listByPointIds = aiProductPointMapper.selectList( |
| | | Wrappers.lambdaQuery(AiProductPoint.class) |
| | | .select(AiProductPoint::getId,AiProductPoint::getTitle) |
| | | .in(AiProductPoint::getId, productPointIdSet) |
| | | ); |
| | | if (CollUtil.isEmpty(listByPointIds)){ |
| | | return new FebsResponse().success().data(vos); |
| | | } |
| | | |
| | | for (AiProductPoint aiProductPoint : listByPointIds){ |
| | | ApiProductPointRecommendVo vo = new ApiProductPointRecommendVo(); |
| | | vo.setId(aiProductPoint.getId()); |
| | | vo.setTitle(aiProductPoint.getTitle()); |
| | | vos.add(vo); |
| | | } |
| | | return new FebsResponse().success().data(vos); |
| | | } |
| | | } |