Commit 438781c8 authored by alex yao's avatar alex yao

feat: 判断知识库是否开启

parent 1395aa5e
......@@ -352,6 +352,100 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return true;
}
@Override
public void collectOrCancelAgentInMall(Integer id, String agentId) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) {
throw new BusinessException("用户未登录");
}
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.get(id);
if (mallEntity == null) {
throw new BusinessException("应用不存在");
}
// 先判断当前应用被当前用户收藏了吗
BizMemberAgentApplicationCollectEntity collectEntity = new BizMemberAgentApplicationCollectEntity();
collectEntity.setAgentId(agentId);
collectEntity.setMemberId(userBaseEntity.getUserId().intValue());
List<BizMemberAgentApplicationCollectEntity> collectEntities = bizMemberAgentApplicationCollectService.findByExample(collectEntity, new PagingInfo());
if (collectEntities.isEmpty() || CommonConstant.IsDeleted.N.equals(collectEntities.get(0).getIsCollect())) { //如果没被收藏
// 收藏该应用
// 说明从来没收藏过
if (collectEntities.isEmpty()) {
// 在用户收藏表中添加数据
BizMemberAgentApplicationCollectEntity entity = new BizMemberAgentApplicationCollectEntity();
entity.setIsCollect(CommonConstant.IsDeleted.Y);
entity.setMemberId(userBaseEntity.getUserId().intValue());
entity.setAgentId(agentId);
bizMemberAgentApplicationCollectService.save(entity);
} else { // 说明之前收藏过,则只需要做个修改
collectEntity.setIsCollect(CommonConstant.IsDeleted.Y);
bizMemberAgentApplicationCollectService.update(collectEntity);
}
// 在应用广场的应用中 添加收藏数
mallEntity.setCollectNumber(mallEntity.getCollectNumber() + 1);
} else {
// 取消收藏该应用
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.N);
bizMemberAgentApplicationCollectService.update(collectEntity);
// 在应用广场的应用中 取消收藏数
mallEntity.setCollectNumber(mallEntity.getCollectNumber() - 1);
}
bizAgentApplicationMallService.update(mallEntity);
}
@Override
public void collectOrCancelAgentInPerson(String agentId) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) {
throw new BusinessException("用户未登录");
}
// 先判断当前应用被当前用户收藏了吗
BizMemberAgentApplicationCollectEntity collectEntity = new BizMemberAgentApplicationCollectEntity();
collectEntity.setAgentId(agentId);
collectEntity.setMemberId(userBaseEntity.getUserId().intValue());
List<BizMemberAgentApplicationCollectEntity> collectEntities = bizMemberAgentApplicationCollectService.findByExample(collectEntity, new PagingInfo());
Integer isCollect = 0;
if (collectEntities.isEmpty() || CommonConstant.IsDeleted.N.equals(collectEntities.get(0).getIsCollect())) { //如果没被收藏
// 收藏该应用
// 说明从来没收藏过
if (collectEntities.isEmpty()) {
// 在用户收藏表中添加数据
BizMemberAgentApplicationCollectEntity entity = new BizMemberAgentApplicationCollectEntity();
entity.setIsCollect(CommonConstant.IsDeleted.Y);
entity.setMemberId(userBaseEntity.getUserId().intValue());
entity.setAgentId(agentId);
bizMemberAgentApplicationCollectService.save(entity);
} else { // 说明之前收藏过,则只需要做个修改
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.Y);
bizMemberAgentApplicationCollectService.update(collectEntities.get(0));
}
isCollect = 1;
} else {
// 取消收藏该应用
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.N);
bizMemberAgentApplicationCollectService.update(collectEntities.get(0));
isCollect = -1;
}
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (publishEntity == null) {
logger.warn("应用尚未发布,agentId:{}", agentId);
return;
}
Integer id = publishEntity.getId();
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(id);
if (mallEntity == null || CommonConstant.YOrN.N.equals(mallEntity.getIsSale())) {
logger.warn("应用尚未上架,agentId:{}", agentId);
return;
}
mallEntity.setCollectNumber(mallEntity.getCollectNumber() + isCollect);
bizAgentApplicationMallService.update(mallEntity);
}
/**
* 构建应用信息提示词
*
......@@ -394,15 +488,18 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
// 调用知识库
if (ArrayUtils.isNotEmpty(kdIds)) {
List<String> knowledgeIds = new ArrayList<>();
for (Integer kdId : kdIds) {
BizKnowledgeDocumentEntity knowledgeDocumentEntity = bizKnowledgeDocumentService.get(kdId);
if (null == knowledgeDocumentEntity) {
if (null == knowledgeDocumentEntity || CommonConstant.YOrN.N.equals(knowledgeDocumentEntity.getIsEnable())) {
continue;
}
knowledgeIds.add(knowledgeDocumentEntity.getKnowledgeId());
}
Object content = messages.get(messages.size() - 1);
String query = "";
if (content instanceof List) {
query = ((List<MultiContent>) content).get(0).getText();
} else {
......@@ -664,96 +761,4 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return largeModelEntity.getModelName();
}
@Override
public void collectOrCancelAgentInMall(Integer id, String agentId) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) {
throw new BusinessException("用户未登录");
}
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.get(id);
if (mallEntity == null) {
throw new BusinessException("应用不存在");
}
// 先判断当前应用被当前用户收藏了吗
BizMemberAgentApplicationCollectEntity collectEntity = new BizMemberAgentApplicationCollectEntity();
collectEntity.setAgentId(agentId);
collectEntity.setMemberId(userBaseEntity.getUserId().intValue());
List<BizMemberAgentApplicationCollectEntity> collectEntities = bizMemberAgentApplicationCollectService.findByExample(collectEntity, new PagingInfo());
if (collectEntities.isEmpty() || CommonConstant.IsDeleted.N.equals(collectEntities.get(0).getIsCollect())) { //如果没被收藏
// 收藏该应用
// 说明从来没收藏过
if (collectEntities.isEmpty()) {
// 在用户收藏表中添加数据
BizMemberAgentApplicationCollectEntity entity = new BizMemberAgentApplicationCollectEntity();
entity.setIsCollect(CommonConstant.IsDeleted.Y);
entity.setMemberId(userBaseEntity.getUserId().intValue());
entity.setAgentId(agentId);
bizMemberAgentApplicationCollectService.save(entity);
} else { // 说明之前收藏过,则只需要做个修改
collectEntity.setIsCollect(CommonConstant.IsDeleted.Y);
bizMemberAgentApplicationCollectService.update(collectEntity);
}
// 在应用广场的应用中 添加收藏数
mallEntity.setCollectNumber(mallEntity.getCollectNumber() + 1);
} else {
// 取消收藏该应用
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.N);
bizMemberAgentApplicationCollectService.update(collectEntity);
// 在应用广场的应用中 取消收藏数
mallEntity.setCollectNumber(mallEntity.getCollectNumber() - 1);
}
bizAgentApplicationMallService.update(mallEntity);
}
@Override
public void collectOrCancelAgentInPerson(String agentId) throws Exception {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) {
throw new BusinessException("用户未登录");
}
// 先判断当前应用被当前用户收藏了吗
BizMemberAgentApplicationCollectEntity collectEntity = new BizMemberAgentApplicationCollectEntity();
collectEntity.setAgentId(agentId);
collectEntity.setMemberId(userBaseEntity.getUserId().intValue());
List<BizMemberAgentApplicationCollectEntity> collectEntities = bizMemberAgentApplicationCollectService.findByExample(collectEntity, new PagingInfo());
Integer isCollect = 0;
if (collectEntities.isEmpty() || CommonConstant.IsDeleted.N.equals(collectEntities.get(0).getIsCollect())) { //如果没被收藏
// 收藏该应用
// 说明从来没收藏过
if (collectEntities.isEmpty()) {
// 在用户收藏表中添加数据
BizMemberAgentApplicationCollectEntity entity = new BizMemberAgentApplicationCollectEntity();
entity.setIsCollect(CommonConstant.IsDeleted.Y);
entity.setMemberId(userBaseEntity.getUserId().intValue());
entity.setAgentId(agentId);
bizMemberAgentApplicationCollectService.save(entity);
} else { // 说明之前收藏过,则只需要做个修改
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.Y);
bizMemberAgentApplicationCollectService.update(collectEntities.get(0));
}
isCollect = 1;
} else {
// 取消收藏该应用
collectEntities.get(0).setIsCollect(CommonConstant.IsDeleted.N);
bizMemberAgentApplicationCollectService.update(collectEntities.get(0));
isCollect = -1;
}
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (publishEntity == null) {
logger.warn("应用尚未发布,agentId:{}", agentId);
return;
}
Integer id = publishEntity.getId();
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(id);
if (mallEntity == null || CommonConstant.YOrN.N.equals(mallEntity.getIsSale())) {
logger.warn("应用尚未上架,agentId:{}", agentId);
return;
}
mallEntity.setCollectNumber(mallEntity.getCollectNumber() + isCollect);
bizAgentApplicationMallService.update(mallEntity);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment