refactor: 代码生成重构
This commit is contained in:
@@ -55,7 +55,7 @@ public class GeneratorProperties {
|
||||
|
||||
private String templatePath;
|
||||
|
||||
private String packageName;
|
||||
private String subpackageName;
|
||||
|
||||
/**
|
||||
* 文件扩展名,如 .java
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.youlai.system.controller;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.common.result.PageResult;
|
||||
import com.youlai.system.common.result.Result;
|
||||
import com.youlai.system.enums.LogModuleEnum;
|
||||
import com.youlai.system.model.form.GenConfigForm;
|
||||
import com.youlai.system.model.query.TablePageQuery;
|
||||
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||
import com.youlai.system.model.vo.TablePageVO;
|
||||
import com.youlai.system.plugin.syslog.annotation.LogAnnotation;
|
||||
import com.youlai.system.service.GeneratorService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -35,6 +37,7 @@ public class GeneratorController {
|
||||
|
||||
@Operation(summary = "获取数据表分页列表")
|
||||
@GetMapping("/table/page")
|
||||
@LogAnnotation(value = "代码生成分页列表", module = LogModuleEnum.OTHER)
|
||||
public PageResult<TablePageVO> getTablePage(
|
||||
TablePageQuery queryParams
|
||||
) {
|
||||
@@ -53,6 +56,7 @@ public class GeneratorController {
|
||||
|
||||
@Operation(summary = "保存代码生成配置")
|
||||
@PostMapping("/{tableName}/config")
|
||||
@LogAnnotation(value = "生成代码", module = LogModuleEnum.OTHER)
|
||||
public Result saveGenConfig(@RequestBody GenConfigForm formData) {
|
||||
generatorService.saveGenConfig(formData);
|
||||
return Result.success();
|
||||
@@ -69,15 +73,15 @@ public class GeneratorController {
|
||||
|
||||
@Operation(summary = "获取预览生成代码")
|
||||
@GetMapping("/{tableName}/preview")
|
||||
@LogAnnotation(value = "预览生成代码", module = LogModuleEnum.OTHER)
|
||||
public Result<List<GeneratorPreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||
List<GeneratorPreviewVO> list = generatorService.getTablePreviewData(tableName);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "下载代码zip")
|
||||
@GetMapping("/{tableName}/downloadZip")
|
||||
@Operation(summary = "下载代码")
|
||||
@GetMapping("/{tableName}/download")
|
||||
@LogAnnotation(value = "下载代码", module = LogModuleEnum.OTHER)
|
||||
public void downloadZip(HttpServletResponse response, @PathVariable String tableName) throws IOException {
|
||||
String[] tableNames = tableName.split(",");
|
||||
byte[] data = generatorService.downloadCode(tableNames);
|
||||
|
||||
@@ -270,12 +270,14 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
|
||||
/* 2. 生成文件路径 */
|
||||
// com.youlai.system
|
||||
// com.youlai
|
||||
String packageName = genConfig.getPackageName();
|
||||
// system
|
||||
String moduleName = genConfig.getModuleName();
|
||||
// controller
|
||||
String subPackageName = templateConfig.getPackageName();
|
||||
// 文件路径 com.youlai.system.controller
|
||||
String filePath = getFilePath(templateName, packageName, subPackageName, entityName);
|
||||
String subpackageName = templateConfig.getSubpackageName();
|
||||
// 文件路径 src/main/java/com/youlai/system/controller
|
||||
String filePath = getFilePath(templateName,moduleName, packageName, subpackageName, entityName);
|
||||
previewVO.setPath(filePath);
|
||||
|
||||
/* 3. 生成文件内容 */
|
||||
@@ -309,7 +311,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
return entityName + templateName + extension;
|
||||
}
|
||||
|
||||
private String getFilePath(String templateName, String packageName, String subPackageName, String entityName) {
|
||||
private String getFilePath(String templateName,String moduleName, String packageName, String subPackageName, String entityName) {
|
||||
String path;
|
||||
if ("MapperXml".equals(templateName)) {
|
||||
path = (generatorProperties.getBackendAppName()
|
||||
@@ -324,16 +326,18 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
);
|
||||
} else if ("VIEW".equals(templateName)) {
|
||||
path = (generatorProperties.getFrontendAppName()
|
||||
+ File.separator
|
||||
+ "src" + File.separator + subPackageName
|
||||
+ File.separator
|
||||
+ StrUtil.toSymbolCase(entityName, '-')
|
||||
+ File.separator + "src"
|
||||
+ File.separator + moduleName
|
||||
+ File.separator + subPackageName
|
||||
+ File.separator + StrUtil.toSymbolCase(entityName, '-')
|
||||
);
|
||||
} else {
|
||||
path = (generatorProperties.getBackendAppName()
|
||||
+ File.separator
|
||||
+ "src" + File.separator + "main" + File.separator + "java"
|
||||
+ File.separator + packageName + File.separator + subPackageName
|
||||
+ File.separator + packageName
|
||||
+ File.separator + moduleName
|
||||
+ File.separator + subPackageName
|
||||
);
|
||||
}
|
||||
|
||||
@@ -357,8 +361,8 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
String entityName = genConfig.getEntityName();
|
||||
|
||||
bindMap.put("package", genConfig.getPackageName());
|
||||
bindMap.put("subPackage", templateConfig.getPackageName());
|
||||
bindMap.put("packageName", genConfig.getPackageName());
|
||||
bindMap.put("moduleName", genConfig.getModuleName());
|
||||
bindMap.put("date", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
|
||||
bindMap.put("entityName", entityName);
|
||||
bindMap.put("tableName", genConfig.getTableName());
|
||||
|
||||
Reference in New Issue
Block a user