| | |
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| | | import com.ruoyi.framework.config.GenConfig; |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.page.TableDataInfo; |
| | | import com.ruoyi.project.tool.gen.domain.GenTable; |
| | | import com.ruoyi.project.tool.gen.domain.GenTableColumn; |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:query')") |
| | | @GetMapping(value = "/{talbleId}") |
| | | public R<?> getInfo(@PathVariable Long talbleId) |
| | | public AjaxResult getInfo(@PathVariable Long talbleId) |
| | | { |
| | | GenTable table = genTableService.selectGenTableById(talbleId); |
| | | List<GenTable> tables = genTableService.selectGenTableAll(); |
| | |
| | | map.put("info", table); |
| | | map.put("rows", list); |
| | | map.put("tables", tables); |
| | | return R.ok(map); |
| | | return success(map); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:import')") |
| | | @Log(title = "代码生成", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/importTable") |
| | | public R<?> importTableSave(String tables) |
| | | public AjaxResult importTableSave(String tables) |
| | | { |
| | | String[] tableNames = Convert.toStrArray(tables); |
| | | // 查询表信息 |
| | | List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); |
| | | genTableService.importGenTable(tableList, SecurityUtils.getUsername()); |
| | | return R.ok(); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasRole('admin')") |
| | | @Log(title = "创建表", businessType = BusinessType.OTHER) |
| | | @PostMapping("/createTable") |
| | | public R<?> createTableSave(String sql) |
| | | public AjaxResult createTableSave(String sql) |
| | | { |
| | | try |
| | | { |
| | |
| | | List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()])); |
| | | String operName = SecurityUtils.getUsername(); |
| | | genTableService.importGenTable(tableList, operName); |
| | | return R.ok(); |
| | | return AjaxResult.success(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.error(e.getMessage(), e); |
| | | return R.fail("创建表结构异常"); |
| | | return AjaxResult.error("创建表结构异常"); |
| | | } |
| | | } |
| | | |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |
| | | @Log(title = "代码生成", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public R<?> editSave(@Validated @RequestBody GenTable genTable) |
| | | public AjaxResult editSave(@Validated @RequestBody GenTable genTable) |
| | | { |
| | | genTableService.validateEdit(genTable); |
| | | genTableService.updateGenTable(genTable); |
| | | return R.ok(); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:remove')") |
| | | @Log(title = "代码生成", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{tableIds}") |
| | | public R<?> remove(@PathVariable Long[] tableIds) |
| | | public AjaxResult remove(@PathVariable Long[] tableIds) |
| | | { |
| | | genTableService.deleteGenTableByIds(tableIds); |
| | | return R.ok(); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:preview')") |
| | | @GetMapping("/preview/{tableId}") |
| | | public R<?> preview(@PathVariable("tableId") Long tableId) throws IOException |
| | | public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException |
| | | { |
| | | Map<String, String> dataMap = genTableService.previewCode(tableId); |
| | | return R.ok(dataMap); |
| | | return success(dataMap); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:code')") |
| | | @Log(title = "代码生成", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/genCode/{tableName}") |
| | | public R<?> genCode(@PathVariable("tableName") String tableName) |
| | | public AjaxResult genCode(@PathVariable("tableName") String tableName) |
| | | { |
| | | if (!GenConfig.isAllowOverwrite()) |
| | | { |
| | | return R.fail("【系统预设】不允许生成文件覆盖到本地"); |
| | | return AjaxResult.error("【系统预设】不允许生成文件覆盖到本地"); |
| | | } |
| | | genTableService.generatorCode(tableName); |
| | | return R.ok(); |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |
| | | @Log(title = "代码生成", businessType = BusinessType.UPDATE) |
| | | @GetMapping("/synchDb/{tableName}") |
| | | public R<?> synchDb(@PathVariable("tableName") String tableName) |
| | | public AjaxResult synchDb(@PathVariable("tableName") String tableName) |
| | | { |
| | | genTableService.synchDb(tableName); |
| | | return R.ok(); |
| | | return success(); |
| | | } |
| | | |
| | | /** |