wip: 代码生成临时提交
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.youlai.system.config.property;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成配置属性
|
||||
*
|
||||
@@ -14,4 +17,20 @@ import org.springframework.stereotype.Component;
|
||||
@ConfigurationProperties(prefix = "generator")
|
||||
@Data
|
||||
public class GeneratorProperties {
|
||||
|
||||
private Map<String, TemplateConfig> templateConfigs = MapUtil.newHashMap(true);
|
||||
|
||||
/**
|
||||
* 模板配置
|
||||
*/
|
||||
@Data
|
||||
public static class TemplateConfig{
|
||||
|
||||
private String templatePath;
|
||||
|
||||
private String packageName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.youlai.system.model.query.TablePageQuery;
|
||||
import com.youlai.system.model.vo.TableColumnVO;
|
||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
||||
import com.youlai.system.model.vo.TablePageVO;
|
||||
import com.youlai.system.service.DatabaseService;
|
||||
import com.youlai.system.service.GeneratorService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -25,14 +25,14 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratorController {
|
||||
|
||||
private final DatabaseService databaseService;
|
||||
private final GeneratorService generatorService;
|
||||
|
||||
@Operation(summary = "获取数据表分页列表")
|
||||
@GetMapping("/table/page")
|
||||
public PageResult<TablePageVO> getTablePage(
|
||||
TablePageQuery queryParams
|
||||
) {
|
||||
Page<TablePageVO> result = databaseService.getTablePage(queryParams);
|
||||
Page<TablePageVO> result = generatorService.getTablePage(queryParams);
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GeneratorController {
|
||||
public Result<List<TableColumnVO>> getTableColumns(
|
||||
@Parameter(description = "表名", example = "sys_user") @PathVariable String tableName
|
||||
) {
|
||||
List<TableColumnVO> list = databaseService.getTableColumns(tableName);
|
||||
List<TableColumnVO> list = generatorService.getTableColumns(tableName);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class GeneratorController {
|
||||
@Operation(summary = "获取预览生成代码")
|
||||
@GetMapping("/table/{tableName}/preview")
|
||||
public Result<List<TableGeneratePreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||
List<TableGeneratePreviewVO> list = databaseService.getTablePreviewData(tableName);
|
||||
List<TableGeneratePreviewVO> list = generatorService.getTablePreviewData(tableName);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
* @author haoxr
|
||||
* @since 2.11.0
|
||||
*/
|
||||
public interface DatabaseService {
|
||||
public interface GeneratorService {
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ import com.youlai.system.model.query.TablePageQuery;
|
||||
import com.youlai.system.model.vo.TableColumnVO;
|
||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
||||
import com.youlai.system.model.vo.TablePageVO;
|
||||
import com.youlai.system.service.DatabaseService;
|
||||
import com.youlai.system.service.GeneratorService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||
@@ -27,7 +27,7 @@ import java.util.*;
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DatabaseServiceImpl implements DatabaseService {
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
private final DatabaseMapper databaseMapper;
|
||||
|
||||
@@ -81,14 +81,28 @@ public class DatabaseServiceImpl implements DatabaseService {
|
||||
|
||||
Template template = templateEngine.getTemplate("generator" + File.separator + "controller.java.vm");
|
||||
String content = template.render(bindingMap);
|
||||
TableGeneratePreviewVO controller = new TableGeneratePreviewVO();
|
||||
controller.setPath("youlai-boot/controller");
|
||||
controller.setContent(content);
|
||||
controller.setFileName("UserController.java");
|
||||
|
||||
list.add(controller);
|
||||
|
||||
TableGeneratePreviewVO vo = new TableGeneratePreviewVO();
|
||||
vo.setPath("controller");
|
||||
vo.setPath("youlai-boot/model/vo");
|
||||
vo.setContent(content);
|
||||
vo.setFileName("UserController.java");
|
||||
vo.setFileName("UserVO.java");
|
||||
|
||||
list.add(vo);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private String generatePath(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user