mirror of https://gitee.com/y_project/RuoYi.git
feat(all): 自动数据源切换修改
parent
7da0ffc2f7
commit
e8c1bae9f8
|
@ -44,11 +44,11 @@ public class OracleSlaveDataAutoPushService {
|
|||
|
||||
@Resource(name = "His")
|
||||
VpMessageRecordService vpMessageRecordService;
|
||||
@Resource(name = "Db1")
|
||||
@Resource(name = "db1")
|
||||
VpMessageRecordService db1vpMessageRecordService;
|
||||
@Resource(name = "Db2")
|
||||
@Resource(name = "db2")
|
||||
VpMessageRecordService db2vpMessageRecordService;
|
||||
@Resource(name = "Db3")
|
||||
@Resource(name = "db3")
|
||||
VpMessageRecordService db3vpMessageRecordService;
|
||||
|
||||
private String url;
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.neuhis.his.domain.entity.VpComPatientinfo;
|
|||
|
||||
import com.neuhis.his.mapper.Db1DataMapper;
|
||||
import com.neuhis.his.service.Db1DataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -15,7 +14,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@DataSource(value = DataSourceType.Db1)
|
||||
@DataSource(value = DataSourceType.WINLIS)
|
||||
public class Db1DataServiceImpl implements Db1DataService {
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
// Robin 2024-7-5
|
||||
@Service("Db1")
|
||||
@DataSource(value = DataSourceType.Db1)
|
||||
@Service("db1")
|
||||
@DataSource(value = DataSourceType.WINLIS)
|
||||
public class Db1VpMessageRecordServiceImpl implements VpMessageRecordService {
|
||||
@Autowired
|
||||
private VpMessageRecordMapper vpMessageRecordMapper;
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@DataSource(value = DataSourceType.Db2)
|
||||
@DataSource(value = DataSourceType.DB2)
|
||||
public class Db2DataServiceImpl implements Db2DataService {
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -6,13 +6,11 @@ import com.neuhis.his.domain.entity.VpMessageRecord;
|
|||
import com.neuhis.his.mapper.VpMessageRecordMapper;
|
||||
import com.neuhis.his.service.VpMessageRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
// Robin 2024-7-5
|
||||
@Service("Db2")
|
||||
@DataSource(value = DataSourceType.Db2)
|
||||
@Service("db2")
|
||||
@DataSource(value = DataSourceType.DB2)
|
||||
public class Db2VpMessageRecordServiceImpl implements VpMessageRecordService {
|
||||
@Autowired
|
||||
private VpMessageRecordMapper vpMessageRecordMapper;
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@DataSource(value = DataSourceType.Db3)
|
||||
@DataSource(value = DataSourceType.DB3)
|
||||
public class Db3DataServiceImpl implements Db3DataService {
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
// Robin 2024-7-5
|
||||
@Service("Db3")
|
||||
@DataSource(value = DataSourceType.Db3)
|
||||
@Service("db3")
|
||||
@DataSource(value = DataSourceType.DB3)
|
||||
public class Db3VpMessageRecordServiceImpl implements VpMessageRecordService {
|
||||
@Autowired
|
||||
private VpMessageRecordMapper vpMessageRecordMapper;
|
||||
|
|
|
@ -3,12 +3,8 @@ package com.neuhis.his.service.impl.winlis;
|
|||
import com.neuhis.his.service.lis.IWinLisService;
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
import com.ruoyi.common.enums.DataSourceType;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Winlis相关
|
||||
*
|
||||
|
@ -16,7 +12,7 @@ import java.util.stream.Collectors;
|
|||
* @date 2025/3/4 17:38
|
||||
**/
|
||||
@Service
|
||||
@DataSource(value = DataSourceType.Db2)
|
||||
@DataSource(value = DataSourceType.DB2)
|
||||
public class WinLisServiceImpl implements IWinLisService {
|
||||
@Override
|
||||
public String getLisCaOriginText(String testdate, String barcode, String machineid) {
|
||||
|
|
|
@ -58,7 +58,7 @@ spring:
|
|||
url: jdbc:oracle:thin:@20.0.0.40:1521/hisdb
|
||||
username: hit_app
|
||||
password: hit
|
||||
db1:
|
||||
winlis: #参考类:DruidConfig、DataSourceType
|
||||
# 从数据源开关/默认关闭
|
||||
enabled: true
|
||||
driverClassName: oracle.jdbc.OracleDriver
|
||||
|
@ -126,75 +126,12 @@ spring:
|
|||
charset: UTF-8
|
||||
enabled: true
|
||||
force: true
|
||||
# 模板引擎
|
||||
thymeleaf:
|
||||
mode: HTML
|
||||
encoding: utf-8
|
||||
# 禁用缓存
|
||||
cache: false
|
||||
# 资源信息
|
||||
messages:
|
||||
# 国际化资源文件路径
|
||||
basename: static/i18n/messages
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
# 文件上传
|
||||
servlet:
|
||||
multipart:
|
||||
# 单个文件大小
|
||||
max-file-size: 10MB
|
||||
# 设置总上传的文件大小
|
||||
max-request-size: 20MB
|
||||
# 服务模块
|
||||
devtools:
|
||||
restart:
|
||||
# 热部署开关
|
||||
enabled: true
|
||||
# PageHelper分页插件
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
supportMethodsArguments: true
|
||||
params: count=countSql
|
||||
|
||||
# Shiro
|
||||
shiro:
|
||||
user:
|
||||
# 登录地址
|
||||
loginUrl: /login
|
||||
# 权限认证失败地址
|
||||
unauthorizedUrl: /unauth
|
||||
# 首页地址
|
||||
indexUrl: /index
|
||||
# 验证码开关
|
||||
captchaEnabled: true
|
||||
# 验证码类型 math 数字计算 char 字符验证
|
||||
captchaType: math
|
||||
cookie:
|
||||
# 设置Cookie的域名 默认空,即当前访问的域名
|
||||
domain:
|
||||
# 设置cookie的有效访问路径
|
||||
path: /
|
||||
# 设置HttpOnly属性
|
||||
httpOnly: true
|
||||
# 设置Cookie的过期时间,天为单位
|
||||
maxAge: 30
|
||||
# 设置密钥,务必保持唯一性(生成方式,直接拷贝到main运行即可)Base64.encodeToString(CipherUtils.generateNewKey(128, "AES").getEncoded()) (默认启动生成随机秘钥,随机秘钥会导致之前客户端RememberMe Cookie无效,如设置固定秘钥RememberMe Cookie则有效)
|
||||
cipherKey:
|
||||
session:
|
||||
# Session超时时间,-1代表永不过期(默认30分钟)
|
||||
expireTime: 30
|
||||
# 同步session到数据库的周期(默认1分钟)
|
||||
dbSyncPeriod: 1
|
||||
# 相隔多久检查一次session的有效性,默认就是10分钟
|
||||
validationInterval: 10
|
||||
# 同一个用户最大会话数,比如2的意思是同一个账号允许最多同时两个人登录(默认-1不限制)
|
||||
maxSession: -1
|
||||
# 踢出之前登录的/之后登录的用户,默认踢出之前登录的用户
|
||||
kickoutAfter: false
|
||||
rememberMe:
|
||||
# 是否开启记住我
|
||||
enabled: true
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
|
@ -217,15 +154,6 @@ task:
|
|||
#删除数据推送历史日志
|
||||
deleteLogPushRecordHis: false
|
||||
|
||||
# 防止XSS攻击
|
||||
xss:
|
||||
# 过滤开关
|
||||
enabled: true
|
||||
# 排除链接(多个用逗号分隔)
|
||||
excludes: /system/notice/*,/system/post/*
|
||||
# 匹配链接
|
||||
urlPatterns: /system/*,/monitor/*,/tool/*
|
||||
|
||||
# Swagger配置
|
||||
swagger:
|
||||
# 是否开启swagger
|
||||
|
|
|
@ -84,7 +84,8 @@ mybatis:
|
|||
|
||||
# PageHelper分页插件
|
||||
pagehelper:
|
||||
helperDialect: mysql
|
||||
#helperDialect: mysql #多数据,注释这里
|
||||
autoRuntimeDialect: true #多数据源,添加此句,
|
||||
supportMethodsArguments: true
|
||||
params: count=countSql
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package com.ruoyi.common.enums;
|
||||
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
|
||||
/**
|
||||
* 数据源
|
||||
*
|
||||
* @author ruoyi
|
||||
* {@link DataSource}
|
||||
*/
|
||||
public enum DataSourceType
|
||||
{
|
||||
|
@ -17,8 +20,20 @@ public enum DataSourceType
|
|||
*/
|
||||
SLAVE,
|
||||
|
||||
Db1,//如:WinLis
|
||||
Db2,//如:Pacs
|
||||
Db3,//如,手麻
|
||||
/**
|
||||
* DruidConfig#winlisDataSource
|
||||
*/
|
||||
WINLIS,
|
||||
/**
|
||||
* DruidConfig#pacsDataSource
|
||||
*/
|
||||
PACS,
|
||||
/**
|
||||
* DruidConfig#orisDataSource
|
||||
*/
|
||||
ORIS,
|
||||
DB1,
|
||||
DB2,
|
||||
DB3,
|
||||
;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import com.ruoyi.framework.datasource.DynamicDataSource;
|
|||
|
||||
/**
|
||||
* druid 配置多数据源
|
||||
*
|
||||
* {@link DataSourceType#SLAVE}
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
|
@ -49,6 +49,41 @@ public class DruidConfig
|
|||
return druidProperties.dataSource(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("spring.datasource.druid.winlis")
|
||||
@ConditionalOnProperty(
|
||||
prefix = "spring.datasource.druid.winlis",
|
||||
name = {"enabled"},
|
||||
havingValue = "true"
|
||||
)
|
||||
public DataSource winlisDataSource(DruidProperties druidProperties) {
|
||||
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
||||
return druidProperties.dataSource(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("spring.datasource.druid.pacs")
|
||||
@ConditionalOnProperty(
|
||||
prefix = "spring.datasource.druid.pacs",
|
||||
name = {"enabled"},
|
||||
havingValue = "true"
|
||||
)
|
||||
public DataSource pacsDataSource(DruidProperties druidProperties) {
|
||||
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
||||
return druidProperties.dataSource(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("spring.datasource.druid.oris")
|
||||
@ConditionalOnProperty(
|
||||
prefix = "spring.datasource.druid.oris",
|
||||
name = {"enabled"},
|
||||
havingValue = "true"
|
||||
)
|
||||
public DataSource orisDataSource(DruidProperties druidProperties) {
|
||||
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
||||
return druidProperties.dataSource(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("spring.datasource.druid.db1")
|
||||
|
@ -82,6 +117,12 @@ public class DruidConfig
|
|||
Map<Object, Object> targetDataSources = new HashMap<>();
|
||||
targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
|
||||
setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");
|
||||
setDataSource(targetDataSources, DataSourceType.WINLIS.name(), "winlisDataSource");
|
||||
setDataSource(targetDataSources, DataSourceType.PACS.name(), "pacsDataSource");
|
||||
setDataSource(targetDataSources, DataSourceType.ORIS.name(), "orisDataSource");
|
||||
setDataSource(targetDataSources, DataSourceType.DB1.name(), "db1DataSource");
|
||||
setDataSource(targetDataSources, DataSourceType.DB2.name(), "db2DataSource");
|
||||
setDataSource(targetDataSources, DataSourceType.DB3.name(), "db3DataSource");
|
||||
return new DynamicDataSource(masterDataSource, targetDataSources);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.generator.config;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
@ -30,6 +31,9 @@ public class GenConfig
|
|||
/** 是否允许生成文件覆盖到本地(自定义路径) */
|
||||
public static boolean allowOverwrite;
|
||||
|
||||
/** 数据库类型: mysql、oracle、sqlite、postgresql */
|
||||
public static DbType dbType;
|
||||
|
||||
public static String getAuthor()
|
||||
{
|
||||
return author;
|
||||
|
@ -84,4 +88,9 @@ public class GenConfig
|
|||
{
|
||||
GenConfig.allowOverwrite = allowOverwrite;
|
||||
}
|
||||
|
||||
@Value("${dbType}")
|
||||
public void setDbType(DbType dbType) {
|
||||
GenConfig.dbType = dbType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,15 @@ package com.ruoyi.generator.controller;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
import com.ruoyi.common.config.datasource.DynamicDataSourceContextHolder;
|
||||
import com.ruoyi.common.enums.DataSourceType;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
|
@ -49,11 +55,15 @@ public class GenController extends BaseController
|
|||
{
|
||||
private String prefix = "tool/gen";
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private IGenTableService genTableService;
|
||||
@Resource(name = "IGenTableService_Oracle")
|
||||
private IGenTableService genTableService2Oracle;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private IGenTableColumnService genTableColumnService;
|
||||
@Resource(name = "IGenTableColumnService_Oracle")
|
||||
private IGenTableColumnService genTableColumnService2Oracle;
|
||||
|
||||
@RequiresPermissions("tool:gen:view")
|
||||
@GetMapping()
|
||||
|
@ -71,7 +81,12 @@ public class GenController extends BaseController
|
|||
public TableDataInfo genList(GenTable genTable)
|
||||
{
|
||||
startPage();
|
||||
List<GenTable> list = genTableService.selectGenTableList(genTable);
|
||||
List<GenTable> list = new ArrayList<>();
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
list = genTableService.selectGenTableList(genTable);
|
||||
} else {
|
||||
list = genTableService2Oracle.selectGenTableList(genTable);
|
||||
}
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
@ -84,7 +99,13 @@ public class GenController extends BaseController
|
|||
public TableDataInfo dataList(GenTable genTable)
|
||||
{
|
||||
startPage();
|
||||
List<GenTable> list = genTableService.selectDbTableList(genTable);
|
||||
List<GenTable> list = new ArrayList<>();
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
list = genTableService.selectDbTableList(genTable);
|
||||
} else {
|
||||
|
||||
list = genTableService2Oracle.selectDbTableList(genTable);
|
||||
}
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
@ -97,7 +118,12 @@ public class GenController extends BaseController
|
|||
public TableDataInfo columnList(GenTableColumn genTableColumn)
|
||||
{
|
||||
TableDataInfo dataInfo = new TableDataInfo();
|
||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(genTableColumn);
|
||||
List<GenTableColumn> list = new ArrayList<>();
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
list = genTableColumnService.selectGenTableColumnListByTableId(genTableColumn);
|
||||
} else {
|
||||
list = genTableColumnService2Oracle.selectGenTableColumnListByTableId(genTableColumn);
|
||||
}
|
||||
dataInfo.setRows(list);
|
||||
dataInfo.setTotal(list.size());
|
||||
return dataInfo;
|
||||
|
@ -133,9 +159,18 @@ public class GenController extends BaseController
|
|||
{
|
||||
String[] tableNames = Convert.toStrArray(tables);
|
||||
// 查询表信息
|
||||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
||||
List<GenTable> tableList = new ArrayList<>();
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
tableList = genTableService.selectDbTableListByNames(tableNames);
|
||||
} else {
|
||||
tableList = genTableService2Oracle.selectDbTableListByNames(tableNames);
|
||||
}
|
||||
String operName = Convert.toStr(PermissionUtils.getPrincipalProperty("loginName"));
|
||||
genTableService.importGenTable(tableList, operName);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
genTableService.importGenTable(tableList, operName);
|
||||
} else {
|
||||
genTableService2Oracle.importGenTable(tableList, operName);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
@ -146,8 +181,16 @@ public class GenController extends BaseController
|
|||
@GetMapping("/edit/{tableId}")
|
||||
public String edit(@PathVariable("tableId") Long tableId, ModelMap mmap)
|
||||
{
|
||||
GenTable table = genTableService.selectGenTableById(tableId);
|
||||
List<GenTable> genTables = genTableService.selectGenTableAll();
|
||||
GenTable table = null;
|
||||
List<GenTable> genTables = new ArrayList<>();
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
genTables = genTableService.selectGenTableAll();
|
||||
table = genTableService.selectGenTableById(tableId);
|
||||
} else {
|
||||
genTables = genTableService2Oracle.selectGenTableAll();
|
||||
table = genTableService2Oracle.selectGenTableById(tableId);
|
||||
}
|
||||
|
||||
List<CxSelect> cxSelect = new ArrayList<CxSelect>();
|
||||
for (GenTable genTable : genTables)
|
||||
{
|
||||
|
@ -177,8 +220,13 @@ public class GenController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult editSave(@Validated GenTable genTable)
|
||||
{
|
||||
genTableService.validateEdit(genTable);
|
||||
genTableService.updateGenTable(genTable);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
genTableService.validateEdit(genTable);
|
||||
genTableService.updateGenTable(genTable);
|
||||
} else {
|
||||
genTableService2Oracle.validateEdit(genTable);
|
||||
genTableService2Oracle.updateGenTable(genTable);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
@ -188,7 +236,11 @@ public class GenController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult remove(String ids)
|
||||
{
|
||||
genTableService.deleteGenTableByIds(ids);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
genTableService.deleteGenTableByIds(ids);
|
||||
} else {
|
||||
genTableService2Oracle.deleteGenTableByIds(ids);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
@ -208,16 +260,30 @@ public class GenController extends BaseController
|
|||
if (sqlStatement instanceof MySqlCreateTableStatement)
|
||||
{
|
||||
MySqlCreateTableStatement createTableStatement = (MySqlCreateTableStatement) sqlStatement;
|
||||
if (genTableService.createTable(createTableStatement.toString()))
|
||||
{
|
||||
String tableName = createTableStatement.getTableName().replaceAll("`", "");
|
||||
tableNames.add(tableName);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
if (genTableService.createTable(createTableStatement.toString()))
|
||||
{
|
||||
String tableName = createTableStatement.getTableName().replaceAll("`", "");
|
||||
tableNames.add(tableName);
|
||||
}
|
||||
} else {
|
||||
if (genTableService2Oracle.createTable(createTableStatement.toString()))
|
||||
{
|
||||
String tableName = createTableStatement.getTableName().replaceAll("`", "");
|
||||
tableNames.add(tableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()]));
|
||||
String operName = Convert.toStr(PermissionUtils.getPrincipalProperty("loginName"));
|
||||
genTableService.importGenTable(tableList, operName);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()]));
|
||||
String operName = Convert.toStr(PermissionUtils.getPrincipalProperty("loginName"));
|
||||
genTableService.importGenTable(tableList, operName);
|
||||
} else {
|
||||
List<GenTable> tableList = genTableService2Oracle.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()]));
|
||||
String operName = Convert.toStr(PermissionUtils.getPrincipalProperty("loginName"));
|
||||
genTableService2Oracle.importGenTable(tableList, operName);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -235,7 +301,12 @@ public class GenController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
|
||||
{
|
||||
Map<String, String> dataMap = genTableService.previewCode(tableId);
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
dataMap = genTableService.previewCode(tableId);
|
||||
} else {
|
||||
dataMap = genTableService2Oracle.previewCode(tableId);
|
||||
}
|
||||
return AjaxResult.success(dataMap);
|
||||
}
|
||||
|
||||
|
@ -247,8 +318,13 @@ public class GenController extends BaseController
|
|||
@GetMapping("/download/{tableName}")
|
||||
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
|
||||
{
|
||||
byte[] data = genTableService.downloadCode(tableName);
|
||||
genCode(response, data);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
byte[] data = genTableService.downloadCode(tableName);
|
||||
genCode(response, data);
|
||||
} else {
|
||||
byte[] data = genTableService2Oracle.downloadCode(tableName);
|
||||
genCode(response, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -264,7 +340,11 @@ public class GenController extends BaseController
|
|||
{
|
||||
return AjaxResult.error("【系统预设】不允许生成文件覆盖到本地");
|
||||
}
|
||||
genTableService.generatorCode(tableName);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
genTableService.generatorCode(tableName);
|
||||
} else {
|
||||
genTableService2Oracle.generatorCode(tableName);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
@ -277,7 +357,11 @@ public class GenController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult synchDb(@PathVariable("tableName") String tableName)
|
||||
{
|
||||
genTableService.synchDb(tableName);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
genTableService.synchDb(tableName);
|
||||
} else {
|
||||
genTableService2Oracle.synchDb(tableName);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
@ -291,8 +375,13 @@ public class GenController extends BaseController
|
|||
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
|
||||
{
|
||||
String[] tableNames = Convert.toStrArray(tables);
|
||||
byte[] data = genTableService.downloadCode(tableNames);
|
||||
genCode(response, data);
|
||||
if (GenConfig.dbType == DbType.mysql || GenConfig.dbType == null) {
|
||||
byte[] data = genTableService.downloadCode(tableNames);
|
||||
genCode(response, data);
|
||||
} else {
|
||||
byte[] data = genTableService2Oracle.downloadCode(tableNames);
|
||||
genCode(response, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,12 +2,14 @@ package com.ruoyi.generator.mapper;
|
|||
|
||||
import java.util.List;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* 业务字段 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Primary
|
||||
public interface GenTableColumnMapper
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -2,12 +2,14 @@ package com.ruoyi.generator.mapper;
|
|||
|
||||
import java.util.List;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* 业务 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Primary
|
||||
public interface GenTableMapper
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package com.ruoyi.generator.mapper.oracle;
|
||||
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 数据层
|
||||
*
|
||||
* @author dazer007
|
||||
*/
|
||||
public interface GenTableColumnOracleMapper
|
||||
{
|
||||
/**
|
||||
* 根据表名称查询列信息
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 列信息
|
||||
*/
|
||||
public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 删除业务字段
|
||||
*
|
||||
* @param genTableColumns 列数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
|
||||
|
||||
/**
|
||||
* 批量删除业务字段
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumnByIds(Long[] ids);
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.ruoyi.generator.mapper.oracle;
|
||||
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
import com.ruoyi.common.enums.DataSourceType;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.bind.annotation.Mapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务 数据层
|
||||
*
|
||||
* @author dazer007
|
||||
*/
|
||||
public interface GenTableOracleMapper
|
||||
{
|
||||
/**
|
||||
* 查询业务列表
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 业务集合
|
||||
*/
|
||||
public List<GenTable> selectGenTableList(GenTable genTable);
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
public List<GenTable> selectDbTableList(GenTable genTable);
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
* @param tableNames 表名称组
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
public List<GenTable> selectDbTableListByNames(String[] tableNames);
|
||||
|
||||
/**
|
||||
* 查询所有表信息
|
||||
*
|
||||
* @return 表信息集合
|
||||
*/
|
||||
public List<GenTable> selectGenTableAll();
|
||||
|
||||
/**
|
||||
* 查询表ID业务信息
|
||||
*
|
||||
* @param id 业务ID
|
||||
* @return 业务信息
|
||||
*/
|
||||
public GenTable selectGenTableById(Long id);
|
||||
|
||||
/**
|
||||
* 查询表名称业务信息
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 业务信息
|
||||
*/
|
||||
public GenTable selectGenTableByName(String tableName);
|
||||
|
||||
/**
|
||||
* 新增业务
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGenTable(GenTable genTable);
|
||||
|
||||
/**
|
||||
* 修改业务
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGenTable(GenTable genTable);
|
||||
|
||||
/**
|
||||
* 批量删除业务
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 创建表
|
||||
*
|
||||
* @param sql
|
||||
* @return 结果
|
||||
*/
|
||||
public int createTable(String sql);
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.ruoyi.generator.service.impl;
|
|||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
|
@ -14,6 +15,7 @@ import com.ruoyi.generator.service.IGenTableColumnService;
|
|||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
@Primary
|
||||
public class GenTableColumnServiceImpl implements IGenTableColumnService
|
||||
{
|
||||
@Autowired
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.apache.velocity.app.Velocity;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
@ -38,11 +39,14 @@ import com.ruoyi.generator.util.GenUtils;
|
|||
import com.ruoyi.generator.util.VelocityInitializer;
|
||||
import com.ruoyi.generator.util.VelocityUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 业务 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
public class GenTableServiceImpl implements IGenTableService
|
||||
{
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package com.ruoyi.generator.service.impl.oracle;
|
||||
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.enums.DataSourceType;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
import com.ruoyi.generator.mapper.oracle.GenTableColumnOracleMapper;
|
||||
import com.ruoyi.generator.service.IGenTableColumnService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service("IGenTableColumnService_Oracle")
|
||||
@DataSource(value = DataSourceType.WINLIS)
|
||||
public class GenTableColumnServiceImpl implements IGenTableColumnService
|
||||
{
|
||||
@Autowired
|
||||
private GenTableColumnOracleMapper genTableColumnMapper;
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.selectGenTableColumnListByTableId(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务字段对象
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteGenTableColumnByIds(String ids)
|
||||
{
|
||||
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,538 @@
|
|||
package com.ruoyi.generator.service.impl.oracle;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.GenConstants;
|
||||
import com.ruoyi.common.core.text.CharsetKit;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.enums.DataSourceType;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
import com.ruoyi.generator.mapper.oracle.GenTableColumnOracleMapper;
|
||||
import com.ruoyi.generator.mapper.oracle.GenTableOracleMapper;
|
||||
import com.ruoyi.generator.service.IGenTableService;
|
||||
import com.ruoyi.generator.util.GenUtils;
|
||||
import com.ruoyi.generator.util.VelocityInitializer;
|
||||
import com.ruoyi.generator.util.VelocityUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* 业务 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service("IGenTableService_Oracle")
|
||||
@DataSource(value = DataSourceType.WINLIS)
|
||||
public class GenTableServiceImpl implements IGenTableService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private GenTableOracleMapper genTableMapper;
|
||||
|
||||
@Autowired
|
||||
private GenTableColumnOracleMapper genTableColumnMapper;
|
||||
|
||||
/**
|
||||
* 查询业务信息
|
||||
*
|
||||
* @param id 业务ID
|
||||
* @return 业务信息
|
||||
*/
|
||||
@Override
|
||||
public GenTable selectGenTableById(Long id)
|
||||
{
|
||||
GenTable genTable = genTableMapper.selectGenTableById(id);
|
||||
setTableFromOptions(genTable);
|
||||
return genTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询业务列表
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 业务集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectGenTableList(GenTable genTable)
|
||||
{
|
||||
return genTableMapper.selectGenTableList(genTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectDbTableList(GenTable genTable)
|
||||
{
|
||||
return genTableMapper.selectDbTableList(genTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
* @param tableNames 表名称组
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectDbTableListByNames(String[] tableNames)
|
||||
{
|
||||
return genTableMapper.selectDbTableListByNames(tableNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有表信息
|
||||
*
|
||||
* @return 表信息集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectGenTableAll()
|
||||
{
|
||||
return genTableMapper.selectGenTableAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateGenTable(GenTable genTable)
|
||||
{
|
||||
String options = JSON.toJSONString(genTable.getParams());
|
||||
genTable.setOptions(options);
|
||||
int row = genTableMapper.updateGenTable(genTable);
|
||||
if (row > 0)
|
||||
{
|
||||
for (GenTableColumn genTableColumn : genTable.getColumns())
|
||||
{
|
||||
genTableColumnMapper.updateGenTableColumn(genTableColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务对象
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteGenTableByIds(String ids)
|
||||
{
|
||||
genTableMapper.deleteGenTableByIds(Convert.toLongArray(ids));
|
||||
genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建表
|
||||
*
|
||||
* @param sql 创建表语句
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable(String sql)
|
||||
{
|
||||
return genTableMapper.createTable(sql) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入表结构
|
||||
*
|
||||
* @param tableList 导入表列表
|
||||
* @param operName 操作人员
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void importGenTable(List<GenTable> tableList, String operName)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (GenTable table : tableList)
|
||||
{
|
||||
String tableName = table.getTableName();
|
||||
GenUtils.initTable(table, operName);
|
||||
int row = genTableMapper.insertGenTable(table);
|
||||
if (row > 0)
|
||||
{
|
||||
// 保存列信息
|
||||
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||
for (GenTableColumn column : genTableColumns)
|
||||
{
|
||||
GenUtils.initColumnField(column, table);
|
||||
genTableColumnMapper.insertGenTableColumn(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 = genTableMapper.selectGenTableById(tableId);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码(下载方式)
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 数据
|
||||
*/
|
||||
@Override
|
||||
public byte[] downloadCode(String tableName)
|
||||
{
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
generatorCode(tableName, zip);
|
||||
IOUtils.closeQuietly(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码(自定义路径)
|
||||
*
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@Override
|
||||
public void generatorCode(String tableName)
|
||||
{
|
||||
// 查询表信息
|
||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
setPkColumn(table);
|
||||
|
||||
VelocityInitializer.initVelocity();
|
||||
|
||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
||||
for (String template : templates)
|
||||
{
|
||||
if (!StringUtils.contains(template, "sql.vm"))
|
||||
{
|
||||
// 渲染模板
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
tpl.merge(context, sw);
|
||||
try
|
||||
{
|
||||
String path = getGenPath(table, template);
|
||||
FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步数据库
|
||||
*
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void synchDb(String tableName)
|
||||
{
|
||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
||||
List<GenTableColumn> tableColumns = table.getColumns();
|
||||
Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
|
||||
|
||||
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||
if (StringUtils.isEmpty(dbTableColumns))
|
||||
{
|
||||
throw new ServiceException("同步数据失败,原表结构不存在");
|
||||
}
|
||||
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
||||
|
||||
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());
|
||||
}
|
||||
genTableColumnMapper.updateGenTableColumn(column);
|
||||
}
|
||||
else
|
||||
{
|
||||
genTableColumnMapper.insertGenTableColumn(column);
|
||||
}
|
||||
});
|
||||
|
||||
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
|
||||
if (StringUtils.isNotEmpty(delColumns))
|
||||
{
|
||||
genTableColumnMapper.deleteGenTableColumns(delColumns);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成代码(下载方式)
|
||||
*
|
||||
* @param tableNames 表数组
|
||||
* @return 数据
|
||||
*/
|
||||
@Override
|
||||
public byte[] downloadCode(String[] tableNames)
|
||||
{
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
for (String tableName : tableNames)
|
||||
{
|
||||
generatorCode(tableName, zip);
|
||||
}
|
||||
IOUtils.closeQuietly(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询表信息并生成代码
|
||||
*/
|
||||
private void generatorCode(String tableName, ZipOutputStream zip)
|
||||
{
|
||||
// 查询表信息
|
||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
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)));
|
||||
IOUtils.write(sw.toString(), zip, Constants.UTF8);
|
||||
IOUtils.closeQuietly(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 = JSON.toJSONString(genTable.getParams());
|
||||
JSONObject paramsObj = JSONObject.parseObject(options);
|
||||
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
|
||||
{
|
||||
throw new ServiceException("树编码字段不能为空");
|
||||
}
|
||||
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
|
||||
{
|
||||
throw new ServiceException("树父编码字段不能为空");
|
||||
}
|
||||
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
|
||||
{
|
||||
throw new ServiceException("树名称字段不能为空");
|
||||
}
|
||||
}
|
||||
else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
|
||||
{
|
||||
if (StringUtils.isEmpty(genTable.getSubTableName()))
|
||||
{
|
||||
throw new ServiceException("关联子表的表名不能为空");
|
||||
}
|
||||
else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
|
||||
{
|
||||
throw new ServiceException("子表关联的外键名不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主键列信息
|
||||
*
|
||||
* @param table 业务表信息
|
||||
*/
|
||||
public void setPkColumn(GenTable table)
|
||||
{
|
||||
for (GenTableColumn column : table.getColumns())
|
||||
{
|
||||
if (column.isPk())
|
||||
{
|
||||
table.setPkColumn(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNull(table.getPkColumn()))
|
||||
{
|
||||
table.setPkColumn(table.getColumns().get(0));
|
||||
}
|
||||
if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
|
||||
{
|
||||
for (GenTableColumn column : table.getSubTable().getColumns())
|
||||
{
|
||||
if (column.isPk())
|
||||
{
|
||||
table.getSubTable().setPkColumn(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNull(table.getSubTable().getPkColumn()))
|
||||
{
|
||||
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主子表信息
|
||||
*
|
||||
* @param table 业务表信息
|
||||
*/
|
||||
public void setSubTable(GenTable table)
|
||||
{
|
||||
String subTableName = table.getSubTableName();
|
||||
if (StringUtils.isNotEmpty(subTableName))
|
||||
{
|
||||
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置代码生成其他选项值
|
||||
*
|
||||
* @param genTable 设置后的生成对象
|
||||
*/
|
||||
public void setTableFromOptions(GenTable genTable)
|
||||
{
|
||||
JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
|
||||
if (StringUtils.isNotNull(paramsObj))
|
||||
{
|
||||
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
|
||||
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
|
||||
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
||||
String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
|
||||
String parentMenuName = paramsObj.getString(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);
|
||||
}
|
||||
}
|
|
@ -10,4 +10,6 @@ gen:
|
|||
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
|
||||
tablePrefix: sys_
|
||||
# 是否允许生成文件覆盖到本地(自定义路径),默认不允许
|
||||
allowOverwrite: false
|
||||
allowOverwrite: false
|
||||
# 数据库类型,mysql、oracle、sqlite、postgresql
|
||||
dbType: oracle
|
|
@ -0,0 +1,147 @@
|
|||
<?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="com.ruoyi.generator.mapper.oracle.GenTableColumnOracleMapper">
|
||||
|
||||
<resultMap type="GenTableColumn" id="GenTableColumnResult">
|
||||
<id property="columnId" column="column_id" />
|
||||
<result property="tableId" column="table_id" />
|
||||
<result property="columnName" column="column_name" />
|
||||
<result property="columnComment" column="column_comment" />
|
||||
<result property="columnType" column="column_type" />
|
||||
<result property="javaType" column="java_type" />
|
||||
<result property="javaField" column="java_field" />
|
||||
<result property="isPk" column="is_pk" />
|
||||
<result property="isIncrement" column="is_increment" />
|
||||
<result property="isRequired" column="is_required" />
|
||||
<result property="isInsert" column="is_insert" />
|
||||
<result property="isEdit" column="is_edit" />
|
||||
<result property="isList" column="is_list" />
|
||||
<result property="isQuery" column="is_query" />
|
||||
<result property="queryType" column="query_type" />
|
||||
<result property="htmlType" column="html_type" />
|
||||
<result property="dictType" column="dict_type" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectGenTableColumnVo">
|
||||
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
|
||||
</sql>
|
||||
|
||||
<select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
|
||||
<include refid="selectGenTableColumnVo"/>
|
||||
where table_id = #{tableId}
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
||||
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
|
||||
</select>
|
||||
|
||||
<insert id="insertGenTableColumn" parameterType="GenTableColumn">
|
||||
<selectKey keyProperty="columnId" resultType="long" order="BEFORE">
|
||||
SELECT seq_gen_table_column.NEXTVAL as columnId FROM DUAL
|
||||
</selectKey>
|
||||
insert into gen_table_column (
|
||||
<if test="columnId != null and columnId != ''">column_id,</if>
|
||||
<if test="tableId != null and tableId != ''">table_id,</if>
|
||||
<if test="columnName != null and columnName != ''">column_name,</if>
|
||||
<if test="columnComment != null and columnComment != ''">column_comment,</if>
|
||||
<if test="columnType != null and columnType != ''">column_type,</if>
|
||||
<if test="javaType != null and javaType != ''">java_type,</if>
|
||||
<if test="javaField != null and javaField != ''">java_field,</if>
|
||||
<if test="isPk != null and isPk != ''">is_pk,</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">is_increment,</if>
|
||||
<if test="isRequired != null and isRequired != ''">is_required,</if>
|
||||
<if test="isInsert != null and isInsert != ''">is_insert,</if>
|
||||
<if test="isEdit != null and isEdit != ''">is_edit,</if>
|
||||
<if test="isList != null and isList != ''">is_list,</if>
|
||||
<if test="isQuery != null and isQuery != ''">is_query,</if>
|
||||
<if test="queryType != null and queryType != ''">query_type,</if>
|
||||
<if test="htmlType != null and htmlType != ''">html_type,</if>
|
||||
<if test="dictType != null and dictType != ''">dict_type,</if>
|
||||
<if test="sort != null">sort,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="columnId != null and columnId != ''">#{columnId},</if>
|
||||
<if test="tableId != null and tableId != ''">#{tableId},</if>
|
||||
<if test="columnName != null and columnName != ''">#{columnName},</if>
|
||||
<if test="columnComment != null and columnComment != ''">#{columnComment},</if>
|
||||
<if test="columnType != null and columnType != ''">#{columnType},</if>
|
||||
<if test="javaType != null and javaType != ''">#{javaType},</if>
|
||||
<if test="javaField != null and javaField != ''">#{javaField},</if>
|
||||
<if test="isPk != null and isPk != ''">#{isPk},</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
|
||||
<if test="isRequired != null and isRequired != ''">#{isRequired},</if>
|
||||
<if test="isInsert != null and isInsert != ''">#{isInsert},</if>
|
||||
<if test="isEdit != null and isEdit != ''">#{isEdit},</if>
|
||||
<if test="isList != null and isList != ''">#{isList},</if>
|
||||
<if test="isQuery != null and isQuery != ''">#{isQuery},</if>
|
||||
<if test="queryType != null and queryType != ''">#{queryType},</if>
|
||||
<if test="htmlType != null and htmlType != ''">#{htmlType},</if>
|
||||
<if test="dictType != null and dictType != ''">#{dictType},</if>
|
||||
<if test="sort != null">#{sort},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateGenTableColumn" parameterType="GenTableColumn">
|
||||
update gen_table_column
|
||||
<set>
|
||||
column_comment = #{columnComment},
|
||||
java_type = #{javaType},
|
||||
java_field = #{javaField},
|
||||
is_insert = #{isInsert,jdbcType=CHAR},
|
||||
is_edit = #{isEdit,jdbcType=CHAR},
|
||||
is_list = #{isList,jdbcType=CHAR},
|
||||
is_query = #{isQuery,jdbcType=CHAR},
|
||||
is_required = #{isRequired,jdbcType=CHAR},
|
||||
query_type = #{queryType},
|
||||
html_type = #{htmlType},
|
||||
dict_type = #{dictType},
|
||||
sort = #{sort},
|
||||
update_by = #{updateBy,jdbcType=VARCHAR},
|
||||
update_time = sysdate
|
||||
</set>
|
||||
where column_id = #{columnId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteGenTableColumnByIds" parameterType="Long">
|
||||
delete from gen_table_column where table_id in
|
||||
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteGenTableColumns">
|
||||
delete from gen_table_column where column_id in
|
||||
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||
#{item.columnId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,226 @@
|
|||
<?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="com.ruoyi.generator.mapper.oracle.GenTableOracleMapper">
|
||||
|
||||
<resultMap type="GenTable" id="GenTableResult">
|
||||
<id property="tableId" column="table_id" />
|
||||
<result property="tableName" column="table_name" />
|
||||
<result property="tableComment" column="table_comment" />
|
||||
<result property="subTableName" column="sub_table_name" />
|
||||
<result property="subTableFkName" column="sub_table_fk_name" />
|
||||
<result property="className" column="class_name" />
|
||||
<result property="tplCategory" column="tpl_category" />
|
||||
<result property="packageName" column="package_name" />
|
||||
<result property="moduleName" column="module_name" />
|
||||
<result property="businessName" column="business_name" />
|
||||
<result property="functionName" column="function_name" />
|
||||
<result property="functionAuthor" column="function_author" />
|
||||
<result property="formColNum" column="form_col_num" />
|
||||
<result property="genType" column="gen_type" />
|
||||
<result property="genPath" column="gen_path" />
|
||||
<result property="options" column="options" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="GenTableColumn" id="GenTableColumnResult">
|
||||
<id property="columnId" column="column_id" />
|
||||
<result property="tableId" column="table_id" />
|
||||
<result property="columnName" column="column_name" />
|
||||
<result property="columnComment" column="column_comment" />
|
||||
<result property="columnType" column="column_type" />
|
||||
<result property="javaType" column="java_type" />
|
||||
<result property="javaField" column="java_field" />
|
||||
<result property="isPk" column="is_pk" />
|
||||
<result property="isIncrement" column="is_increment" />
|
||||
<result property="isRequired" column="is_required" />
|
||||
<result property="isInsert" column="is_insert" />
|
||||
<result property="isEdit" column="is_edit" />
|
||||
<result property="isList" column="is_list" />
|
||||
<result property="isQuery" column="is_query" />
|
||||
<result property="queryType" column="query_type" />
|
||||
<result property="htmlType" column="html_type" />
|
||||
<result property="dictType" column="dict_type" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectGenTableVo">
|
||||
select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, form_col_num, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
|
||||
</sql>
|
||||
|
||||
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
|
||||
<include refid="selectGenTableVo"/>
|
||||
<where>
|
||||
<if test="tableName != null and tableName != ''">
|
||||
AND lower(table_name) like lower(concat(concat('%', #{tableName}), '%'))
|
||||
</if>
|
||||
<if test="tableComment != null and tableComment != ''">
|
||||
AND lower(table_comment) like lower(concat(concat('%', #{tableComment}), '%'))
|
||||
</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
||||
AND to_char(create_time, 'yyyy-mm-dd') >= #{params.beginTime}
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||
AND to_char(create_time, 'yyyy-mm-dd') <= #{params.endTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
|
||||
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 'QRTZ_%' AND dt.table_name NOT LIKE 'GEN_%'
|
||||
AND lower(dt.table_name) NOT IN (select table_name from gen_table)
|
||||
<if test="tableName != null and tableName != ''">
|
||||
AND lower(dt.table_name) like lower(concat(concat('%', #{tableName}), '%'))
|
||||
</if>
|
||||
<if test="tableComment != null and tableComment != ''">
|
||||
AND lower(dtc.comments) like lower(concat(concat('%', #{tableComment}), '%'))
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectDbTableListByNames" resultMap="GenTableResult">
|
||||
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 'QRTZ_%' 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>
|
||||
</select>
|
||||
|
||||
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
|
||||
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 'QRTZ_%' 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}
|
||||
</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.form_col_num, 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.form_col_num, 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.form_col_num, 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
|
||||
order by c.sort
|
||||
</select>
|
||||
|
||||
<select id="selectMenuId" resultType="java.lang.Long">
|
||||
SELECT seq_sys_menu.nextval FROM dual
|
||||
</select>
|
||||
|
||||
<insert id="insertGenTable" parameterType="GenTable">
|
||||
<selectKey keyProperty="tableId" resultType="long" order="BEFORE">
|
||||
SELECT seq_gen_table.NEXTVAL as tableId FROM DUAL
|
||||
</selectKey>
|
||||
insert into gen_table (
|
||||
<if test="tableId != null">table_id,</if>
|
||||
<if test="tableName != null">table_name,</if>
|
||||
<if test="tableComment != null and tableComment != ''">table_comment,</if>
|
||||
<if test="className != null and className != ''">class_name,</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
|
||||
<if test="packageName != null and packageName != ''">package_name,</if>
|
||||
<if test="moduleName != null and moduleName != ''">module_name,</if>
|
||||
<if test="businessName != null and businessName != ''">business_name,</if>
|
||||
<if test="functionName != null and functionName != ''">function_name,</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
|
||||
<if test="formColNum != null">form_col_num,</if>
|
||||
<if test="genType != null and genType != ''">gen_type,</if>
|
||||
<if test="genPath != null and genPath != ''">gen_path,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="tableId != null">#{tableId},</if>
|
||||
<if test="tableName != null">#{tableName},</if>
|
||||
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
|
||||
<if test="className != null and className != ''">#{className},</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
|
||||
<if test="packageName != null and packageName != ''">#{packageName},</if>
|
||||
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
|
||||
<if test="businessName != null and businessName != ''">#{businessName},</if>
|
||||
<if test="functionName != null and functionName != ''">#{functionName},</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
|
||||
<if test="formColNum != null">#{formColNum},</if>
|
||||
<if test="genType != null and genType != ''">#{genType},</if>
|
||||
<if test="genPath != null and genPath != ''">#{genPath},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="createTable">
|
||||
${sql}
|
||||
</update>
|
||||
|
||||
<update id="updateGenTable" parameterType="GenTable">
|
||||
update gen_table
|
||||
<set>
|
||||
<if test="tableName != null">table_name = #{tableName},</if>
|
||||
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
|
||||
<if test="subTableName != null">sub_table_name = #{subTableName},</if>
|
||||
<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
|
||||
<if test="className != null and className != ''">class_name = #{className},</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
|
||||
<if test="formColNum != null">form_col_num = #{formColNum},</if>
|
||||
<if test="genType != null and genType != ''">gen_type = #{genType},</if>
|
||||
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
|
||||
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
|
||||
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
|
||||
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
|
||||
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
|
||||
<if test="options != null and options != ''">options = #{options},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
update_time = sysdate
|
||||
</set>
|
||||
where table_id = #{tableId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteGenTableByIds" parameterType="Long">
|
||||
delete from gen_table where table_id in
|
||||
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue