| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiAgent; |
| | | import cc.mrbird.febs.ai.entity.*; |
| | | import cc.mrbird.febs.ai.enumerates.AiCommonEnum; |
| | | import cc.mrbird.febs.ai.enumerates.ProductCategoryLevelEnum; |
| | | import cc.mrbird.febs.ai.mapper.AiAgentCategoryMapper; |
| | | import cc.mrbird.febs.ai.mapper.AiAgentMapper; |
| | | import cc.mrbird.febs.ai.mapper.AiAgentStartQuestionMapper; |
| | | import cc.mrbird.febs.ai.req.agent.AiAgentInitDto; |
| | | import cc.mrbird.febs.ai.req.agent.ApiAgentCategoryAllDto; |
| | | import cc.mrbird.febs.ai.req.agent.ApiAgentPageDto; |
| | | import cc.mrbird.febs.ai.res.agent.AiAgentInitVo; |
| | | import cc.mrbird.febs.ai.res.agent.ApiAgentCategoryVo; |
| | | import cc.mrbird.febs.ai.res.agent.ApiAgentVo; |
| | | import cc.mrbird.febs.ai.res.product.ApiProductVo; |
| | | import cc.mrbird.febs.ai.res.productCategory.ApiProductCategoryVo; |
| | | import cc.mrbird.febs.ai.service.AiAgentService; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | 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 java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class AiAgentServiceImpl extends ServiceImpl<AiAgentMapper, AiAgent> implements AiAgentService { |
| | | |
| | | private final AiAgentMapper aiAgentMapper; |
| | | private final AiAgentCategoryMapper aiAgentCategoryMapper; |
| | | private final AiAgentStartQuestionMapper aiAgentStartQuestionMapper; |
| | | |
| | | @Override |
| | | public FebsResponse allCategoryList(ApiAgentCategoryAllDto dto) { |
| | | List<ApiAgentCategoryVo> list = new ArrayList<>(); |
| | | LambdaQueryWrapper<AiAgentCategory> query = Wrappers.lambdaQuery(AiAgentCategory.class); |
| | | if (StrUtil.isEmpty(dto.getCompanyId())){ |
| | | dto.setCompanyId(AiCommonEnum.COMPANY_ID.getPrompt()); |
| | | } |
| | | query.eq(AiAgentCategory::getCompanyId, dto.getCompanyId()); |
| | | query.eq(AiAgentCategory::getState, 1); |
| | | query.orderByAsc(AiAgentCategory::getSort); |
| | | List<AiAgentCategory> listByQuery = aiAgentCategoryMapper.selectList(query); |
| | | if (CollUtil.isNotEmpty(listByQuery)){ |
| | | for (AiAgentCategory entity : listByQuery){ |
| | | ApiAgentCategoryVo vo = new ApiAgentCategoryVo(); |
| | | vo.setId(entity.getId()); |
| | | vo.setName(entity.getName()); |
| | | list.add(vo); |
| | | } |
| | | |
| | | } |
| | | return new FebsResponse().success().data(list); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse agentList(ApiAgentPageDto dto) { |
| | | // 创建分页对象,传入当前页和每页大小 |
| | | Page<ApiAgentVo> page = new Page<>(dto.getPageNow(), dto.getPageSize()); |
| | | Page<ApiAgentVo> pageListByQuery = aiAgentMapper.getPageListByQuery(page, dto); |
| | | return new FebsResponse().success().data(pageListByQuery); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse initAgent(AiAgentInitDto dto) { |
| | | String id = dto.getId(); |
| | | |
| | | AiAgent aiAgent = aiAgentMapper.selectById(id); |
| | | if (aiAgent == null) { |
| | | throw new FebsException("智能体异常"); |
| | | } |
| | | AiAgentInitVo vo = new AiAgentInitVo(); |
| | | //将chatWebPlugin复制给apiInitPluginVo |
| | | BeanUtil.copyProperties(aiAgent, vo); |
| | | |
| | | List<AiAgentStartQuestion> aiAgentStartQuestions = aiAgentStartQuestionMapper.selectList( |
| | | Wrappers.lambdaQuery(AiAgentStartQuestion.class) |
| | | .select(AiAgentStartQuestion::getTitle) |
| | | .eq(AiAgentStartQuestion::getAgentId, id) |
| | | ); |
| | | if (CollUtil.isNotEmpty(aiAgentStartQuestions)){ |
| | | List<String> items = new ArrayList<>(); |
| | | for (AiAgentStartQuestion aiAgentStartQuestion : aiAgentStartQuestions) { |
| | | items.add(aiAgentStartQuestion.getTitle()); |
| | | } |
| | | vo.setItems( items); |
| | | } |
| | | |
| | | return new FebsResponse().success().data(vo); |
| | | } |
| | | } |