Skip to content

Commit

Permalink
适配 Oracle 数据库
Browse files Browse the repository at this point in the history
1. 去除关键字,避免数据库的查询冲突
  • Loading branch information
YunaiV committed May 1, 2022
1 parent 1bd86d6 commit 7db1a58
Show file tree
Hide file tree
Showing 47 changed files with 878 additions and 868 deletions.
756 changes: 378 additions & 378 deletions sql/mysql/ruoyi-vue-pro.sql

Large diffs are not rendered by default.

797 changes: 402 additions & 395 deletions sql/postgresql/ruoyi-vue-pro.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/**
* SQL相关常量类
*
* @author 芋道源码
*/
public interface SqlConstants {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class BpmTaskAssignRuleDO extends BaseDO {
*
* 枚举 {@link BpmTaskAssignRuleTypeEnum}
*/
@TableField("\"type\"")
private Integer type;
/**
* 规则值数组,一般关联指定表的编号
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
Expand Down Expand Up @@ -42,7 +41,6 @@ public class BpmOALeaveDO extends BaseDO {
/**
* 请假类型
*/
@TableField("\"type\"")
private Integer type;
/**
* 原因
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ErrorCodeConstants {
ErrorCode CONFIG_NOT_EXISTS = new ErrorCode(1001000001, "参数配置不存在");
ErrorCode CONFIG_KEY_DUPLICATE = new ErrorCode(1001000002, "参数配置 key 重复");
ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1001000003, "不能删除类型为系统内置的参数配置");
ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1001000004, "不允许获取敏感配置到前端");
ErrorCode CONFIG_GET_VALUE_ERROR_IF_VISIBLE = new ErrorCode(1001000004, "获取参数配置失败,原因:不允许获取不可见配置");

// ========== 定时任务 1001001000 ==========
ErrorCode JOB_NOT_EXISTS = new ErrorCode(1001001000, "定时任务不存在");
Expand All @@ -36,7 +36,6 @@ public interface ErrorCodeConstants {
ErrorCode CODEGEN_TABLE_EXISTS = new ErrorCode(1003001000, "表定义已经存在");
ErrorCode CODEGEN_IMPORT_TABLE_NULL = new ErrorCode(1003001001, "导入的表不存在");
ErrorCode CODEGEN_IMPORT_COLUMNS_NULL = new ErrorCode(1003001002, "导入的字段不存在");
ErrorCode CODEGEN_PARSE_SQL_ERROR = new ErrorCode(1003001003, "解析 SQL 失败,请检查");
ErrorCode CODEGEN_TABLE_NOT_EXISTS = new ErrorCode(1003001004, "表定义不存在");
ErrorCode CODEGEN_COLUMN_NOT_EXISTS = new ErrorCode(1003001005, "字段义不存在");
ErrorCode CODEGEN_SYNC_COLUMNS_NULL = new ErrorCode(1003001006, "同步的字段不存在");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public CommonResult<ConfigRespVO> getConfig(@RequestParam("id") Long id) {
}

@GetMapping(value = "/get-value-by-key")
@ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端")
@ApiOperation(value = "根据参数键名查询参数值", notes = "不可见的配置,不允许返回给前端")
@ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class)
public CommonResult<String> getConfigKey(@RequestParam("key") String key) {
ConfigDO config = configService.getConfigByKey(key);
if (config == null) {
return null;
}
if (config.getSensitive()) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE);
if (config.getVisible()) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE);
}
return success(config.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ConfigBaseVO {
@ApiModelProperty(value = "参数分组", required = true, example = "biz")
@NotEmpty(message = "参数分组不能为空")
@Size(max = 50, message = "参数名称不能超过50个字符")
private String group;
private String category;

@ApiModelProperty(value = "参数名称", required = true, example = "数据库名")
@NotBlank(message = "参数名称不能为空")
Expand All @@ -32,7 +32,7 @@ public class ConfigBaseVO {

@ApiModelProperty(value = "是否敏感", required = true, example = "true")
@NotNull(message = "是否敏感不能为空")
private Boolean sensitive;
private Boolean visible;

@ApiModelProperty(value = "备注", example = "备注一下很帅气!")
private String remark;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;
Expand All @@ -18,12 +19,15 @@ public interface ConfigConvert {

PageResult<ConfigRespVO> convertPage(PageResult<ConfigDO> page);

@Mapping(source = "configKey", target = "key")
ConfigRespVO convert(ConfigDO bean);

@Mapping(source = "key", target = "configKey")
ConfigDO convert(ConfigCreateReqVO bean);

ConfigDO convert(ConfigUpdateReqVO bean);

@Mapping(source = "configKey", target = "key")
List<ConfigExcelVO> convertList(List<ConfigDO> list);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
Expand All @@ -28,19 +27,19 @@ public class ConfigDO extends BaseDO {
@TableId
private Long id;
/**
* 参数分组
* 参数分类
*/
@TableField("\"group\"")
private String group;
private String category;
/**
* 参数名称
*/
private String name;
/**
* 参数键名
*
* 支持多 DB 类型时,无法直接使用 key + @TableField("config_key") 来实现转换,原因是 "config_key" AS key 而存在报错
*/
@TableField("\"key\"")
private String key;
private String configKey;
/**
* 参数键值
*/
Expand All @@ -50,15 +49,13 @@ public class ConfigDO extends BaseDO {
*
* 枚举 {@link ConfigTypeEnum}
*/
@TableField("\"type\"")
private Integer type;
/**
* 是否敏感
* 是否可见
*
* 对于敏感配置,需要管理权限才能查看
* 不可见的参数,一般是敏感参数,前端不可获取
*/
@TableField("\"sensitive\"")
private Boolean sensitive;
private Boolean visible;
/**
* 备注
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;

Expand Down Expand Up @@ -47,7 +46,6 @@ public class FileDO extends BaseDO {
*
* 通过 {@link cn.hutool.core.io.FileTypeUtil#getType(InputStream)} 获取
*/
@TableField("\"type\"")
private String type;
/**
* 文件大小
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
public interface ConfigMapper extends BaseMapperX<ConfigDO> {

default ConfigDO selectByKey(String key) {
return selectOne(ConfigDO::getKey, key);
return selectOne(ConfigDO::getConfigKey, key);
}

default PageResult<ConfigDO> selectPage(ConfigPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ConfigDO>()
.likeIfPresent(ConfigDO::getName, reqVO.getName())
.likeIfPresent(ConfigDO::getKey, reqVO.getKey())
.likeIfPresent(ConfigDO::getConfigKey, reqVO.getKey())
.eqIfPresent(ConfigDO::getType, reqVO.getType())
.betweenIfPresent(ConfigDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime()));
}

default List<ConfigDO> selectList(ConfigExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ConfigDO>()
.likeIfPresent(ConfigDO::getName, reqVO.getName())
.likeIfPresent(ConfigDO::getKey, reqVO.getKey())
.likeIfPresent(ConfigDO::getConfigKey, reqVO.getKey())
.eqIfPresent(ConfigDO::getType, reqVO.getType())
.betweenIfPresent(ConfigDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ default PageResult<FileConfigDO> selectPage(FileConfigPageReqVO reqVO) {
.orderByDesc(FileConfigDO::getId));
}

@Select("SELECT id FROM infra_file_config WHERE update_time > #{maxUpdateTime} LIMIT 1")
Long selectExistsByUpdateTimeAfter(Date maxUpdateTime);
@Select("SELECT COUNT(*) FROM infra_file_config WHERE update_time > #{maxUpdateTime}")
Long selectCountByUpdateTimeGt(Date maxUpdateTime);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenColumnMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenTableMapper;
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum;
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder;
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine;
import cn.iocoder.yudao.module.infra.service.db.DatabaseTableService;
Expand Down Expand Up @@ -88,6 +89,7 @@ private Long createCodegen0(Long userId, Long dataSourceConfigId, TableInfo tabl
// 构建 CodegenTableDO 对象,插入到 DB 中
CodegenTableDO table = codegenBuilder.buildTable(tableInfo);
table.setDataSourceConfigId(dataSourceConfigId);
table.setScene(CodegenSceneEnum.ADMIN.getScene()); // 默认配置下,使用管理后台的模板
table.setAuthor(userApi.getUser(userId).getNickname());
codegenTableMapper.insert(table);
// 构建 CodegenColumnDO 数组,插入到 DB 中
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.infra.service.config;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO;
Expand Down Expand Up @@ -96,7 +97,9 @@ private void checkCreateOrUpdate(Long id, String key) {
// 校验自己存在
checkConfigExists(id);
// 校验参数配置 key 的唯一性
checkConfigKeyUnique(id, key);
if (StrUtil.isNotEmpty(key)) {
checkConfigKeyUnique(id, key);
}
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private List<FileConfigDO> loadFileConfigIfUpdate(Date maxUpdateTime) {
if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据
log.info("[loadFileConfigIfUpdate][首次加载全量文件配置]");
} else { // 判断数据库中是否有更新的文件配置
if (fileConfigMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) == null) {
if (fileConfigMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) {
return null;
}
log.info("[loadFileConfigIfUpdate][增量加载全量文件配置]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void testCheckConfigKeyUnique_keyDuplicateForCreate() {
// 准备参数
String key = randomString();
// mock 数据
configMapper.insert(randomConfigDO(o -> o.setKey(key)));
configMapper.insert(randomConfigDO(o -> o.setConfigKey(key)));

// 调用,校验异常
assertServiceException(() -> configService.checkConfigKeyUnique(null, key),
Expand All @@ -150,7 +150,7 @@ public void testCheckConfigKeyUnique_keyDuplicateForUpdate() {
Long id = randomLongId();
String key = randomString();
// mock 数据
configMapper.insert(randomConfigDO(o -> o.setKey(key)));
configMapper.insert(randomConfigDO(o -> o.setConfigKey(key)));

// 调用,校验异常
assertServiceException(() -> configService.checkConfigKeyUnique(id, key),
Expand All @@ -162,15 +162,15 @@ public void testGetConfigPage() {
// mock 数据
ConfigDO dbConfig = randomConfigDO(o -> { // 等会查询到
o.setName("芋艿");
o.setKey("yunai");
o.setConfigKey("yunai");
o.setType(ConfigTypeEnum.SYSTEM.getType());
o.setCreateTime(buildTime(2021, 2, 1));
});
configMapper.insert(dbConfig);
// 测试 name 不匹配
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
// 测试 key 不匹配
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setKey("tudou")));
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou")));
// 测试 type 不匹配
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType())));
// 测试 createTime 不匹配
Expand All @@ -196,15 +196,15 @@ public void testGetConfigList() {
// mock 数据
ConfigDO dbConfig = randomConfigDO(o -> { // 等会查询到
o.setName("芋艿");
o.setKey("yunai");
o.setConfigKey("yunai");
o.setType(ConfigTypeEnum.SYSTEM.getType());
o.setCreateTime(buildTime(2021, 2, 1));
});
configMapper.insert(dbConfig);
// 测试 name 不匹配
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
// 测试 key 不匹配
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setKey("tudou")));
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou")));
// 测试 type 不匹配
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType())));
// 测试 createTime 不匹配
Expand All @@ -230,7 +230,7 @@ public void testGetConfigByKey() {
ConfigDO dbConfig = randomConfigDO();
configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据
// 准备参数
String key = dbConfig.getKey();
String key = dbConfig.getConfigKey();

// 调用
ConfigDO config = configService.getConfigByKey(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ default PayChannelDO selectByAppIdAndCode(Long appId, String code) {
return selectOne(PayChannelDO::getAppId, appId, PayChannelDO::getCode, code);
}

@Select("SELECT id FROM pay_channel WHERE update_time > #{maxUpdateTime} LIMIT 1")
Long selectExistsByUpdateTimeAfter(Date maxUpdateTime);
@Select("SELECT COUNT(*) FROM pay_channel WHERE update_time > #{maxUpdateTime}")
Long selectCountByUpdateTimeGt(Date maxUpdateTime);

default PageResult<PayChannelDO> selectPage(PayChannelPageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<PayChannelDO>()
Expand All @@ -33,7 +33,7 @@ default PageResult<PayChannelDO> selectPage(PayChannelPageReqVO reqVO) {
.eqIfPresent("merchant_id", reqVO.getMerchantId())
.eqIfPresent("app_id", reqVO.getAppId())
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc("id") );
.orderByDesc("id"));
}

default List<PayChannelDO> selectList(PayChannelExportReqVO reqVO) {
Expand All @@ -45,7 +45,7 @@ default List<PayChannelDO> selectList(PayChannelExportReqVO reqVO) {
.eqIfPresent("merchant_id", reqVO.getMerchantId())
.eqIfPresent("app_id", reqVO.getAppId())
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc("id") );
.orderByDesc("id"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private List<PayChannelDO> loadPayChannelIfUpdate(Date maxUpdateTime) {
if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据
log.info("[loadPayChannelIfUpdate][首次加载全量支付渠道]");
} else { // 判断数据库中是否有更新的支付渠道
if (channelMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) == null) {
if (channelMapper.selectCountByUpdateTimeGt(maxUpdateTime) == 0) {
return null;
}
log.info("[loadPayChannelIfUpdate][增量加载全量支付渠道]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class DictTypeDO extends BaseDO {
/**
* 字典类型
*/
@TableField("\"type\"")
private String type;
/**
* 状态
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class OperateLogDO extends BaseDO {
*
* 枚举 {@link OperateTypeEnum}
*/
@TableField("operate_type")
private Integer type;
/**
* 操作内容,记录整个操作的明细
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.system.enums.notice.NoticeTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -33,7 +32,6 @@ public class NoticeDO extends BaseDO {
*
* 枚举 {@link NoticeTypeEnum}
*/
@TableField("\"type\"")
private Integer type;
/**
* 公告内容
Expand Down
Loading

0 comments on commit 7db1a58

Please sign in to comment.