From 72d18b056bb9b59922ec0ac5eec3261bffb094f6 Mon Sep 17 00:00:00 2001 From: leosanqing Date: Fri, 18 Feb 2022 11:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20baseMapper=20selectCount?= =?UTF-8?q?=20int=20->=20long=20Mybatis=20Plus=20=E5=9C=A83.4=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B9=8B=E5=90=8E=E5=B0=86=20selectCount=20=E4=BB=8EI?= =?UTF-8?q?nteger=20=E6=94=B9=E4=B8=BALong?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/mybatis/core/mapper/BaseMapperX.java | 12 ++++++++---- .../module/infra/dal/mysql/file/FileMapper.java | 2 +- .../module/system/dal/mysql/dept/DeptMapper.java | 2 +- .../module/system/dal/mysql/dict/DictDataMapper.java | 2 +- .../system/dal/mysql/permission/MenuMapper.java | 2 +- .../system/dal/mysql/sms/SmsTemplateMapper.java | 2 +- .../module/system/service/dict/DictDataService.java | 2 +- .../system/service/dict/DictDataServiceImpl.java | 2 +- .../system/service/permission/MenuServiceImpl.java | 1 + .../system/service/sms/SmsTemplateService.java | 2 +- .../system/service/sms/SmsTemplateServiceImpl.java | 2 +- .../system/service/dict/DictTypeServiceTest.java | 2 +- .../system/service/sms/SmsChannelServiceTest.java | 2 +- 13 files changed, 20 insertions(+), 15 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index ec3194cec..fff6f7028 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -43,12 +43,12 @@ public interface BaseMapperX extends BaseMapper { return selectOne(new LambdaQueryWrapper().eq(field1, value1).eq(field2, value2)); } - default Integer selectCount(String field, Object value) { - return selectCount(new QueryWrapper().eq(field, value)).intValue(); + default Long selectCount(String field, Object value) { + return selectCount(new QueryWrapper().eq(field, value)); } - default Integer selectCount(SFunction field, Object value) { - return selectCount(new LambdaQueryWrapper().eq(field, value)).intValue(); + default Long selectCount(SFunction field, Object value) { + return selectCount(new LambdaQueryWrapper().eq(field, value)); } default List selectList() { @@ -76,4 +76,8 @@ public interface BaseMapperX extends BaseMapper { entities.forEach(this::insert); } + default Boolean exists(SFunction field, Object value) { + return selectCount(field, value) > 0; + } + } diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java index 06e887dde..f332ba770 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java @@ -24,7 +24,7 @@ public interface FileMapper extends BaseMapperX { .orderByDesc("create_time")); } - default Integer selectCountById(String id) { + default Long selectCountById(String id) { return selectCount(FileDO::getId, id); } 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 1a3a09873..703c6c23a 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 @@ -25,7 +25,7 @@ public interface DeptMapper extends BaseMapperX { .eq(DeptDO::getName, name)); } - default Integer selectCountByParentId(Long parentId) { + default Long selectCountByParentId(Long parentId) { return selectCount(DeptDO::getParentId, parentId); } 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 28e4e468d..a00dc791a 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 @@ -28,7 +28,7 @@ public interface DictDataMapper extends BaseMapperX { .in(DictDataDO::getValue, values)); } - default int selectCountByDictType(String dictType) { + default long selectCountByDictType(String dictType) { return selectCount(DictDataDO::getDictType, dictType); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java index dd0e775ae..2720652ec 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java @@ -20,7 +20,7 @@ public interface MenuMapper extends BaseMapperX { .eq(MenuDO::getName, name)); } - default Integer selectCountByParentId(Long parentId) { + default Long selectCountByParentId(Long parentId) { return selectCount(MenuDO::getParentId, parentId); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java index 0002e79ff..f4ad4cd02 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java @@ -48,7 +48,7 @@ public interface SmsTemplateMapper extends BaseMapperX { .orderByDesc(SmsTemplateDO::getId)); } - default Integer selectCountByChannelId(Long channelId) { + default Long selectCountByChannelId(Long channelId) { return selectCount(SmsTemplateDO::getChannelId, channelId); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java index 0742f8293..db1a1b624 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java @@ -82,7 +82,7 @@ public interface DictDataService extends DictDataFrameworkService { * @param dictType 字典类型 * @return 数据数量 */ - int countByDictType(String dictType); + long countByDictType(String dictType); /** * 校验字典数据们是否有效。如下情况,视为无效: 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 4832507cd..89ed28c50 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 @@ -209,7 +209,7 @@ public class DictDataServiceImpl implements DictDataService { } @Override - public int countByDictType(String dictType) { + public long countByDictType(String dictType) { return dictDataMapper.selectCountByDictType(dictType); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java index 40d8c13c5..269aae283 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java @@ -166,6 +166,7 @@ public class MenuServiceImpl implements MenuService { * @param menuId 菜单编号 */ @Transactional(rollbackFor = Exception.class) + @Override public void deleteMenu(Long menuId) { // 校验是否还有子菜单 if (menuMapper.selectCountByParentId(menuId) > 0) { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java index eaa655066..997586c73 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java @@ -110,6 +110,6 @@ public interface SmsTemplateService { * @param channelId 短信渠道编号 * @return 数量 */ - Integer countByChannelId(Long channelId); + Long countByChannelId(Long channelId); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java index ce8e71435..4a65551b4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java @@ -220,7 +220,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { } @Override - public Integer countByChannelId(Long channelId) { + public Long countByChannelId(Long channelId) { return smsTemplateMapper.selectCountByChannelId(channelId); } diff --git a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceTest.java b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceTest.java index 406f1e8a4..0c5045258 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceTest.java +++ b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceTest.java @@ -177,7 +177,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { // 准备参数 Long id = dbDictType.getId(); // mock 方法 - when(dictDataService.countByDictType(eq(dbDictType.getType()))).thenReturn(1); + when(dictDataService.countByDictType(eq(dbDictType.getType()))).thenReturn(1L); // 调用, 并断言异常 assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_HAS_CHILDREN); diff --git a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java index 7e8b8445e..8ff9683a6 100644 --- a/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java +++ b/yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java @@ -147,7 +147,7 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { // 准备参数 Long id = dbSmsChannel.getId(); // mock 方法 - when(smsTemplateService.countByChannelId(eq(id))).thenReturn(10); + when(smsTemplateService.countByChannelId(eq(id))).thenReturn(10L); // 调用, 并断言异常 assertServiceException(() -> smsChannelService.deleteSmsChannel(id), SMS_CHANNEL_HAS_CHILDREN);