|
@@ -10,14 +10,18 @@ import com.ruoyi.generator.domain.GenTable;
|
|
import com.ruoyi.generator.domain.GenTableColumn;
|
|
import com.ruoyi.generator.domain.GenTableColumn;
|
|
import com.ruoyi.generator.service.IGenTableColumnService;
|
|
import com.ruoyi.generator.service.IGenTableColumnService;
|
|
import com.ruoyi.generator.service.IGenTableService;
|
|
import com.ruoyi.generator.service.IGenTableService;
|
|
-import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -27,13 +31,12 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 代码生成 操作处理
|
|
* 代码生成 操作处理
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author ruoyi
|
|
* @author ruoyi
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/tool/gen")
|
|
@RequestMapping("/tool/gen")
|
|
-public class GenController extends BaseController
|
|
|
|
-{
|
|
|
|
|
|
+public class GenController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private IGenTableService genTableService;
|
|
private IGenTableService genTableService;
|
|
|
|
|
|
@@ -43,20 +46,16 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 查询代码生成列表
|
|
* 查询代码生成列表
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
|
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
- public TableDataInfo genList(GenTable genTable)
|
|
|
|
- {
|
|
|
|
|
|
+ public TableDataInfo genList(GenTable genTable) {
|
|
return genTableService.selectPageGenTableList(genTable);
|
|
return genTableService.selectPageGenTableList(genTable);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 修改代码生成业务
|
|
* 修改代码生成业务
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:query')")
|
|
|
|
@GetMapping(value = "/{talbleId}")
|
|
@GetMapping(value = "/{talbleId}")
|
|
- public AjaxResult getInfo(@PathVariable Long talbleId)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult getInfo(@PathVariable Long talbleId) {
|
|
GenTable table = genTableService.selectGenTableById(talbleId);
|
|
GenTable table = genTableService.selectGenTableById(talbleId);
|
|
List<GenTable> tables = genTableService.selectGenTableAll();
|
|
List<GenTable> tables = genTableService.selectGenTableAll();
|
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
|
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
|
|
@@ -70,20 +69,16 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 查询数据库列表
|
|
* 查询数据库列表
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
|
|
|
@GetMapping("/db/list")
|
|
@GetMapping("/db/list")
|
|
- public TableDataInfo dataList(GenTable genTable)
|
|
|
|
- {
|
|
|
|
|
|
+ public TableDataInfo dataList(GenTable genTable) {
|
|
return genTableService.selectPageDbTableList(genTable);
|
|
return genTableService.selectPageDbTableList(genTable);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询数据表字段列表
|
|
* 查询数据表字段列表
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
|
|
|
@GetMapping(value = "/column/{talbleId}")
|
|
@GetMapping(value = "/column/{talbleId}")
|
|
- public TableDataInfo columnList(Long tableId)
|
|
|
|
- {
|
|
|
|
|
|
+ public TableDataInfo columnList(Long tableId) {
|
|
TableDataInfo dataInfo = new TableDataInfo();
|
|
TableDataInfo dataInfo = new TableDataInfo();
|
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
|
dataInfo.setRows(list);
|
|
dataInfo.setRows(list);
|
|
@@ -94,12 +89,10 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 导入表结构(保存)
|
|
* 导入表结构(保存)
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:import')")
|
|
|
|
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
|
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
|
@PostMapping("/importTable")
|
|
@PostMapping("/importTable")
|
|
@ApiOperation("导入表结构(保存)")
|
|
@ApiOperation("导入表结构(保存)")
|
|
- public AjaxResult importTableSave(String tables)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult importTableSave(String tables) {
|
|
String[] tableNames = Convert.toStrArray(tables);
|
|
String[] tableNames = Convert.toStrArray(tables);
|
|
// 查询表信息
|
|
// 查询表信息
|
|
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
|
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
|
@@ -110,12 +103,10 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 修改保存代码生成业务
|
|
* 修改保存代码生成业务
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:edit')")
|
|
|
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
@PutMapping
|
|
@ApiOperation("修改保存代码生成业务")
|
|
@ApiOperation("修改保存代码生成业务")
|
|
- public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult editSave(@Validated @RequestBody GenTable genTable) {
|
|
genTableService.validateEdit(genTable);
|
|
genTableService.validateEdit(genTable);
|
|
genTableService.updateGenTable(genTable);
|
|
genTableService.updateGenTable(genTable);
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
@@ -124,12 +115,10 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 删除代码生成
|
|
* 删除代码生成
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:remove')")
|
|
|
|
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
|
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{tableIds}")
|
|
@DeleteMapping("/{tableIds}")
|
|
@ApiOperation("删除代码生成")
|
|
@ApiOperation("删除代码生成")
|
|
- public AjaxResult remove(@PathVariable Long[] tableIds)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult remove(@PathVariable Long[] tableIds) {
|
|
genTableService.deleteGenTableByIds(tableIds);
|
|
genTableService.deleteGenTableByIds(tableIds);
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
}
|
|
}
|
|
@@ -137,10 +126,8 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 预览代码
|
|
* 预览代码
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:preview')")
|
|
|
|
@GetMapping("/preview/{tableId}")
|
|
@GetMapping("/preview/{tableId}")
|
|
- public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException {
|
|
Map<String, String> dataMap = genTableService.previewCode(tableId);
|
|
Map<String, String> dataMap = genTableService.previewCode(tableId);
|
|
return AjaxResult.success(dataMap);
|
|
return AjaxResult.success(dataMap);
|
|
}
|
|
}
|
|
@@ -148,11 +135,9 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 生成代码(下载方式)
|
|
* 生成代码(下载方式)
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:code')")
|
|
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
@GetMapping("/download/{tableName}")
|
|
@GetMapping("/download/{tableName}")
|
|
- public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
|
|
|
|
- {
|
|
|
|
|
|
+ public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
|
|
byte[] data = genTableService.downloadCode(tableName);
|
|
byte[] data = genTableService.downloadCode(tableName);
|
|
genCode(response, data);
|
|
genCode(response, data);
|
|
}
|
|
}
|
|
@@ -160,11 +145,9 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 生成代码(自定义路径)
|
|
* 生成代码(自定义路径)
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:code')")
|
|
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
@GetMapping("/genCode/{tableName}")
|
|
@GetMapping("/genCode/{tableName}")
|
|
- public AjaxResult genCode(@PathVariable("tableName") String tableName)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult genCode(@PathVariable("tableName") String tableName) {
|
|
genTableService.generatorCode(tableName);
|
|
genTableService.generatorCode(tableName);
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
}
|
|
}
|
|
@@ -172,11 +155,9 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 同步数据库
|
|
* 同步数据库
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:edit')")
|
|
|
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
@GetMapping("/synchDb/{tableName}")
|
|
@GetMapping("/synchDb/{tableName}")
|
|
- public AjaxResult synchDb(@PathVariable("tableName") String tableName)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
|
|
genTableService.synchDb(tableName);
|
|
genTableService.synchDb(tableName);
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
}
|
|
}
|
|
@@ -184,11 +165,9 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 批量生成代码
|
|
* 批量生成代码
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('tool:gen:code')")
|
|
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
@GetMapping("/batchGenCode")
|
|
@GetMapping("/batchGenCode")
|
|
- public void batchGenCode(HttpServletResponse response, String tables) throws IOException
|
|
|
|
- {
|
|
|
|
|
|
+ public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
|
|
String[] tableNames = Convert.toStrArray(tables);
|
|
String[] tableNames = Convert.toStrArray(tables);
|
|
byte[] data = genTableService.downloadCode(tableNames);
|
|
byte[] data = genTableService.downloadCode(tableNames);
|
|
genCode(response, data);
|
|
genCode(response, data);
|
|
@@ -197,8 +176,7 @@ public class GenController extends BaseController
|
|
/**
|
|
/**
|
|
* 生成zip文件
|
|
* 生成zip文件
|
|
*/
|
|
*/
|
|
- private void genCode(HttpServletResponse response, byte[] data) throws IOException
|
|
|
|
- {
|
|
|
|
|
|
+ private void genCode(HttpServletResponse response, byte[] data) throws IOException {
|
|
response.reset();
|
|
response.reset();
|
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
|
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
@@ -207,4 +185,4 @@ public class GenController extends BaseController
|
|
response.setContentType("application/octet-stream; charset=UTF-8");
|
|
response.setContentType("application/octet-stream; charset=UTF-8");
|
|
IOUtils.write(data, response.getOutputStream());
|
|
IOUtils.write(data, response.getOutputStream());
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|