| | |
| | | import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | |
| | | |
| | | /** |
| | | * 代码生成 操作处理 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:query')") |
| | | @GetMapping(value = "/{tableId}") |
| | | public AjaxResult getInfo(@PathVariable Long tableId) |
| | | public Result getInfo(@PathVariable Long tableId) |
| | | { |
| | | GenTable table = genTableService.selectGenTableById(tableId); |
| | | List<GenTable> tables = genTableService.selectGenTableAll(); |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:import')") |
| | | @Log(title = "代码生成", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/importTable") |
| | | public AjaxResult importTableSave(String tables) |
| | | public Result importTableSave(String tables) |
| | | { |
| | | String[] tableNames = Convert.toStrArray(tables); |
| | | // 查询表信息 |
| | |
| | | @PreAuthorize("@ss.hasRole('admin')") |
| | | @Log(title = "创建表", businessType = BusinessType.OTHER) |
| | | @PostMapping("/createTable") |
| | | public AjaxResult createTableSave(String sql) |
| | | public Result createTableSave(String sql) |
| | | { |
| | | try |
| | | { |
| | |
| | | List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()])); |
| | | String operName = SecurityUtils.getUsername(); |
| | | genTableService.importGenTable(tableList, operName); |
| | | return AjaxResult.success(); |
| | | return Result.success(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | return AjaxResult.error("创建表结构异常"); |
| | | return Result.error("创建表结构异常"); |
| | | } |
| | | } |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |
| | | @Log(title = "代码生成", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult editSave(@Validated @RequestBody GenTable genTable) |
| | | public Result editSave(@Validated @RequestBody GenTable genTable) |
| | | { |
| | | genTableService.validateEdit(genTable); |
| | | genTableService.updateGenTable(genTable); |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:remove')") |
| | | @Log(title = "代码生成", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{tableIds}") |
| | | public AjaxResult remove(@PathVariable Long[] tableIds) |
| | | public Result remove(@PathVariable Long[] tableIds) |
| | | { |
| | | genTableService.deleteGenTableByIds(tableIds); |
| | | return success(); |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:preview')") |
| | | @GetMapping("/preview/{tableId}") |
| | | public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException |
| | | public Result preview(@PathVariable("tableId") Long tableId) throws IOException |
| | | { |
| | | Map<String, String> dataMap = genTableService.previewCode(tableId); |
| | | return success(dataMap); |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:code')") |
| | | @Log(title = "代码生成", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/genCode/{tableName}") |
| | | public AjaxResult genCode(@PathVariable("tableName") String tableName) |
| | | public Result genCode(@PathVariable("tableName") String tableName) |
| | | { |
| | | if (!GenConfig.isAllowOverwrite()) |
| | | { |
| | | return AjaxResult.error("【系统预设】不允许生成文件覆盖到本地"); |
| | | return Result.error("【系统预设】不允许生成文件覆盖到本地"); |
| | | } |
| | | genTableService.generatorCode(tableName); |
| | | return success(); |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |
| | | @Log(title = "代码生成", businessType = BusinessType.UPDATE) |
| | | @GetMapping("/synchDb/{tableName}") |
| | | public AjaxResult synchDb(@PathVariable("tableName") String tableName) |
| | | public Result synchDb(@PathVariable("tableName") String tableName) |
| | | { |
| | | genTableService.synchDb(tableName); |
| | | return success(); |
| | |
| | | response.setContentType("application/octet-stream; charset=UTF-8"); |
| | | IOUtils.write(data, response.getOutputStream()); |
| | | } |
| | | } |
| | | } |