|
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
@@ -30,13 +31,12 @@ import com.ruoyi.generator.service.IGenTableService;
|
|
|
|
|
|
/**
|
|
|
* 代码生成 操作处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/tool/gen")
|
|
|
-public class GenController extends BaseController
|
|
|
-{
|
|
|
+public class GenController extends BaseController {
|
|
|
@Autowired
|
|
|
private IGenTableService genTableService;
|
|
|
|
|
@@ -48,8 +48,7 @@ public class GenController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
|
|
@GetMapping("/list")
|
|
|
- public TableDataInfo genList(GenTable genTable)
|
|
|
- {
|
|
|
+ public TableDataInfo genList(GenTable genTable) {
|
|
|
startPage();
|
|
|
List<GenTable> list = genTableService.selectGenTableList(genTable);
|
|
|
return getDataTable(list);
|
|
@@ -60,8 +59,7 @@ public class GenController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:query')")
|
|
|
@GetMapping(value = "/{talbleId}")
|
|
|
- public AjaxResult getInfo(@PathVariable Long talbleId)
|
|
|
- {
|
|
|
+ public AjaxResult getInfo(@PathVariable Long talbleId) {
|
|
|
GenTable table = genTableService.selectGenTableById(talbleId);
|
|
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
@@ -75,8 +73,7 @@ public class GenController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
|
|
@GetMapping("/db/list")
|
|
|
- public TableDataInfo dataList(GenTable genTable)
|
|
|
- {
|
|
|
+ public TableDataInfo dataList(GenTable genTable) {
|
|
|
startPage();
|
|
|
List<GenTable> list = genTableService.selectDbTableList(genTable);
|
|
|
return getDataTable(list);
|
|
@@ -87,8 +84,7 @@ public class GenController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
|
|
@GetMapping(value = "/column/{talbleId}")
|
|
|
- public TableDataInfo columnList(Long tableId)
|
|
|
- {
|
|
|
+ public TableDataInfo columnList(Long tableId) {
|
|
|
TableDataInfo dataInfo = new TableDataInfo();
|
|
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
|
|
dataInfo.setRows(list);
|
|
@@ -102,8 +98,7 @@ public class GenController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
|
|
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
|
|
@PostMapping("/importTable")
|
|
|
- public AjaxResult importTableSave(String tables)
|
|
|
- {
|
|
|
+ public AjaxResult importTableSave(String tables) {
|
|
|
String[] tableNames = Convert.toStrArray(tables);
|
|
|
// 查询表信息
|
|
|
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
|
@@ -117,8 +112,7 @@ public class GenController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:edit')")
|
|
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
- public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
|
|
|
- {
|
|
|
+ public AjaxResult editSave(@Validated @RequestBody GenTable genTable) {
|
|
|
genTableService.validateEdit(genTable);
|
|
|
genTableService.updateGenTable(genTable);
|
|
|
return AjaxResult.success();
|
|
@@ -130,8 +124,7 @@ public class GenController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:remove')")
|
|
|
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
|
|
@DeleteMapping("/{tableIds}")
|
|
|
- public AjaxResult remove(@PathVariable Long[] tableIds)
|
|
|
- {
|
|
|
+ public AjaxResult remove(@PathVariable Long[] tableIds) {
|
|
|
genTableService.deleteGenTableByIds(tableIds);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
@@ -141,8 +134,7 @@ public class GenController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:preview')")
|
|
|
@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);
|
|
|
return AjaxResult.success(dataMap);
|
|
|
}
|
|
@@ -153,8 +145,7 @@ public class GenController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
|
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
|
@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);
|
|
|
genCode(response, data);
|
|
|
}
|
|
@@ -165,8 +156,7 @@ public class GenController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
|
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
|
@GetMapping("/genCode/{tableName}")
|
|
|
- public AjaxResult genCode(@PathVariable("tableName") String tableName)
|
|
|
- {
|
|
|
+ public AjaxResult genCode(@PathVariable("tableName") String tableName) {
|
|
|
genTableService.generatorCode(tableName);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
@@ -177,8 +167,7 @@ public class GenController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:edit')")
|
|
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
|
@GetMapping("/synchDb/{tableName}")
|
|
|
- public AjaxResult synchDb(@PathVariable("tableName") String tableName)
|
|
|
- {
|
|
|
+ public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
|
|
|
genTableService.synchDb(tableName);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
@@ -189,8 +178,7 @@ public class GenController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
|
|
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
|
@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);
|
|
|
byte[] data = genTableService.downloadCode(tableNames);
|
|
|
genCode(response, data);
|
|
@@ -199,8 +187,7 @@ public class GenController extends BaseController
|
|
|
/**
|
|
|
* 生成zip文件
|
|
|
*/
|
|
|
- private void genCode(HttpServletResponse response, byte[] data) throws IOException
|
|
|
- {
|
|
|
+ private void genCode(HttpServletResponse response, byte[] data) throws IOException {
|
|
|
response.reset();
|
|
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
|
|
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
@@ -209,4 +196,4 @@ public class GenController extends BaseController
|
|
|
response.setContentType("application/octet-stream; charset=UTF-8");
|
|
|
IOUtils.write(data, response.getOutputStream());
|
|
|
}
|
|
|
-}
|
|
|
+}
|