Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
9e38c7de
Commit
9e38c7de
authored
Sep 18, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码生成支持同步数据库
parent
9ca28d6d
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
96 additions
and
5 deletions
+96
-5
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
...in/java/com/ruoyi/generator/controller/GenController.java
+13
-1
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java
...java/com/ruoyi/generator/mapper/GenTableColumnMapper.java
+9
-1
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
...java/com/ruoyi/generator/service/GenTableServiceImpl.java
+32
-1
ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java
...in/java/com/ruoyi/generator/service/IGenTableService.java
+7
-0
ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
.../main/resources/mapper/generator/GenTableColumnMapper.xml
+6
-0
ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
...or/src/main/resources/mapper/generator/GenTableMapper.xml
+1
-1
ruoyi-ui/src/api/tool/gen.js
ruoyi-ui/src/api/tool/gen.js
+7
-0
ruoyi-ui/src/views/tool/gen/index.vue
ruoyi-ui/src/views/tool/gen/index.vue
+21
-1
No files found.
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
View file @
9e38c7de
...
...
@@ -165,12 +165,24 @@ public class GenController extends BaseController
@PreAuthorize
(
"@ss.hasPermi('tool:gen:code')"
)
@Log
(
title
=
"代码生成"
,
businessType
=
BusinessType
.
GENCODE
)
@GetMapping
(
"/genCode/{tableName}"
)
public
AjaxResult
genCode
(
HttpServletResponse
response
,
@PathVariable
(
"tableName"
)
String
tableName
)
public
AjaxResult
genCode
(
@PathVariable
(
"tableName"
)
String
tableName
)
{
genTableService
.
generatorCode
(
tableName
);
return
AjaxResult
.
success
();
}
/**
* 同步数据库
*/
@PreAuthorize
(
"@ss.hasPermi('tool:gen:edit')"
)
@Log
(
title
=
"代码生成"
,
businessType
=
BusinessType
.
UPDATE
)
@GetMapping
(
"/synchDb/{tableName}"
)
public
AjaxResult
synchDb
(
@PathVariable
(
"tableName"
)
String
tableName
)
{
genTableService
.
synchDb
(
tableName
);
return
AjaxResult
.
success
();
}
/**
* 批量生成代码
*/
...
...
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java
View file @
9e38c7de
...
...
@@ -42,6 +42,14 @@ public interface GenTableColumnMapper
*/
public
int
updateGenTableColumn
(
GenTableColumn
genTableColumn
);
/**
* 删除业务字段
*
* @param genTableColumns 列数据
* @return 结果
*/
public
int
deleteGenTableColumns
(
List
<
GenTableColumn
>
genTableColumns
);
/**
* 批量删除业务字段
*
...
...
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
View file @
9e38c7de
...
...
@@ -7,6 +7,7 @@ import java.io.StringWriter;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
org.apache.commons.io.IOUtils
;
...
...
@@ -224,7 +225,6 @@ public class GenTableServiceImpl implements IGenTableService
* 生成代码(自定义路径)
*
* @param tableName 表名称
* @return 数据
*/
@Override
public
void
generatorCode
(
String
tableName
)
...
...
@@ -262,6 +262,37 @@ public class GenTableServiceImpl implements IGenTableService
}
}
/**
* 同步数据库
*
* @param tableName 表名称
*/
@Override
@Transactional
public
void
synchDb
(
String
tableName
)
{
GenTable
table
=
genTableMapper
.
selectGenTableByName
(
tableName
);
List
<
GenTableColumn
>
tableColumns
=
table
.
getColumns
();
List
<
String
>
tableColumnNames
=
tableColumns
.
stream
().
map
(
GenTableColumn:
:
getColumnName
).
collect
(
Collectors
.
toList
());
List
<
GenTableColumn
>
dbTableColumns
=
genTableColumnMapper
.
selectDbTableColumnsByName
(
tableName
);
List
<
String
>
dbTableColumnNames
=
dbTableColumns
.
stream
().
map
(
GenTableColumn:
:
getColumnName
).
collect
(
Collectors
.
toList
());
dbTableColumns
.
forEach
(
column
->
{
if
(!
tableColumnNames
.
contains
(
column
.
getColumnName
()))
{
GenUtils
.
initColumnField
(
column
,
table
);
genTableColumnMapper
.
insertGenTableColumn
(
column
);
}
});
List
<
GenTableColumn
>
delColumns
=
tableColumns
.
stream
().
filter
(
column
->
!
dbTableColumnNames
.
contains
(
column
.
getColumnName
())).
collect
(
Collectors
.
toList
());
if
(
StringUtils
.
isNotEmpty
(
delColumns
))
{
genTableColumnMapper
.
deleteGenTableColumns
(
delColumns
);
}
}
/**
* 批量生成代码(下载方式)
*
...
...
ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java
View file @
9e38c7de
...
...
@@ -90,6 +90,13 @@ public interface IGenTableService
*/
public
void
generatorCode
(
String
tableName
);
/**
* 同步数据库
*
* @param tableName 表名称
*/
public
void
synchDb
(
String
tableName
);
/**
* 批量生成代码(下载方式)
*
...
...
ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
View file @
9e38c7de
...
...
@@ -117,4 +117,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<delete
id=
"deleteGenTableColumns"
>
delete from gen_table_column where column_id in
<foreach
collection=
"list"
item=
"item"
open=
"("
separator=
","
close=
")"
>
#{item.columnId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
View file @
9e38c7de
ruoyi-ui/src/api/tool/gen.js
View file @
9e38c7de
...
...
@@ -67,3 +67,10 @@ export function genCode(tableName) {
})
}
// 同步数据库
export
function
synchDb
(
tableName
)
{
return
request
({
url
:
'
/tool/gen/synchDb/
'
+
tableName
,
method
:
'
get
'
})
}
ruoyi-ui/src/views/tool/gen/index.vue
View file @
9e38c7de
...
...
@@ -132,6 +132,13 @@
@
click=
"handleDelete(scope.row)"
v-hasPermi=
"['tool:gen:remove']"
>
删除
</el-button>
<el-button
type=
"text"
size=
"small"
icon=
"el-icon-refresh"
@
click=
"handleSynchDb(scope.row)"
v-hasPermi=
"['tool:gen:edit']"
>
同步
</el-button>
<el-button
type=
"text"
size=
"small"
...
...
@@ -167,7 +174,7 @@
</template>
<
script
>
import
{
listTable
,
previewTable
,
delTable
,
genCode
}
from
"
@/api/tool/gen
"
;
import
{
listTable
,
previewTable
,
delTable
,
genCode
,
synchDb
}
from
"
@/api/tool/gen
"
;
import
importTable
from
"
./importTable
"
;
import
{
downLoadZip
}
from
"
@/utils/zipdownload
"
;
export
default
{
...
...
@@ -252,6 +259,19 @@ export default {
downLoadZip
(
"
/tool/gen/batchGenCode?tables=
"
+
tableNames
,
"
ruoyi
"
);
}
},
/** 同步数据库操作 */
handleSynchDb
(
row
)
{
const
tableName
=
row
.
tableName
;
this
.
$confirm
(
'
确认要强制同步"
'
+
tableName
+
'
"表结构吗?
'
,
"
警告
"
,
{
confirmButtonText
:
"
确定
"
,
cancelButtonText
:
"
取消
"
,
type
:
"
warning
"
}).
then
(
function
()
{
return
synchDb
(
tableName
);
}).
then
(()
=>
{
this
.
msgSuccess
(
"
同步成功
"
);
}).
catch
(
function
()
{});
},
/** 打开导入表弹窗 */
openImportTable
()
{
this
.
$refs
.
import
.
show
();
...
...
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