代码生成支持同步数据库

pull/24/head
RuoYi 4 years ago
parent 5d1701fd69
commit f4f89f9de6

@ -164,12 +164,24 @@ public class GenController extends BaseController
@PreAuthorize(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(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();
}
/**
*
*/

@ -42,6 +42,14 @@ public interface GenTableColumnMapper
*/
public int updateGenTableColumn(GenTableColumn genTableColumn);
/**
*
*
* @param genTableColumns
* @return
*/
public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
/**
*
*

@ -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;
@ -223,7 +224,6 @@ public class GenTableServiceImpl implements IGenTableService
*
*
* @param tableName
* @return
*/
@Override
public void generatorCode(String tableName)
@ -261,6 +261,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);
}
}
/**
*
*

@ -90,6 +90,13 @@ public interface IGenTableService
*/
public void generatorCode(String tableName);
/**
*
*
* @param tableName
*/
public void synchDb(String tableName);
/**
*
*

@ -117,4 +117,11 @@ 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>

@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
<if test="deptId != null and deptId != 0">
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE FIND_IN_SET (#{deptId},ancestors) ))
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
</if>
<!-- 数据范围过滤 -->
${params.dataScope}

@ -66,3 +66,11 @@ export function genCode(tableName) {
method: 'get'
})
}
// 同步数据库
export function synchDb(tableName) {
return request({
url: '/code/gen/synchDb/' + tableName,
method: 'get'
})
}

@ -135,6 +135,13 @@
<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"
icon="el-icon-download"
@click="handleGenTable(scope.row)"
v-hasPermi="['tool:gen:code']"
@ -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("/code/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();

Loading…
Cancel
Save