Browse Source

Merge pull request #82 from leosanqing/optimize-baseMapper

修改 baseMapper selectCount int -> long
芋道源码 3 years ago
parent
commit
e52d7d33be
13 changed files with 20 additions and 15 deletions
  1. 8 4
      yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java
  2. 1 1
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/file/FileMapper.java
  3. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java
  4. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java
  5. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java
  6. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsTemplateMapper.java
  7. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java
  8. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java
  9. 1 0
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
  10. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java
  11. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java
  12. 1 1
      yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceTest.java
  13. 1 1
      yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceTest.java

+ 8 - 4
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> {
         return selectOne(new LambdaQueryWrapper<T>().eq(field1, value1).eq(field2, value2));
         return selectOne(new LambdaQueryWrapper<T>().eq(field1, value1).eq(field2, value2));
     }
     }
 
 
-    default Integer selectCount(String field, Object value) {
-        return selectCount(new QueryWrapper<T>().eq(field, value)).intValue();
+    default Long selectCount(String field, Object value) {
+        return selectCount(new QueryWrapper<T>().eq(field, value));
     }
     }
 
 
-    default Integer selectCount(SFunction<T, ?> field, Object value) {
-        return selectCount(new LambdaQueryWrapper<T>().eq(field, value)).intValue();
+    default Long selectCount(SFunction<T, ?> field, Object value) {
+        return selectCount(new LambdaQueryWrapper<T>().eq(field, value));
     }
     }
 
 
     default List<T> selectList() {
     default List<T> selectList() {
@@ -76,4 +76,8 @@ public interface BaseMapperX<T> extends BaseMapper<T> {
         entities.forEach(this::insert);
         entities.forEach(this::insert);
     }
     }
 
 
+    default Boolean exists(SFunction<T, ?> field, Object value) {
+        return selectCount(field, value) > 0;
+    }
+
 }
 }

+ 1 - 1
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> {
                 .orderByDesc("create_time"));
                 .orderByDesc("create_time"));
     }
     }
 
 
-    default Integer selectCountById(String id) {
+    default Long selectCountById(String id) {
         return selectCount(FileDO::getId, id);
         return selectCount(FileDO::getId, id);
     }
     }
 
 

+ 1 - 1
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> {
                 .eq(DeptDO::getName, name));
                 .eq(DeptDO::getName, name));
     }
     }
 
 
-    default Integer selectCountByParentId(Long parentId) {
+    default Long selectCountByParentId(Long parentId) {
         return selectCount(DeptDO::getParentId, parentId);
         return selectCount(DeptDO::getParentId, parentId);
     }
     }
 
 

+ 1 - 1
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> {
                 .in(DictDataDO::getValue, values));
                 .in(DictDataDO::getValue, values));
     }
     }
 
 
-    default int selectCountByDictType(String dictType) {
+    default long selectCountByDictType(String dictType) {
         return selectCount(DictDataDO::getDictType, dictType);
         return selectCount(DictDataDO::getDictType, dictType);
     }
     }
 
 

+ 1 - 1
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> {
                 .eq(MenuDO::getName, name));
                 .eq(MenuDO::getName, name));
     }
     }
 
 
-    default Integer selectCountByParentId(Long parentId) {
+    default Long selectCountByParentId(Long parentId) {
         return selectCount(MenuDO::getParentId, parentId);
         return selectCount(MenuDO::getParentId, parentId);
     }
     }
 
 

+ 1 - 1
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> {
                 .orderByDesc(SmsTemplateDO::getId));
                 .orderByDesc(SmsTemplateDO::getId));
     }
     }
 
 
-    default Integer selectCountByChannelId(Long channelId) {
+    default Long selectCountByChannelId(Long channelId) {
         return selectCount(SmsTemplateDO::getChannelId, channelId);
         return selectCount(SmsTemplateDO::getChannelId, channelId);
     }
     }
 
 

+ 1 - 1
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 字典类型
      * @param dictType 字典类型
      * @return 数据数量
      * @return 数据数量
      */
      */
-    int countByDictType(String dictType);
+    long countByDictType(String dictType);
 
 
     /**
     /**
      * 校验字典数据们是否有效。如下情况,视为无效:
      * 校验字典数据们是否有效。如下情况,视为无效:

+ 1 - 1
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
     @Override
-    public int countByDictType(String dictType) {
+    public long countByDictType(String dictType) {
         return dictDataMapper.selectCountByDictType(dictType);
         return dictDataMapper.selectCountByDictType(dictType);
     }
     }
 
 

+ 1 - 0
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 菜单编号
      * @param menuId 菜单编号
      */
      */
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
+    @Override
     public void deleteMenu(Long menuId) {
     public void deleteMenu(Long menuId) {
         // 校验是否还有子菜单
         // 校验是否还有子菜单
         if (menuMapper.selectCountByParentId(menuId) > 0) {
         if (menuMapper.selectCountByParentId(menuId) > 0) {

+ 1 - 1
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 短信渠道编号
      * @param channelId 短信渠道编号
      * @return 数量
      * @return 数量
      */
      */
-    Integer countByChannelId(Long channelId);
+    Long countByChannelId(Long channelId);
 
 
 }
 }

+ 1 - 1
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
     @Override
-    public Integer countByChannelId(Long channelId) {
+    public Long countByChannelId(Long channelId) {
         return smsTemplateMapper.selectCountByChannelId(channelId);
         return smsTemplateMapper.selectCountByChannelId(channelId);
     }
     }
 
 

+ 1 - 1
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();
         Long id = dbDictType.getId();
         // mock 方法
         // 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);
         assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_HAS_CHILDREN);

+ 1 - 1
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();
         Long id = dbSmsChannel.getId();
         // mock 方法
         // mock 方法
-        when(smsTemplateService.countByChannelId(eq(id))).thenReturn(10);
+        when(smsTemplateService.countByChannelId(eq(id))).thenReturn(10L);
 
 
         // 调用, 并断言异常
         // 调用, 并断言异常
         assertServiceException(() -> smsChannelService.deleteSmsChannel(id), SMS_CHANNEL_HAS_CHILDREN);
         assertServiceException(() -> smsChannelService.deleteSmsChannel(id), SMS_CHANNEL_HAS_CHILDREN);