Commit 0ba9aec4 authored by alex yao's avatar alex yao

fix:上传空文件应提示“上传文件内容不能为空" --bug==1009501

parent da406147
...@@ -11,6 +11,7 @@ import cn.com.poc.agent_application.utils.AgentApplicationTools; ...@@ -11,6 +11,7 @@ import cn.com.poc.agent_application.utils.AgentApplicationTools;
import cn.com.poc.common.annotation.RedisLimit; import cn.com.poc.common.annotation.RedisLimit;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.DocumentLoad;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool; import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool;
...@@ -29,6 +30,7 @@ import org.springframework.util.Assert; ...@@ -29,6 +30,7 @@ import org.springframework.util.Assert;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -205,10 +207,14 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -205,10 +207,14 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
try { try {
String agentId = dto.getAgentId(); String agentId = dto.getAgentId();
String dialogueId = dto.getAgentId(); String dialogueId = dto.getAgentId();
List<String> fileUrls = dto.getFileUrls();
BizAgentApplicationInfoEntity infoEntity = bizAgentApplicationInfoService.getByAgentId(agentId); BizAgentApplicationInfoEntity infoEntity = bizAgentApplicationInfoService.getByAgentId(agentId);
if (infoEntity == null) { if (infoEntity == null) {
throw new I18nMessageException("exception/application.does.not.exist"); throw new I18nMessageException("exception/application.does.not.exist");
} }
// 判断文件是否为空,如果不为空
AgentApplicationTools.checkDialogueContentIsEmpty(fileUrls);
//获取知识库配置 //获取知识库配置
List<Integer> kdIds = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds()); List<Integer> kdIds = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
......
...@@ -2,19 +2,27 @@ package cn.com.poc.agent_application.utils; ...@@ -2,19 +2,27 @@ package cn.com.poc.agent_application.utils;
import cn.com.poc.agent_application.entity.Variable; import cn.com.poc.agent_application.entity.Variable;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.DocumentLoad;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool; import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Tool;
import cn.com.poc.thirdparty.resource.demand.ai.function.LargeModelFunctionEnum; import cn.com.poc.thirdparty.resource.demand.ai.function.LargeModelFunctionEnum;
import cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriter; import cn.com.poc.thirdparty.resource.demand.ai.function.memory_variable_writer.MemoryVariableWriter;
import cn.com.yict.framemax.core.i18n.I18nMessageException;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* @author alex.yao
* @description agent应用配置工具类
*/
public class AgentApplicationTools { public class AgentApplicationTools {
...@@ -94,4 +102,21 @@ public class AgentApplicationTools { ...@@ -94,4 +102,21 @@ public class AgentApplicationTools {
return dialogueId + ":" + agentId; return dialogueId + ":" + agentId;
} }
/**
* 检查对话文件内容是否为空
*
* @throws I18nMessageException 文件内容为空时抛出异常
*/
public static void checkDialogueContentIsEmpty(List<String> fileUrls) {
// 判断文件是否为空,如果不为空
if (CollectionUtils.isNotEmpty(fileUrls)) {
for (String fileUrl : fileUrls) {
File file = DocumentLoad.downloadURLDocument(fileUrl);
String documentContent = DocumentLoad.documentToText(file);
if (StringUtils.isBlank(documentContent)) {
throw new I18nMessageException("exception/file.content.empty");
}
}
}
}
} }
...@@ -18,6 +18,7 @@ import cn.com.poc.common.constant.CommonConstant; ...@@ -18,6 +18,7 @@ import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.constant.XLangConstant; import cn.com.poc.common.constant.XLangConstant;
import cn.com.poc.common.service.RedisService; import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.DocumentLoad;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.expose.aggregate.AgentApplicationService; import cn.com.poc.expose.aggregate.AgentApplicationService;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
...@@ -41,6 +42,7 @@ import org.springframework.stereotype.Service; ...@@ -41,6 +42,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
...@@ -108,6 +110,9 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -108,6 +110,9 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
throw new I18nMessageException("exception/app.not.found"); throw new I18nMessageException("exception/app.not.found");
} }
// 判断文件是否为空,如果不为空
AgentApplicationTools.checkDialogueContentIsEmpty(fileUrls);
if (StringUtils.isBlank(dialogsId)) { if (StringUtils.isBlank(dialogsId)) {
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空 // 用于针对只有单Agent应用分享使用的场景,dialogsId为空
dialogsId = agentId + "-" + userBaseEntity.getUserId(); dialogsId = agentId + "-" + userBaseEntity.getUserId();
......
...@@ -76,4 +76,5 @@ file.load.error=File loading failure ...@@ -76,4 +76,5 @@ file.load.error=File loading failure
content.cannot.null=Content can not be null content.cannot.null=Content can not be null
arg.cannot.null=Arg can not be null arg.cannot.null=Arg can not be null
nickName.max.len=Overnickname nickName.max.len=Overnickname
remark.max.len=Remark content too long remark.max.len=Remark content too long
\ No newline at end of file file.content.empty=The file content cannot be empty
\ No newline at end of file
...@@ -76,4 +76,5 @@ file.load.error=\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25 ...@@ -76,4 +76,5 @@ file.load.error=\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25
content.cannot.null=\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A content.cannot.null=\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A
arg.cannot.null=\u8BF7\u6C42\u53C2\u6570\u4E0D\u80FD\u4E3A\u7A7A arg.cannot.null=\u8BF7\u6C42\u53C2\u6570\u4E0D\u80FD\u4E3A\u7A7A
nickName.max.len=\u6635\u79F0\u8FC7\u957F nickName.max.len=\u6635\u79F0\u8FC7\u957F
remark.max.len=\u5185\u5BB9\u8FC7\u957F remark.max.len=\u5185\u5BB9\u8FC7\u957F
\ No newline at end of file file.content.empty=\u6587\u6863\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A
\ No newline at end of file
...@@ -76,4 +76,5 @@ file.load.error=\u6587\u4EF6\u52A0\u8F09\u5931\u6557 ...@@ -76,4 +76,5 @@ file.load.error=\u6587\u4EF6\u52A0\u8F09\u5931\u6557
content.cannot.null=\u5185\u5BB9\u4E0D\u80FD\u7232\u7A7A content.cannot.null=\u5185\u5BB9\u4E0D\u80FD\u7232\u7A7A
arg.cannot.null=\u8ACB\u6C42\u53C3\u6578\u4E0D\u80FD\u7232\u7A7A arg.cannot.null=\u8ACB\u6C42\u53C3\u6578\u4E0D\u80FD\u7232\u7A7A
nickName.max.len=\u6635\u7A31\u904E\u9577 nickName.max.len=\u6635\u7A31\u904E\u9577
remark.max.len=\u5185\u5BB9\u904E\u9577 remark.max.len=\u5185\u5BB9\u904E\u9577
\ No newline at end of file file.content.empty=\u6587\u4EF6\u5185\u5BB9\u4E0D\u80FD\u7232\u7A7A
\ No newline at end of file
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