mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-13 14:09:00 +08:00
✨ Introducing new features. close #3396 代码生成支持数据库表结构文档导出
This commit is contained in:
1 parent
08e7eccaf1
commit
61983ec946
3 files changed
+37
-1
No files matched your search
+29
@@ -17,18 +17,25 @@
|
||||
|
||||
package com.pig4cloud.pigx.codegen.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.smallbun.screw.boot.config.Screw;
|
||||
import cn.smallbun.screw.boot.properties.ScrewProperties;
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.codegen.entity.GenConfig;
|
||||
import com.pig4cloud.pigx.codegen.service.GenTableColumnService;
|
||||
import com.pig4cloud.pigx.codegen.service.GeneratorService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* 代码生成器
|
||||
@@ -41,6 +48,8 @@ import javax.servlet.http.HttpServletResponse;
|
||||
@RequestMapping("/generator")
|
||||
public class GeneratorController {
|
||||
|
||||
private final Screw screw;
|
||||
|
||||
private final GeneratorService generatorService;
|
||||
|
||||
private final GenTableColumnService columnService;
|
||||
@@ -94,4 +103,24 @@ public class GeneratorController {
|
||||
IoUtil.write(response.getOutputStream(), Boolean.TRUE, data);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@GetMapping("/doc")
|
||||
public void generatorDoc(String[] tableNames, String dsName, HttpServletResponse response) {
|
||||
// 设置指定的数据源
|
||||
DynamicRoutingDataSource dynamicRoutingDataSource = SpringContextHolder.getBean(DynamicRoutingDataSource.class);
|
||||
DynamicDataSourceContextHolder.push(dsName);
|
||||
DataSource dataSource = dynamicRoutingDataSource.determineDataSource();
|
||||
|
||||
// 设置指定的目标表
|
||||
ScrewProperties screwProperties = SpringContextHolder.getBean(ScrewProperties.class);
|
||||
screwProperties.setDesignatedTableName(CollUtil.toList(tableNames));
|
||||
|
||||
// 生成
|
||||
byte[] data = screw.documentGeneration(dataSource, screwProperties).toByteArray();
|
||||
response.reset();
|
||||
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IoUtil.write(response.getOutputStream(), Boolean.TRUE, data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user