Search in sources :

Example 1 with SysDataSource

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());
    }
}
Also used : SysDataSource(vip.mate.code.entity.SysDataSource) CodeConfig(vip.mate.code.dto.CodeConfig) PreAuth(vip.mate.core.auth.annotation.PreAuth) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(vip.mate.core.log.annotation.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with SysDataSource

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);
}
Also used : ConfigBuilder(com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder) SysDataSource(vip.mate.code.entity.SysDataSource) TableInfo(com.baomidou.mybatisplus.generator.config.po.TableInfo) PreAuth(vip.mate.core.auth.annotation.PreAuth) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(vip.mate.core.log.annotation.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 SysDataSource (vip.mate.code.entity.SysDataSource)2 PreAuth (vip.mate.core.auth.annotation.PreAuth)2 Log (vip.mate.core.log.annotation.Log)2 ConfigBuilder (com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder)1 TableInfo (com.baomidou.mybatisplus.generator.config.po.TableInfo)1 CodeConfig (vip.mate.code.dto.CodeConfig)1