Commit f3d8ea05 by pengshun

fix: 快速切换智能体错误

parent c0c4d670
...@@ -152,6 +152,11 @@ public class AgentChatController { ...@@ -152,6 +152,11 @@ public class AgentChatController {
// 发送请求并接收响应 // 发送请求并接收响应
ResponseEntity<String> response = restTemplate.exchange(requestUrl, HttpMethod.GET, entity, String.class); ResponseEntity<String> response = restTemplate.exchange(requestUrl, HttpMethod.GET, entity, String.class);
// 检查 HTTP 状态码,非2xx也视为失败
if (!response.getStatusCode().is2xxSuccessful()) {
return buildEmptyResponse("下游服务返回错误: " + response.getStatusCode());
}
JSONObject initJson = new JSONObject(response.getBody()); JSONObject initJson = new JSONObject(response.getBody());
JSONObject initData = initJson.getJSONObject("data"); JSONObject initData = initJson.getJSONObject("data");
// JSONArray variablesConfig = initData.getJSONObject("app") // JSONArray variablesConfig = initData.getJSONObject("app")
...@@ -169,6 +174,15 @@ public class AgentChatController { ...@@ -169,6 +174,15 @@ public class AgentChatController {
return ResponseEntity.ok(data.toString()); return ResponseEntity.ok(data.toString());
} }
// 辅助方法:构造指定格式的空数据响应
private ResponseEntity<?> buildEmptyResponse(String errorMsg) {
JSONObject emptyData = new JSONObject();
emptyData.put("status", 200);
emptyData.put("data", new JSONObject()); // 空对象,也可改为空数组或 null
emptyData.put("msg", errorMsg);
return ResponseEntity.ok(emptyData.toString()); // 仍返回 HTTP 200,但业务内标记失败
}
@PostMapping("/get-messages-v2") @PostMapping("/get-messages-v2")
@Operation(summary = "获得智能体对话消息") @Operation(summary = "获得智能体对话消息")
public ResponseEntity<?> getAgentMessagesv2(@RequestBody @Valid AgentMsgReqVO reqVO) { public ResponseEntity<?> getAgentMessagesv2(@RequestBody @Valid AgentMsgReqVO reqVO) {
......
...@@ -7,6 +7,7 @@ import jakarta.validation.constraints.NotNull; ...@@ -7,6 +7,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.URL; import org.hibernate.validator.constraints.URL;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Schema(description = "管理后台 - AI 知识库文档批量创建 Request VO") @Schema(description = "管理后台 - AI 知识库文档批量创建 Request VO")
...@@ -46,4 +47,7 @@ public class AiKnowledgeDocumentCreateListReqVO { ...@@ -46,4 +47,7 @@ public class AiKnowledgeDocumentCreateListReqVO {
} }
@Schema(description = "发文时间", example = "1736906400000")
private LocalDateTime releaseTime;
} }
\ No newline at end of file
...@@ -4,6 +4,8 @@ import io.swagger.v3.oas.annotations.media.Schema; ...@@ -4,6 +4,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - AI 知识库文档更新 Request VO") @Schema(description = "管理后台 - AI 知识库文档更新 Request VO")
@Data @Data
public class AiKnowledgeDocumentUpdateReqVO { public class AiKnowledgeDocumentUpdateReqVO {
...@@ -22,4 +24,7 @@ public class AiKnowledgeDocumentUpdateReqVO { ...@@ -22,4 +24,7 @@ public class AiKnowledgeDocumentUpdateReqVO {
// @NotNull(message = "上一级目录编号不能为空") // @NotNull(message = "上一级目录编号不能为空")
private Long parentId; private Long parentId;
@Schema(description = "发文时间", example = "1736906400000")
private LocalDateTime releaseTime;
} }
...@@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotNull; ...@@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.URL; import org.hibernate.validator.constraints.URL;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - AI 知识库文档的创建 Request VO") @Schema(description = "管理后台 - AI 知识库文档的创建 Request VO")
@Data @Data
...@@ -39,4 +41,7 @@ public class AiKnowledgeDocumentCreateReqVO { ...@@ -39,4 +41,7 @@ public class AiKnowledgeDocumentCreateReqVO {
@Schema(description = "是否来自压缩包", example = "false") @Schema(description = "是否来自压缩包", example = "false")
private Boolean fromZip; private Boolean fromZip;
@Schema(description = "发文时间", example = "1736906400000")
private LocalDateTime releaseTime;
} }
...@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableId; ...@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
/** /**
* AI 知识库-文档 DO * AI 知识库-文档 DO
* *
...@@ -76,4 +78,6 @@ public class AiKnowledgeDocumentDO extends BaseDO { ...@@ -76,4 +78,6 @@ public class AiKnowledgeDocumentDO extends BaseDO {
private Boolean deletable; private Boolean deletable;
private LocalDateTime releaseTime;
} }
...@@ -46,7 +46,8 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume ...@@ -46,7 +46,8 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume
.eqIfPresent(AiKnowledgeDocumentDO::getKnowledgeId, reqVO.getKnowledgeId()) .eqIfPresent(AiKnowledgeDocumentDO::getKnowledgeId, reqVO.getKnowledgeId())
.likeIfPresent(AiKnowledgeDocumentDO::getName, reqVO.getName()) .likeIfPresent(AiKnowledgeDocumentDO::getName, reqVO.getName())
.eqIfPresent(AiKnowledgeDocumentDO::getParentId, reqVO.getParentId()) .eqIfPresent(AiKnowledgeDocumentDO::getParentId, reqVO.getParentId())
.orderByDesc(AiKnowledgeDocumentDO::getId)); .orderByDesc(AiKnowledgeDocumentDO::getReleaseTime)
.orderByDesc(AiKnowledgeDocumentDO::getCreateTime));
} }
default PageResult<AiKnowledgeDocumentDO> selectPageOwner(AiKnowledgeDocumentPageReqVO reqVO, Long userId){ default PageResult<AiKnowledgeDocumentDO> selectPageOwner(AiKnowledgeDocumentPageReqVO reqVO, Long userId){
...@@ -54,8 +55,10 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume ...@@ -54,8 +55,10 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume
.eqIfPresent(AiKnowledgeDocumentDO::getKnowledgeId, reqVO.getKnowledgeId()) .eqIfPresent(AiKnowledgeDocumentDO::getKnowledgeId, reqVO.getKnowledgeId())
.likeIfPresent(AiKnowledgeDocumentDO::getName, reqVO.getName()) .likeIfPresent(AiKnowledgeDocumentDO::getName, reqVO.getName())
.eqIfPresent(AiKnowledgeDocumentDO::getParentId, reqVO.getParentId()) .eqIfPresent(AiKnowledgeDocumentDO::getParentId, reqVO.getParentId())
.eq(AiKnowledgeDocumentDO::getCreator, userId) .eq(AiKnowledgeDocumentDO::getCreator, userId).eq(AiKnowledgeDocumentDO::getDeleted, false)
.orderByDesc(AiKnowledgeDocumentDO::getId)); .orderByDesc(AiKnowledgeDocumentDO::getReleaseTime)
.orderByDesc(AiKnowledgeDocumentDO::getCreateTime)
);
} }
default PageResult<AiKnowledgeDocumentDO> selectPageDept(AiKnowledgeDocumentPageReqVO reqVO, List<Long> userIds) { default PageResult<AiKnowledgeDocumentDO> selectPageDept(AiKnowledgeDocumentPageReqVO reqVO, List<Long> userIds) {
...@@ -68,7 +71,8 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume ...@@ -68,7 +71,8 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume
.or() .or()
.eq(AiKnowledgeDocumentDO::getStatus, 1) // 或者状态为1 .eq(AiKnowledgeDocumentDO::getStatus, 1) // 或者状态为1
) )
.orderByDesc(AiKnowledgeDocumentDO::getId)); .orderByDesc(AiKnowledgeDocumentDO::getReleaseTime)
.orderByDesc(AiKnowledgeDocumentDO::getCreateTime));
} }
default List<AiKnowledgeDocumentDO> selectDirListByKnowledgeId(Long id) { default List<AiKnowledgeDocumentDO> selectDirListByKnowledgeId(Long id) {
...@@ -89,7 +93,7 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume ...@@ -89,7 +93,7 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocume
.in(AiKnowledgeDocumentDO::getId, ids)); .in(AiKnowledgeDocumentDO::getId, ids));
} }
@Select("SELECT COALESCE(SUM(content_length), 0) FROM ai_knowledge_document WHERE creator = #{userId} AND is_dir = 0 AND knowledge_id = 6") @Select("SELECT COALESCE(SUM(content_length), 0) FROM ai_knowledge_document WHERE creator = #{userId} AND is_dir = 0 AND knowledge_id = 6 AND deleted = 0")
Long selectCountKBSize(Long userId); Long selectCountKBSize(Long userId);
default List<AiKnowledgeDocumentDO> selectListByParentId(Long id) { default List<AiKnowledgeDocumentDO> selectListByParentId(Long id) {
......
...@@ -92,7 +92,8 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic ...@@ -92,7 +92,8 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic
.setStatus(CommonStatusEnum.ENABLE.getStatus()) .setStatus(CommonStatusEnum.ENABLE.getStatus())
.setParentId(parentId) .setParentId(parentId)
.setIsDir(isDir) .setIsDir(isDir)
.setFromZip(createReqVO.getFromZip()); .setFromZip(createReqVO.getFromZip())
.setReleaseTime(createReqVO.getReleaseTime());
if(isDir == 0){ if(isDir == 0){
documentDO.setRetrievalCount(0); documentDO.setRetrievalCount(0);
// 调用递归函数更新所有父级 // 调用递归函数更新所有父级
...@@ -207,7 +208,9 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic ...@@ -207,7 +208,9 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic
.setParentId(parentId) .setParentId(parentId)
.setIsDir(isDir) .setIsDir(isDir)
.setSegmentMaxTokens(createListReqVO.getSegmentMaxTokens()) .setSegmentMaxTokens(createListReqVO.getSegmentMaxTokens())
.setStatus(CommonStatusEnum.ENABLE.getStatus())); .setStatus(CommonStatusEnum.ENABLE.getStatus())
.setReleaseTime(createListReqVO.getReleaseTime())
);
documentDOs.get(i).setContentLength(contentLength.get(i)); documentDOs.get(i).setContentLength(contentLength.get(i));
// AiKnowledgeDocumentDO knowledgeDocument = knowledgeDocumentMapper.selectById(documentDOs.get(i).getParentId()); // AiKnowledgeDocumentDO knowledgeDocument = knowledgeDocumentMapper.selectById(documentDOs.get(i).getParentId());
// if (knowledgeDocument != null) { // if (knowledgeDocument != null) {
...@@ -328,7 +331,7 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic ...@@ -328,7 +331,7 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic
if(hasKbAdmin){ if(hasKbAdmin){
AiKnowledgeDO aiKnowledgeDO = knowledgeService.getKnowledge(document.getKnowledgeId()); AiKnowledgeDO aiKnowledgeDO = knowledgeService.getKnowledge(document.getKnowledgeId());
String permission = aiKnowledgeDO.getEmbeddingModel(); String permission = aiKnowledgeDO.getEmbeddingModel();
if(Objects.equals(permission, "owner_kb")){ if(Objects.equals(permission, "owner_kb") && !Objects.equals(document.getCreator(), userId.toString())){
throw exception(KNOWLEDGE_NO_AUTH); throw exception(KNOWLEDGE_NO_AUTH);
} }
} else if (!Objects.equals(document.getCreator(), userId.toString())) { } else if (!Objects.equals(document.getCreator(), userId.toString())) {
......
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 sign in to comment