Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
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
fangxinjiang
yifu-mvp
Commits
6f0d8f51
Commit
6f0d8f51
authored
Jun 14, 2022
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增代码平台服务
parent
40bf2b76
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
16 deletions
+22
-16
GenDsConfController.java
....plus.v1/yifu/codegen/controller/GenDsConfController.java
+2
-2
GenDatasourceConfService.java
...lus.v1/yifu/codegen/service/GenDatasourceConfService.java
+4
-3
GenDatasourceConfServiceImpl.java
...fu/codegen/service/impl/GenDatasourceConfServiceImpl.java
+16
-11
No files found.
yifu-visual/yifu-codegen/src/main/java/com/yifu.cloud.plus.v1/yifu/codegen/controller/GenDsConfController.java
View file @
6f0d8f51
...
...
@@ -82,7 +82,7 @@ public class GenDsConfController {
@SysLog
(
"新增数据源表"
)
@PostMapping
public
R
<
Boolean
>
save
(
@RequestBody
GenDatasourceConf
datasourceConf
)
{
return
R
.
ok
(
datasourceConfService
.
saveDsByEnc
(
datasourceConf
)
);
return
datasourceConfService
.
saveDsByEnc
(
datasourceConf
);
}
/**
...
...
@@ -93,7 +93,7 @@ public class GenDsConfController {
@SysLog
(
"修改数据源表"
)
@PutMapping
public
R
<
Boolean
>
updateById
(
@RequestBody
GenDatasourceConf
conf
)
{
return
R
.
ok
(
datasourceConfService
.
updateDsByEnc
(
conf
)
);
return
datasourceConfService
.
updateDsByEnc
(
conf
);
}
/**
...
...
yifu-visual/yifu-codegen/src/main/java/com/yifu.cloud.plus.v1/yifu/codegen/service/GenDatasourceConfService.java
View file @
6f0d8f51
...
...
@@ -17,6 +17,7 @@ package com.yifu.cloud.plus.v1.yifu.codegen.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.yifu.cloud.plus.v1.yifu.codegen.entity.GenDatasourceConf
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
/**
* 数据源表
...
...
@@ -31,14 +32,14 @@ public interface GenDatasourceConfService extends IService<GenDatasourceConf> {
* @param genDatasourceConf
* @return
*/
Boolean
saveDsByEnc
(
GenDatasourceConf
genDatasourceConf
);
R
<
Boolean
>
saveDsByEnc
(
GenDatasourceConf
genDatasourceConf
);
/**
* 更新数据源
* @param genDatasourceConf
* @return
*/
Boolean
updateDsByEnc
(
GenDatasourceConf
genDatasourceConf
);
R
<
Boolean
>
updateDsByEnc
(
GenDatasourceConf
genDatasourceConf
);
/**
* 更新动态数据的数据源列表
...
...
@@ -52,7 +53,7 @@ public interface GenDatasourceConfService extends IService<GenDatasourceConf> {
* @param datasourceConf 数据源信息
* @return 有效/无效
*/
Boolean
checkDataSource
(
GenDatasourceConf
datasourceConf
);
String
checkDataSource
(
GenDatasourceConf
datasourceConf
);
/**
* 通过数据源名称删除
...
...
yifu-visual/yifu-codegen/src/main/java/com/yifu.cloud.plus.v1/yifu/codegen/service/impl/GenDatasourceConfServiceImpl.java
View file @
6f0d8f51
...
...
@@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
com.yifu.cloud.plus.v1.yifu.codegen.entity.GenDatasourceConf
;
import
com.yifu.cloud.plus.v1.yifu.codegen.mapper.GenDatasourceConfMapper
;
import
com.yifu.cloud.plus.v1.yifu.codegen.service.GenDatasourceConfService
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.SpringContextHolder
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -55,10 +57,11 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
* @return
*/
@Override
public
Boolean
saveDsByEnc
(
GenDatasourceConf
conf
)
{
public
R
<
Boolean
>
saveDsByEnc
(
GenDatasourceConf
conf
)
{
String
checkOut
=
checkDataSource
(
conf
);
// 校验配置合法性
if
(
!
checkDataSource
(
conf
))
{
return
Boolean
.
FALSE
;
if
(
Common
.
isNotNull
(
checkOut
))
{
return
R
.
failed
(
false
,
checkOut
)
;
}
// 添加动态数据源
...
...
@@ -67,7 +70,7 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
// 更新数据库配置
conf
.
setPassword
(
stringEncryptor
.
encrypt
(
conf
.
getPassword
()));
this
.
baseMapper
.
insert
(
conf
);
return
Boolean
.
TRUE
;
return
R
.
ok
(
true
)
;
}
/**
...
...
@@ -76,9 +79,11 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
* @return
*/
@Override
public
Boolean
updateDsByEnc
(
GenDatasourceConf
conf
)
{
if
(!
checkDataSource
(
conf
))
{
return
Boolean
.
FALSE
;
public
R
<
Boolean
>
updateDsByEnc
(
GenDatasourceConf
conf
)
{
String
checkOut
=
checkDataSource
(
conf
);
// 校验配置合法性
if
(
Common
.
isNotNull
(
checkOut
))
{
return
R
.
failed
(
false
,
checkOut
);
}
// 先移除
SpringContextHolder
.
getBean
(
DynamicRoutingDataSource
.
class
)
...
...
@@ -92,7 +97,7 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
conf
.
setPassword
(
stringEncryptor
.
encrypt
(
conf
.
getPassword
()));
}
this
.
baseMapper
.
updateById
(
conf
);
return
Boolean
.
TRUE
;
return
R
.
ok
(
true
)
;
}
/**
...
...
@@ -131,15 +136,15 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
* @return 有效/无效
*/
@Override
public
Boolean
checkDataSource
(
GenDatasourceConf
conf
)
{
public
String
checkDataSource
(
GenDatasourceConf
conf
)
{
try
{
DriverManager
.
getConnection
(
conf
.
getUrl
(),
conf
.
getUsername
(),
conf
.
getPassword
());
}
catch
(
SQLException
e
)
{
log
.
error
(
"数据源配置 {} , 获取链接失败"
,
conf
.
getName
(),
e
);
return
Boolean
.
FALSE
;
return
"数据源配置 {} , 获取链接失败"
+
conf
.
getName
()
;
}
return
Boolean
.
TRUE
;
return
null
;
}
}
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