mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-16 13:23:42 +00:00
feat: 1. 调整项目结构 2.增加插件管理
This commit is contained in:
@@ -3,6 +3,7 @@ package org.ruoyi.generator.controller;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import org.ruoyi.common.mybatis.helper.DataBaseHelper;
|
||||
import org.ruoyi.generator.domain.GenTable;
|
||||
import org.ruoyi.generator.domain.GenTableColumn;
|
||||
import org.ruoyi.generator.service.IGenTableService;
|
||||
@@ -41,6 +42,7 @@ public class GenController extends BaseController {
|
||||
@SaCheckPermission("tool:gen:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<GenTable> genList(GenTable genTable, PageQuery pageQuery) {
|
||||
|
||||
return genTableService.selectPageGenTableList(genTable, pageQuery);
|
||||
}
|
||||
|
||||
@@ -142,13 +144,13 @@ public class GenController extends BaseController {
|
||||
/**
|
||||
* 生成代码(下载方式)
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param tableId 表名
|
||||
*/
|
||||
@SaCheckPermission("tool:gen:code")
|
||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||
@GetMapping("/download/{tableName}")
|
||||
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
|
||||
byte[] data = genTableService.downloadCode(tableName);
|
||||
@GetMapping("/download/{tableId}")
|
||||
public void download(HttpServletResponse response, @PathVariable("tableId") Long tableId) throws IOException {
|
||||
byte[] data = genTableService.downloadCode(tableId);
|
||||
genCode(response, data);
|
||||
}
|
||||
|
||||
@@ -181,17 +183,18 @@ public class GenController extends BaseController {
|
||||
/**
|
||||
* 批量生成代码
|
||||
*
|
||||
* @param tables 表名串
|
||||
* @param tableIdStr 表名串
|
||||
*/
|
||||
@SaCheckPermission("tool:gen:code")
|
||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||
@GetMapping("/batchGenCode")
|
||||
public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
|
||||
String[] tableNames = Convert.toStrArray(tables);
|
||||
byte[] data = genTableService.downloadCode(tableNames);
|
||||
public void batchGenCode(HttpServletResponse response, String tableIdStr) throws IOException {
|
||||
String[] tableIds = Convert.toStrArray(tableIdStr);
|
||||
byte[] data = genTableService.downloadCode(tableIds);
|
||||
genCode(response, data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成zip文件
|
||||
*/
|
||||
@@ -204,4 +207,13 @@ public class GenController extends BaseController {
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IoUtil.write(response.getOutputStream(), false, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据源名称列表
|
||||
*/
|
||||
@SaCheckPermission("tool:gen:list")
|
||||
@GetMapping(value = "/getDataNames")
|
||||
public R<Object> getCurrentDataSourceNameList(){
|
||||
return R.ok(DataBaseHelper.getDataSourceNameList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ import java.util.zip.ZipOutputStream;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@DS("#header.datasource")
|
||||
//@DS("#header.datasource")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@@ -228,17 +228,29 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] downloadCode(Long tableId) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
generatorCode(tableId, zip);
|
||||
IoUtil.close(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码(下载方式)
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @param tableIds 表名称
|
||||
* @return 数据
|
||||
*/
|
||||
@Override
|
||||
public byte[] downloadCode(String tableName) {
|
||||
public byte[] downloadCode(String[] tableIds) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
generatorCode(tableName, zip);
|
||||
for (String tableId : tableIds) {
|
||||
generatorCode(Long.parseLong(tableId), zip);
|
||||
}
|
||||
IoUtil.close(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
@@ -327,28 +339,14 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成代码(下载方式)
|
||||
*
|
||||
* @param tableNames 表数组
|
||||
* @return 数据
|
||||
* 查询表信息并生成代码
|
||||
*/
|
||||
@Override
|
||||
public byte[] downloadCode(String[] tableNames) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
for (String tableName : tableNames) {
|
||||
generatorCode(tableName, zip);
|
||||
}
|
||||
IoUtil.close(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询表信息并生成代码
|
||||
*/
|
||||
private void generatorCode(String tableName, ZipOutputStream zip) {
|
||||
private void generatorCode(Long tableId, ZipOutputStream zip) {
|
||||
// 查询表信息
|
||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
||||
List<Long> menuIds = new ArrayList<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
menuIds.add(identifierGenerator.nextId(null).longValue());
|
||||
|
||||
@@ -99,7 +99,7 @@ public interface IGenTableService {
|
||||
* @param tableName 表名称
|
||||
* @return 数据
|
||||
*/
|
||||
byte[] downloadCode(String tableName);
|
||||
byte[] downloadCode(Long tableName);
|
||||
|
||||
/**
|
||||
* 生成代码(自定义路径)
|
||||
@@ -119,10 +119,10 @@ public interface IGenTableService {
|
||||
/**
|
||||
* 批量生成代码(下载方式)
|
||||
*
|
||||
* @param tableNames 表数组
|
||||
* @param tableIds 表数组
|
||||
* @return 数据
|
||||
*/
|
||||
byte[] downloadCode(String[] tableNames);
|
||||
byte[] downloadCode(String[] tableIds);
|
||||
|
||||
/**
|
||||
* 修改保存参数校验
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.ruoyi.generator.util;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.ruoyi.generator.constant.GenConstants;
|
||||
import org.ruoyi.generator.domain.GenTable;
|
||||
import org.ruoyi.generator.domain.GenTableColumn;
|
||||
@@ -74,6 +75,27 @@ public class VelocityUtils {
|
||||
if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||
setTreeVelocityContext(velocityContext, genTable);
|
||||
}
|
||||
// 判断是modal还是drawer
|
||||
Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
||||
if (ObjectUtil.isNotNull(paramsObj)) {
|
||||
String popupComponent = Optional
|
||||
.ofNullable(paramsObj.getStr("popupComponent"))
|
||||
.orElse("modal");
|
||||
velocityContext.put("popupComponent", popupComponent);
|
||||
velocityContext.put("PopupComponent", StringUtils.capitalize(popupComponent));
|
||||
} else {
|
||||
velocityContext.put("popupComponent", "modal");
|
||||
velocityContext.put("PopupComponent", "Modal");
|
||||
}
|
||||
// 判断是原生antd表单还是useForm表单
|
||||
// native 原生antd表单
|
||||
// useForm useVbenForm
|
||||
if (ObjectUtil.isNotNull(paramsObj)) {
|
||||
String formComponent = Optional
|
||||
.ofNullable(paramsObj.getStr("formComponent"))
|
||||
.orElse("useForm");
|
||||
velocityContext.put("formComponent", formComponent);
|
||||
}
|
||||
return velocityContext;
|
||||
}
|
||||
|
||||
@@ -109,7 +131,7 @@ public class VelocityUtils {
|
||||
* @return 模板列表
|
||||
*/
|
||||
public static List<String> getTemplateList(String tplCategory) {
|
||||
List<String> templates = new ArrayList<String>();
|
||||
List<String> templates = new ArrayList<>();
|
||||
templates.add("vm/java/domain.java.vm");
|
||||
templates.add("vm/java/vo.java.vm");
|
||||
templates.add("vm/java/bo.java.vm");
|
||||
@@ -134,6 +156,21 @@ public class VelocityUtils {
|
||||
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||
templates.add("vm/vue/index-tree.vue.vm");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加vben5
|
||||
*/
|
||||
templates.add("vm/vben5/api/index.ts.vm");
|
||||
templates.add("vm/vben5/api/model.d.ts.vm");
|
||||
templates.add("vm/vben5/views/data.ts.vm");
|
||||
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
|
||||
templates.add("vm/vben5/views/index_vben.vue.vm");
|
||||
templates.add("vm/vben5/views/popup.vue.vm");
|
||||
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||
templates.add("vm/vben5/views/index_vben_tree.vue.vm");
|
||||
templates.add("vm/vben5/views/popup_tree.vue.vm");
|
||||
}
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
@@ -186,6 +223,38 @@ public class VelocityUtils {
|
||||
} else if (template.contains("index-tree.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
|
||||
}
|
||||
|
||||
// 判断是modal还是drawer
|
||||
Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
||||
String popupComponent = "modal";
|
||||
if (ObjectUtil.isNotNull(paramsObj)) {
|
||||
popupComponent = Optional
|
||||
.ofNullable(paramsObj.getStr("popupComponent"))
|
||||
.orElse("modal");
|
||||
}
|
||||
String vben5Path = "vben5";
|
||||
if (template.contains("vm/vben5/api/index.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/api/{}/{}/index.ts", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/api/model.d.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/api/{}/{}/model.d.ts", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/index_vben.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/index_vben_tree.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/data.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/data.ts", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/popup.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/popup_tree.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent);
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@@ -208,13 +277,16 @@ public class VelocityUtils {
|
||||
*/
|
||||
public static HashSet<String> getImportList(GenTable genTable) {
|
||||
List<GenTableColumn> columns = genTable.getColumns();
|
||||
HashSet<String> importList = new HashSet<String>();
|
||||
HashSet<String> importList = new HashSet<>();
|
||||
for (GenTableColumn column : columns) {
|
||||
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
|
||||
importList.add("java.util.Date");
|
||||
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
|
||||
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
|
||||
importList.add("java.math.BigDecimal");
|
||||
} else if (!column.isSuperColumn() && "imageUpload".equals(column.getHtmlType())) {
|
||||
importList.add("org.dromara.common.translation.annotation.Translation");
|
||||
importList.add("org.dromara.common.translation.constant.TransConstant");
|
||||
}
|
||||
}
|
||||
return importList;
|
||||
|
||||
Reference in New Issue
Block a user