diff --git a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/ConfigFrameworkDAO.java b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/ConfigFrameworkDAO.java index c2fbd290b..95f44b36c 100644 --- a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/ConfigFrameworkDAO.java +++ b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/ConfigFrameworkDAO.java @@ -15,12 +15,12 @@ import java.util.List; public interface ConfigFrameworkDAO { /** - * 查询是否存在比 maxUpdateTime 更新记录更晚的配置 + * 查询是否存在比 maxUpdateTime 的更新记录数量 * * @param maxUpdateTime 最大更新时间 * @return 是否存在 */ - boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime); + int selectCountByUpdateTimeGt(Date maxUpdateTime); /** * 查询配置列表 diff --git a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java index 08573d33d..e41cb5780 100644 --- a/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java +++ b/yudao-framework/yudao-spring-boot-starter-config/src/main/java/cn/iocoder/yudao/framework/apollo/internals/DBConfigRepository.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.function.Predicate; @Slf4j public class DBConfigRepository extends AbstractConfigRepository { @@ -172,7 +171,7 @@ public class DBConfigRepository extends AbstractConfigRepository { if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 log.info("[loadConfigIfUpdate][首次加载全量配置]"); } else { // 判断数据库中是否有更新的配置 - if (!configFrameworkDAO.selectExistsByUpdateTimeAfter(maxUpdateTime)) { + if (configFrameworkDAO.selectCountByUpdateTimeGt(maxUpdateTime) == 0) { return null; } log.info("[loadConfigIfUpdate][增量加载全量配置]"); diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java index 8bb10aea4..a370b45e9 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/IdTypeEnvironmentPostProcessor.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.mybatis.config; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.collection.SetUtils; +import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants; import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.annotation.IdType; @@ -41,6 +42,9 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor // TODO 芋艿:暂时没有找到特别合适的地方,先放在这里 setJobStoreDriverIfPresent(environment, dbType); + // 初始化 SQL 静态变量 + SqlConstants.init(dbType); + // 如果非 NONE,则不进行处理 IdType idType = getIdType(environment); if (idType != IdType.NONE) { diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/enums/SqlConstants.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/enums/SqlConstants.java index 7e2c233bb..d775f17c7 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/enums/SqlConstants.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/enums/SqlConstants.java @@ -1,12 +1,21 @@ package cn.iocoder.yudao.framework.mybatis.core.enums; +import com.baomidou.mybatisplus.annotation.DbType; + /** * SQL相关常量类 * * @author 芋道源码 */ -public interface SqlConstants { +public class SqlConstants { - String LIMIT1 = "LIMIT 1"; + /** + * 数据库的类型 + */ + public static DbType DB_TYPE; + + public static void init(DbType dbType) { + DB_TYPE = dbType; + } } diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/QueryWrapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/QueryWrapperX.java index 865755d34..f520821ee 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/QueryWrapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/QueryWrapperX.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.framework.mybatis.core.query; +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.ArrayUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; @@ -124,4 +126,24 @@ public class QueryWrapperX extends QueryWrapper { return this; } + /** + * 设置只返回最后一条 + * + * TODO 芋艿:不是完美解,需要在思考下。如果使用多数据源,并且数据源是多种类型时,可能会存在问题:实现之返回一条的语法不同 + * + * @return this + */ + public QueryWrapperX limit1() { + Assert.notNull(SqlConstants.DB_TYPE, "获取不到数据库的类型"); + switch (SqlConstants.DB_TYPE) { + case ORACLE: + case ORACLE_12C: + super.eq("ROWNUM", 1); + break; + default: + super.last("LIMIT 1"); + } + return this; + } + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigDAOImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigDAOImpl.java index 12c78f4b6..5ac88dcc3 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigDAOImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/config/ConfigDAOImpl.java @@ -2,12 +2,10 @@ package cn.iocoder.yudao.module.infra.dal.mysql.config; import cn.iocoder.yudao.framework.apollo.internals.ConfigFrameworkDAO; import cn.iocoder.yudao.framework.apollo.internals.dto.ConfigRespDTO; -import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; import javax.sql.DataSource; -import java.sql.ResultSet; import java.util.Date; import java.util.List; @@ -26,14 +24,18 @@ public class ConfigDAOImpl implements ConfigFrameworkDAO { } @Override - public boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { - return jdbcTemplate.query("SELECT id FROM infra_config WHERE update_time > ? LIMIT 1", - ResultSet::next, maxUpdateTime); + public int selectCountByUpdateTimeGt(Date maxUpdateTime) { + return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM infra_config WHERE update_time > ?", + Integer.class, maxUpdateTime); } @Override public List selectList() { - return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM infra_config", new BeanPropertyRowMapper<>(ConfigRespDTO.class)); + return jdbcTemplate.query("SELECT config_key, value, update_time, deleted FROM infra_config", + (rs, rowNum) -> new ConfigRespDTO().setKey(rs.getString("config_key")) + .setValue(rs.getString("value")) + .setUpdateTime(rs.getDate("update_time")) + .setDeleted(rs.getBoolean("deleted"))); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http index d609e8f0c..7a10c7754 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.http @@ -9,7 +9,7 @@ tenant-id: {{appTenentId}} } ### 请求 /send-sms-code 接口 => 成功 -POST {{appApi}}/member/send-sms-code +POST {{appApi}}/member/auth/send-sms-code Content-Type: application/json tenant-id: {{appTenentId}} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsCodeMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsCodeMapper.java index 335c2d800..854eb7faa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsCodeMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsCodeMapper.java @@ -1,8 +1,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.sms; -import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO; import org.apache.ibatis.annotations.Mapper; @@ -18,12 +17,12 @@ public interface SmsCodeMapper extends BaseMapperX { * @return 手机验证码 */ default SmsCodeDO selectLastByMobile(String mobile, String code, Integer scene) { - return selectOne(new LambdaQueryWrapperX() - .eq(SmsCodeDO::getCode, mobile) - .eqIfPresent(SmsCodeDO::getScene, scene) - .eqIfPresent(SmsCodeDO::getCode, code) - .orderByDesc(SmsCodeDO::getId) - .last(SqlConstants.LIMIT1)); + return selectOne(new QueryWrapperX() + .eq("mobile", mobile) + .eqIfPresent("scene", scene) + .eqIfPresent("code", code) + .orderByDesc("id") + .limit1()); } }