| | |
| | | @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();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量生成代码
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('tool:gen:code')")
|
| | |
| | | * @return 列信息
|
| | | */
|
| | | public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
| | | |
| | |
|
| | | /**
|
| | | * 查询业务字段列表
|
| | | *
|
| | |
| | | public int updateGenTableColumn(GenTableColumn genTableColumn);
|
| | |
|
| | | /**
|
| | | * 删除业务字段
|
| | | * |
| | | * @param genTableColumns 列数据
|
| | | * @return 结果
|
| | | */
|
| | | public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
|
| | |
|
| | | /**
|
| | | * 批量删除业务字段
|
| | | *
|
| | | * @param ids 需要删除的数据ID
|
| | |
| | | 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;
|
| | |
| | | * 生成代码(自定义路径)
|
| | | *
|
| | | * @param tableName 表名称
|
| | | * @return 数据
|
| | | */
|
| | | @Override
|
| | | public void generatorCode(String tableName)
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 同步数据库
|
| | | * |
| | | * @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);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量生成代码(下载方式)
|
| | | *
|
| | | * @param tableNames 表数组
|
| | |
| | | public void generatorCode(String tableName);
|
| | |
|
| | | /**
|
| | | * 同步数据库
|
| | | * |
| | | * @param tableName 表名称
|
| | | */
|
| | | public void synchDb(String tableName);
|
| | |
|
| | | /**
|
| | | * 批量生成代码(下载方式)
|
| | | *
|
| | | * @param tableNames 表数组
|
| | |
| | | </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> |
| | |
| | | </foreach>
|
| | | </delete>
|
| | |
|
| | | </mapper> |
| | | </mapper> |
| | |
| | | })
|
| | | }
|
| | |
|
| | | // 同步数据库
|
| | | export function synchDb(tableName) {
|
| | | return request({
|
| | | url: '/tool/gen/synchDb/' + tableName,
|
| | | method: 'get'
|
| | | })
|
| | | }
|
| | |
| | | <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']"
|
| | |
| | | </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 {
|
| | |
| | | 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();
|