use of vip.mate.code.entity.SysDataSource in project matecloud by matevip.
the class SysCodeController method execute.
/**
* 代码生成
* @param packageName 包名
* @param prefix 前缀
* @param modelName 模块名
* @param datasourceId 数据源名
* @param tableName 表名
*/
@PreAuth
@Log(value = "代码生成", exception = "代码生成请求异常")
@ApiOperation(value = "代码生成", notes = "代码生成")
@PostMapping("/generator-code")
public void execute(@RequestParam String packageName, @RequestParam String prefix, @RequestParam String modelName, @RequestParam String datasourceId, @RequestParam String tableName, HttpServletRequest request, HttpServletResponse response) {
SysDataSource sysDataSource = sysDataSourceService.getById(datasourceId);
String outputDir = System.getProperty("user.dir") + File.separator + "temp" + File.separator + "generator" + File.separator + UUID.randomUUID().toString();
CodeConfig config = new CodeConfig();
config.setDbType(DbType.getDbType(sysDataSource.getName()));
config.setUrl(sysDataSource.getUrl());
config.setUsername(sysDataSource.getUsername());
config.setPassword(sysDataSource.getPassword());
config.setDriverName(sysDataSource.getDriverClass());
config.setModelName(modelName);
config.setOutputDir(outputDir);
config.setPackageName(packageName);
config.setTableName(tableName);
config.setPrefix(prefix);
config.setOutputDir(outputDir);
GeneratorUtil.execute(config);
String fileName = "code" + UUID.randomUUID().toString() + ".zip";
String filePath = outputDir + File.separator + fileName;
// 压缩目录
String[] srcDir = { outputDir + File.separator + (config.getPackageName().substring(0, config.getPackageName().indexOf("."))) };
try {
ZipUtil.toZip(srcDir, filePath, true);
FileUtil.download(filePath, fileName, true, response);
} catch (Exception e) {
log.error(e.getMessage());
}
}
use of vip.mate.code.entity.SysDataSource in project matecloud by matevip.
the class SysCodeController method tableList.
/**
* 数据库表信息
* @param dataSourceId 数据源Id
* @return Result
*/
@PreAuth
@Log(value = "数据库表信息", exception = "数据库表信息请求异常")
@ApiOperation(value = "数据库表信息", notes = "数据库表信息")
@PostMapping("/table-list")
public Result<List<TableInfo>> tableList(@RequestParam String dataSourceId) {
SysDataSource sysDataSource = sysDataSourceService.getById(dataSourceId);
GlobalConfig gc = new GlobalConfig();
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.getDbType(sysDataSource.getDbType()));
dsc.setDriverName(sysDataSource.getDriverClass());
dsc.setUrl(sysDataSource.getUrl());
dsc.setUsername(sysDataSource.getUsername());
dsc.setPassword(sysDataSource.getPassword());
StrategyConfig strategyConfig = new StrategyConfig();
TemplateConfig templateConfig = new TemplateConfig();
ConfigBuilder config = new ConfigBuilder(new PackageConfig(), dsc, strategyConfig, templateConfig, gc);
List<TableInfo> list = config.getTableInfoList();
return Result.data(list);
}
Aggregations