@@ -36,17 +36,9 @@ func (l *CodebaseTreeLogic) GetCodebaseTree(req *types.CodebaseTreeRequest) (*ty
3636 }
3737 log .Printf ("[DEBUG] 参数验证通过" )
3838
39- // 权限验证
40- codebaseId , err := l .verifyCodebasePermission (req )
41- if err != nil {
42- log .Printf ("[DEBUG] 权限验证失败: %v" , err )
43- return nil , errs .FileNotFound
44- }
45- log .Printf ("[DEBUG] 权限验证通过,获得 codebaseId: %d" , codebaseId )
46-
4739 // 构建目录树
4840 log .Printf ("[DEBUG] 开始构建目录树..." )
49- tree , err := l .buildDirectoryTree (codebaseId , req )
41+ tree , err := l .buildDirectoryTree (req . ClientId , req )
5042 if err != nil {
5143 log .Printf ("[DEBUG] 构建目录树失败: %v" , err )
5244 return nil , fmt .Errorf ("构建目录树失败: %w" , err )
@@ -87,40 +79,6 @@ func (l *CodebaseTreeLogic) validateRequest(req *types.CodebaseTreeRequest) erro
8779 return nil
8880}
8981
90- func (l * CodebaseTreeLogic ) verifyCodebasePermission (req * types.CodebaseTreeRequest ) (int32 , error ) {
91- // 添加调试日志
92- log .Printf ("[DEBUG] verifyCodebasePermission - 开始权限验证" )
93- log .Printf ("[DEBUG] verifyCodebasePermission - ClientId: %s" , req .ClientId )
94- log .Printf ("[DEBUG] verifyCodebasePermission - CodebasePath: %s" , req .CodebasePath )
95- log .Printf ("[DEBUG] verifyCodebasePermission - CodebaseName: %s" , req .CodebaseName )
96-
97- // 检查是否应该根据 ClientId 和 CodebasePath 从数据库查询真实的 codebaseId
98- log .Printf ("[DEBUG] verifyCodebasePermission - 检查数据库中是否存在匹配的 codebase 记录" )
99-
100- // 尝试根据 ClientId 和 CodebasePath 查询真实的 codebase
101- codebase , err := l .svcCtx .Querier .Codebase .WithContext (l .ctx ).
102- Where (l .svcCtx .Querier .Codebase .ClientID .Eq (req .ClientId )).
103- Where (l .svcCtx .Querier .Codebase .ClientPath .Eq (req .CodebasePath )).
104- First ()
105-
106- if err != nil {
107- log .Printf ("[DEBUG] verifyCodebasePermission - 数据库查询失败或未找到匹配记录: %v" , err )
108- log .Printf ("[DEBUG] verifyCodebasePermission - 将使用模拟的 codebaseId: 1" )
109- // 这里应该实现实际的权限验证逻辑
110- // 由于是MVP版本,我们暂时返回一个模拟的ID
111- codebaseId := int32 (1 )
112- log .Printf ("[DEBUG] verifyCodebasePermission - 返回模拟 codebaseId: %d" , codebaseId )
113- return codebaseId , nil
114- }
115-
116- log .Printf ("[DEBUG] verifyCodebasePermission - 找到匹配的 codebase 记录" )
117- log .Printf ("[DEBUG] verifyCodebasePermission - 数据库记录 ID: %d, Name: %s, Status: %s" ,
118- codebase .ID , codebase .Name , codebase .Status )
119-
120- log .Printf ("[DEBUG] verifyCodebasePermission - 返回真实的 codebaseId: %d" , codebase .ID )
121- return codebase .ID , nil
122- }
123-
12482// printTreeStructure 递归打印树结构
12583func (l * CodebaseTreeLogic ) printTreeStructure (tree * types.TreeNode ) {
12684 // 递归打印树结构
@@ -138,15 +96,12 @@ func (l *CodebaseTreeLogic) printTreeStructure(tree *types.TreeNode) {
13896 printTree (tree , "" )
13997}
14098
141- func (l * CodebaseTreeLogic ) buildDirectoryTree (codebaseId int32 , req * types.CodebaseTreeRequest ) (* types.TreeNode , error ) {
99+ func (l * CodebaseTreeLogic ) buildDirectoryTree (clientId string , req * types.CodebaseTreeRequest ) (* types.TreeNode , error ) {
142100 log .Printf ("[DEBUG] ===== buildDirectoryTree 开始执行 =====" )
143- log .Printf ("[DEBUG] 输入参数: codebaseId=%d, codebasePath=%s" , codebaseId , req .CodebasePath )
144-
145- // 检查数据库中是否存在该 codebaseId
146- l .checkCodebaseInDatabase (codebaseId )
101+ log .Printf ("[DEBUG] 输入参数: clientId=%s, codebasePath=%s" , clientId , req .CodebasePath )
147102
148103 // 从向量存储中获取文件路径
149- records , err := l .getRecordsFromVectorStore (codebaseId , req .CodebasePath )
104+ records , err := l .getRecordsFromVectorStore (clientId , req .CodebasePath )
150105 if err != nil {
151106 return nil , err
152107 }
@@ -191,18 +146,18 @@ func (l *CodebaseTreeLogic) checkCodebaseInDatabase(codebaseId int32) {
191146}
192147
193148// getRecordsFromVectorStore 从向量存储中获取文件记录
194- func (l * CodebaseTreeLogic ) getRecordsFromVectorStore (codebaseId int32 , codebasePath string ) ([]* types.CodebaseRecord , error ) {
149+ func (l * CodebaseTreeLogic ) getRecordsFromVectorStore (clientId string , codebasePath string ) ([]* types.CodebaseRecord , error ) {
195150 if l .svcCtx .VectorStore == nil {
196151 return nil , fmt .Errorf ("VectorStore 未初始化" )
197152 }
198153
199- records , err := l .svcCtx .VectorStore .GetCodebaseRecords (l .ctx , codebaseId , codebasePath )
154+ records , err := l .svcCtx .VectorStore .GetCodebaseRecords (l .ctx , clientId , codebasePath )
200155 if err != nil {
201156 return nil , fmt .Errorf ("查询文件路径失败: %w" , err )
202157 }
203158
204159 if len (records ) == 0 {
205- l .logEmptyRecordsDiagnostic (codebaseId , codebasePath )
160+ l .logEmptyRecordsDiagnostic (clientId , codebasePath )
206161 }
207162
208163 // 合并相同文件路径的记录
@@ -281,7 +236,7 @@ func (l *CodebaseTreeLogic) mergeSingleFileRecords(records []*types.CodebaseReco
281236}
282237
283238// logEmptyRecordsDiagnostic 记录空记录的诊断信息
284- func (l * CodebaseTreeLogic ) logEmptyRecordsDiagnostic (codebaseId int32 , codebasePath string ) {
239+ func (l * CodebaseTreeLogic ) logEmptyRecordsDiagnostic (clientId string , codebasePath string ) {
285240 // 详细诊断:检查数据库和向量存储的连接状态
286241 log .Printf ("[DEBUG] ===== 深度诊断:数据库和向量存储状态检查 =====" )
287242
@@ -307,7 +262,7 @@ func (l *CodebaseTreeLogic) logEmptyRecordsDiagnostic(codebaseId int32, codebase
307262 log .Printf ("[DEBUG] 3. 尝试查询向量存储中的所有记录..." )
308263 if l .svcCtx .VectorStore != nil {
309264 // 尝试使用一个空的 codebasePath 来获取所有记录
310- allRecords , err := l .svcCtx .VectorStore .GetCodebaseRecords (l .ctx , codebaseId , "" )
265+ allRecords , err := l .svcCtx .VectorStore .GetCodebaseRecords (l .ctx , clientId , "" )
311266 if err != nil {
312267 log .Printf ("[DEBUG] ❌ 查询所有向量存储记录失败: %v" , err )
313268 } else {
@@ -323,7 +278,7 @@ func (l *CodebaseTreeLogic) logEmptyRecordsDiagnostic(codebaseId int32, codebase
323278
324279 // 4. 检查请求参数的详细情况
325280 log .Printf ("[DEBUG] 4. 请求参数详细分析:" )
326- log .Printf ("[DEBUG] codebaseId : %d (类型: %T)" , codebaseId , codebaseId )
281+ log .Printf ("[DEBUG] clientId : %s (类型: %T)" , clientId , clientId )
327282 log .Printf ("[DEBUG] req.CodebasePath: '%s' (长度: %d)" , codebasePath , len (codebasePath ))
328283 log .Printf ("[DEBUG] req.CodebasePath 为空: %v" , codebasePath == "" )
329284 log .Printf ("[DEBUG] req.CodebasePath 为 '.': %v" , codebasePath == "." )
0 commit comments