Commit e52d7d33bef376d5a6b544f8a5bb11fffea0c25b
Committed by
GitHub
Merge pull request #82 from leosanqing/optimize-baseMapper
修改 baseMapper selectCount int -> long
Showing
13 changed files
with
20 additions
and
15 deletions
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<T> extends BaseMapper<T> { |
| 43 | 43 | return selectOne(new LambdaQueryWrapper<T>().eq(field1, value1).eq(field2, value2)); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - default Integer selectCount(String field, Object value) { | |
| 47 | - return selectCount(new QueryWrapper<T>().eq(field, value)).intValue(); | |
| 46 | + default Long selectCount(String field, Object value) { | |
| 47 | + return selectCount(new QueryWrapper<T>().eq(field, value)); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - default Integer selectCount(SFunction<T, ?> field, Object value) { | |
| 51 | - return selectCount(new LambdaQueryWrapper<T>().eq(field, value)).intValue(); | |
| 50 | + default Long selectCount(SFunction<T, ?> field, Object value) { | |
| 51 | + return selectCount(new LambdaQueryWrapper<T>().eq(field, value)); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | default List<T> selectList() { |
| ... | ... | @@ -76,4 +76,8 @@ public interface BaseMapperX<T> extends BaseMapper<T> { |
| 76 | 76 | entities.forEach(this::insert); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | + default Boolean exists(SFunction<T, ?> field, Object value) { | |
| 80 | + return selectCount(field, value) > 0; | |
| 81 | + } | |
| 82 | + | |
| 79 | 83 | } | ... | ... |
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<FileDO> { |
| 24 | 24 | .orderByDesc("create_time")); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - default Integer selectCountById(String id) { | |
| 27 | + default Long selectCountById(String id) { | |
| 28 | 28 | return selectCount(FileDO::getId, id); |
| 29 | 29 | } |
| 30 | 30 | ... | ... |
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<DeptDO> { |
| 25 | 25 | .eq(DeptDO::getName, name)); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - default Integer selectCountByParentId(Long parentId) { | |
| 28 | + default Long selectCountByParentId(Long parentId) { | |
| 29 | 29 | return selectCount(DeptDO::getParentId, parentId); |
| 30 | 30 | } |
| 31 | 31 | ... | ... |
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<DictDataDO> { |
| 28 | 28 | .in(DictDataDO::getValue, values)); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - default int selectCountByDictType(String dictType) { | |
| 31 | + default long selectCountByDictType(String dictType) { | |
| 32 | 32 | return selectCount(DictDataDO::getDictType, dictType); |
| 33 | 33 | } |
| 34 | 34 | ... | ... |
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<MenuDO> { |
| 20 | 20 | .eq(MenuDO::getName, name)); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - default Integer selectCountByParentId(Long parentId) { | |
| 23 | + default Long selectCountByParentId(Long parentId) { | |
| 24 | 24 | return selectCount(MenuDO::getParentId, parentId); |
| 25 | 25 | } |
| 26 | 26 | ... | ... |
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<SmsTemplateDO> { |
| 48 | 48 | .orderByDesc(SmsTemplateDO::getId)); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - default Integer selectCountByChannelId(Long channelId) { | |
| 51 | + default Long selectCountByChannelId(Long channelId) { | |
| 52 | 52 | return selectCount(SmsTemplateDO::getChannelId, channelId); |
| 53 | 53 | } |
| 54 | 54 | ... | ... |
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java
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 { |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | @Override |
| 212 | - public int countByDictType(String dictType) { | |
| 212 | + public long countByDictType(String dictType) { | |
| 213 | 213 | return dictDataMapper.selectCountByDictType(dictType); |
| 214 | 214 | } |
| 215 | 215 | ... | ... |
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 { |
| 166 | 166 | * @param menuId 菜单编号 |
| 167 | 167 | */ |
| 168 | 168 | @Transactional(rollbackFor = Exception.class) |
| 169 | + @Override | |
| 169 | 170 | public void deleteMenu(Long menuId) { |
| 170 | 171 | // 校验是否还有子菜单 |
| 171 | 172 | if (menuMapper.selectCountByParentId(menuId) > 0) { | ... | ... |
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java
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 { |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | @Override |
| 223 | - public Integer countByChannelId(Long channelId) { | |
| 223 | + public Long countByChannelId(Long channelId) { | |
| 224 | 224 | return smsTemplateMapper.selectCountByChannelId(channelId); |
| 225 | 225 | } |
| 226 | 226 | ... | ... |
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 { |
| 177 | 177 | // 准备参数 |
| 178 | 178 | Long id = dbDictType.getId(); |
| 179 | 179 | // mock 方法 |
| 180 | - when(dictDataService.countByDictType(eq(dbDictType.getType()))).thenReturn(1); | |
| 180 | + when(dictDataService.countByDictType(eq(dbDictType.getType()))).thenReturn(1L); | |
| 181 | 181 | |
| 182 | 182 | // 调用, 并断言异常 |
| 183 | 183 | assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_HAS_CHILDREN); | ... | ... |
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 { |
| 147 | 147 | // 准备参数 |
| 148 | 148 | Long id = dbSmsChannel.getId(); |
| 149 | 149 | // mock 方法 |
| 150 | - when(smsTemplateService.countByChannelId(eq(id))).thenReturn(10); | |
| 150 | + when(smsTemplateService.countByChannelId(eq(id))).thenReturn(10L); | |
| 151 | 151 | |
| 152 | 152 | // 调用, 并断言异常 |
| 153 | 153 | assertServiceException(() -> smsChannelService.deleteSmsChannel(id), SMS_CHANNEL_HAS_CHILDREN); | ... | ... |