mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-14 04:13:39 +00:00
Compare commits
8 Commits
63ec00cd71
...
37f832c31c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37f832c31c | ||
|
|
25cf1f9744 | ||
|
|
a48178685c | ||
|
|
7e60cb357f | ||
|
|
915a393427 | ||
|
|
de323d8c45 | ||
|
|
ffe4867d40 | ||
|
|
8b3c0b4134 |
@@ -133,6 +133,9 @@ security:
|
|||||||
- /chat/send
|
- /chat/send
|
||||||
# 文件上传
|
# 文件上传
|
||||||
- /chat/upload
|
- /chat/upload
|
||||||
|
# 代码生成调用
|
||||||
|
- /tool/gen/getByTableName
|
||||||
|
- /tool/gen/batchGenCode
|
||||||
# 静态资源
|
# 静态资源
|
||||||
- /*.html
|
- /*.html
|
||||||
- /**/*.html
|
- /**/*.html
|
||||||
@@ -185,7 +188,7 @@ mybatis-plus:
|
|||||||
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
|
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
|
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||||
logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||||
global-config:
|
global-config:
|
||||||
# 是否打印 Logo banner
|
# 是否打印 Logo banner
|
||||||
banner: true
|
banner: true
|
||||||
|
|||||||
@@ -11,9 +11,12 @@ import org.ruoyi.enums.DataBaseType;
|
|||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库助手
|
* 数据库助手
|
||||||
@@ -78,4 +81,83 @@ public class DataBaseHelper {
|
|||||||
public static List<String> getDataSourceNameList() {
|
public static List<String> getDataSourceNameList() {
|
||||||
return new ArrayList<>(DS.getDataSources().keySet());
|
return new ArrayList<>(DS.getDataSources().keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前连接的所有表名称
|
||||||
|
*/
|
||||||
|
public static List<String> getCurrentDataSourceTableNameList() {
|
||||||
|
DataSource dataSource = DS.determineDataSource();
|
||||||
|
List<String> tableNames = new ArrayList<>();
|
||||||
|
try (Connection conn = dataSource.getConnection()) {
|
||||||
|
DatabaseMetaData metaData = conn.getMetaData();
|
||||||
|
String catalog = conn.getCatalog();
|
||||||
|
String schema = conn.getSchema();
|
||||||
|
|
||||||
|
// 获取所有表名
|
||||||
|
try (var resultSet = metaData.getTables(catalog, schema, "%", new String[]{"TABLE"})) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
String tableName = resultSet.getString("TABLE_NAME");
|
||||||
|
tableNames.add(tableName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ServiceException("获取表名称失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return tableNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定表的字段信息
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return 字段信息列表
|
||||||
|
*/
|
||||||
|
public static List<Map<String, Object>> getTableColumnInfo(String tableName) {
|
||||||
|
DataSource dataSource = DS.determineDataSource();
|
||||||
|
List<Map<String, Object>> columns = new ArrayList<>();
|
||||||
|
|
||||||
|
try (Connection conn = dataSource.getConnection()) {
|
||||||
|
DatabaseMetaData metaData = conn.getMetaData();
|
||||||
|
String catalog = conn.getCatalog();
|
||||||
|
String schema = conn.getSchema();
|
||||||
|
|
||||||
|
// 获取表字段信息
|
||||||
|
try (ResultSet resultSet = metaData.getColumns(catalog, schema, tableName, "%")) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
Map<String, Object> column = new HashMap<>();
|
||||||
|
column.put("columnName", resultSet.getString("COLUMN_NAME"));
|
||||||
|
column.put("columnComment", resultSet.getString("REMARKS"));
|
||||||
|
column.put("dataType", resultSet.getString("TYPE_NAME"));
|
||||||
|
column.put("columnSize", resultSet.getInt("COLUMN_SIZE"));
|
||||||
|
column.put("isNullable", "YES".equals(resultSet.getString("IS_NULLABLE")));
|
||||||
|
column.put("ordinalPosition", resultSet.getInt("ORDINAL_POSITION"));
|
||||||
|
|
||||||
|
// 设置默认值
|
||||||
|
String defaultValue = resultSet.getString("COLUMN_DEF");
|
||||||
|
column.put("columnDefault", defaultValue);
|
||||||
|
|
||||||
|
columns.add(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取主键信息
|
||||||
|
try (ResultSet pkResultSet = metaData.getPrimaryKeys(catalog, schema, tableName)) {
|
||||||
|
List<String> primaryKeys = new ArrayList<>();
|
||||||
|
while (pkResultSet.next()) {
|
||||||
|
primaryKeys.add(pkResultSet.getString("COLUMN_NAME"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标记主键字段
|
||||||
|
for (Map<String, Object> column : columns) {
|
||||||
|
String columnName = (String) column.get("columnName");
|
||||||
|
column.put("isPrimaryKey", primaryKeys.contains(columnName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ServiceException("获取表字段信息失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,21 +53,21 @@ public class GenConfig {
|
|||||||
GenConfig.packageName = packageName;
|
GenConfig.packageName = packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getAutoRemovePre() {
|
|
||||||
return autoRemovePre;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Value("${autoRemovePre}")
|
@Value("${autoRemovePre}")
|
||||||
public void setAutoRemovePre(boolean autoRemovePre) {
|
public void setAutoRemovePre(boolean autoRemovePre) {
|
||||||
GenConfig.autoRemovePre = autoRemovePre;
|
GenConfig.autoRemovePre = autoRemovePre;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTablePrefix() {
|
public static boolean getAutoRemovePre() {
|
||||||
return tablePrefix;
|
return autoRemovePre;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${tablePrefix}")
|
@Value("${tablePrefix}")
|
||||||
public void setTablePrefix(String tablePrefix) {
|
public void setTablePrefix(String tablePrefix) {
|
||||||
GenConfig.tablePrefix = tablePrefix;
|
GenConfig.tablePrefix = tablePrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getTablePrefix() {
|
||||||
|
return tablePrefix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,186 +0,0 @@
|
|||||||
package org.ruoyi.generator.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 代码生成通用常量
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public interface GenConstants {
|
|
||||||
/**
|
|
||||||
* 单表(增删改查)
|
|
||||||
*/
|
|
||||||
String TPL_CRUD = "crud";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 树表(增删改查)
|
|
||||||
*/
|
|
||||||
String TPL_TREE = "tree";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 树编码字段
|
|
||||||
*/
|
|
||||||
String TREE_CODE = "treeCode";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 树父编码字段
|
|
||||||
*/
|
|
||||||
String TREE_PARENT_CODE = "treeParentCode";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 树名称字段
|
|
||||||
*/
|
|
||||||
String TREE_NAME = "treeName";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上级菜单ID字段
|
|
||||||
*/
|
|
||||||
String PARENT_MENU_ID = "parentMenuId";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上级菜单名称字段
|
|
||||||
*/
|
|
||||||
String PARENT_MENU_NAME = "parentMenuName";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库字符串类型
|
|
||||||
*/
|
|
||||||
String[] COLUMNTYPE_STR = {"char", "varchar", "enum", "set", "nchar", "nvarchar", "varchar2", "nvarchar2"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库文本类型
|
|
||||||
*/
|
|
||||||
String[] COLUMNTYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext", "binary", "varbinary", "blob",
|
|
||||||
"ntext", "image", "bytea"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库时间类型
|
|
||||||
*/
|
|
||||||
String[] COLUMNTYPE_TIME = {"datetime", "time", "date", "timestamp", "year", "interval",
|
|
||||||
"smalldatetime", "datetime2", "datetimeoffset"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库数字类型
|
|
||||||
*/
|
|
||||||
String[] COLUMNTYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer",
|
|
||||||
"bit", "bigint", "float", "double", "decimal", "numeric", "real", "double precision",
|
|
||||||
"smallserial", "serial", "bigserial", "money", "smallmoney"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BO对象 不需要添加字段
|
|
||||||
*/
|
|
||||||
String[] COLUMNNAME_NOT_ADD = {"create_dept", "create_by", "create_time", "del_flag", "update_by",
|
|
||||||
"update_time", "version", "tenant_id"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BO对象 不需要编辑字段
|
|
||||||
*/
|
|
||||||
String[] COLUMNNAME_NOT_EDIT = {"create_dept", "create_by", "create_time", "del_flag", "update_by",
|
|
||||||
"update_time", "version", "tenant_id"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* VO对象 不需要返回字段
|
|
||||||
*/
|
|
||||||
String[] COLUMNNAME_NOT_LIST = {"create_dept", "create_by", "create_time", "del_flag", "update_by",
|
|
||||||
"update_time", "version", "tenant_id"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BO对象 不需要查询字段
|
|
||||||
*/
|
|
||||||
String[] COLUMNNAME_NOT_QUERY = {"id", "create_dept", "create_by", "create_time", "del_flag", "update_by",
|
|
||||||
"update_time", "remark", "version", "tenant_id"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entity基类字段
|
|
||||||
*/
|
|
||||||
String[] BASE_ENTITY = {"createDept", "createBy", "createTime", "updateBy", "updateTime", "tenantId"};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文本框
|
|
||||||
*/
|
|
||||||
String HTML_INPUT = "input";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文本域
|
|
||||||
*/
|
|
||||||
String HTML_TEXTAREA = "textarea";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下拉框
|
|
||||||
*/
|
|
||||||
String HTML_SELECT = "select";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单选框
|
|
||||||
*/
|
|
||||||
String HTML_RADIO = "radio";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 复选框
|
|
||||||
*/
|
|
||||||
String HTML_CHECKBOX = "checkbox";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期控件
|
|
||||||
*/
|
|
||||||
String HTML_DATETIME = "datetime";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图片上传控件
|
|
||||||
*/
|
|
||||||
String HTML_IMAGE_UPLOAD = "imageUpload";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件上传控件
|
|
||||||
*/
|
|
||||||
String HTML_FILE_UPLOAD = "fileUpload";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 富文本控件
|
|
||||||
*/
|
|
||||||
String HTML_EDITOR = "editor";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字符串类型
|
|
||||||
*/
|
|
||||||
String TYPE_STRING = "String";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 整型
|
|
||||||
*/
|
|
||||||
String TYPE_INTEGER = "Integer";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 长整型
|
|
||||||
*/
|
|
||||||
String TYPE_LONG = "Long";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 浮点型
|
|
||||||
*/
|
|
||||||
String TYPE_DOUBLE = "Double";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 高精度计算类型
|
|
||||||
*/
|
|
||||||
String TYPE_BIGDECIMAL = "BigDecimal";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间类型
|
|
||||||
*/
|
|
||||||
String TYPE_DATE = "Date";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模糊查询
|
|
||||||
*/
|
|
||||||
String QUERY_LIKE = "LIKE";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 相等查询
|
|
||||||
*/
|
|
||||||
String QUERY_EQ = "EQ";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 需要
|
|
||||||
*/
|
|
||||||
String REQUIRE = "1";
|
|
||||||
}
|
|
||||||
@@ -1,219 +1,48 @@
|
|||||||
package org.ruoyi.generator.controller;
|
package org.ruoyi.generator.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.ruoyi.common.core.domain.R;
|
import org.ruoyi.common.core.domain.R;
|
||||||
import org.ruoyi.common.log.annotation.Log;
|
|
||||||
import org.ruoyi.common.log.enums.BusinessType;
|
|
||||||
import org.ruoyi.common.web.core.BaseController;
|
import org.ruoyi.common.web.core.BaseController;
|
||||||
import org.ruoyi.core.page.PageQuery;
|
|
||||||
import org.ruoyi.core.page.TableDataInfo;
|
|
||||||
import org.ruoyi.generator.domain.GenTable;
|
|
||||||
import org.ruoyi.generator.domain.GenTableColumn;
|
|
||||||
import org.ruoyi.generator.service.IGenTableService;
|
import org.ruoyi.generator.service.IGenTableService;
|
||||||
import org.ruoyi.helper.DataBaseHelper;
|
import org.ruoyi.generator.service.SchemaFieldService;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import java.io.IOException;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成 操作处理
|
* 代码生成 操作处理
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@Validated
|
@Profile("dev")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/tool/gen")
|
@RequestMapping("/tool/gen")
|
||||||
public class GenController extends BaseController {
|
public class GenController extends BaseController {
|
||||||
|
|
||||||
private final IGenTableService genTableService;
|
private final IGenTableService genTableService;
|
||||||
|
private final SchemaFieldService schemaFieldService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询代码生成列表
|
* 根据表名获取代码生成元数据-前端代码生成
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:list")
|
|
||||||
@GetMapping("/list")
|
|
||||||
public TableDataInfo<GenTable> genList(GenTable genTable, PageQuery pageQuery) {
|
|
||||||
|
|
||||||
return genTableService.selectPageGenTableList(genTable, pageQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改代码生成业务
|
|
||||||
*
|
|
||||||
* @param tableId 表ID
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:query")
|
|
||||||
@GetMapping(value = "/{tableId}")
|
|
||||||
public R<Map<String, Object>> getInfo(@PathVariable Long tableId) {
|
|
||||||
GenTable table = genTableService.selectGenTableById(tableId);
|
|
||||||
List<GenTable> tables = genTableService.selectGenTableAll();
|
|
||||||
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
map.put("info", table);
|
|
||||||
map.put("rows", list);
|
|
||||||
map.put("tables", tables);
|
|
||||||
return R.ok(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询数据库列表
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:list")
|
|
||||||
@GetMapping("/db/list")
|
|
||||||
public TableDataInfo<GenTable> dataList(GenTable genTable, PageQuery pageQuery) {
|
|
||||||
return genTableService.selectPageDbTableList(genTable, pageQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询数据表字段列表
|
|
||||||
*
|
|
||||||
* @param tableId 表ID
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:list")
|
|
||||||
@GetMapping(value = "/column/{tableId}")
|
|
||||||
public TableDataInfo<GenTableColumn> columnList(Long tableId) {
|
|
||||||
TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>();
|
|
||||||
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
|
|
||||||
dataInfo.setRows(list);
|
|
||||||
dataInfo.setTotal(list.size());
|
|
||||||
return dataInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导入表结构(保存)
|
|
||||||
*
|
|
||||||
* @param tables 表名串
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:import")
|
|
||||||
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
|
||||||
@PostMapping("/importTable")
|
|
||||||
public R<Void> importTableSave(String tables) {
|
|
||||||
String[] tableNames = Convert.toStrArray(tables);
|
|
||||||
// 查询表信息
|
|
||||||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
|
||||||
genTableService.importGenTable(tableList);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改保存代码生成业务
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:edit")
|
|
||||||
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
||||||
@PutMapping
|
|
||||||
public R<Void> editSave(@Validated @RequestBody GenTable genTable) {
|
|
||||||
genTableService.validateEdit(genTable);
|
|
||||||
genTableService.updateGenTable(genTable);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除代码生成
|
|
||||||
*
|
|
||||||
* @param tableIds 表ID串
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:remove")
|
|
||||||
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
|
||||||
@DeleteMapping("/{tableIds}")
|
|
||||||
public R<Void> remove(@PathVariable Long[] tableIds) {
|
|
||||||
genTableService.deleteGenTableByIds(tableIds);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 预览代码
|
|
||||||
*
|
|
||||||
* @param tableId 表ID
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:preview")
|
|
||||||
@GetMapping("/preview/{tableId}")
|
|
||||||
public R<Map<String, String>> preview(@PathVariable("tableId") Long tableId) throws IOException {
|
|
||||||
Map<String, String> dataMap = genTableService.previewCode(tableId);
|
|
||||||
return R.ok(dataMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(下载方式)
|
|
||||||
*
|
|
||||||
* @param tableId 表名
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:code")
|
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
||||||
@GetMapping("/download/{tableId}")
|
|
||||||
public void download(HttpServletResponse response, @PathVariable("tableId") Long tableId) throws IOException {
|
|
||||||
byte[] data = genTableService.downloadCode(tableId);
|
|
||||||
genCode(response, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(自定义路径)
|
|
||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:code")
|
@GetMapping("/getByTableName")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
public R<Object> getByTableName(@NotNull(message = "表名不能为空") String tableName) {
|
||||||
@GetMapping("/genCode/{tableName}")
|
return R.ok(schemaFieldService.getMetaDataByTableName(tableName));
|
||||||
public R<Void> genCode(@PathVariable("tableName") String tableName) {
|
|
||||||
genTableService.generatorCode(tableName);
|
|
||||||
return R.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 生成后端代码
|
||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableNameStr 表名
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:edit")
|
|
||||||
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
|
||||||
@GetMapping("/synchDb/{tableName}")
|
|
||||||
public R<Void> synchDb(@PathVariable("tableName") String tableName) {
|
|
||||||
genTableService.synchDb(tableName);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量生成代码
|
|
||||||
*
|
|
||||||
* @param tableIdStr 表名串
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:code")
|
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
||||||
@GetMapping("/batchGenCode")
|
@GetMapping("/batchGenCode")
|
||||||
public void batchGenCode(HttpServletResponse response, String tableIdStr) throws IOException {
|
public R<String> batchGenCode(String tableNameStr) {
|
||||||
String[] tableIds = Convert.toStrArray(tableIdStr);
|
genTableService.generateCodeToClasspathByTableNames(tableNameStr);
|
||||||
byte[] data = genTableService.downloadCode(tableIds);
|
return R.ok("代码生成成功");
|
||||||
genCode(response, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成zip文件
|
|
||||||
*/
|
|
||||||
private void genCode(HttpServletResponse response, byte[] data) throws IOException {
|
|
||||||
response.reset();
|
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
|
||||||
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
|
|
||||||
response.addHeader("Content-Length", "" + data.length);
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package org.ruoyi.generator.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.ruoyi.common.core.domain.R;
|
||||||
|
import org.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import org.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
||||||
|
import org.ruoyi.common.log.annotation.Log;
|
||||||
|
import org.ruoyi.common.log.enums.BusinessType;
|
||||||
|
import org.ruoyi.common.web.core.BaseController;
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||||
|
import org.ruoyi.generator.service.SchemaService;
|
||||||
|
import org.ruoyi.helper.DataBaseHelper;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/dev/schema")
|
||||||
|
public class SchemaController extends BaseController {
|
||||||
|
|
||||||
|
private final SchemaService schemaService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schema:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SchemaVo> list(SchemaBo bo, PageQuery pageQuery) {
|
||||||
|
return schemaService.queryPageList(bo, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据模型详细信息
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schema:query")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public R<SchemaVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||||
|
return R.ok(schemaService.queryById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schema:add")
|
||||||
|
@Log(title = "数据模型", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping()
|
||||||
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody SchemaBo bo) {
|
||||||
|
return toAjax(schemaService.insertByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schema:edit")
|
||||||
|
@Log(title = "数据模型", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping()
|
||||||
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SchemaBo bo) {
|
||||||
|
return toAjax(schemaService.updateByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据模型
|
||||||
|
*
|
||||||
|
* @param ids 主键串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schema:remove")
|
||||||
|
@Log(title = "数据模型", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||||
|
return toAjax(schemaService.deleteWithValidByIds(List.of(ids), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据源表名
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schema:getTableNameList")
|
||||||
|
@GetMapping(value = "/getDataNames")
|
||||||
|
public R<Object> getCurrentDataSourceTableNameList() {
|
||||||
|
return R.ok(DataBaseHelper.getCurrentDataSourceTableNameList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package org.ruoyi.generator.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.ruoyi.common.core.domain.R;
|
||||||
|
import org.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import org.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
||||||
|
import org.ruoyi.common.log.annotation.Log;
|
||||||
|
import org.ruoyi.common.log.enums.BusinessType;
|
||||||
|
import org.ruoyi.common.web.core.BaseController;
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaFieldBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaFieldVo;
|
||||||
|
import org.ruoyi.generator.service.SchemaFieldService;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型字段
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/dev/schemaField")
|
||||||
|
public class SchemaFieldController extends BaseController {
|
||||||
|
|
||||||
|
private final SchemaFieldService schemaFieldService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型字段列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaField:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SchemaFieldVo> list(SchemaFieldBo bo, PageQuery pageQuery) {
|
||||||
|
return schemaFieldService.queryPageList(bo, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据模型字段详细信息
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaField:query")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public R<SchemaFieldVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
|
@PathVariable Long id) {
|
||||||
|
return R.ok(schemaFieldService.queryById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型字段
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaField:add")
|
||||||
|
@Log(title = "数据模型字段", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping()
|
||||||
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody SchemaFieldBo bo) {
|
||||||
|
return toAjax(schemaFieldService.insertByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型字段
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaField:edit")
|
||||||
|
@Log(title = "数据模型字段", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping()
|
||||||
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SchemaFieldBo bo) {
|
||||||
|
return toAjax(schemaFieldService.updateByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据模型字段
|
||||||
|
*
|
||||||
|
* @param ids 主键串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaField:remove")
|
||||||
|
@Log(title = "数据模型字段", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ids) {
|
||||||
|
return toAjax(schemaFieldService.deleteWithValidByIds(List.of(ids), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新字段配置
|
||||||
|
*
|
||||||
|
* @param fields 字段配置列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaField:edit")
|
||||||
|
@Log(title = "批量更新字段配置", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping("/batchUpdate")
|
||||||
|
public R<Void> batchUpdateFieldConfig(@Validated(EditGroup.class) @RequestBody List<SchemaFieldBo> fields) {
|
||||||
|
return toAjax(schemaFieldService.batchUpdateFieldConfig(fields));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据模型ID查询字段列表
|
||||||
|
*
|
||||||
|
* @param schemaId 模型ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaField:list")
|
||||||
|
@GetMapping("/listBySchemaId/{schemaId}")
|
||||||
|
public R<List<SchemaFieldVo>> listBySchemaId(@NotNull(message = "模型ID不能为空") @PathVariable Long schemaId) {
|
||||||
|
return R.ok(schemaFieldService.queryListBySchemaId(schemaId));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package org.ruoyi.generator.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.ruoyi.common.core.domain.R;
|
||||||
|
import org.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import org.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
||||||
|
import org.ruoyi.common.log.annotation.Log;
|
||||||
|
import org.ruoyi.common.log.enums.BusinessType;
|
||||||
|
import org.ruoyi.common.web.core.BaseController;
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaGroupBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaGroupVo;
|
||||||
|
import org.ruoyi.generator.service.SchemaGroupService;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型分组
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/dev/schemaGroup")
|
||||||
|
public class SchemaGroupController extends BaseController {
|
||||||
|
|
||||||
|
private final SchemaGroupService schemaGroupService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型分组列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaGroup:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SchemaGroupVo> list(SchemaGroupBo bo, PageQuery pageQuery) {
|
||||||
|
return schemaGroupService.queryPageList(bo, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据模型分组选择列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/select")
|
||||||
|
public R<List<SchemaGroupVo>> select() {
|
||||||
|
SchemaGroupBo bo = new SchemaGroupBo();
|
||||||
|
List<SchemaGroupVo> list = schemaGroupService.queryList(bo);
|
||||||
|
return R.ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据模型分组详细信息
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaGroup:query")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public R<SchemaGroupVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||||||
|
return R.ok(schemaGroupService.queryById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型分组
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaGroup:add")
|
||||||
|
@Log(title = "数据模型分组", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping()
|
||||||
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody SchemaGroupBo bo) {
|
||||||
|
return toAjax(schemaGroupService.insertByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型分组
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaGroup:edit")
|
||||||
|
@Log(title = "数据模型分组", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping()
|
||||||
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SchemaGroupBo bo) {
|
||||||
|
return toAjax(schemaGroupService.updateByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据模型分组
|
||||||
|
*
|
||||||
|
* @param ids 主键串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("dev:schemaGroup:remove")
|
||||||
|
@Log(title = "数据模型分组", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||||||
|
return toAjax(schemaGroupService.deleteWithValidByIds(List.of(ids), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
package org.ruoyi.generator.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.ruoyi.common.core.utils.StringUtils;
|
|
||||||
import org.ruoyi.core.domain.BaseEntity;
|
|
||||||
import org.ruoyi.generator.constant.GenConstants;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务表 gen_table
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@TableName("gen_table")
|
|
||||||
public class GenTable extends BaseEntity {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编号
|
|
||||||
*/
|
|
||||||
@TableId(value = "table_id")
|
|
||||||
private Long tableId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 表名称
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "表名称不能为空")
|
|
||||||
private String tableName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 表描述
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "表描述不能为空")
|
|
||||||
private String tableComment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关联父表的表名
|
|
||||||
*/
|
|
||||||
private String subTableName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 本表关联父表的外键名
|
|
||||||
*/
|
|
||||||
private String subTableFkName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 实体类名称(首字母大写)
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "实体类名称不能为空")
|
|
||||||
private String className;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用的模板(crud单表操作 tree树表操作 sub主子表操作)
|
|
||||||
*/
|
|
||||||
private String tplCategory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成包路径
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "生成包路径不能为空")
|
|
||||||
private String packageName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成模块名
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "生成模块名不能为空")
|
|
||||||
private String moduleName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成业务名
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "生成业务名不能为空")
|
|
||||||
private String businessName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成功能名
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "生成功能名不能为空")
|
|
||||||
private String functionName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成作者
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "作者不能为空")
|
|
||||||
private String functionAuthor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码方式(0zip压缩包 1自定义路径)
|
|
||||||
*/
|
|
||||||
private String genType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成路径(不填默认项目路径)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
|
||||||
private String genPath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键信息
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private GenTableColumn pkColumn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 表列信息
|
|
||||||
*/
|
|
||||||
@Valid
|
|
||||||
@TableField(exist = false)
|
|
||||||
private List<GenTableColumn> columns;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 其它生成选项
|
|
||||||
*/
|
|
||||||
private String options;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备注
|
|
||||||
*/
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 树编码字段
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String treeCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 树父编码字段
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String treeParentCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 树名称字段
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String treeName;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 菜单id列表
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private List<Long> menuIds;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上级菜单ID字段
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String parentMenuId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上级菜单名称字段
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String parentMenuName;
|
|
||||||
|
|
||||||
public boolean isTree() {
|
|
||||||
return isTree(this.tplCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTree(String tplCategory) {
|
|
||||||
return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCrud() {
|
|
||||||
return isCrud(this.tplCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isCrud(String tplCategory) {
|
|
||||||
return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSuperColumn(String javaField) {
|
|
||||||
return isSuperColumn(this.tplCategory, javaField);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isSuperColumn(String tplCategory, String javaField) {
|
|
||||||
return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
package org.ruoyi.generator.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.apache.ibatis.type.JdbcType;
|
|
||||||
import org.ruoyi.common.core.utils.StringUtils;
|
|
||||||
import org.ruoyi.core.domain.BaseEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 代码生成业务字段表 gen_table_column
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@TableName("gen_table_column")
|
|
||||||
public class GenTableColumn extends BaseEntity {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编号
|
|
||||||
*/
|
|
||||||
@TableId(value = "column_id")
|
|
||||||
private Long columnId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 归属表编号
|
|
||||||
*/
|
|
||||||
private Long tableId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 列名称
|
|
||||||
*/
|
|
||||||
private String columnName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 列描述
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String columnComment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 列类型
|
|
||||||
*/
|
|
||||||
private String columnType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JAVA类型
|
|
||||||
*/
|
|
||||||
private String javaType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JAVA字段名
|
|
||||||
*/
|
|
||||||
@NotBlank(message = "Java属性不能为空")
|
|
||||||
private String javaField;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否主键(1是)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String isPk;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否自增(1是)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String isIncrement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否必填(1是)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String isRequired;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为插入字段(1是)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String isInsert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否编辑字段(1是)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String isEdit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否列表字段(1是)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String isList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否查询字段(1是)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.ALWAYS, jdbcType = JdbcType.VARCHAR)
|
|
||||||
private String isQuery;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围)
|
|
||||||
*/
|
|
||||||
private String queryType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件)
|
|
||||||
*/
|
|
||||||
private String htmlType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字典类型
|
|
||||||
*/
|
|
||||||
private String dictType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 排序
|
|
||||||
*/
|
|
||||||
private Integer sort;
|
|
||||||
|
|
||||||
public String getCapJavaField() {
|
|
||||||
return StringUtils.capitalize(javaField);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPk() {
|
|
||||||
return isPk(this.isPk);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPk(String isPk) {
|
|
||||||
return isPk != null && StringUtils.equals("1", isPk);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIncrement() {
|
|
||||||
return isIncrement(this.isIncrement);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIncrement(String isIncrement) {
|
|
||||||
return isIncrement != null && StringUtils.equals("1", isIncrement);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRequired() {
|
|
||||||
return isRequired(this.isRequired);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRequired(String isRequired) {
|
|
||||||
return isRequired != null && StringUtils.equals("1", isRequired);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInsert() {
|
|
||||||
return isInsert(this.isInsert);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInsert(String isInsert) {
|
|
||||||
return isInsert != null && StringUtils.equals("1", isInsert);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEdit() {
|
|
||||||
return isInsert(this.isEdit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEdit(String isEdit) {
|
|
||||||
return isEdit != null && StringUtils.equals("1", isEdit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isList() {
|
|
||||||
return isList(this.isList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isList(String isList) {
|
|
||||||
return isList != null && StringUtils.equals("1", isList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isQuery() {
|
|
||||||
return isQuery(this.isQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isQuery(String isQuery) {
|
|
||||||
return isQuery != null && StringUtils.equals("1", isQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSuperColumn() {
|
|
||||||
return isSuperColumn(this.javaField);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isSuperColumn(String javaField) {
|
|
||||||
return StringUtils.equalsAnyIgnoreCase(javaField,
|
|
||||||
// BaseEntity
|
|
||||||
"createBy", "createTime", "updateBy", "updateTime",
|
|
||||||
// TreeEntity
|
|
||||||
"parentName", "parentId");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUsableColumn() {
|
|
||||||
return isUsableColumn(javaField);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isUsableColumn(String javaField) {
|
|
||||||
// isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
|
|
||||||
return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String readConverterExp() {
|
|
||||||
String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
if (StringUtils.isNotEmpty(remarks)) {
|
|
||||||
for (String value : remarks.split(" ")) {
|
|
||||||
if (StringUtils.isNotEmpty(value)) {
|
|
||||||
Object startStr = value.subSequence(0, 1);
|
|
||||||
String endStr = value.substring(1);
|
|
||||||
sb.append(StringUtils.EMPTY).append(startStr).append("=").append(endStr).append(StringUtils.SEPARATOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.deleteCharAt(sb.length() - 1).toString();
|
|
||||||
} else {
|
|
||||||
return this.columnComment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package org.ruoyi.generator.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.ruoyi.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型对象 dev_schema
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("dev_schema")
|
||||||
|
public class Schema extends BaseEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组ID
|
||||||
|
*/
|
||||||
|
private Long schemaGroupId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表注释
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储引擎
|
||||||
|
*/
|
||||||
|
private String engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表字段
|
||||||
|
*/
|
||||||
|
private String listKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索表单字段
|
||||||
|
*/
|
||||||
|
private String searchFormKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单设计
|
||||||
|
*/
|
||||||
|
private String designer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
@TableLogic
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户编号
|
||||||
|
*/
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package org.ruoyi.generator.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.ruoyi.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型字段对象 dev_schema_field
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("dev_schema_field")
|
||||||
|
public class SchemaField extends BaseEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型ID
|
||||||
|
*/
|
||||||
|
private Long schemaId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
private String schemaName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段注释
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否主键
|
||||||
|
*/
|
||||||
|
private String isPk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否必填
|
||||||
|
*/
|
||||||
|
private String isRequired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否唯一
|
||||||
|
*/
|
||||||
|
private String isUnique;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认值
|
||||||
|
*/
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段长度
|
||||||
|
*/
|
||||||
|
private Integer length;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小数位数
|
||||||
|
*/
|
||||||
|
private Integer scale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否列表显示(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否查询字段(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否插入字段(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isInsert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否编辑字段(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isEdit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围)
|
||||||
|
*/
|
||||||
|
private String queryType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示类型(input输入框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传、upload文件上传、editor富文本编辑器)
|
||||||
|
*/
|
||||||
|
private String htmlType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型
|
||||||
|
*/
|
||||||
|
private String dictType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展JSON
|
||||||
|
*/
|
||||||
|
private String extendJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
@TableLogic
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户编号
|
||||||
|
*/
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package org.ruoyi.generator.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.ruoyi.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型分组对象 dev_schema_group
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("dev_schema_group")
|
||||||
|
public class SchemaGroup extends BaseEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图标
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
@TableLogic
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户编号
|
||||||
|
*/
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package org.ruoyi.generator.domain.bo;
|
||||||
|
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import org.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import org.ruoyi.core.domain.BaseEntity;
|
||||||
|
import org.ruoyi.generator.domain.Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型业务对象 SchemaBo
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AutoMapper(target = Schema.class, reverseConvertGenerate = false)
|
||||||
|
public class SchemaBo extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组ID
|
||||||
|
*/
|
||||||
|
private Long schemaGroupId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "模型名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型编码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "模型编码不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表注释
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储引擎
|
||||||
|
*/
|
||||||
|
private String engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表字段
|
||||||
|
*/
|
||||||
|
private String listKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索表单字段
|
||||||
|
*/
|
||||||
|
private String searchFormKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单设计
|
||||||
|
*/
|
||||||
|
private String designer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package org.ruoyi.generator.domain.bo;
|
||||||
|
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import org.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import org.ruoyi.core.domain.BaseEntity;
|
||||||
|
import org.ruoyi.generator.domain.SchemaField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型字段业务对象 SchemaFieldBo
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AutoMapper(target = SchemaField.class, reverseConvertGenerate = false)
|
||||||
|
public class SchemaFieldBo extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "模型ID不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private Long schemaId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
@NotNull(message = "模型名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private String schemaName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "字段名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段编码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "字段编码不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段注释
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否主键
|
||||||
|
*/
|
||||||
|
private String isPk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否必填
|
||||||
|
*/
|
||||||
|
private String isRequired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否唯一
|
||||||
|
*/
|
||||||
|
private String isUnique;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认值
|
||||||
|
*/
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段长度
|
||||||
|
*/
|
||||||
|
private Integer length;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小数位数
|
||||||
|
*/
|
||||||
|
private Integer scale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否列表显示(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否查询字段(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否插入字段(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isInsert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否编辑字段(0否 1是)
|
||||||
|
*/
|
||||||
|
private String isEdit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询方式
|
||||||
|
*/
|
||||||
|
private String queryType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示类型
|
||||||
|
*/
|
||||||
|
private String htmlType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型
|
||||||
|
*/
|
||||||
|
private String dictType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展JSON
|
||||||
|
*/
|
||||||
|
private String extendJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package org.ruoyi.generator.domain.bo;
|
||||||
|
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import org.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import org.ruoyi.core.domain.BaseEntity;
|
||||||
|
import org.ruoyi.generator.domain.SchemaGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型分组业务对象 SchemaGroupBo
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AutoMapper(target = SchemaGroup.class, reverseConvertGenerate = false)
|
||||||
|
public class SchemaGroupBo extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "分组名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组编码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "分组编码不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图标
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
package org.ruoyi.generator.domain.vo;
|
||||||
|
|
||||||
|
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.ruoyi.generator.domain.SchemaField;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型字段视图对象 SchemaFieldVo
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AutoMapper(target = SchemaField.class)
|
||||||
|
public class SchemaFieldVo implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型ID
|
||||||
|
*/
|
||||||
|
private Long schemaId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
private String schemaName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段注释
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否主键
|
||||||
|
*/
|
||||||
|
private String isPk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否必填
|
||||||
|
*/
|
||||||
|
private String isRequired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否唯一
|
||||||
|
*/
|
||||||
|
private String isUnique;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认值
|
||||||
|
*/
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段长度
|
||||||
|
*/
|
||||||
|
private Integer length;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小数位数
|
||||||
|
*/
|
||||||
|
private Integer scale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
@Schema(description = "排序")
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否列表显示(0否 1是)
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否列表显示")
|
||||||
|
private String isList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否查询字段(0否 1是)
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否查询字段")
|
||||||
|
private String isQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否插入字段(0否 1是)
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否插入字段")
|
||||||
|
private String isInsert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否编辑字段(0否 1是)
|
||||||
|
*/
|
||||||
|
@Schema(description = "是否编辑字段")
|
||||||
|
private String isEdit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询方式
|
||||||
|
*/
|
||||||
|
@Schema(description = "查询方式")
|
||||||
|
private String queryType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "显示类型")
|
||||||
|
private String htmlType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型
|
||||||
|
*/
|
||||||
|
@Schema(description = "字典类型")
|
||||||
|
private String dictType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@Schema(description = "状态")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展JSON
|
||||||
|
*/
|
||||||
|
private String extendJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package org.ruoyi.generator.domain.vo;
|
||||||
|
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.ruoyi.generator.domain.SchemaGroup;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型分组视图对象 SchemaGroupVo
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AutoMapper(target = SchemaGroup.class)
|
||||||
|
public class SchemaGroupVo implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图标
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package org.ruoyi.generator.domain.vo;
|
||||||
|
|
||||||
|
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.ruoyi.generator.domain.Schema;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型视图对象 SchemaVo
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AutoMapper(target = Schema.class)
|
||||||
|
public class SchemaVo implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组ID
|
||||||
|
*/
|
||||||
|
private Long schemaGroupId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表注释
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储引擎
|
||||||
|
*/
|
||||||
|
private String engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表字段
|
||||||
|
*/
|
||||||
|
private String listKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索表单字段
|
||||||
|
*/
|
||||||
|
private String searchFormKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单设计
|
||||||
|
*/
|
||||||
|
private String designer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.ruoyi.generator.event;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型添加事件
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class SchemaAddedEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
private final Long schemaId;
|
||||||
|
private final String tableName;
|
||||||
|
|
||||||
|
public SchemaAddedEvent(Object source, Long schemaId, String tableName) {
|
||||||
|
super(source);
|
||||||
|
this.schemaId = schemaId;
|
||||||
|
this.tableName = tableName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.ruoyi.generator.event;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.ruoyi.generator.service.SchemaFieldService;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型事件监听器
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SchemaEventListener {
|
||||||
|
|
||||||
|
private final SchemaFieldService schemaFieldService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听数据模型添加事件,自动插入字段数据
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
@EventListener
|
||||||
|
public void handleSchemaAddedEvent(SchemaAddedEvent event) {
|
||||||
|
try {
|
||||||
|
Long schemaId = event.getSchemaId();
|
||||||
|
String tableName = event.getTableName();
|
||||||
|
log.info("开始为数据模型 {} 自动插入字段数据,表名: {}", schemaId, tableName);
|
||||||
|
boolean success = schemaFieldService.batchInsertFieldsByTableName(schemaId, tableName);
|
||||||
|
if (success) {
|
||||||
|
log.info("数据模型 {} 字段数据插入成功", schemaId);
|
||||||
|
} else {
|
||||||
|
log.warn("数据模型 {} 字段数据插入失败", schemaId);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("自动插入字段数据失败: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,445 @@
|
|||||||
|
package org.ruoyi.generator.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.velocity.Template;
|
||||||
|
import org.apache.velocity.VelocityContext;
|
||||||
|
import org.apache.velocity.app.Velocity;
|
||||||
|
import org.ruoyi.common.core.constant.Constants;
|
||||||
|
import org.ruoyi.generator.config.GenConfig;
|
||||||
|
import org.ruoyi.generator.service.IGenTableService;
|
||||||
|
import org.ruoyi.generator.service.SchemaFieldService;
|
||||||
|
import org.ruoyi.generator.service.SchemaService;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaFieldVo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||||
|
import org.ruoyi.generator.util.VelocityInitializer;
|
||||||
|
import org.ruoyi.generator.util.VelocityUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务 服务层实现
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class GenTableServiceImpl implements IGenTableService {
|
||||||
|
|
||||||
|
private final IdentifierGenerator identifierGenerator;
|
||||||
|
private final SchemaService schemaService;
|
||||||
|
private final SchemaFieldService schemaFieldService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于表名称批量生成代码到classpath路径
|
||||||
|
*
|
||||||
|
* @param tableName 表名称数组
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void generateCodeToClasspathByTableNames(String tableName) {
|
||||||
|
try {
|
||||||
|
generateSchemaCodeToClasspathByTableName(tableName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("基于表名称生成代码失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名称生成代码到classpath
|
||||||
|
*/
|
||||||
|
private void generateSchemaCodeToClasspathByTableName(String tableName) {
|
||||||
|
// 查询Schema信息
|
||||||
|
SchemaVo schema = schemaService.queryByTableName(tableName);
|
||||||
|
if (Objects.isNull(schema)) {
|
||||||
|
log.warn("Schema不存在,表名: {}", tableName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 查询Schema字段信息
|
||||||
|
List<SchemaFieldVo> fields = schemaFieldService.queryListByTableName(tableName);
|
||||||
|
if (CollUtil.isEmpty(fields)) {
|
||||||
|
log.warn("Schema字段为空,表名: {}", tableName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
generateCodeFromSchemaData(schema, fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据Schema数据生成代码
|
||||||
|
*/
|
||||||
|
private void generateCodeFromSchemaData(SchemaVo schema, List<SchemaFieldVo> fields) {
|
||||||
|
|
||||||
|
// 初始化Velocity
|
||||||
|
VelocityInitializer.initVelocity();
|
||||||
|
|
||||||
|
// 准备Velocity上下文 - 直接基于Schema数据
|
||||||
|
VelocityContext context = prepareSchemaContext(schema, fields);
|
||||||
|
|
||||||
|
// 获取模板列表
|
||||||
|
List<String> templates = VelocityUtils.getTemplateList();
|
||||||
|
|
||||||
|
// 获取项目根路径
|
||||||
|
String projectPath = getProjectRootPath();
|
||||||
|
|
||||||
|
for (String template : templates) {
|
||||||
|
try {
|
||||||
|
// 渲染模板
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||||
|
tpl.merge(context, sw);
|
||||||
|
|
||||||
|
// 获取文件路径 - 直接基于Schema数据
|
||||||
|
String fileName = getSchemaFileName(template, schema);
|
||||||
|
String fullPath = projectPath + File.separator + fileName;
|
||||||
|
|
||||||
|
// 创建目录
|
||||||
|
File file = new File(fullPath);
|
||||||
|
File parentDir = file.getParentFile();
|
||||||
|
if (!parentDir.exists()) {
|
||||||
|
parentDir.mkdirs();
|
||||||
|
}
|
||||||
|
// 写入文件
|
||||||
|
try (FileWriter writer = new FileWriter(file, StandardCharsets.UTF_8)) {
|
||||||
|
writer.write(sw.toString());
|
||||||
|
}
|
||||||
|
log.info("生成文件: {}", fullPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("生成文件失败,模板: {}, Schema: {}", template, schema.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备基于Schema的Velocity上下文
|
||||||
|
*/
|
||||||
|
private VelocityContext prepareSchemaContext(SchemaVo schema, List<SchemaFieldVo> fields) {
|
||||||
|
VelocityContext context = new VelocityContext();
|
||||||
|
|
||||||
|
// 从配置文件读取基本配置
|
||||||
|
String packageName = GenConfig.getPackageName();
|
||||||
|
String author = GenConfig.getAuthor();
|
||||||
|
String tablePrefix = GenConfig.getTablePrefix();
|
||||||
|
boolean autoRemovePre = GenConfig.getAutoRemovePre();
|
||||||
|
|
||||||
|
// 处理表名和类名
|
||||||
|
String tableName = schema.getTableName();
|
||||||
|
String baseClassName = schema.getTableName();
|
||||||
|
|
||||||
|
// 自动去除表前缀
|
||||||
|
if (autoRemovePre && StrUtil.isNotBlank(tablePrefix)) {
|
||||||
|
String[] prefixes = tablePrefix.split(",");
|
||||||
|
for (String prefix : prefixes) {
|
||||||
|
if (baseClassName.startsWith(prefix.trim())) {
|
||||||
|
baseClassName = baseClassName.substring(prefix.trim().length());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String className = toCamelCase(baseClassName, true); // 首字母大写的类名,如:SysRole
|
||||||
|
String classname = toCamelCase(baseClassName, false); // 首字母小写的类名,如:sysRole
|
||||||
|
String businessName = toCamelCase(baseClassName, false);
|
||||||
|
String moduleName = getModuleName(packageName);
|
||||||
|
|
||||||
|
// 基本信息
|
||||||
|
context.put("tableName", tableName);
|
||||||
|
context.put("tableComment", schema.getComment());
|
||||||
|
context.put("className", classname); // 首字母小写
|
||||||
|
context.put("classname", classname); // 首字母小写(兼容性)
|
||||||
|
context.put("ClassName", className); // 首字母大写
|
||||||
|
context.put("functionName", schema.getName());
|
||||||
|
context.put("functionAuthor", author);
|
||||||
|
context.put("author", author);
|
||||||
|
context.put("datetime", new Date());
|
||||||
|
context.put("packageName", packageName);
|
||||||
|
context.put("moduleName", moduleName);
|
||||||
|
context.put("businessName", businessName);
|
||||||
|
|
||||||
|
// 权限相关
|
||||||
|
context.put("permissionPrefix", moduleName + ":" + businessName);
|
||||||
|
context.put("parentMenuId", "2000"); // 默认父菜单ID,可配置
|
||||||
|
|
||||||
|
// 生成菜单ID
|
||||||
|
List<Long> menuIds = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
menuIds.add(identifierGenerator.nextId(null).longValue());
|
||||||
|
}
|
||||||
|
context.put("menuIds", menuIds);
|
||||||
|
|
||||||
|
// 创建table对象,包含menuIds等信息和方法
|
||||||
|
Map<String, Object> table = new HashMap<>();
|
||||||
|
table.put("menuIds", menuIds);
|
||||||
|
table.put("tableName", tableName);
|
||||||
|
table.put("tableComment", schema.getComment());
|
||||||
|
table.put("className", className);
|
||||||
|
table.put("classname", classname);
|
||||||
|
table.put("functionName", schema.getName());
|
||||||
|
|
||||||
|
// 添加表类型属性(默认为crud类型)
|
||||||
|
table.put("crud", true);
|
||||||
|
table.put("sub", false);
|
||||||
|
table.put("tree", false);
|
||||||
|
|
||||||
|
// 添加isSuperColumn方法
|
||||||
|
table.put("isSuperColumn", new Object() {
|
||||||
|
public boolean isSuperColumn(String javaField) {
|
||||||
|
// 定义超类字段(BaseEntity中的字段)
|
||||||
|
return "createBy".equals(javaField) || "createTime".equals(javaField)
|
||||||
|
|| "updateBy".equals(javaField) || "updateTime".equals(javaField)
|
||||||
|
|| "remark".equals(javaField) || "tenantId".equals(javaField);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
context.put("table", table);
|
||||||
|
|
||||||
|
// 处理字段信息
|
||||||
|
List<Map<String, Object>> columns = new ArrayList<>();
|
||||||
|
Map<String, Object> pkColumn = null;
|
||||||
|
Set<String> importList = new HashSet<>();
|
||||||
|
|
||||||
|
// 添加基础导入
|
||||||
|
importList.add("java.io.Serializable");
|
||||||
|
|
||||||
|
for (SchemaFieldVo field : fields) {
|
||||||
|
Map<String, Object> column = new HashMap<>();
|
||||||
|
String javaType = getJavaType(field.getType());
|
||||||
|
String javaField = StrUtil.toCamelCase(field.getCode());
|
||||||
|
|
||||||
|
column.put("columnName", field.getCode());
|
||||||
|
column.put("columnComment", field.getName());
|
||||||
|
column.put("comment", field.getName()); // 添加comment别名
|
||||||
|
column.put("columnType", field.getType());
|
||||||
|
column.put("javaType", javaType);
|
||||||
|
column.put("javaField", javaField);
|
||||||
|
column.put("capJavaField", toCamelCase(field.getCode(), true));
|
||||||
|
|
||||||
|
// 布尔值属性(兼容两种格式)
|
||||||
|
boolean isPk = "1".equals(field.getIsPk());
|
||||||
|
boolean isRequired = "1".equals(field.getIsRequired());
|
||||||
|
boolean isInsert = "1".equals(field.getIsInsert());
|
||||||
|
boolean isEdit = "1".equals(field.getIsEdit());
|
||||||
|
boolean isList = "1".equals(field.getIsList());
|
||||||
|
boolean isQuery = "1".equals(field.getIsQuery());
|
||||||
|
|
||||||
|
column.put("isPk", isPk ? 1 : 0);
|
||||||
|
column.put("pk", isPk); // 添加pk别名
|
||||||
|
column.put("isRequired", isRequired);
|
||||||
|
column.put("required", isRequired); // 添加required别名
|
||||||
|
column.put("isInsert", isInsert);
|
||||||
|
column.put("insert", isInsert); // 添加insert别名
|
||||||
|
column.put("isEdit", isEdit);
|
||||||
|
column.put("edit", isEdit); // 添加edit别名
|
||||||
|
column.put("isList", isList);
|
||||||
|
column.put("list", isList); // 添加list别名
|
||||||
|
column.put("isQuery", isQuery);
|
||||||
|
column.put("query", isQuery); // 添加query别名
|
||||||
|
|
||||||
|
column.put("queryType", field.getQueryType());
|
||||||
|
column.put("htmlType", field.getHtmlType());
|
||||||
|
column.put("dictType", field.getDictType());
|
||||||
|
column.put("sort", field.getSort());
|
||||||
|
|
||||||
|
// 添加readConverterExp方法
|
||||||
|
column.put("readConverterExp", new Object() {
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据Java类型添加相应的导入
|
||||||
|
addImportForJavaType(javaType, importList);
|
||||||
|
|
||||||
|
columns.add(column);
|
||||||
|
|
||||||
|
// 设置主键列
|
||||||
|
if (isPk) {
|
||||||
|
pkColumn = column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有主键,使用第一个字段作为主键
|
||||||
|
if (pkColumn == null && !columns.isEmpty()) {
|
||||||
|
pkColumn = columns.get(0);
|
||||||
|
// 将第一个字段设置为主键
|
||||||
|
pkColumn.put("isPk", 1);
|
||||||
|
pkColumn.put("pk", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.put("columns", columns);
|
||||||
|
context.put("pkColumn", pkColumn);
|
||||||
|
context.put("importList", new ArrayList<>(importList));
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据Java类型添加相应的导入
|
||||||
|
*/
|
||||||
|
private void addImportForJavaType(String javaType, Set<String> importList) {
|
||||||
|
switch (javaType) {
|
||||||
|
case "BigDecimal":
|
||||||
|
importList.add("java.math.BigDecimal");
|
||||||
|
break;
|
||||||
|
case "Date":
|
||||||
|
importList.add("java.util.Date");
|
||||||
|
break;
|
||||||
|
case "LocalDateTime":
|
||||||
|
importList.add("java.time.LocalDateTime");
|
||||||
|
break;
|
||||||
|
case "LocalDate":
|
||||||
|
importList.add("java.time.LocalDate");
|
||||||
|
break;
|
||||||
|
case "LocalTime":
|
||||||
|
importList.add("java.time.LocalTime");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// 基本类型不需要导入
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从包名中提取模块名
|
||||||
|
*/
|
||||||
|
private String getModuleName(String packageName) {
|
||||||
|
if (StrUtil.isBlank(packageName)) {
|
||||||
|
return "generator";
|
||||||
|
}
|
||||||
|
String[] parts = packageName.split("\\.");
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
return parts[2]; // org.ruoyi.system -> system
|
||||||
|
}
|
||||||
|
return "generator";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取基于Schema的文件名
|
||||||
|
*/
|
||||||
|
private String getSchemaFileName(String template, SchemaVo schema) {
|
||||||
|
// 从配置文件读取配置
|
||||||
|
String packageName = GenConfig.getPackageName();
|
||||||
|
String tablePrefix = GenConfig.getTablePrefix();
|
||||||
|
boolean autoRemovePre = GenConfig.getAutoRemovePre();
|
||||||
|
|
||||||
|
// 处理类名
|
||||||
|
String baseClassName = schema.getTableName();
|
||||||
|
|
||||||
|
// 自动去除表前缀
|
||||||
|
if (autoRemovePre && StrUtil.isNotBlank(tablePrefix)) {
|
||||||
|
String[] prefixes = tablePrefix.split(",");
|
||||||
|
for (String prefix : prefixes) {
|
||||||
|
if (baseClassName.startsWith(prefix.trim())) {
|
||||||
|
baseClassName = baseClassName.substring(prefix.trim().length());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String className = toCamelCase(baseClassName, true); // 首字母大写,如:SysRole
|
||||||
|
// 首字母小写,如:sysRole
|
||||||
|
String moduleName = getModuleName(packageName);
|
||||||
|
String javaPath = "src/main/java/";
|
||||||
|
String mybatisPath = "src/main/resources/mapper/";
|
||||||
|
|
||||||
|
if (template.contains("domain.java.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/domain/" + className + ".java";
|
||||||
|
} else if (template.contains("mapper.java.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/mapper/" + className + "Mapper.java";
|
||||||
|
} else if (template.contains("service.java.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/service/" + className + "Service.java";
|
||||||
|
} else if (template.contains("serviceImpl.java.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/service/impl/" + className + "ServiceImpl.java";
|
||||||
|
} else if (template.contains("controller.java.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/controller/" + className + "Controller.java";
|
||||||
|
} else if (template.contains("vo.java.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/domain/vo/" + className + "Vo.java";
|
||||||
|
} else if (template.contains("bo.java.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/domain/bo/" + className + "Bo.java";
|
||||||
|
} else if (template.contains("mapper.xml.vm")) {
|
||||||
|
return mybatisPath + moduleName + "/" + className + "Mapper.xml";
|
||||||
|
} else if (template.contains("sql.vm")) {
|
||||||
|
return javaPath + packageName.replace(".", "/") + "/sql/" + baseClassName + "_menu.sql";
|
||||||
|
}
|
||||||
|
return template.replace(".vm", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取项目根路径
|
||||||
|
*/
|
||||||
|
private String getProjectRootPath() {
|
||||||
|
// 获取当前类的路径,然后向上查找到项目根目录
|
||||||
|
String classPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
|
File currentDir = new File(classPath).getParentFile();
|
||||||
|
|
||||||
|
// 向上查找,直到找到包含src目录的项目根目录
|
||||||
|
while (currentDir != null && currentDir.exists()) {
|
||||||
|
File srcDir = new File(currentDir, "src");
|
||||||
|
if (srcDir.exists() && srcDir.isDirectory()) {
|
||||||
|
return currentDir.getAbsolutePath();
|
||||||
|
}
|
||||||
|
currentDir = currentDir.getParentFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果找不到,使用当前工作目录
|
||||||
|
return System.getProperty("user.dir");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为驼峰命名
|
||||||
|
*/
|
||||||
|
private String toCamelCase(String str, boolean firstUpperCase) {
|
||||||
|
if (StrUtil.isBlank(str)) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String[] parts = str.split("_");
|
||||||
|
for (int i = 0; i < parts.length; i++) {
|
||||||
|
String part = parts[i].toLowerCase();
|
||||||
|
if (i == 0 && !firstUpperCase) {
|
||||||
|
result.append(part);
|
||||||
|
} else {
|
||||||
|
result.append(part.substring(0, 1).toUpperCase()).append(part.substring(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Java类型
|
||||||
|
*/
|
||||||
|
private String getJavaType(String dbType) {
|
||||||
|
if (StrUtil.isBlank(dbType)) {
|
||||||
|
return "String";
|
||||||
|
}
|
||||||
|
String type = dbType.toLowerCase();
|
||||||
|
if (type.contains("int") || type.contains("tinyint") || type.contains("smallint")) {
|
||||||
|
return "Integer";
|
||||||
|
} else if (type.contains("bigint")) {
|
||||||
|
return "Long";
|
||||||
|
} else if (type.contains("decimal") || type.contains("numeric") || type.contains("float") || type.contains(
|
||||||
|
"double")) {
|
||||||
|
return "BigDecimal";
|
||||||
|
} else if (type.contains("date") || type.contains("time")) {
|
||||||
|
return "Date";
|
||||||
|
} else if (type.contains("bit") || type.contains("boolean")) {
|
||||||
|
return "Boolean";
|
||||||
|
} else {
|
||||||
|
return "String";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,394 @@
|
|||||||
|
package org.ruoyi.generator.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||||
|
import org.ruoyi.common.core.utils.StringUtils;
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.service.SchemaFieldService;
|
||||||
|
import org.ruoyi.generator.service.SchemaGroupService;
|
||||||
|
import org.ruoyi.generator.service.SchemaService;
|
||||||
|
import org.ruoyi.generator.domain.SchemaField;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaFieldBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaFieldVo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaGroupVo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||||
|
import org.ruoyi.generator.mapper.SchemaFieldMapper;
|
||||||
|
import org.ruoyi.helper.DataBaseHelper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型字段Service业务层处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||||
|
|
||||||
|
private final SchemaFieldMapper baseMapper;
|
||||||
|
private final SchemaService schemaService;
|
||||||
|
private final SchemaGroupService schemaGroupService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型字段
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchemaFieldVo queryById(Long id) {
|
||||||
|
return baseMapper.selectVoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型字段列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<SchemaFieldVo> queryPageList(SchemaFieldBo bo, PageQuery pageQuery) {
|
||||||
|
if (Objects.isNull(bo.getSchemaId())) {
|
||||||
|
return TableDataInfo.build();
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<SchemaField> lqw = buildQueryWrapper(bo);
|
||||||
|
Page<SchemaFieldVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<SchemaField> buildQueryWrapper(SchemaFieldBo bo) {
|
||||||
|
LambdaQueryWrapper<SchemaField> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(SchemaField::getSchemaId, bo.getSchemaId());
|
||||||
|
lqw.like(StringUtils.isNotBlank(bo.getName()), SchemaField::getName, bo.getName());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getCode()), SchemaField::getCode, bo.getCode());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getType()), SchemaField::getType, bo.getType());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getIsPk()), SchemaField::getIsPk, bo.getIsPk());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getIsRequired()), SchemaField::getIsRequired, bo.getIsRequired());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getIsList()), SchemaField::getIsList, bo.getIsList());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getIsQuery()), SchemaField::getIsQuery, bo.getIsQuery());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getIsInsert()), SchemaField::getIsInsert, bo.getIsInsert());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getIsEdit()), SchemaField::getIsEdit, bo.getIsEdit());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getQueryType()), SchemaField::getQueryType, bo.getQueryType());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getHtmlType()), SchemaField::getHtmlType, bo.getHtmlType());
|
||||||
|
lqw.like(StringUtils.isNotBlank(bo.getDictType()), SchemaField::getDictType, bo.getDictType());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SchemaField::getStatus, bo.getStatus());
|
||||||
|
lqw.orderByAsc(SchemaField::getSort);
|
||||||
|
return lqw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型字段
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean insertByBo(SchemaFieldBo bo) {
|
||||||
|
SchemaField add = MapstructUtils.convert(bo, SchemaField.class);
|
||||||
|
validEntityBeforeSave(add);
|
||||||
|
boolean flag = baseMapper.insert(add) > 0;
|
||||||
|
if (flag) {
|
||||||
|
bo.setId(add.getId());
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型字段
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean updateByBo(SchemaFieldBo bo) {
|
||||||
|
SchemaField update = MapstructUtils.convert(bo, SchemaField.class);
|
||||||
|
validEntityBeforeSave(update);
|
||||||
|
return baseMapper.updateById(update) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存前的数据校验
|
||||||
|
*/
|
||||||
|
private void validEntityBeforeSave(SchemaField entity) {
|
||||||
|
//TODO 做一些数据校验,如唯一约束
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除数据模型字段
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
|
if (isValid) {
|
||||||
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
|
}
|
||||||
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新字段配置
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean batchUpdateFieldConfig(List<SchemaFieldBo> fields) {
|
||||||
|
if (fields == null || fields.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SchemaFieldBo field : fields) {
|
||||||
|
SchemaField update = MapstructUtils.convert(field, SchemaField.class);
|
||||||
|
validEntityBeforeSave(update);
|
||||||
|
baseMapper.updateById(update);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据模型ID查询字段列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SchemaFieldVo> queryListBySchemaId(Long schemaId) {
|
||||||
|
LambdaQueryWrapper<SchemaField> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(SchemaField::getSchemaId, schemaId);
|
||||||
|
lqw.eq(SchemaField::getStatus, "0"); // 只查询正常状态的字段
|
||||||
|
lqw.orderByAsc(SchemaField::getSort);
|
||||||
|
return baseMapper.selectVoList(lqw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名称查询字段列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SchemaFieldVo> queryListByTableName(String tableName) {
|
||||||
|
// 先根据表名查询Schema
|
||||||
|
SchemaVo schema = schemaService.queryByTableName(tableName);
|
||||||
|
if (schema == null) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
// 再根据Schema ID查询字段列表
|
||||||
|
return queryListBySchemaId(schema.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名获取代码生成元数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object getMetaDataByTableName(String tableName) {
|
||||||
|
// 根据表名查询Schema
|
||||||
|
SchemaVo schema = schemaService.queryByTableName(tableName);
|
||||||
|
if (schema == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SchemaGroupVo schemaGroupVo = schemaGroupService.queryById(schema.getSchemaGroupId());
|
||||||
|
if (schemaGroupVo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 查询Schema对应的字段列表
|
||||||
|
List<SchemaFieldVo> fields = queryListBySchemaId(schema.getId());
|
||||||
|
if (CollUtil.isEmpty(fields)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建代码生成器需要的数据结构
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("schemaGroupCode", schemaGroupVo.getCode());
|
||||||
|
result.put("tableName", schema.getTableName());
|
||||||
|
result.put("tableComment", schema.getComment());
|
||||||
|
result.put("className", toCamelCase(schema.getTableName(), true));
|
||||||
|
// result.put("className", StrUtil.toCamelCase(schema.getTableName()));
|
||||||
|
result.put("tableCamelName", StrUtil.toCamelCase(schema.getTableName()));
|
||||||
|
result.put("functionName", schema.getName());
|
||||||
|
result.put("schemaName", schema.getName());
|
||||||
|
|
||||||
|
// 查找主键字段
|
||||||
|
SchemaFieldVo pkField = fields.stream()
|
||||||
|
.filter(field -> "1".equals(field.getIsPk()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (pkField != null) {
|
||||||
|
Map<String, Object> pkColumn = new HashMap<>();
|
||||||
|
pkColumn.put("columnName", pkField.getCode());
|
||||||
|
pkColumn.put("columnComment", pkField.getName());
|
||||||
|
pkColumn.put("javaField", StrUtil.toCamelCase(pkField.getCode()));
|
||||||
|
pkColumn.put("javaType", getJavaType(pkField.getType()));
|
||||||
|
result.put("pkColumn", pkColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建字段列表
|
||||||
|
List<Map<String, Object>> columns = new ArrayList<>();
|
||||||
|
for (SchemaFieldVo field : fields) {
|
||||||
|
Map<String, Object> column = new HashMap<>();
|
||||||
|
column.put("columnName", field.getCode());
|
||||||
|
column.put("columnComment", field.getName());
|
||||||
|
column.put("javaField", StrUtil.toCamelCase(field.getCode()));
|
||||||
|
column.put("javaType", getJavaType(field.getType()));
|
||||||
|
column.put("htmlType", field.getHtmlType());
|
||||||
|
column.put("isPk", field.getIsPk());
|
||||||
|
column.put("isRequired", field.getIsRequired());
|
||||||
|
column.put("isInsert", field.getIsInsert());
|
||||||
|
column.put("isEdit", field.getIsEdit());
|
||||||
|
column.put("isList", field.getIsList());
|
||||||
|
column.put("isQuery", field.getIsQuery());
|
||||||
|
column.put("component", getComponentType(field.getHtmlType(), field.getQueryType()));
|
||||||
|
column.put("queryType", field.getQueryType());
|
||||||
|
column.put("remark", field.getRemark());
|
||||||
|
columns.add(column);
|
||||||
|
}
|
||||||
|
result.put("columns", columns);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean batchInsertFieldsByTableName(Long schemaId, String tableName) {
|
||||||
|
try {
|
||||||
|
// 获取表的字段信息
|
||||||
|
List<Map<String, Object>> columnInfos = DataBaseHelper.getTableColumnInfo(tableName);
|
||||||
|
if (CollUtil.isEmpty(columnInfos)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<SchemaField> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(SchemaField::getSchemaName, tableName);
|
||||||
|
lqw.eq(SchemaField::getStatus, "0");
|
||||||
|
// 检查是否已存在字段数据
|
||||||
|
List<SchemaFieldVo> existingFields = baseMapper.selectVoList(lqw);
|
||||||
|
if (CollUtil.isNotEmpty(existingFields)) {
|
||||||
|
// 如果已存在字段,则不重复插入
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 转换为 SchemaField 对象并批量插入
|
||||||
|
List<SchemaField> fieldsToInsert = new ArrayList<>();
|
||||||
|
int sort = 1;
|
||||||
|
for (Map<String, Object> columnInfo : columnInfos) {
|
||||||
|
SchemaField field = new SchemaField();
|
||||||
|
field.setSchemaId(schemaId);
|
||||||
|
field.setSchemaName(tableName);
|
||||||
|
field.setName((String) columnInfo.get("columnComment"));
|
||||||
|
field.setCode(StrUtil.toCamelCase((String) columnInfo.get("columnName")));
|
||||||
|
field.setType((String) columnInfo.get("dataType"));
|
||||||
|
field.setLength(Integer.valueOf(String.valueOf(columnInfo.get("columnSize"))));
|
||||||
|
field.setIsPk((Boolean) columnInfo.get("isPrimaryKey") ? "1" : "0");
|
||||||
|
field.setIsRequired(!(Boolean) columnInfo.get("isNullable") ? "1" : "0");
|
||||||
|
field.setIsInsert("1");
|
||||||
|
field.setIsEdit("1");
|
||||||
|
field.setIsList("1");
|
||||||
|
field.setIsQuery("1");
|
||||||
|
field.setQueryType("EQ");
|
||||||
|
field.setHtmlType(getDefaultHtmlType((String) columnInfo.get("dataType")));
|
||||||
|
field.setSort(sort++);
|
||||||
|
field.setStatus("0");
|
||||||
|
// 如果字段名为空,使用字段代码作为名称
|
||||||
|
if (StringUtils.isBlank(field.getName())) {
|
||||||
|
field.setName(field.getCode());
|
||||||
|
}
|
||||||
|
fieldsToInsert.add(field);
|
||||||
|
}
|
||||||
|
// 批量插入
|
||||||
|
fieldsToInsert.forEach(baseMapper::insert);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据数据库类型获取默认的HTML类型
|
||||||
|
*/
|
||||||
|
private String getDefaultHtmlType(String dbType) {
|
||||||
|
if (StringUtils.isBlank(dbType)) {
|
||||||
|
return "input";
|
||||||
|
}
|
||||||
|
|
||||||
|
String type = dbType.toLowerCase();
|
||||||
|
if (type.contains("text") || type.contains("longtext")) {
|
||||||
|
return "textarea";
|
||||||
|
} else if ("datetime".equals(type) || "timestamp".equals(type)) {
|
||||||
|
return "datetime";
|
||||||
|
} else if ("date".equals(type)) {
|
||||||
|
return "date";
|
||||||
|
} else if ("time".equals(type)) {
|
||||||
|
return "time";
|
||||||
|
} else if (type.contains("bit") || type.contains("boolean")) {
|
||||||
|
return "radio";
|
||||||
|
} else {
|
||||||
|
return "input";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为驼峰命名
|
||||||
|
*/
|
||||||
|
private String toCamelCase(String str, boolean firstUpperCase) {
|
||||||
|
if (StringUtils.isBlank(str)) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String[] parts = str.split("_");
|
||||||
|
for (int i = 0; i < parts.length; i++) {
|
||||||
|
String part = parts[i].toLowerCase();
|
||||||
|
if (i == 0 && !firstUpperCase) {
|
||||||
|
result.append(part);
|
||||||
|
} else {
|
||||||
|
result.append(part.substring(0, 1).toUpperCase()).append(part.substring(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Java类型
|
||||||
|
*/
|
||||||
|
private String getJavaType(String dbType) {
|
||||||
|
if (StringUtils.isBlank(dbType)) {
|
||||||
|
return "String";
|
||||||
|
}
|
||||||
|
|
||||||
|
String type = dbType.toLowerCase();
|
||||||
|
if (type.contains("int") || type.contains("tinyint") || type.contains("smallint")) {
|
||||||
|
return "Integer";
|
||||||
|
} else if (type.contains("bigint")) {
|
||||||
|
return "Long";
|
||||||
|
} else if (type.contains("decimal") || type.contains("numeric") || type.contains("float") || type.contains(
|
||||||
|
"double")) {
|
||||||
|
return "BigDecimal";
|
||||||
|
} else if (type.contains("date") || type.contains("time")) {
|
||||||
|
return "Date";
|
||||||
|
} else if (type.contains("bit") || type.contains("boolean")) {
|
||||||
|
return "Boolean";
|
||||||
|
} else {
|
||||||
|
return "String";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取组件类型
|
||||||
|
*/
|
||||||
|
private String getComponentType(String htmlType, String queryType) {
|
||||||
|
if (StringUtils.isBlank(htmlType)) {
|
||||||
|
return "Input";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是范围查询且为日期时间类型,使用 RangePicker
|
||||||
|
if ("BETWEEN".equals(queryType) &&
|
||||||
|
("datetime".equals(htmlType) || "date".equals(htmlType) || "time".equals(htmlType))) {
|
||||||
|
return "RangePicker";
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch (htmlType) {
|
||||||
|
case "textarea" -> "Textarea";
|
||||||
|
case "select" -> "Select";
|
||||||
|
case "radio" -> "RadioGroup";
|
||||||
|
case "checkbox" -> "CheckboxGroup";
|
||||||
|
case "datetime", "date" -> "DatePicker";
|
||||||
|
case "time" -> "TimePicker";
|
||||||
|
case "imageUpload" -> "ImageUpload";
|
||||||
|
case "fileUpload" -> "FileUpload";
|
||||||
|
case "editor" -> "Editor";
|
||||||
|
default -> "Input";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package org.ruoyi.generator.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||||
|
import org.ruoyi.common.core.utils.StringUtils;
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.domain.SchemaGroup;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaGroupBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaGroupVo;
|
||||||
|
import org.ruoyi.generator.mapper.SchemaGroupMapper;
|
||||||
|
import org.ruoyi.generator.service.SchemaGroupService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型分组Service业务层处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class SchemaGroupServiceImpl implements SchemaGroupService {
|
||||||
|
|
||||||
|
private final SchemaGroupMapper baseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型分组
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchemaGroupVo queryById(Long id) {
|
||||||
|
return baseMapper.selectVoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型分组列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<SchemaGroupVo> queryPageList(SchemaGroupBo bo, PageQuery pageQuery) {
|
||||||
|
LambdaQueryWrapper<SchemaGroup> lqw = buildQueryWrapper(bo);
|
||||||
|
Page<SchemaGroupVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型分组列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SchemaGroupVo> queryList(SchemaGroupBo bo) {
|
||||||
|
LambdaQueryWrapper<SchemaGroup> lqw = buildQueryWrapper(bo);
|
||||||
|
return baseMapper.selectVoList(lqw);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<SchemaGroup> buildQueryWrapper(SchemaGroupBo bo) {
|
||||||
|
LambdaQueryWrapper<SchemaGroup> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.like(StringUtils.isNotBlank(bo.getName()), SchemaGroup::getName, bo.getName());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getCode()), SchemaGroup::getCode, bo.getCode());
|
||||||
|
lqw.eq(bo.getSort() != null, SchemaGroup::getSort, bo.getSort());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SchemaGroup::getStatus, bo.getStatus());
|
||||||
|
lqw.orderByAsc(SchemaGroup::getSort);
|
||||||
|
return lqw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型分组
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean insertByBo(SchemaGroupBo bo) {
|
||||||
|
SchemaGroup add = MapstructUtils.convert(bo, SchemaGroup.class);
|
||||||
|
validEntityBeforeSave(add);
|
||||||
|
boolean flag = baseMapper.insert(add) > 0;
|
||||||
|
if (flag) {
|
||||||
|
bo.setId(add.getId());
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型分组
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean updateByBo(SchemaGroupBo bo) {
|
||||||
|
SchemaGroup update = MapstructUtils.convert(bo, SchemaGroup.class);
|
||||||
|
validEntityBeforeSave(update);
|
||||||
|
return baseMapper.updateById(update) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存前的数据校验
|
||||||
|
*/
|
||||||
|
private void validEntityBeforeSave(SchemaGroup entity) {
|
||||||
|
//TODO 做一些数据校验,如唯一约束
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除数据模型分组
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
|
if (isValid) {
|
||||||
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
|
}
|
||||||
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package org.ruoyi.generator.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||||
|
import org.ruoyi.common.core.utils.StringUtils;
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.service.SchemaService;
|
||||||
|
import org.ruoyi.generator.domain.Schema;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||||
|
import org.ruoyi.generator.event.SchemaAddedEvent;
|
||||||
|
import org.ruoyi.generator.mapper.SchemaMapper;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型Service业务层处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class SchemaServiceImpl implements SchemaService {
|
||||||
|
|
||||||
|
private final SchemaMapper baseMapper;
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchemaVo queryById(Long id) {
|
||||||
|
return baseMapper.selectVoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<SchemaVo> queryPageList(SchemaBo bo, PageQuery pageQuery) {
|
||||||
|
LambdaQueryWrapper<Schema> lqw = buildQueryWrapper(bo);
|
||||||
|
Page<SchemaVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SchemaVo> queryList(SchemaBo bo) {
|
||||||
|
LambdaQueryWrapper<Schema> lqw = buildQueryWrapper(bo);
|
||||||
|
return baseMapper.selectVoList(lqw);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<Schema> buildQueryWrapper(SchemaBo bo) {
|
||||||
|
LambdaQueryWrapper<Schema> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(bo.getSchemaGroupId() != null, Schema::getSchemaGroupId, bo.getSchemaGroupId());
|
||||||
|
lqw.like(StringUtils.isNotBlank(bo.getName()), Schema::getName, bo.getName());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getCode()), Schema::getCode, bo.getCode());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getTableName()), Schema::getTableName, bo.getTableName());
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), Schema::getStatus, bo.getStatus());
|
||||||
|
lqw.orderByAsc(Schema::getSort);
|
||||||
|
return lqw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean insertByBo(SchemaBo bo) {
|
||||||
|
Schema add = MapstructUtils.convert(bo, Schema.class);
|
||||||
|
validEntityBeforeSave(add);
|
||||||
|
boolean flag = baseMapper.insert(add) > 0;
|
||||||
|
if (flag) {
|
||||||
|
bo.setId(add.getId());
|
||||||
|
|
||||||
|
// 发布数据模型添加事件,由事件监听器处理字段插入
|
||||||
|
if (StringUtils.isNotBlank(bo.getTableName())) {
|
||||||
|
eventPublisher.publishEvent(new SchemaAddedEvent(this, add.getId(), bo.getTableName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean updateByBo(SchemaBo bo) {
|
||||||
|
Schema update = MapstructUtils.convert(bo, Schema.class);
|
||||||
|
validEntityBeforeSave(update);
|
||||||
|
return baseMapper.updateById(update) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存前的数据校验
|
||||||
|
*/
|
||||||
|
private void validEntityBeforeSave(Schema entity) {
|
||||||
|
//TODO 做一些数据校验,如唯一约束
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除数据模型
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
|
if (isValid) {
|
||||||
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
|
}
|
||||||
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名查询数据模型
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchemaVo queryByTableName(String tableName) {
|
||||||
|
LambdaQueryWrapper<Schema> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(Schema::getTableName, tableName);
|
||||||
|
// 只查询正常状态的模型
|
||||||
|
lqw.eq(Schema::getStatus, "0");
|
||||||
|
return baseMapper.selectVoOne(lqw);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package org.ruoyi.generator.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
|
||||||
import org.ruoyi.core.mapper.BaseMapperPlus;
|
|
||||||
import org.ruoyi.generator.domain.GenTableColumn;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务字段 数据层
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
@InterceptorIgnore(dataPermission = "true", tenantLine = "true")
|
|
||||||
public interface GenTableColumnMapper extends BaseMapperPlus<GenTableColumn, GenTableColumn> {
|
|
||||||
/**
|
|
||||||
* 根据表名称查询列信息
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
* @return 列信息
|
|
||||||
*/
|
|
||||||
List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package org.ruoyi.generator.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.ruoyi.core.mapper.BaseMapperPlus;
|
|
||||||
import org.ruoyi.generator.domain.GenTable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务 数据层
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
@InterceptorIgnore(dataPermission = "true", tenantLine = "true")
|
|
||||||
public interface GenTableMapper extends BaseMapperPlus<GenTable, GenTable> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询据库列表
|
|
||||||
*
|
|
||||||
* @param genTable 查询条件
|
|
||||||
* @return 数据库表集合
|
|
||||||
*/
|
|
||||||
Page<GenTable> selectPageDbTableList(@Param("page") Page<GenTable> page, @Param("genTable") GenTable genTable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询据库列表
|
|
||||||
*
|
|
||||||
* @param tableNames 表名称组
|
|
||||||
* @return 数据库表集合
|
|
||||||
*/
|
|
||||||
List<GenTable> selectDbTableListByNames(String[] tableNames);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有表信息
|
|
||||||
*
|
|
||||||
* @return 表信息集合
|
|
||||||
*/
|
|
||||||
List<GenTable> selectGenTableAll();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询表ID业务信息
|
|
||||||
*
|
|
||||||
* @param id 业务ID
|
|
||||||
* @return 业务信息
|
|
||||||
*/
|
|
||||||
GenTable selectGenTableById(Long id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询表名称业务信息
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
* @return 业务信息
|
|
||||||
*/
|
|
||||||
GenTable selectGenTableByName(String tableName);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.ruoyi.generator.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import org.ruoyi.core.mapper.BaseMapperPlus;
|
||||||
|
import org.ruoyi.generator.domain.SchemaField;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaFieldVo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型字段Mapper接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
public interface SchemaFieldMapper extends BaseMapperPlus<SchemaField, SchemaFieldVo> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.ruoyi.generator.mapper;
|
||||||
|
|
||||||
|
import org.ruoyi.core.mapper.BaseMapperPlus;
|
||||||
|
import org.ruoyi.generator.domain.SchemaGroup;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaGroupVo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型分组Mapper接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
public interface SchemaGroupMapper extends BaseMapperPlus<SchemaGroup, SchemaGroupVo> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.ruoyi.generator.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import org.ruoyi.core.mapper.BaseMapperPlus;
|
||||||
|
import org.ruoyi.generator.domain.Schema;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型Mapper接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
public interface SchemaMapper extends BaseMapperPlus<Schema, SchemaVo> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,456 +0,0 @@
|
|||||||
package org.ruoyi.generator.service;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
|
||||||
import cn.hutool.core.lang.Dict;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.velocity.Template;
|
|
||||||
import org.apache.velocity.VelocityContext;
|
|
||||||
import org.apache.velocity.app.Velocity;
|
|
||||||
import org.ruoyi.common.core.constant.Constants;
|
|
||||||
import org.ruoyi.common.core.exception.ServiceException;
|
|
||||||
import org.ruoyi.common.core.utils.StreamUtils;
|
|
||||||
import org.ruoyi.common.core.utils.StringUtils;
|
|
||||||
import org.ruoyi.common.core.utils.file.FileUtils;
|
|
||||||
import org.ruoyi.common.json.utils.JsonUtils;
|
|
||||||
import org.ruoyi.common.satoken.utils.LoginHelper;
|
|
||||||
import org.ruoyi.core.page.PageQuery;
|
|
||||||
import org.ruoyi.core.page.TableDataInfo;
|
|
||||||
import org.ruoyi.generator.constant.GenConstants;
|
|
||||||
import org.ruoyi.generator.domain.GenTable;
|
|
||||||
import org.ruoyi.generator.domain.GenTableColumn;
|
|
||||||
import org.ruoyi.generator.mapper.GenTableColumnMapper;
|
|
||||||
import org.ruoyi.generator.mapper.GenTableMapper;
|
|
||||||
import org.ruoyi.generator.util.GenUtils;
|
|
||||||
import org.ruoyi.generator.util.VelocityInitializer;
|
|
||||||
import org.ruoyi.generator.util.VelocityUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务 服务层实现
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
//@DS("#header.datasource")
|
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Service
|
|
||||||
public class GenTableServiceImpl implements IGenTableService {
|
|
||||||
|
|
||||||
private final GenTableMapper baseMapper;
|
|
||||||
private final GenTableColumnMapper genTableColumnMapper;
|
|
||||||
private final IdentifierGenerator identifierGenerator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询业务字段列表
|
|
||||||
*
|
|
||||||
* @param tableId 业务字段编号
|
|
||||||
* @return 业务字段集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
|
||||||
return genTableColumnMapper.selectList(new LambdaQueryWrapper<GenTableColumn>()
|
|
||||||
.eq(GenTableColumn::getTableId, tableId)
|
|
||||||
.orderByAsc(GenTableColumn::getSort));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询业务信息
|
|
||||||
*
|
|
||||||
* @param id 业务ID
|
|
||||||
* @return 业务信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public GenTable selectGenTableById(Long id) {
|
|
||||||
GenTable genTable = baseMapper.selectGenTableById(id);
|
|
||||||
setTableFromOptions(genTable);
|
|
||||||
return genTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery) {
|
|
||||||
Page<GenTable> page = baseMapper.selectPage(pageQuery.build(), this.buildGenTableQueryWrapper(genTable));
|
|
||||||
return TableDataInfo.build(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
private QueryWrapper<GenTable> buildGenTableQueryWrapper(GenTable genTable) {
|
|
||||||
Map<String, Object> params = genTable.getParams();
|
|
||||||
QueryWrapper<GenTable> wrapper = Wrappers.query();
|
|
||||||
wrapper.like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName()))
|
|
||||||
.like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment()))
|
|
||||||
.between(params.get("beginTime") != null && params.get("endTime") != null,
|
|
||||||
"create_time", params.get("beginTime"), params.get("endTime"));
|
|
||||||
return wrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery) {
|
|
||||||
Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), genTable);
|
|
||||||
return TableDataInfo.build(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询据库列表
|
|
||||||
*
|
|
||||||
* @param tableNames 表名称组
|
|
||||||
* @return 数据库表集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<GenTable> selectDbTableListByNames(String[] tableNames) {
|
|
||||||
return baseMapper.selectDbTableListByNames(tableNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有表信息
|
|
||||||
*
|
|
||||||
* @return 表信息集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<GenTable> selectGenTableAll() {
|
|
||||||
return baseMapper.selectGenTableAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改业务
|
|
||||||
*
|
|
||||||
* @param genTable 业务信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@Override
|
|
||||||
public void updateGenTable(GenTable genTable) {
|
|
||||||
String options = JsonUtils.toJsonString(genTable.getParams());
|
|
||||||
genTable.setOptions(options);
|
|
||||||
int row = baseMapper.updateById(genTable);
|
|
||||||
if (row > 0) {
|
|
||||||
for (GenTableColumn cenTableColumn : genTable.getColumns()) {
|
|
||||||
genTableColumnMapper.updateById(cenTableColumn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除业务对象
|
|
||||||
*
|
|
||||||
* @param tableIds 需要删除的数据ID
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@Override
|
|
||||||
public void deleteGenTableByIds(Long[] tableIds) {
|
|
||||||
List<Long> ids = Arrays.asList(tableIds);
|
|
||||||
baseMapper.deleteBatchIds(ids);
|
|
||||||
genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, ids));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导入表结构
|
|
||||||
*
|
|
||||||
* @param tableList 导入表列表
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@Override
|
|
||||||
public void importGenTable(List<GenTable> tableList) {
|
|
||||||
String operName = LoginHelper.getUsername();
|
|
||||||
try {
|
|
||||||
for (GenTable table : tableList) {
|
|
||||||
String tableName = table.getTableName();
|
|
||||||
GenUtils.initTable(table, operName);
|
|
||||||
int row = baseMapper.insert(table);
|
|
||||||
if (row > 0) {
|
|
||||||
// 保存列信息
|
|
||||||
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
|
||||||
List<GenTableColumn> saveColumns = new ArrayList<>();
|
|
||||||
for (GenTableColumn column : genTableColumns) {
|
|
||||||
GenUtils.initColumnField(column, table);
|
|
||||||
saveColumns.add(column);
|
|
||||||
}
|
|
||||||
if (CollUtil.isNotEmpty(saveColumns)) {
|
|
||||||
genTableColumnMapper.insertBatch(saveColumns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ServiceException("导入失败:" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 预览代码
|
|
||||||
*
|
|
||||||
* @param tableId 表编号
|
|
||||||
* @return 预览数据列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Map<String, String> previewCode(Long tableId) {
|
|
||||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
|
||||||
// 查询表信息
|
|
||||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
|
||||||
List<Long> menuIds = new ArrayList<>();
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
menuIds.add(identifierGenerator.nextId(null).longValue());
|
|
||||||
}
|
|
||||||
table.setMenuIds(menuIds);
|
|
||||||
// 设置主键列信息
|
|
||||||
setPkColumn(table);
|
|
||||||
VelocityInitializer.initVelocity();
|
|
||||||
|
|
||||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
|
||||||
|
|
||||||
// 获取模板列表
|
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
|
||||||
for (String template : templates) {
|
|
||||||
// 渲染模板
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
|
||||||
tpl.merge(context, sw);
|
|
||||||
dataMap.put(template, sw.toString());
|
|
||||||
}
|
|
||||||
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 tableIds 表名称
|
|
||||||
* @return 数据
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public byte[] downloadCode(String[] tableIds) {
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
|
||||||
for (String tableId : tableIds) {
|
|
||||||
generatorCode(Long.parseLong(tableId), zip);
|
|
||||||
}
|
|
||||||
IoUtil.close(zip);
|
|
||||||
return outputStream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(自定义路径)
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void generatorCode(String tableName) {
|
|
||||||
// 查询表信息
|
|
||||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
|
||||||
// 设置主键列信息
|
|
||||||
setPkColumn(table);
|
|
||||||
|
|
||||||
VelocityInitializer.initVelocity();
|
|
||||||
|
|
||||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
|
||||||
|
|
||||||
// 获取模板列表
|
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
|
||||||
for (String template : templates) {
|
|
||||||
if (!StringUtils.containsAny(template, "sql.vm", "api.ts.vm", "types.ts.vm", "index.vue.vm", "index-tree.vue.vm")) {
|
|
||||||
// 渲染模板
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
|
||||||
tpl.merge(context, sw);
|
|
||||||
try {
|
|
||||||
String path = getGenPath(table, template);
|
|
||||||
FileUtils.writeUtf8String(sw.toString(), path);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步数据库
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@Override
|
|
||||||
public void synchDb(String tableName) {
|
|
||||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
|
||||||
List<GenTableColumn> tableColumns = table.getColumns();
|
|
||||||
Map<String, GenTableColumn> tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName);
|
|
||||||
|
|
||||||
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
|
||||||
if (CollUtil.isEmpty(dbTableColumns)) {
|
|
||||||
throw new ServiceException("同步数据失败,原表结构不存在");
|
|
||||||
}
|
|
||||||
List<String> dbTableColumnNames = StreamUtils.toList(dbTableColumns, GenTableColumn::getColumnName);
|
|
||||||
|
|
||||||
List<GenTableColumn> saveColumns = new ArrayList<>();
|
|
||||||
dbTableColumns.forEach(column -> {
|
|
||||||
GenUtils.initColumnField(column, table);
|
|
||||||
if (tableColumnMap.containsKey(column.getColumnName())) {
|
|
||||||
GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
|
|
||||||
column.setColumnId(prevColumn.getColumnId());
|
|
||||||
if (column.isList()) {
|
|
||||||
// 如果是列表,继续保留查询方式/字典类型选项
|
|
||||||
column.setDictType(prevColumn.getDictType());
|
|
||||||
column.setQueryType(prevColumn.getQueryType());
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk()
|
|
||||||
&& (column.isInsert() || column.isEdit())
|
|
||||||
&& ((column.isUsableColumn()) || (!column.isSuperColumn()))) {
|
|
||||||
// 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
|
|
||||||
column.setIsRequired(prevColumn.getIsRequired());
|
|
||||||
column.setHtmlType(prevColumn.getHtmlType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
saveColumns.add(column);
|
|
||||||
});
|
|
||||||
if (CollUtil.isNotEmpty(saveColumns)) {
|
|
||||||
genTableColumnMapper.insertOrUpdateBatch(saveColumns);
|
|
||||||
}
|
|
||||||
List<GenTableColumn> delColumns = StreamUtils.filter(tableColumns, column -> !dbTableColumnNames.contains(column.getColumnName()));
|
|
||||||
if (CollUtil.isNotEmpty(delColumns)) {
|
|
||||||
List<Long> ids = StreamUtils.toList(delColumns, GenTableColumn::getColumnId);
|
|
||||||
genTableColumnMapper.deleteBatchIds(ids);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询表信息并生成代码
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* 查询表信息并生成代码
|
|
||||||
*/
|
|
||||||
private void generatorCode(Long tableId, ZipOutputStream zip) {
|
|
||||||
// 查询表信息
|
|
||||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
|
||||||
List<Long> menuIds = new ArrayList<>();
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
menuIds.add(identifierGenerator.nextId(null).longValue());
|
|
||||||
}
|
|
||||||
table.setMenuIds(menuIds);
|
|
||||||
// 设置主键列信息
|
|
||||||
setPkColumn(table);
|
|
||||||
|
|
||||||
VelocityInitializer.initVelocity();
|
|
||||||
|
|
||||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
|
||||||
|
|
||||||
// 获取模板列表
|
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
|
||||||
for (String template : templates) {
|
|
||||||
// 渲染模板
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
|
||||||
tpl.merge(context, sw);
|
|
||||||
try {
|
|
||||||
// 添加到zip
|
|
||||||
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
|
|
||||||
IoUtil.write(zip, StandardCharsets.UTF_8, false, sw.toString());
|
|
||||||
IoUtil.close(sw);
|
|
||||||
zip.flush();
|
|
||||||
zip.closeEntry();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改保存参数校验
|
|
||||||
*
|
|
||||||
* @param genTable 业务信息
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void validateEdit(GenTable genTable) {
|
|
||||||
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
|
|
||||||
String options = JsonUtils.toJsonString(genTable.getParams());
|
|
||||||
Dict paramsObj = JsonUtils.parseMap(options);
|
|
||||||
if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) {
|
|
||||||
throw new ServiceException("树编码字段不能为空");
|
|
||||||
} else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_PARENT_CODE))) {
|
|
||||||
throw new ServiceException("树父编码字段不能为空");
|
|
||||||
} else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_NAME))) {
|
|
||||||
throw new ServiceException("树名称字段不能为空");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置主键列信息
|
|
||||||
*
|
|
||||||
* @param table 业务表信息
|
|
||||||
*/
|
|
||||||
public void setPkColumn(GenTable table) {
|
|
||||||
for (GenTableColumn column : table.getColumns()) {
|
|
||||||
if (column.isPk()) {
|
|
||||||
table.setPkColumn(column);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ObjectUtil.isNull(table.getPkColumn())) {
|
|
||||||
table.setPkColumn(table.getColumns().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置代码生成其他选项值
|
|
||||||
*
|
|
||||||
* @param genTable 设置后的生成对象
|
|
||||||
*/
|
|
||||||
public void setTableFromOptions(GenTable genTable) {
|
|
||||||
Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
|
||||||
if (ObjectUtil.isNotNull(paramsObj)) {
|
|
||||||
String treeCode = paramsObj.getStr(GenConstants.TREE_CODE);
|
|
||||||
String treeParentCode = paramsObj.getStr(GenConstants.TREE_PARENT_CODE);
|
|
||||||
String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
|
|
||||||
String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID);
|
|
||||||
String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME);
|
|
||||||
|
|
||||||
genTable.setTreeCode(treeCode);
|
|
||||||
genTable.setTreeParentCode(treeParentCode);
|
|
||||||
genTable.setTreeName(treeName);
|
|
||||||
genTable.setParentMenuId(parentMenuId);
|
|
||||||
genTable.setParentMenuName(parentMenuName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取代码生成地址
|
|
||||||
*
|
|
||||||
* @param table 业务表信息
|
|
||||||
* @param template 模板文件路径
|
|
||||||
* @return 生成地址
|
|
||||||
*/
|
|
||||||
public static String getGenPath(GenTable table, String template) {
|
|
||||||
String genPath = table.getGenPath();
|
|
||||||
if (StringUtils.equals(genPath, "/")) {
|
|
||||||
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
|
|
||||||
}
|
|
||||||
return genPath + File.separator + VelocityUtils.getFileName(template, table);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,13 +1,5 @@
|
|||||||
package org.ruoyi.generator.service;
|
package org.ruoyi.generator.service;
|
||||||
|
|
||||||
import org.ruoyi.core.page.PageQuery;
|
|
||||||
import org.ruoyi.core.page.TableDataInfo;
|
|
||||||
import org.ruoyi.generator.domain.GenTable;
|
|
||||||
import org.ruoyi.generator.domain.GenTableColumn;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务 服务层
|
* 业务 服务层
|
||||||
*
|
*
|
||||||
@@ -16,118 +8,9 @@ import java.util.Map;
|
|||||||
public interface IGenTableService {
|
public interface IGenTableService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询业务字段列表
|
* 基于表名称批量生成代码到classpath路径
|
||||||
*
|
*
|
||||||
* @param tableId 业务字段编号
|
* @param tableName 表名称数组
|
||||||
* @return 业务字段集合
|
|
||||||
*/
|
*/
|
||||||
List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
void generateCodeToClasspathByTableNames(String tableName);
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询业务列表
|
|
||||||
*
|
|
||||||
* @param genTable 业务信息
|
|
||||||
* @return 业务集合
|
|
||||||
*/
|
|
||||||
TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询据库列表
|
|
||||||
*
|
|
||||||
* @param genTable 业务信息
|
|
||||||
* @return 数据库表集合
|
|
||||||
*/
|
|
||||||
TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询据库列表
|
|
||||||
*
|
|
||||||
* @param tableNames 表名称组
|
|
||||||
* @return 数据库表集合
|
|
||||||
*/
|
|
||||||
List<GenTable> selectDbTableListByNames(String[] tableNames);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询所有表信息
|
|
||||||
*
|
|
||||||
* @return 表信息集合
|
|
||||||
*/
|
|
||||||
List<GenTable> selectGenTableAll();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询业务信息
|
|
||||||
*
|
|
||||||
* @param id 业务ID
|
|
||||||
* @return 业务信息
|
|
||||||
*/
|
|
||||||
GenTable selectGenTableById(Long id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改业务
|
|
||||||
*
|
|
||||||
* @param genTable 业务信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
void updateGenTable(GenTable genTable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除业务信息
|
|
||||||
*
|
|
||||||
* @param tableIds 需要删除的表数据ID
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
void deleteGenTableByIds(Long[] tableIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导入表结构
|
|
||||||
*
|
|
||||||
* @param tableList 导入表列表
|
|
||||||
*/
|
|
||||||
void importGenTable(List<GenTable> tableList);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 预览代码
|
|
||||||
*
|
|
||||||
* @param tableId 表编号
|
|
||||||
* @return 预览数据列表
|
|
||||||
*/
|
|
||||||
Map<String, String> previewCode(Long tableId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(下载方式)
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
* @return 数据
|
|
||||||
*/
|
|
||||||
byte[] downloadCode(Long tableName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(自定义路径)
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
* @return 数据
|
|
||||||
*/
|
|
||||||
void generatorCode(String tableName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步数据库
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
*/
|
|
||||||
void synchDb(String tableName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量生成代码(下载方式)
|
|
||||||
*
|
|
||||||
* @param tableIds 表数组
|
|
||||||
* @return 数据
|
|
||||||
*/
|
|
||||||
byte[] downloadCode(String[] tableIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改保存参数校验
|
|
||||||
*
|
|
||||||
* @param genTable 业务信息
|
|
||||||
*/
|
|
||||||
void validateEdit(GenTable genTable);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package org.ruoyi.generator.service;
|
||||||
|
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaFieldBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaFieldVo;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型字段Service接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
public interface SchemaFieldService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型字段
|
||||||
|
*/
|
||||||
|
SchemaFieldVo queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型字段列表
|
||||||
|
*/
|
||||||
|
TableDataInfo<SchemaFieldVo> queryPageList(SchemaFieldBo bo, PageQuery pageQuery);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型字段
|
||||||
|
*/
|
||||||
|
Boolean insertByBo(SchemaFieldBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型字段
|
||||||
|
*/
|
||||||
|
Boolean updateByBo(SchemaFieldBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验并批量删除数据模型字段信息
|
||||||
|
*/
|
||||||
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新字段配置
|
||||||
|
*/
|
||||||
|
Boolean batchUpdateFieldConfig(List<SchemaFieldBo> fields);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据模型ID查询字段列表
|
||||||
|
*/
|
||||||
|
List<SchemaFieldVo> queryListBySchemaId(Long schemaId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名获取代码生成元数据
|
||||||
|
*/
|
||||||
|
Object getMetaDataByTableName(String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名批量插入字段
|
||||||
|
*
|
||||||
|
* @param schemaId 模型ID
|
||||||
|
* @param tableName 表名
|
||||||
|
*/
|
||||||
|
boolean batchInsertFieldsByTableName(Long schemaId, String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名称查询字段列表
|
||||||
|
*
|
||||||
|
* @param tableName 表名称
|
||||||
|
* @return 字段列表
|
||||||
|
*/
|
||||||
|
List<SchemaFieldVo> queryListByTableName(String tableName);
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package org.ruoyi.generator.service;
|
||||||
|
|
||||||
|
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaGroupBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaGroupVo;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型分组Service接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
public interface SchemaGroupService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型分组
|
||||||
|
*/
|
||||||
|
SchemaGroupVo queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型分组列表
|
||||||
|
*/
|
||||||
|
TableDataInfo<SchemaGroupVo> queryPageList(SchemaGroupBo bo, PageQuery pageQuery);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型分组列表
|
||||||
|
*/
|
||||||
|
List<SchemaGroupVo> queryList(SchemaGroupBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型分组
|
||||||
|
*/
|
||||||
|
Boolean insertByBo(SchemaGroupBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型分组
|
||||||
|
*/
|
||||||
|
Boolean updateByBo(SchemaGroupBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验并批量删除数据模型分组信息
|
||||||
|
*/
|
||||||
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package org.ruoyi.generator.service;
|
||||||
|
|
||||||
|
|
||||||
|
import org.ruoyi.core.page.PageQuery;
|
||||||
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
|
import org.ruoyi.generator.domain.bo.SchemaBo;
|
||||||
|
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据模型Service接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-01-01
|
||||||
|
*/
|
||||||
|
public interface SchemaService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型
|
||||||
|
*/
|
||||||
|
SchemaVo queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型列表
|
||||||
|
*/
|
||||||
|
TableDataInfo<SchemaVo> queryPageList(SchemaBo bo, PageQuery pageQuery);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询数据模型列表
|
||||||
|
*/
|
||||||
|
List<SchemaVo> queryList(SchemaBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据模型
|
||||||
|
*/
|
||||||
|
Boolean insertByBo(SchemaBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据模型
|
||||||
|
*/
|
||||||
|
Boolean updateByBo(SchemaBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验并批量删除数据模型信息
|
||||||
|
*/
|
||||||
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名查询数据模型
|
||||||
|
*/
|
||||||
|
SchemaVo queryByTableName(String tableName);
|
||||||
|
}
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
package org.ruoyi.generator.util;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.apache.commons.lang3.RegExUtils;
|
|
||||||
import org.ruoyi.common.core.utils.StringUtils;
|
|
||||||
import org.ruoyi.common.satoken.utils.LoginHelper;
|
|
||||||
import org.ruoyi.generator.config.GenConfig;
|
|
||||||
import org.ruoyi.generator.constant.GenConstants;
|
|
||||||
import org.ruoyi.generator.domain.GenTable;
|
|
||||||
import org.ruoyi.generator.domain.GenTableColumn;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 代码生成器 工具类
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class GenUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化表信息
|
|
||||||
*/
|
|
||||||
public static void initTable(GenTable genTable, String operName) {
|
|
||||||
genTable.setClassName(convertClassName(genTable.getTableName()));
|
|
||||||
genTable.setPackageName(GenConfig.getPackageName());
|
|
||||||
genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
|
|
||||||
genTable.setBusinessName(getBusinessName(genTable.getTableName()));
|
|
||||||
genTable.setFunctionName(replaceText(genTable.getTableComment()));
|
|
||||||
genTable.setFunctionAuthor(GenConfig.getAuthor());
|
|
||||||
genTable.setCreateBy(LoginHelper.getUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化列属性字段
|
|
||||||
*/
|
|
||||||
public static void initColumnField(GenTableColumn column, GenTable table) {
|
|
||||||
String dataType = getDbType(column.getColumnType());
|
|
||||||
String columnName = column.getColumnName();
|
|
||||||
column.setTableId(table.getTableId());
|
|
||||||
column.setCreateBy(table.getCreateBy());
|
|
||||||
// 设置java字段名
|
|
||||||
column.setJavaField(StringUtils.toCamelCase(columnName));
|
|
||||||
// 设置默认类型
|
|
||||||
column.setJavaType(GenConstants.TYPE_STRING);
|
|
||||||
column.setQueryType(GenConstants.QUERY_EQ);
|
|
||||||
|
|
||||||
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
|
|
||||||
// 字符串长度超过500设置为文本域
|
|
||||||
Integer columnLength = getColumnLength(column.getColumnType());
|
|
||||||
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
|
|
||||||
column.setHtmlType(htmlType);
|
|
||||||
} else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
|
|
||||||
column.setJavaType(GenConstants.TYPE_DATE);
|
|
||||||
column.setHtmlType(GenConstants.HTML_DATETIME);
|
|
||||||
} else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
|
|
||||||
column.setHtmlType(GenConstants.HTML_INPUT);
|
|
||||||
|
|
||||||
// 如果是浮点型 统一用BigDecimal
|
|
||||||
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), StringUtils.SEPARATOR);
|
|
||||||
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
|
|
||||||
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
|
|
||||||
}
|
|
||||||
// 如果是整形
|
|
||||||
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
|
|
||||||
column.setJavaType(GenConstants.TYPE_INTEGER);
|
|
||||||
}
|
|
||||||
// 长整形
|
|
||||||
else {
|
|
||||||
column.setJavaType(GenConstants.TYPE_LONG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BO对象 默认插入勾选
|
|
||||||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_ADD, columnName) && !column.isPk()) {
|
|
||||||
column.setIsInsert(GenConstants.REQUIRE);
|
|
||||||
}
|
|
||||||
// BO对象 默认编辑勾选
|
|
||||||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) {
|
|
||||||
column.setIsEdit(GenConstants.REQUIRE);
|
|
||||||
}
|
|
||||||
// BO对象 默认是否必填勾选
|
|
||||||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) {
|
|
||||||
column.setIsRequired(GenConstants.REQUIRE);
|
|
||||||
}
|
|
||||||
// VO对象 默认返回勾选
|
|
||||||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName)) {
|
|
||||||
column.setIsList(GenConstants.REQUIRE);
|
|
||||||
}
|
|
||||||
// BO对象 默认查询勾选
|
|
||||||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
|
|
||||||
column.setIsQuery(GenConstants.REQUIRE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询字段类型
|
|
||||||
if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
|
|
||||||
column.setQueryType(GenConstants.QUERY_LIKE);
|
|
||||||
}
|
|
||||||
// 状态字段设置单选框
|
|
||||||
if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
|
|
||||||
column.setHtmlType(GenConstants.HTML_RADIO);
|
|
||||||
}
|
|
||||||
// 类型&性别字段设置下拉框
|
|
||||||
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|
|
||||||
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) {
|
|
||||||
column.setHtmlType(GenConstants.HTML_SELECT);
|
|
||||||
}
|
|
||||||
// 图片字段设置图片上传控件
|
|
||||||
else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
|
|
||||||
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
|
|
||||||
}
|
|
||||||
// 文件字段设置文件上传控件
|
|
||||||
else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
|
|
||||||
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
|
|
||||||
}
|
|
||||||
// 内容字段设置富文本控件
|
|
||||||
else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
|
|
||||||
column.setHtmlType(GenConstants.HTML_EDITOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验数组是否包含指定值
|
|
||||||
*
|
|
||||||
* @param arr 数组
|
|
||||||
* @param targetValue 值
|
|
||||||
* @return 是否包含
|
|
||||||
*/
|
|
||||||
public static boolean arraysContains(String[] arr, String targetValue) {
|
|
||||||
return Arrays.asList(arr).contains(targetValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取模块名
|
|
||||||
*
|
|
||||||
* @param packageName 包名
|
|
||||||
* @return 模块名
|
|
||||||
*/
|
|
||||||
public static String getModuleName(String packageName) {
|
|
||||||
int lastIndex = packageName.lastIndexOf(".");
|
|
||||||
int nameLength = packageName.length();
|
|
||||||
return StringUtils.substring(packageName, lastIndex + 1, nameLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取业务名
|
|
||||||
*
|
|
||||||
* @param tableName 表名
|
|
||||||
* @return 业务名
|
|
||||||
*/
|
|
||||||
public static String getBusinessName(String tableName) {
|
|
||||||
int firstIndex = tableName.indexOf("_");
|
|
||||||
int nameLength = tableName.length();
|
|
||||||
String businessName = StringUtils.substring(tableName, firstIndex + 1, nameLength);
|
|
||||||
businessName = StringUtils.toCamelCase(businessName);
|
|
||||||
return businessName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 表名转换成Java类名
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
* @return 类名
|
|
||||||
*/
|
|
||||||
public static String convertClassName(String tableName) {
|
|
||||||
boolean autoRemovePre = GenConfig.getAutoRemovePre();
|
|
||||||
String tablePrefix = GenConfig.getTablePrefix();
|
|
||||||
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
|
|
||||||
String[] searchList = StringUtils.split(tablePrefix, StringUtils.SEPARATOR);
|
|
||||||
tableName = replaceFirst(tableName, searchList);
|
|
||||||
}
|
|
||||||
return StringUtils.convertToCamelCase(tableName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量替换前缀
|
|
||||||
*
|
|
||||||
* @param replacementm 替换值
|
|
||||||
* @param searchList 替换列表
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String replaceFirst(String replacementm, String[] searchList) {
|
|
||||||
String text = replacementm;
|
|
||||||
for (String searchString : searchList) {
|
|
||||||
if (replacementm.startsWith(searchString)) {
|
|
||||||
text = replacementm.replaceFirst(searchString, "");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关键字替换
|
|
||||||
*
|
|
||||||
* @param text 需要被替换的名字
|
|
||||||
* @return 替换后的名字
|
|
||||||
*/
|
|
||||||
public static String replaceText(String text) {
|
|
||||||
return RegExUtils.replaceAll(text, "(?:表|若依)", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取数据库类型字段
|
|
||||||
*
|
|
||||||
* @param columnType 列类型
|
|
||||||
* @return 截取后的列类型
|
|
||||||
*/
|
|
||||||
public static String getDbType(String columnType) {
|
|
||||||
if (StringUtils.indexOf(columnType, '(') > 0) {
|
|
||||||
return StringUtils.substringBefore(columnType, "(");
|
|
||||||
} else {
|
|
||||||
return columnType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取字段长度
|
|
||||||
*
|
|
||||||
* @param columnType 列类型
|
|
||||||
* @return 截取后的列类型
|
|
||||||
*/
|
|
||||||
public static Integer getColumnLength(String columnType) {
|
|
||||||
if (StringUtils.indexOf(columnType, '(') > 0) {
|
|
||||||
String length = StringUtils.substringBetween(columnType, "(", ")");
|
|
||||||
return Integer.valueOf(length);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,8 @@ public class VelocityInitializer {
|
|||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
try {
|
try {
|
||||||
// 加载classpath目录下的vm文件
|
// 加载classpath目录下的vm文件
|
||||||
p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
p.setProperty("resource.loader.file.class",
|
||||||
|
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||||
// 定义字符集
|
// 定义字符集
|
||||||
p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8);
|
p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8);
|
||||||
// 初始化Velocity引擎,指定配置Properties
|
// 初始化Velocity引擎,指定配置Properties
|
||||||
|
|||||||
@@ -1,21 +1,11 @@
|
|||||||
package org.ruoyi.generator.util;
|
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 lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.apache.velocity.VelocityContext;
|
|
||||||
import org.ruoyi.common.core.utils.DateUtils;
|
|
||||||
import org.ruoyi.common.core.utils.StringUtils;
|
|
||||||
import org.ruoyi.common.json.utils.JsonUtils;
|
|
||||||
import org.ruoyi.generator.constant.GenConstants;
|
|
||||||
import org.ruoyi.generator.domain.GenTable;
|
|
||||||
import org.ruoyi.generator.domain.GenTableColumn;
|
|
||||||
import org.ruoyi.helper.DataBaseHelper;
|
import org.ruoyi.helper.DataBaseHelper;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板处理工具类
|
* 模板处理工具类
|
||||||
@@ -25,386 +15,33 @@ import java.util.*;
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class VelocityUtils {
|
public class VelocityUtils {
|
||||||
|
|
||||||
/**
|
|
||||||
* 项目空间路径
|
|
||||||
*/
|
|
||||||
private static final String PROJECT_PATH = "main/java";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mybatis空间路径
|
|
||||||
*/
|
|
||||||
private static final String MYBATIS_PATH = "main/resources/mapper";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认上级菜单,系统工具
|
|
||||||
*/
|
|
||||||
private static final String DEFAULT_PARENT_MENU_ID = "3";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置模板变量信息
|
|
||||||
*
|
|
||||||
* @return 模板列表
|
|
||||||
*/
|
|
||||||
public static VelocityContext prepareContext(GenTable genTable) {
|
|
||||||
String moduleName = genTable.getModuleName();
|
|
||||||
String businessName = genTable.getBusinessName();
|
|
||||||
String packageName = genTable.getPackageName();
|
|
||||||
String tplCategory = genTable.getTplCategory();
|
|
||||||
String functionName = genTable.getFunctionName();
|
|
||||||
|
|
||||||
VelocityContext velocityContext = new VelocityContext();
|
|
||||||
velocityContext.put("tplCategory", genTable.getTplCategory());
|
|
||||||
velocityContext.put("tableName", genTable.getTableName());
|
|
||||||
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
|
|
||||||
velocityContext.put("ClassName", genTable.getClassName());
|
|
||||||
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
|
|
||||||
velocityContext.put("moduleName", genTable.getModuleName());
|
|
||||||
velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName()));
|
|
||||||
velocityContext.put("businessName", genTable.getBusinessName());
|
|
||||||
velocityContext.put("basePackage", getPackagePrefix(packageName));
|
|
||||||
velocityContext.put("packageName", packageName);
|
|
||||||
velocityContext.put("author", genTable.getFunctionAuthor());
|
|
||||||
velocityContext.put("datetime", DateUtils.getDate());
|
|
||||||
velocityContext.put("pkColumn", genTable.getPkColumn());
|
|
||||||
velocityContext.put("importList", getImportList(genTable));
|
|
||||||
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
|
|
||||||
velocityContext.put("columns", genTable.getColumns());
|
|
||||||
velocityContext.put("table", genTable);
|
|
||||||
velocityContext.put("dicts", getDicts(genTable));
|
|
||||||
setMenuVelocityContext(velocityContext, genTable);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
|
|
||||||
String options = genTable.getOptions();
|
|
||||||
Dict paramsObj = JsonUtils.parseMap(options);
|
|
||||||
String parentMenuId = getParentMenuId(paramsObj);
|
|
||||||
context.put("parentMenuId", parentMenuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
|
|
||||||
String options = genTable.getOptions();
|
|
||||||
Dict paramsObj = JsonUtils.parseMap(options);
|
|
||||||
String treeCode = getTreecode(paramsObj);
|
|
||||||
String treeParentCode = getTreeParentCode(paramsObj);
|
|
||||||
String treeName = getTreeName(paramsObj);
|
|
||||||
|
|
||||||
context.put("treeCode", treeCode);
|
|
||||||
context.put("treeParentCode", treeParentCode);
|
|
||||||
context.put("treeName", treeName);
|
|
||||||
context.put("expandColumn", getExpandColumn(genTable));
|
|
||||||
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
|
|
||||||
context.put("tree_parent_code", paramsObj.get(GenConstants.TREE_PARENT_CODE));
|
|
||||||
}
|
|
||||||
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
|
|
||||||
context.put("tree_name", paramsObj.get(GenConstants.TREE_NAME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取模板信息
|
|
||||||
*
|
|
||||||
* @return 模板列表
|
|
||||||
*/
|
|
||||||
public static List<String> getTemplateList(String tplCategory) {
|
|
||||||
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");
|
|
||||||
templates.add("vm/java/mapper.java.vm");
|
|
||||||
templates.add("vm/java/service.java.vm");
|
|
||||||
templates.add("vm/java/serviceImpl.java.vm");
|
|
||||||
templates.add("vm/java/controller.java.vm");
|
|
||||||
templates.add("vm/xml/mapper.xml.vm");
|
|
||||||
if (DataBaseHelper.isOracle()) {
|
|
||||||
templates.add("vm/sql/oracle/sql.vm");
|
|
||||||
} else if (DataBaseHelper.isPostgerSql()) {
|
|
||||||
templates.add("vm/sql/postgres/sql.vm");
|
|
||||||
} else if (DataBaseHelper.isSqlServer()) {
|
|
||||||
templates.add("vm/sql/sqlserver/sql.vm");
|
|
||||||
} else {
|
|
||||||
templates.add("vm/sql/sql.vm");
|
|
||||||
}
|
|
||||||
templates.add("vm/ts/api.ts.vm");
|
|
||||||
templates.add("vm/ts/types.ts.vm");
|
|
||||||
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
|
|
||||||
templates.add("vm/vue/index.vue.vm");
|
|
||||||
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
|
||||||
templates.add("vm/vue/index-tree.vue.vm");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加vben5
|
* 获取模板信息
|
||||||
|
*
|
||||||
|
* @return 模板列表
|
||||||
*/
|
*/
|
||||||
templates.add("vm/vben5/api/index.ts.vm");
|
public static List<String> getTemplateList() {
|
||||||
templates.add("vm/vben5/api/model.d.ts.vm");
|
List<String> templates = new ArrayList<>();
|
||||||
templates.add("vm/vben5/views/data.ts.vm");
|
templates.add("vm/java/domain.java.vm");
|
||||||
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
|
templates.add("vm/java/vo.java.vm");
|
||||||
templates.add("vm/vben5/views/index_vben.vue.vm");
|
templates.add("vm/java/bo.java.vm");
|
||||||
templates.add("vm/vben5/views/popup.vue.vm");
|
templates.add("vm/java/mapper.java.vm");
|
||||||
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
templates.add("vm/java/service.java.vm");
|
||||||
templates.add("vm/vben5/views/index_vben_tree.vue.vm");
|
templates.add("vm/java/serviceImpl.java.vm");
|
||||||
templates.add("vm/vben5/views/popup_tree.vue.vm");
|
templates.add("vm/java/controller.java.vm");
|
||||||
}
|
templates.add("vm/xml/mapper.xml.vm");
|
||||||
|
if (DataBaseHelper.isOracle()) {
|
||||||
return templates;
|
templates.add("vm/sql/oracle/sql.vm");
|
||||||
}
|
} else if (DataBaseHelper.isPostgerSql()) {
|
||||||
|
templates.add("vm/sql/postgres/sql.vm");
|
||||||
/**
|
} else if (DataBaseHelper.isSqlServer()) {
|
||||||
* 获取文件名
|
templates.add("vm/sql/sqlserver/sql.vm");
|
||||||
*/
|
} else {
|
||||||
public static String getFileName(String template, GenTable genTable) {
|
templates.add("vm/sql/sql.vm");
|
||||||
// 文件名称
|
|
||||||
String fileName = "";
|
|
||||||
// 包路径
|
|
||||||
String packageName = genTable.getPackageName();
|
|
||||||
// 模块名
|
|
||||||
String moduleName = genTable.getModuleName();
|
|
||||||
// 大写类名
|
|
||||||
String className = genTable.getClassName();
|
|
||||||
// 业务名称
|
|
||||||
String businessName = genTable.getBusinessName();
|
|
||||||
|
|
||||||
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
|
|
||||||
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
|
|
||||||
String vuePath = "vue";
|
|
||||||
|
|
||||||
if (template.contains("domain.java.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
|
|
||||||
}
|
|
||||||
if (template.contains("vo.java.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/domain/vo/{}Vo.java", javaPath, className);
|
|
||||||
}
|
|
||||||
if (template.contains("bo.java.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/domain/bo/{}Bo.java", javaPath, className);
|
|
||||||
}
|
|
||||||
if (template.contains("mapper.java.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
|
|
||||||
} else if (template.contains("service.java.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
|
|
||||||
} else if (template.contains("serviceImpl.java.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
|
|
||||||
} else if (template.contains("controller.java.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
|
|
||||||
} else if (template.contains("mapper.xml.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
|
|
||||||
} else if (template.contains("sql.vm")) {
|
|
||||||
fileName = businessName + "Menu.sql";
|
|
||||||
} else if (template.contains("api.ts.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/api/{}/{}/index.ts", vuePath, moduleName, businessName);
|
|
||||||
} else if (template.contains("types.ts.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/api/{}/{}/types.ts", vuePath, moduleName, businessName);
|
|
||||||
} else if (template.contains("index.vue.vm")) {
|
|
||||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
|
|
||||||
} 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取包前缀
|
|
||||||
*
|
|
||||||
* @param packageName 包名称
|
|
||||||
* @return 包前缀名称
|
|
||||||
*/
|
|
||||||
public static String getPackagePrefix(String packageName) {
|
|
||||||
int lastIndex = packageName.lastIndexOf(".");
|
|
||||||
return StringUtils.substring(packageName, 0, lastIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据列类型获取导入包
|
|
||||||
*
|
|
||||||
* @param genTable 业务表对象
|
|
||||||
* @return 返回需要导入的包列表
|
|
||||||
*/
|
|
||||||
public static HashSet<String> getImportList(GenTable genTable) {
|
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
|
||||||
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.ruoyi.common.translation.annotation.Translation");
|
|
||||||
importList.add("org.ruoyi.common.translation.constant.TransConstant");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return importList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据列类型获取字典组
|
|
||||||
*
|
|
||||||
* @param genTable 业务表对象
|
|
||||||
* @return 返回字典组
|
|
||||||
*/
|
|
||||||
public static String getDicts(GenTable genTable) {
|
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
|
||||||
Set<String> dicts = new HashSet<>();
|
|
||||||
addDicts(dicts, columns);
|
|
||||||
return StringUtils.join(dicts, ", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加字典列表
|
|
||||||
*
|
|
||||||
* @param dicts 字典列表
|
|
||||||
* @param columns 列集合
|
|
||||||
*/
|
|
||||||
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) {
|
|
||||||
for (GenTableColumn column : columns) {
|
|
||||||
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
|
|
||||||
column.getHtmlType(),
|
|
||||||
new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX })) {
|
|
||||||
dicts.add("'" + column.getDictType() + "'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取权限前缀
|
|
||||||
*
|
|
||||||
* @param moduleName 模块名称
|
|
||||||
* @param businessName 业务名称
|
|
||||||
* @return 返回权限前缀
|
|
||||||
*/
|
|
||||||
public static String getPermissionPrefix(String moduleName, String businessName) {
|
|
||||||
return StringUtils.format("{}:{}", moduleName, businessName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取上级菜单ID字段
|
|
||||||
*
|
|
||||||
* @param paramsObj 生成其他选项
|
|
||||||
* @return 上级菜单ID字段
|
|
||||||
*/
|
|
||||||
public static String getParentMenuId(Dict paramsObj) {
|
|
||||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
|
|
||||||
&& StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.PARENT_MENU_ID))) {
|
|
||||||
return paramsObj.getStr(GenConstants.PARENT_MENU_ID);
|
|
||||||
}
|
|
||||||
return DEFAULT_PARENT_MENU_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取树编码
|
|
||||||
*
|
|
||||||
* @param paramsObj 生成其他选项
|
|
||||||
* @return 树编码
|
|
||||||
*/
|
|
||||||
public static String getTreecode(Map<String, Object> paramsObj) {
|
|
||||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE)) {
|
|
||||||
return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)));
|
|
||||||
}
|
|
||||||
return StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取树父编码
|
|
||||||
*
|
|
||||||
* @param paramsObj 生成其他选项
|
|
||||||
* @return 树父编码
|
|
||||||
*/
|
|
||||||
public static String getTreeParentCode(Dict paramsObj) {
|
|
||||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_PARENT_CODE));
|
|
||||||
}
|
|
||||||
return StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取树名称
|
|
||||||
*
|
|
||||||
* @param paramsObj 生成其他选项
|
|
||||||
* @return 树名称
|
|
||||||
*/
|
|
||||||
public static String getTreeName(Dict paramsObj) {
|
|
||||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) {
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_NAME));
|
|
||||||
}
|
|
||||||
return StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取需要在哪一列上面显示展开按钮
|
|
||||||
*
|
|
||||||
* @param genTable 业务表对象
|
|
||||||
* @return 展开按钮列序号
|
|
||||||
*/
|
|
||||||
public static int getExpandColumn(GenTable genTable) {
|
|
||||||
String options = genTable.getOptions();
|
|
||||||
Dict paramsObj = JsonUtils.parseMap(options);
|
|
||||||
String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
|
|
||||||
int num = 0;
|
|
||||||
for (GenTableColumn column : genTable.getColumns()) {
|
|
||||||
if (column.isList()) {
|
|
||||||
num++;
|
|
||||||
String columnName = column.getColumnName();
|
|
||||||
if (columnName.equals(treeName)) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
return templates;
|
||||||
}
|
}
|
||||||
return num;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper
|
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="org.ruoyi.generator.mapper.GenTableColumnMapper">
|
|
||||||
|
|
||||||
<resultMap type="org.ruoyi.generator.domain.GenTableColumn" id="GenTableColumnResult">
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isMySql()">
|
|
||||||
select column_name,
|
|
||||||
(case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required,
|
|
||||||
(case when column_key = 'PRI' then '1' else '0' end) as is_pk,
|
|
||||||
ordinal_position as sort,
|
|
||||||
column_comment,
|
|
||||||
(case when extra = 'auto_increment' then '1' else '0' end) as is_increment,
|
|
||||||
column_type
|
|
||||||
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
|
|
||||||
order by ordinal_position
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isOracle()">
|
|
||||||
select lower(temp.column_name) as column_name,
|
|
||||||
(case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required,
|
|
||||||
(case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk,
|
|
||||||
temp.column_id as sort,
|
|
||||||
temp.comments as column_comment,
|
|
||||||
(case when temp.constraint_type = 'P' then '1' else '0' end) as is_increment,
|
|
||||||
lower(temp.data_type) as column_type
|
|
||||||
from (
|
|
||||||
select col.column_id, col.column_name,col.nullable, col.data_type, colc.comments, uc.constraint_type, row_number()
|
|
||||||
over (partition by col.column_name order by uc.constraint_type desc) as row_flg
|
|
||||||
from user_tab_columns col
|
|
||||||
left join user_col_comments colc on colc.table_name = col.table_name and colc.column_name = col.column_name
|
|
||||||
left join user_cons_columns ucc on ucc.table_name = col.table_name and ucc.column_name = col.column_name
|
|
||||||
left join user_constraints uc on uc.constraint_name = ucc.constraint_name
|
|
||||||
where col.table_name = upper(#{tableName})
|
|
||||||
) temp
|
|
||||||
WHERE temp.row_flg = 1
|
|
||||||
ORDER BY temp.column_id
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isPostgerSql()">
|
|
||||||
SELECT column_name, is_required, is_pk, sort, column_comment, is_increment, column_type
|
|
||||||
FROM (
|
|
||||||
SELECT c.relname AS table_name,
|
|
||||||
a.attname AS column_name,
|
|
||||||
d.description AS column_comment,
|
|
||||||
CASE WHEN a.attnotnull AND con.conname IS NULL THEN 1 ELSE 0
|
|
||||||
END AS is_required,
|
|
||||||
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0
|
|
||||||
END AS is_pk,
|
|
||||||
a.attnum AS sort,
|
|
||||||
CASE WHEN "position"(pg_get_expr(ad.adbin, ad.adrelid),
|
|
||||||
((c.relname::text || '_'::text) || a.attname::text) || '_seq'::text) > 0 THEN 1 ELSE 0
|
|
||||||
END AS is_increment,
|
|
||||||
btrim(
|
|
||||||
CASE WHEN t.typelem <![CDATA[ <> ]]> 0::oid AND t.typlen = '-1'::integer THEN 'ARRAY'::text ELSE
|
|
||||||
CASE WHEN t.typtype = 'd'::"char" THEN format_type(t.typbasetype, NULL::integer)
|
|
||||||
ELSE format_type(a.atttypid, NULL::integer) END
|
|
||||||
END, '"'::text
|
|
||||||
) AS column_type
|
|
||||||
FROM pg_attribute a
|
|
||||||
JOIN (pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid) ON a.attrelid = c.oid
|
|
||||||
LEFT JOIN pg_description d ON d.objoid = c.oid AND a.attnum = d.objsubid
|
|
||||||
LEFT JOIN pg_constraint con ON con.conrelid = c.oid AND (a.attnum = ANY (con.conkey))
|
|
||||||
LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
|
|
||||||
LEFT JOIN pg_type t ON a.atttypid = t.oid
|
|
||||||
WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
|
|
||||||
AND a.attnum > 0
|
|
||||||
AND n.nspname = 'public'::name
|
|
||||||
ORDER BY c.relname, a.attnum
|
|
||||||
) temp
|
|
||||||
WHERE table_name = (#{tableName})
|
|
||||||
AND column_type <![CDATA[ <> ]]> '-'
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isSqlServer()">
|
|
||||||
SELECT
|
|
||||||
cast(A.NAME as nvarchar) as column_name,
|
|
||||||
cast(B.NAME as nvarchar) + (case when B.NAME = 'numeric' then '(' + cast(A.prec as nvarchar) + ',' + cast(A.scale as nvarchar) + ')' else '' end) as column_type,
|
|
||||||
cast(G.[VALUE] as nvarchar) as column_comment,
|
|
||||||
(SELECT 1 FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE Z WHERE TABLE_NAME = D.NAME and A.NAME = Z.column_name ) as is_pk,
|
|
||||||
colorder as sort
|
|
||||||
FROM SYSCOLUMNS A
|
|
||||||
LEFT JOIN SYSTYPES B ON A.XTYPE = B.XUSERTYPE
|
|
||||||
INNER JOIN SYSOBJECTS D ON A.ID = D.ID AND D.XTYPE='U' AND D.NAME != 'DTPROPERTIES'
|
|
||||||
LEFT JOIN SYS.EXTENDED_PROPERTIES G ON A.ID = G.MAJOR_ID AND A.COLID = G.MINOR_ID
|
|
||||||
LEFT JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID AND F.MINOR_ID = 0
|
|
||||||
WHERE D.NAME = #{tableName}
|
|
||||||
ORDER BY A.COLORDER
|
|
||||||
</if>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper
|
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="org.ruoyi.generator.mapper.GenTableMapper">
|
|
||||||
|
|
||||||
<!-- 多结构嵌套自动映射需带上每个实体的主键id 否则映射会失败 -->
|
|
||||||
<resultMap type="org.ruoyi.generator.domain.GenTable" id="GenTableResult">
|
|
||||||
<id property="tableId" column="table_id" />
|
|
||||||
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<resultMap type="org.ruoyi.generator.domain.GenTableColumn" id="GenTableColumnResult">
|
|
||||||
<id property="columnId" column="column_id"/>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<select id="selectPageDbTableList" resultMap="GenTableResult">
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isMySql()">
|
|
||||||
select table_name, table_comment, create_time, update_time
|
|
||||||
from information_schema.tables
|
|
||||||
where table_schema = (select database())
|
|
||||||
AND table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
|
|
||||||
AND table_name NOT IN (select table_name from gen_table)
|
|
||||||
<if test="genTable.tableName != null and genTable.tableName != ''">
|
|
||||||
AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
|
|
||||||
</if>
|
|
||||||
<if test="genTable.tableComment != null and genTable.tableComment != ''">
|
|
||||||
AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%'))
|
|
||||||
</if>
|
|
||||||
order by create_time desc
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isOracle()">
|
|
||||||
select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
|
|
||||||
from user_tables dt, user_tab_comments dtc, user_objects uo
|
|
||||||
where dt.table_name = dtc.table_name
|
|
||||||
and dt.table_name = uo.object_name
|
|
||||||
and uo.object_type = 'TABLE'
|
|
||||||
AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
|
|
||||||
AND lower(dt.table_name) NOT IN (select table_name from gen_table)
|
|
||||||
<if test="genTable.tableName != null and genTable.tableName != ''">
|
|
||||||
AND lower(dt.table_name) like lower(concat(concat('%', #{genTable.tableName}), '%'))
|
|
||||||
</if>
|
|
||||||
<if test="genTable.tableComment != null and genTable.tableComment != ''">
|
|
||||||
AND lower(dtc.comments) like lower(concat(concat('%', #{genTable.tableComment}), '%'))
|
|
||||||
</if>
|
|
||||||
order by create_time desc
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isPostgerSql()">
|
|
||||||
select table_name, table_comment, create_time, update_time
|
|
||||||
from (
|
|
||||||
SELECT c.relname AS table_name,
|
|
||||||
obj_description(c.oid) AS table_comment,
|
|
||||||
CURRENT_TIMESTAMP AS create_time,
|
|
||||||
CURRENT_TIMESTAMP AS update_time
|
|
||||||
FROM pg_class c
|
|
||||||
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
||||||
WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
|
|
||||||
AND c.relname != 'spatial_%'::text
|
|
||||||
AND n.nspname = 'public'::name
|
|
||||||
AND n.nspname <![CDATA[ <> ]]> ''::name
|
|
||||||
) list_table
|
|
||||||
where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
|
|
||||||
AND table_name NOT IN (select table_name from gen_table)
|
|
||||||
<if test="genTable.tableName != null and genTable.tableName != ''">
|
|
||||||
AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
|
|
||||||
</if>
|
|
||||||
<if test="genTable.tableComment != null and genTable.tableComment != ''">
|
|
||||||
AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%'))
|
|
||||||
</if>
|
|
||||||
order by create_time desc
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isSqlServer()">
|
|
||||||
SELECT cast(D.NAME as nvarchar) as table_name,
|
|
||||||
cast(F.VALUE as nvarchar) as table_comment,
|
|
||||||
crdate as create_time,
|
|
||||||
refdate as update_time
|
|
||||||
FROM SYSOBJECTS D
|
|
||||||
INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
|
|
||||||
AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
|
|
||||||
AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
|
|
||||||
AND D.NAME NOT IN (select table_name from gen_table)
|
|
||||||
<if test="genTable.tableName != null and genTable.tableName != ''">
|
|
||||||
AND lower(D.NAME) like lower(concat(N'%', N'${genTable.tableName}', N'%'))
|
|
||||||
</if>
|
|
||||||
<if test="genTable.tableComment != null and genTable.tableComment != ''">
|
|
||||||
AND lower(CAST(F.VALUE AS nvarchar)) like lower(concat(N'%', N'${genTable.tableComment}', N'%'))
|
|
||||||
</if>
|
|
||||||
order by crdate desc
|
|
||||||
</if>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectDbTableListByNames" resultMap="GenTableResult">
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isMySql()">
|
|
||||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
|
||||||
where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
|
|
||||||
and table_name in
|
|
||||||
<foreach collection="array" item="name" open="(" separator="," close=")">
|
|
||||||
#{name}
|
|
||||||
</foreach>
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isOracle()">
|
|
||||||
select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
|
|
||||||
from user_tables dt, user_tab_comments dtc, user_objects uo
|
|
||||||
where dt.table_name = dtc.table_name
|
|
||||||
and dt.table_name = uo.object_name
|
|
||||||
and uo.object_type = 'TABLE'
|
|
||||||
AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
|
|
||||||
AND dt.table_name NOT IN (select table_name from gen_table)
|
|
||||||
and lower(dt.table_name) in
|
|
||||||
<foreach collection="array" item="name" open="(" separator="," close=")">
|
|
||||||
#{name}
|
|
||||||
</foreach>
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isPostgerSql()">
|
|
||||||
select table_name, table_comment, create_time, update_time
|
|
||||||
from (
|
|
||||||
SELECT c.relname AS table_name,
|
|
||||||
obj_description(c.oid) AS table_comment,
|
|
||||||
CURRENT_TIMESTAMP AS create_time,
|
|
||||||
CURRENT_TIMESTAMP AS update_time
|
|
||||||
FROM pg_class c
|
|
||||||
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
||||||
WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
|
|
||||||
AND c.relname != 'spatial_%'::text
|
|
||||||
AND n.nspname = 'public'::name
|
|
||||||
AND n.nspname <![CDATA[ <> ]]> ''::name
|
|
||||||
) list_table
|
|
||||||
where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%'
|
|
||||||
and table_name in
|
|
||||||
<foreach collection="array" item="name" open="(" separator="," close=")">
|
|
||||||
#{name}
|
|
||||||
</foreach>
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isSqlServer()">
|
|
||||||
SELECT cast(D.NAME as nvarchar) as table_name,
|
|
||||||
cast(F.VALUE as nvarchar) as table_comment,
|
|
||||||
crdate as create_time,
|
|
||||||
refdate as update_time
|
|
||||||
FROM SYSOBJECTS D
|
|
||||||
INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
|
|
||||||
AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
|
|
||||||
AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
|
|
||||||
AND D.NAME in
|
|
||||||
<foreach collection="array" item="name" open="(" separator="," close=")">
|
|
||||||
#{name}
|
|
||||||
</foreach>
|
|
||||||
</if>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isMySql()">
|
|
||||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
|
||||||
where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
|
|
||||||
and table_name = #{tableName}
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isOracle()">
|
|
||||||
select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time
|
|
||||||
from user_tables dt, user_tab_comments dtc, user_objects uo
|
|
||||||
where dt.table_name = dtc.table_name
|
|
||||||
and dt.table_name = uo.object_name
|
|
||||||
and uo.object_type = 'TABLE'
|
|
||||||
AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
|
|
||||||
AND dt.table_name NOT IN (select table_name from gen_table)
|
|
||||||
and lower(dt.table_name) = #{tableName}
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isPostgerSql()">
|
|
||||||
select table_name, table_comment, create_time, update_time
|
|
||||||
from (
|
|
||||||
SELECT c.relname AS table_name,
|
|
||||||
obj_description(c.oid) AS table_comment,
|
|
||||||
CURRENT_TIMESTAMP AS create_time,
|
|
||||||
CURRENT_TIMESTAMP AS update_time
|
|
||||||
FROM pg_class c
|
|
||||||
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
||||||
WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
|
|
||||||
AND c.relname != 'spatial_%'::text
|
|
||||||
AND n.nspname = 'public'::name
|
|
||||||
AND n.nspname <![CDATA[ <> ]]> ''::name
|
|
||||||
) list_table
|
|
||||||
where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%'
|
|
||||||
and table_name = #{tableName}
|
|
||||||
</if>
|
|
||||||
<if test="@org.ruoyi.helper.DataBaseHelper@isSqlServer()">
|
|
||||||
SELECT cast(D.NAME as nvarchar) as table_name,
|
|
||||||
cast(F.VALUE as nvarchar) as table_comment,
|
|
||||||
crdate as create_time,
|
|
||||||
refdate as update_time
|
|
||||||
FROM SYSOBJECTS D
|
|
||||||
INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
|
|
||||||
AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
|
|
||||||
AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
|
|
||||||
AND D.NAME = #{tableName}
|
|
||||||
</if>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
|
|
||||||
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
|
||||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
|
||||||
FROM gen_table t
|
|
||||||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
|
||||||
where t.table_id = #{tableId} order by c.sort
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
|
|
||||||
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
|
||||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
|
||||||
FROM gen_table t
|
|
||||||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
|
||||||
where t.table_name = #{tableName} order by c.sort
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
|
|
||||||
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
|
|
||||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
|
||||||
FROM gen_table t
|
|
||||||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
|
||||||
order by c.sort
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
java包使用 `.` 分割 resource 目录使用 `/` 分割
|
|
||||||
<br>
|
|
||||||
此文件目的 防止文件夹粘连找不到 `xml` 文件
|
|
||||||
@@ -21,28 +21,28 @@ import ${import};
|
|||||||
@AutoMapper(target = ${ClassName}.class, reverseConvertGenerate = false)
|
@AutoMapper(target = ${ClassName}.class, reverseConvertGenerate = false)
|
||||||
public class ${ClassName}Bo extends BaseEntity {
|
public class ${ClassName}Bo extends BaseEntity {
|
||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if(!$table.isSuperColumn($column.javaField) && ($column.query || $column.insert || $column.edit))
|
#if(!$table.isSuperColumn($column.javaField) && ($column.query || $column.insert || $column.edit))
|
||||||
/**
|
/**
|
||||||
* $column.columnComment
|
* $column.columnComment
|
||||||
*/
|
*/
|
||||||
#if($column.insert && $column.edit)
|
#if($column.insert && $column.edit)
|
||||||
#set($Group="AddGroup.class, EditGroup.class")
|
#set($Group="AddGroup.class, EditGroup.class")
|
||||||
#elseif($column.insert)
|
#elseif($column.insert)
|
||||||
#set($Group="AddGroup.class")
|
#set($Group="AddGroup.class")
|
||||||
#elseif($column.edit)
|
#elseif($column.edit)
|
||||||
#set($Group="EditGroup.class")
|
#set($Group="EditGroup.class")
|
||||||
#end
|
#end
|
||||||
#if($column.required)
|
#if($column.required)
|
||||||
#if($column.javaType == 'String')
|
#if($column.javaType == 'String')
|
||||||
@NotBlank(message = "$column.columnComment不能为空", groups = { $Group })
|
@NotBlank(message = "$column.columnComment不能为空", groups = { $Group })
|
||||||
#else
|
#else
|
||||||
@NotNull(message = "$column.columnComment不能为空", groups = { $Group })
|
@NotNull(message = "$column.columnComment不能为空", groups = { $Group })
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
private $column.javaType $column.javaField;
|
private $column.javaType $column.javaField;
|
||||||
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,21 +39,21 @@ public class ${ClassName}Controller extends BaseController {
|
|||||||
|
|
||||||
private final I${ClassName}Service ${className}Service;
|
private final I${ClassName}Service ${className}Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("${permissionPrefix}:list")
|
@SaCheckPermission("${permissionPrefix}:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud || $table.sub)
|
||||||
public TableDataInfo<${ClassName}Vo> list(${ClassName}Bo bo, PageQuery pageQuery) {
|
public TableDataInfo<${ClassName}Vo> list(${ClassName}Bo bo, PageQuery pageQuery) {
|
||||||
return ${className}Service.queryPageList(bo, pageQuery);
|
return ${className}Service.queryPageList(bo, pageQuery);
|
||||||
}
|
}
|
||||||
#elseif($table.tree)
|
#elseif($table.tree)
|
||||||
public R<List<${ClassName}Vo>> list(${ClassName}Bo bo) {
|
public R<List<${ClassName}Vo>> list(${ClassName}Bo bo) {
|
||||||
List<${ClassName}Vo> list = ${className}Service.queryList(bo);
|
List<${ClassName}Vo> list = ${className}Service.queryList(bo);
|
||||||
return R.ok(list);
|
return R.ok(list);
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出${functionName}列表
|
* 导出${functionName}列表
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
package ${packageName}.domain;
|
package ${packageName}.domain;
|
||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.javaField=='tenantId')
|
#if($column.javaField=='tenantId')
|
||||||
#set($IsTenant=1)
|
#set($IsTenant=1)
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#if($IsTenant==1)
|
#if($IsTenant==1)
|
||||||
import core.tenant.common.org.ruoyi.TenantEntity;
|
import core.tenant.common.org.ruoyi.TenantEntity;
|
||||||
#else
|
#else
|
||||||
#end
|
#end
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
#foreach ($import in $importList)
|
#foreach ($import in $importList)
|
||||||
import ${import};
|
import ${import};
|
||||||
#end
|
#end
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|
||||||
@@ -25,35 +25,35 @@ import java.io.Serial;
|
|||||||
* @date ${datetime}
|
* @date ${datetime}
|
||||||
*/
|
*/
|
||||||
#if($IsTenant==1)
|
#if($IsTenant==1)
|
||||||
#set($Entity="TenantEntity")
|
#set($Entity="TenantEntity")
|
||||||
#else
|
#else
|
||||||
#set($Entity="BaseEntity")
|
#set($Entity="BaseEntity")
|
||||||
#end
|
#end
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName("${tableName}")
|
@TableName("${tableName}")
|
||||||
public class ${ClassName} extends ${Entity} {
|
public class ${ClassName} extends ${Entity} {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if(!$table.isSuperColumn($column.javaField))
|
#if(!$table.isSuperColumn($column.javaField))
|
||||||
/**
|
/**
|
||||||
* $column.columnComment
|
* $column.columnComment
|
||||||
*/
|
*/
|
||||||
#if($column.javaField=='delFlag')
|
#if($column.javaField=='delFlag')
|
||||||
@TableLogic
|
@TableLogic
|
||||||
#end
|
#end
|
||||||
#if($column.javaField=='version')
|
#if($column.javaField=='version')
|
||||||
@Version
|
@Version
|
||||||
#end
|
#end
|
||||||
#if($column.isPk==1)
|
#if($column.isPk==1)
|
||||||
@TableId(value = "$column.columnName")
|
@TableId(value = "$column.columnName")
|
||||||
#end
|
#end
|
||||||
private $column.javaType $column.javaField;
|
private $column.javaType $column.javaField;
|
||||||
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package ${packageName}.service;
|
|||||||
import ${packageName}.domain.${ClassName};
|
import ${packageName}.domain.${ClassName};
|
||||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||||
import ${packageName}.domain.bo.${ClassName}Bo;
|
import ${packageName}.domain.bo.${ClassName}Bo;
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud || $table.sub)
|
||||||
import org.ruoyi.core.page.TableDataInfo;
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
import org.ruoyi.core.page.PageQuery;
|
import org.ruoyi.core.page.PageQuery;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -22,14 +22,14 @@ public interface I${ClassName}Service {
|
|||||||
/**
|
/**
|
||||||
* 查询${functionName}
|
* 查询${functionName}
|
||||||
*/
|
*/
|
||||||
${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField});
|
${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||||
|
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud || $table.sub)
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
*/
|
*/
|
||||||
TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery);
|
TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package ${packageName}.service.impl;
|
|||||||
|
|
||||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud || $table.sub)
|
||||||
import org.ruoyi.core.page.TableDataInfo;
|
import org.ruoyi.core.page.TableDataInfo;
|
||||||
import org.ruoyi.core.page.PageQuery;
|
import org.ruoyi.core.page.PageQuery;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
#end
|
#end
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -36,21 +36,21 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
|||||||
* 查询${functionName}
|
* 查询${functionName}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){
|
public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
||||||
return baseMapper.selectVoById(${pkColumn.javaField});
|
return baseMapper.selectVoById(${pkColumn.javaField});
|
||||||
}
|
}
|
||||||
|
|
||||||
#if($table.crud || $table.sub)
|
#if($table.crud || $table.sub)
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery) {
|
public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery) {
|
||||||
LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo);
|
LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo);
|
||||||
Page<${ClassName}Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
Page<${ClassName}Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询${functionName}列表
|
* 查询${functionName}列表
|
||||||
@@ -64,27 +64,27 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
|||||||
private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}Bo bo) {
|
private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}Bo bo) {
|
||||||
Map<String, Object> params = bo.getParams();
|
Map<String, Object> params = bo.getParams();
|
||||||
LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery();
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if($column.query)
|
#if($column.query)
|
||||||
#set($queryType=$column.queryType)
|
#set($queryType=$column.queryType)
|
||||||
#set($javaField=$column.javaField)
|
#set($javaField=$column.javaField)
|
||||||
#set($javaType=$column.javaType)
|
#set($javaType=$column.javaType)
|
||||||
#set($columnName=$column.columnName)
|
#set($columnName=$column.columnName)
|
||||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
#set($mpMethod=$column.queryType.toLowerCase())
|
#set($mpMethod=$column.queryType.toLowerCase())
|
||||||
#if($queryType != 'BETWEEN')
|
#if($queryType != 'BETWEEN')
|
||||||
#if($javaType == 'String')
|
#if($javaType == 'String')
|
||||||
#set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())')
|
#set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())')
|
||||||
#else
|
#else
|
||||||
#set($condition='bo.get'+$AttrName+'() != null')
|
#set($condition='bo.get'+$AttrName+'() != null')
|
||||||
#end
|
#end
|
||||||
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName());
|
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName());
|
||||||
#else
|
#else
|
||||||
lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null,
|
lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null,
|
||||||
${ClassName}::get$AttrName ,params.get("begin$AttrName"), params.get("end$AttrName"));
|
${ClassName}::get$AttrName , params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
return lqw;
|
return lqw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,10 +93,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean insertByBo(${ClassName}Bo bo) {
|
public Boolean insertByBo(${ClassName}Bo bo) {
|
||||||
${ClassName} add = MapstructUtils.convert(bo, ${ClassName}.class);
|
${ClassName} add = MapstructUtils.convert(bo, ${ClassName}. class);
|
||||||
validEntityBeforeSave(add);
|
validEntityBeforeSave(add);
|
||||||
boolean flag = baseMapper.insert(add) > 0;
|
boolean flag = baseMapper.insert(add) > 0;
|
||||||
#set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)})
|
#set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)})
|
||||||
if (flag) {
|
if (flag) {
|
||||||
bo.set$pk(add.get$pk());
|
bo.set$pk(add.get$pk());
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateByBo(${ClassName}Bo bo) {
|
public Boolean updateByBo(${ClassName}Bo bo) {
|
||||||
${ClassName} update = MapstructUtils.convert(bo, ${ClassName}.class);
|
${ClassName} update = MapstructUtils.convert(bo, ${ClassName}. class);
|
||||||
validEntityBeforeSave(update);
|
validEntityBeforeSave(update);
|
||||||
return baseMapper.updateById(update) > 0;
|
return baseMapper.updateById(update) > 0;
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
|||||||
/**
|
/**
|
||||||
* 保存前的数据校验
|
* 保存前的数据校验
|
||||||
*/
|
*/
|
||||||
private void validEntityBeforeSave(${ClassName} entity){
|
private void validEntityBeforeSave(${ClassName} entity) {
|
||||||
//TODO 做一些数据校验,如唯一约束
|
//TODO 做一些数据校验,如唯一约束
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) {
|
public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) {
|
||||||
if(isValid){
|
if (isValid) {
|
||||||
//TODO 做一些业务上的校验,判断是否需要校验
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
}
|
}
|
||||||
return baseMapper.deleteBatchIds(ids) > 0;
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ${packageName}.domain.vo;
|
package ${packageName}.domain.vo;
|
||||||
|
|
||||||
#foreach ($import in $importList)
|
#foreach ($import in $importList)
|
||||||
import ${import};
|
import ${import};
|
||||||
#end
|
#end
|
||||||
import ${packageName}.domain.${ClassName};
|
import ${packageName}.domain.${ClassName};
|
||||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
@@ -16,7 +16,6 @@ import java.io.Serializable;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${functionName}视图对象 ${tableName}
|
* ${functionName}视图对象 ${tableName}
|
||||||
*
|
*
|
||||||
@@ -31,29 +30,29 @@ public class ${ClassName}Vo implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.list)
|
#if($column.list)
|
||||||
/**
|
/**
|
||||||
* $column.columnComment
|
* $column.columnComment
|
||||||
*/
|
*/
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
#if($parentheseIndex != -1)
|
#if($parentheseIndex != -1)
|
||||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
#else
|
#else
|
||||||
#set($comment=$column.columnComment)
|
#set($comment=$column.columnComment)
|
||||||
#end
|
#end
|
||||||
#if(${column.dictType} && ${column.dictType} != '')
|
#if(${column.dictType} && ${column.dictType} != '')
|
||||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||||
@ExcelDictFormat(dictType = "${column.dictType}")
|
@ExcelDictFormat(dictType = "${column.dictType}")
|
||||||
#elseif($parentheseIndex != -1)
|
#elseif($parentheseIndex != -1)
|
||||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||||
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
||||||
#else
|
#else
|
||||||
@ExcelProperty(value = "${comment}")
|
@ExcelProperty(value = "${comment}")
|
||||||
#end
|
#end
|
||||||
private $column.javaType $column.javaField;
|
private $column.javaType $column.javaField;
|
||||||
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
import request from '@/utils/request'
|
|
||||||
|
|
||||||
// 查询${functionName}列表
|
|
||||||
export function list${BusinessName}(query) {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}/list',
|
|
||||||
method: 'get',
|
|
||||||
params: query
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询${functionName}详细
|
|
||||||
export function get${BusinessName}(${pkColumn.javaField}) {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增${functionName}
|
|
||||||
export function add${BusinessName}(data) {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改${functionName}
|
|
||||||
export function update${BusinessName}(data) {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}',
|
|
||||||
method: 'put',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除${functionName}
|
|
||||||
export function del${BusinessName}(${pkColumn.javaField}) {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
|
||||||
method: 'delete'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
import request from '@/utils/request';
|
|
||||||
import {AxiosPromise} from 'axios';
|
|
||||||
import {${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO} from '@/api/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询${functionName}列表
|
|
||||||
* @param query
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const list${BusinessName} = (query?: ${BusinessName}Query): AxiosPromise<${BusinessName}VO[]> => {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}/list',
|
|
||||||
method: 'get',
|
|
||||||
params: query
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询${functionName}详细
|
|
||||||
* @param ${pkColumn.javaField}
|
|
||||||
*/
|
|
||||||
export const get${BusinessName} = (${pkColumn.javaField}: string | number): AxiosPromise<${BusinessName}VO> => {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
|
||||||
method: 'get'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增${functionName}
|
|
||||||
* @param data
|
|
||||||
*/
|
|
||||||
export const add${BusinessName} = (data: ${BusinessName}Form) => {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改${functionName}
|
|
||||||
* @param data
|
|
||||||
*/
|
|
||||||
export const update${BusinessName} = (data: ${BusinessName}Form) => {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}',
|
|
||||||
method: 'put',
|
|
||||||
data: data
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除${functionName}
|
|
||||||
* @param ${pkColumn.javaField}
|
|
||||||
*/
|
|
||||||
export const del${BusinessName} = (${pkColumn.javaField}: string | number | Array<string | number>) => {
|
|
||||||
return request({
|
|
||||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
|
||||||
method: 'delete'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
export interface ${BusinessName}VO {
|
|
||||||
#foreach ($column in $columns)
|
|
||||||
#if($column.insert || $column.edit)
|
|
||||||
/**
|
|
||||||
* $column.columnComment
|
|
||||||
*/
|
|
||||||
$column.javaField:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
|
||||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
|
||||||
#elseif($column.javaType == 'Boolean') boolean;
|
|
||||||
#else string;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ${BusinessName}Form extends BaseEntity {
|
|
||||||
#foreach ($column in $columns)
|
|
||||||
#if($column.insert || $column.edit)
|
|
||||||
/**
|
|
||||||
* $column.columnComment
|
|
||||||
*/
|
|
||||||
$column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
|
||||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
|
||||||
#elseif($column.javaType == 'Boolean') boolean;
|
|
||||||
#else string;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ${BusinessName}Query #if(!${treeCode})extends PageQuery #end{
|
|
||||||
#foreach ($column in $columns)
|
|
||||||
#if($column.query)
|
|
||||||
/**
|
|
||||||
* $column.columnComment
|
|
||||||
*/
|
|
||||||
$column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
|
||||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
|
||||||
#elseif($column.javaType == 'Boolean') boolean;
|
|
||||||
#else string;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user