Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poc
poc-api
Commits
ce52568b
Commit
ce52568b
authored
Apr 29, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: database数据表查询
parent
4652b4fc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
12 deletions
+111
-12
BizAgentApplicationInfoServiceImpl.java
...tion/service/impl/BizAgentApplicationInfoServiceImpl.java
+1
-3
BizAgentApplicationPublishServiceImpl.java
...n/service/impl/BizAgentApplicationPublishServiceImpl.java
+1
-3
DatabaseUtil.java
src/main/java/cn/com/poc/common/utils/DatabaseUtil.java
+1
-2
DatabaseTableInfoCache.java
...va/cn/com/poc/knowledge/cache/DatabaseTableInfoCache.java
+37
-0
BizKnowledgeDatabaseDto.java
...ava/cn/com/poc/knowledge/dto/BizKnowledgeDatabaseDto.java
+19
-0
DatabaseRestImpl.java
...java/cn/com/poc/knowledge/rest/impl/DatabaseRestImpl.java
+52
-4
No files found.
src/main/java/cn/com/poc/agent_application/service/impl/BizAgentApplicationInfoServiceImpl.java
View file @
ce52568b
...
...
@@ -226,9 +226,7 @@ public class BizAgentApplicationInfoServiceImpl extends BaseServiceImpl
model
.
setContinuousQuestionStatus
(
entity
.
getContinuousQuestionStatus
());
model
.
setContinuousQuestionSystem
(
entity
.
getContinuousQuestionSystem
());
model
.
setKnowledgeIds
(
JsonUtils
.
serialize
(
entity
.
getKnowledgeIds
()));
if
(
ArrayUtils
.
isNotEmpty
(
entity
.
getKnowledgeDatabaseIds
())){
model
.
setKnowledgeDatabaseIds
(
JsonUtils
.
serialize
(
entity
.
getKnowledgeDatabaseIds
()));
}
model
.
setKnowledgeDatabaseIds
(
JsonUtils
.
serialize
(
entity
.
getKnowledgeDatabaseIds
()));
if
(
StringUtils
.
isNotBlank
(
entity
.
getKnowledgeSearchType
()))
{
model
.
setKnowledgeSearchType
(
entity
.
getKnowledgeSearchType
());
}
...
...
src/main/java/cn/com/poc/agent_application/service/impl/BizAgentApplicationPublishServiceImpl.java
View file @
ce52568b
...
...
@@ -182,9 +182,7 @@ public class BizAgentApplicationPublishServiceImpl extends BaseServiceImpl
if
(
ArrayUtils
.
isNotEmpty
(
entity
.
getKnowledgeIds
()))
{
model
.
setKnowledgeIds
(
JsonUtils
.
serialize
(
entity
.
getKnowledgeIds
()));
}
if
(
ArrayUtils
.
isNotEmpty
(
entity
.
getKnowledgeDatabaseIds
())){
model
.
setKnowledgeDatabaseIds
(
JsonUtils
.
serialize
(
entity
.
getKnowledgeDatabaseIds
()));
}
model
.
setKnowledgeDatabaseIds
(
JsonUtils
.
serialize
(
entity
.
getKnowledgeDatabaseIds
()));
if
(
StringUtils
.
isNotBlank
(
entity
.
getKnowledgeSearchType
()))
{
model
.
setKnowledgeSearchType
(
entity
.
getKnowledgeSearchType
());
}
...
...
src/main/java/cn/com/poc/common/utils/DatabaseUtil.java
View file @
ce52568b
...
...
@@ -76,11 +76,10 @@ public class DatabaseUtil {
tableInfo
.
setTABLE_COLUMN
(
resultSet
.
getInt
(
"TABLE_COLUMN"
));
tableInfoList
.
add
(
tableInfo
);
}
System
.
out
.
println
(
tableInfoList
);
return
tableInfoList
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"连接数据库失败"
,
e
);
throw
new
BusinessException
(
"连接数据库失败"
)
;
return
null
;
}
}
...
...
src/main/java/cn/com/poc/knowledge/cache/DatabaseTableInfoCache.java
0 → 100644
View file @
ce52568b
package
cn
.
com
.
poc
.
knowledge
.
cache
;
import
cn.com.poc.common.service.RedisService
;
import
cn.com.poc.common.utils.DatabaseUtil
;
import
cn.com.poc.common.utils.SpringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
/**
* @author alex.yao
* @date 2025/4/29
*/
public
class
DatabaseTableInfoCache
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
DatabaseTableInfoCache
.
class
);
private
static
final
String
prefix
=
"KNOWLEDGE_DATABASE_TABLE_INFO:"
;
private
static
Long
expireTime
=
30
*
24
*
60
*
60L
;
public
static
boolean
updateOrSaveCache
(
int
id
,
List
<
DatabaseUtil
.
TableInfo
>
tableInfos
)
{
logger
.
info
(
"updateOrSaveCache id:{},tableInfos:{}"
,
id
,
tableInfos
);
RedisService
redisService
=
SpringUtils
.
getBean
(
RedisService
.
class
);
return
redisService
.
set
(
prefix
+
id
,
tableInfos
,
expireTime
);
}
public
static
List
<
DatabaseUtil
.
TableInfo
>
getCache
(
int
id
)
{
RedisService
redisService
=
SpringUtils
.
getBean
(
RedisService
.
class
);
if
(
redisService
.
hasKey
(
prefix
+
id
))
{
return
(
List
<
DatabaseUtil
.
TableInfo
>)
redisService
.
get
(
prefix
+
id
);
}
return
null
;
}
}
src/main/java/cn/com/poc/knowledge/dto/BizKnowledgeDatabaseDto.java
View file @
ce52568b
package
cn
.
com
.
poc
.
knowledge
.
dto
;
import
cn.com.poc.common.utils.DatabaseUtil
;
import
java.util.List
;
public
class
BizKnowledgeDatabaseDto
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -157,4 +161,19 @@ public class BizKnowledgeDatabaseDto {
public
void
setModifiedTime
(
java
.
util
.
Date
modifiedTime
)
{
this
.
modifiedTime
=
modifiedTime
;
}
/**
* tableInfos
* 数据库表信息
*/
private
List
<
DatabaseUtil
.
TableInfo
>
tableInfos
;
public
List
<
DatabaseUtil
.
TableInfo
>
getTableInfos
()
{
return
tableInfos
;
}
public
void
setTableInfos
(
List
<
DatabaseUtil
.
TableInfo
>
tableInfos
)
{
this
.
tableInfos
=
tableInfos
;
}
}
\ No newline at end of file
src/main/java/cn/com/poc/knowledge/rest/impl/DatabaseRestImpl.java
View file @
ce52568b
...
...
@@ -4,6 +4,7 @@ import cn.com.poc.common.utils.Assert;
import
cn.com.poc.common.utils.BlContext
;
import
cn.com.poc.common.utils.DatabaseUtil
;
import
cn.com.poc.common.utils.StringUtils
;
import
cn.com.poc.knowledge.cache.DatabaseTableInfoCache
;
import
cn.com.poc.knowledge.convert.BizKnowledgeDatabaseConvert
;
import
cn.com.poc.knowledge.dto.BizDatabaseTableInfoDto
;
import
cn.com.poc.knowledge.dto.BizKnowledgeDatabaseDto
;
...
...
@@ -42,7 +43,11 @@ public class DatabaseRestImpl implements DatabaseRest {
Assert
.
notBlank
(
dto
.
getDbName
(),
"Database Name must not be blank"
);
Assert
.
notBlank
(
dto
.
getDbUsername
(),
"Database Username must not be blank"
);
Assert
.
notBlank
(
dto
.
getDbPassword
(),
"Database Password must not be blank"
);
boolean
connect
=
DatabaseUtil
.
testConnect
(
dto
.
getDbHost
(),
dto
.
getDbPort
(),
dto
.
getDbUsername
(),
dto
.
getDbPassword
(),
dto
.
getDbName
());
List
<
DatabaseUtil
.
TableInfo
>
tableInfos
=
DatabaseUtil
.
getTableInfo
(
dto
.
getDbHost
(),
dto
.
getDbPort
(),
dto
.
getDbUsername
(),
dto
.
getDbPassword
(),
dto
.
getDbName
());
if
(!
connect
||
tableInfos
==
null
)
{
throw
new
BusinessException
(
"Database connection failed"
);
}
UserBaseEntity
userBaseEntity
=
BlContext
.
getCurrentUserNotException
();
Long
userId
=
userBaseEntity
.
getUserId
();
BizKnowledgeDatabaseEntity
bizKnowledgeDatabaseEntity
=
BizKnowledgeDatabaseConvert
.
dtoToEntity
(
dto
);
...
...
@@ -51,7 +56,7 @@ public class DatabaseRestImpl implements DatabaseRest {
if
(
saveEntity
==
null
)
{
throw
new
BusinessException
(
"create database error"
);
}
DatabaseTableInfoCache
.
updateOrSaveCache
(
saveEntity
.
getId
().
intValue
(),
tableInfos
);
return
BizKnowledgeDatabaseConvert
.
entityToDto
(
saveEntity
);
}
...
...
@@ -78,7 +83,21 @@ public class DatabaseRestImpl implements DatabaseRest {
if
(
bizKnowledgeDatabaseEntity
==
null
&&
!
bizKnowledgeDatabaseEntity
.
getMemberId
().
equals
(
userId
.
intValue
()))
{
throw
new
BusinessException
(
"no database found"
);
}
return
BizKnowledgeDatabaseConvert
.
entityToDto
(
bizKnowledgeDatabaseEntity
);
BizKnowledgeDatabaseDto
bizKnowledgeDatabaseDto
=
BizKnowledgeDatabaseConvert
.
entityToDto
(
bizKnowledgeDatabaseEntity
);
//获取表信息
List
<
DatabaseUtil
.
TableInfo
>
tableInfos
=
DatabaseTableInfoCache
.
getCache
(
id
);
if
(
tableInfos
==
null
)
{
tableInfos
=
DatabaseUtil
.
getTableInfo
(
bizKnowledgeDatabaseEntity
.
getDbHost
(),
bizKnowledgeDatabaseEntity
.
getDbPort
(),
bizKnowledgeDatabaseEntity
.
getDbUsername
(),
bizKnowledgeDatabaseEntity
.
getDbPassword
(),
bizKnowledgeDatabaseEntity
.
getDbName
());
if
(
tableInfos
==
null
)
{
throw
new
BusinessException
(
"connection database error"
);
}
}
bizKnowledgeDatabaseDto
.
setTableInfos
(
tableInfos
);
return
bizKnowledgeDatabaseDto
;
}
@Override
...
...
@@ -92,7 +111,21 @@ public class DatabaseRestImpl implements DatabaseRest {
if
(
bizKnowledgeDatabaseEntity
==
null
&&
!
bizKnowledgeDatabaseEntity
.
getMemberId
().
equals
(
userId
.
intValue
()))
{
continue
;
}
result
.
add
(
BizKnowledgeDatabaseConvert
.
entityToDto
(
bizKnowledgeDatabaseEntity
));
BizKnowledgeDatabaseDto
bizKnowledgeDatabaseDto
=
BizKnowledgeDatabaseConvert
.
entityToDto
(
bizKnowledgeDatabaseEntity
);
//获取表信息
List
<
DatabaseUtil
.
TableInfo
>
tableInfos
=
DatabaseTableInfoCache
.
getCache
(
id
);
if
(
tableInfos
==
null
)
{
tableInfos
=
DatabaseUtil
.
getTableInfo
(
bizKnowledgeDatabaseEntity
.
getDbHost
(),
bizKnowledgeDatabaseEntity
.
getDbPort
(),
bizKnowledgeDatabaseEntity
.
getDbUsername
(),
bizKnowledgeDatabaseEntity
.
getDbPassword
(),
bizKnowledgeDatabaseEntity
.
getDbName
());
if
(
tableInfos
==
null
)
{
continue
;
}
}
bizKnowledgeDatabaseDto
.
setTableInfos
(
tableInfos
);
result
.
add
(
bizKnowledgeDatabaseDto
);
}
return
result
;
}
...
...
@@ -134,11 +167,25 @@ public class DatabaseRestImpl implements DatabaseRest {
public
BizKnowledgeDatabaseDto
update
(
BizKnowledgeDatabaseDto
dto
)
{
Assert
.
notNull
(
dto
,
"response can not be null"
);
Assert
.
notNull
(
dto
.
getId
(),
"id can not be null"
);
boolean
connect
=
DatabaseUtil
.
testConnect
(
dto
.
getDbHost
(),
dto
.
getDbPort
(),
dto
.
getDbUsername
(),
dto
.
getDbPassword
(),
dto
.
getDbName
());
List
<
DatabaseUtil
.
TableInfo
>
tableInfos
=
DatabaseUtil
.
getTableInfo
(
dto
.
getDbHost
(),
dto
.
getDbPort
(),
dto
.
getDbUsername
(),
dto
.
getDbPassword
(),
dto
.
getDbName
());
if
(!
connect
||
tableInfos
==
null
)
{
throw
new
BusinessException
(
"Database connection failed"
);
}
BizKnowledgeDatabaseEntity
bizKnowledgeDatabaseEntity
=
BizKnowledgeDatabaseConvert
.
dtoToEntity
(
dto
);
BizKnowledgeDatabaseEntity
updateEntity
=
bizKnowledgeDatabaseService
.
update
(
bizKnowledgeDatabaseEntity
);
if
(
updateEntity
==
null
)
{
throw
new
BusinessException
(
"update database info error"
);
}
DatabaseTableInfoCache
.
updateOrSaveCache
(
updateEntity
.
getId
().
intValue
(),
tableInfos
);
return
BizKnowledgeDatabaseConvert
.
entityToDto
(
updateEntity
);
}
...
...
@@ -160,6 +207,7 @@ public class DatabaseRestImpl implements DatabaseRest {
if
(
CollectionUtils
.
isEmpty
(
tableInfos
))
{
throw
new
BusinessException
(
"connection database error"
);
}
DatabaseTableInfoCache
.
updateOrSaveCache
(
id
,
tableInfos
);
return
tableInfos
.
stream
().
map
(
info
->
{
BizDatabaseTableInfoDto
dto
=
new
BizDatabaseTableInfoDto
();
dto
.
setTableName
(
info
.
getTABLE_NAME
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment