From 0bac28386426a3a349c4cd5fcd7e6b10ba06d418 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 6 Feb 2022 20:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20Spring=20=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=B8=8B=EF=BC=8C=E6=97=A0=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E7=BC=96=E5=8F=B7=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=9F=A5=E8=AF=A2=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/dal/mysql/dept/DeptMapper.java | 13 ++++++++----- .../system/dal/mysql/dict/DictDataMapper.java | 16 ++++++---------- .../system/service/dept/DeptServiceImpl.java | 4 ++-- .../system/service/dict/DictDataServiceImpl.java | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java index dec9515b9..1a3a09873 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept; -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.module.system.controller.admin.dept.vo.dept.DeptListReqVO; @@ -8,6 +7,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; import java.util.Date; import java.util.List; @@ -29,10 +29,13 @@ public interface DeptMapper extends BaseMapperX { return selectCount(DeptDO::getParentId, parentId); } + @Select("SELECT id FROM system_dept WHERE update_time > #{maxUpdateTime} LIMIT 1") @InterceptorIgnore(tenantLine = "true") // 该方法忽略多租户。原因:该方法被异步 task 调用,此时获取不到租户编号 - default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { - return selectOne(new LambdaQueryWrapper().select(DeptDO::getId) - .gt(DeptDO::getUpdateTime, maxUpdateTime).last(SqlConstants.LIMIT1)) != null; - } + Long selectExistsByUpdateTimeAfter(Date maxUpdateTime); + + // TODO 芋艿:后续想想,有没可能优化下。大体思路,是支持某个方法,忽略租户 + @Select("SELECT * FROM system_dept") + @InterceptorIgnore(tenantLine = "true") + List selectListIgnoreTenant(); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java index 26e40bf6d..28e4e468d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java @@ -1,15 +1,14 @@ package cn.iocoder.yudao.module.system.dal.mysql.dict; -import cn.iocoder.yudao.framework.mybatis.core.enums.SqlConstants; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; import java.util.Arrays; import java.util.Collection; @@ -47,10 +46,7 @@ public interface DictDataMapper extends BaseMapperX { .eqIfPresent(DictDataDO::getStatus, reqVO.getStatus())); } - @InterceptorIgnore(tenantLine = "true") // 该方法忽略多租户。原因:该方法被异步 task 调用,此时获取不到租户编号 - default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { - return selectOne(new LambdaQueryWrapper().select(DictDataDO::getId) - .gt(DictDataDO::getUpdateTime, maxUpdateTime).last(SqlConstants.LIMIT1)) != null; - } + @Select("SELECT id FROM system_dict_data WHERE update_time > #{maxUpdateTime} LIMIT 1") + Long selectExistsByUpdateTimeAfter(Date maxUpdateTime); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index 955ce890a..7b1baba80 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -112,13 +112,13 @@ public class DeptServiceImpl implements DeptService { if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 log.info("[loadMenuIfUpdate][首次加载全量部门]"); } else { // 判断数据库中是否有更新的部门 - if (!deptMapper.selectExistsByUpdateTimeAfter(maxUpdateTime)) { + if (deptMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) != null) { return null; } log.info("[loadMenuIfUpdate][增量加载全量部门]"); } // 第二步,如果有更新,则从数据库加载所有部门 - return deptMapper.selectList(); + return deptMapper.selectListIgnoreTenant(); } @Override diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java index 1ecbdd41c..4832507cd 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java @@ -116,7 +116,7 @@ public class DictDataServiceImpl implements DictDataService { if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据 log.info("[loadDictDataIfUpdate][首次加载全量字典数据]"); } else { // 判断数据库中是否有更新的字典数据 - if (!dictDataMapper.selectExistsByUpdateTimeAfter(maxUpdateTime)) { + if (dictDataMapper.selectExistsByUpdateTimeAfter(maxUpdateTime) == null) { return null; } log.info("[loadDictDataIfUpdate][增量加载全量字典数据]");