Commit b5b23b3d7ca2d19179130ba309b41e2ebc7f8db1
1 parent
10f7352e
infra:完善 config 的单元测试
Showing
7 changed files
with
71 additions
and
58 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.config; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| ... | ... | @@ -8,8 +7,8 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 8 | 7 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.*; |
| 9 | 8 | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; |
| 10 | 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 11 | -import cn.iocoder.yudao.module.infra.service.config.ConfigService; | |
| 12 | 10 | import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants; |
| 11 | +import cn.iocoder.yudao.module.infra.service.config.ConfigService; | |
| 13 | 12 | import io.swagger.annotations.Api; |
| 14 | 13 | import io.swagger.annotations.ApiImplicitParam; |
| 15 | 14 | import io.swagger.annotations.ApiOperation; |
| ... | ... | @@ -23,6 +22,7 @@ import javax.validation.Valid; |
| 23 | 22 | import java.io.IOException; |
| 24 | 23 | import java.util.List; |
| 25 | 24 | |
| 25 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 26 | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 27 | 27 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 28 | 28 | |
| ... | ... | @@ -76,7 +76,7 @@ public class ConfigController { |
| 76 | 76 | return null; |
| 77 | 77 | } |
| 78 | 78 | if (!config.getVisible()) { |
| 79 | - throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE); | |
| 79 | + throw exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE); | |
| 80 | 80 | } |
| 81 | 81 | return success(config.getValue()); |
| 82 | 82 | } |
| ... | ... | @@ -93,8 +93,8 @@ public class ConfigController { |
| 93 | 93 | @ApiOperation("导出参数配置") |
| 94 | 94 | @PreAuthorize("@ss.hasPermission('infra:config:export')") |
| 95 | 95 | @OperateLog(type = EXPORT) |
| 96 | - public void exportSysConfig(@Valid ConfigExportReqVO reqVO, | |
| 97 | - HttpServletResponse response) throws IOException { | |
| 96 | + public void exportConfig(@Valid ConfigExportReqVO reqVO, | |
| 97 | + HttpServletResponse response) throws IOException { | |
| 98 | 98 | List<ConfigDO> list = configService.getConfigList(reqVO); |
| 99 | 99 | // 拼接数据 |
| 100 | 100 | List<ConfigExcelVO> datas = ConfigConvert.INSTANCE.convertList(list); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java
| ... | ... | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqV |
| 9 | 9 | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; |
| 10 | 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 11 | 11 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; |
| 12 | -import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants; | |
| 13 | 12 | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; |
| 14 | 13 | import com.google.common.annotations.VisibleForTesting; |
| 15 | 14 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -20,6 +19,7 @@ import javax.annotation.Resource; |
| 20 | 19 | import java.util.List; |
| 21 | 20 | |
| 22 | 21 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * 参数配置 Service 实现类 |
| ... | ... | @@ -35,7 +35,7 @@ public class ConfigServiceImpl implements ConfigService { |
| 35 | 35 | @Override |
| 36 | 36 | public Long createConfig(ConfigCreateReqVO reqVO) { |
| 37 | 37 | // 校验正确性 |
| 38 | - checkCreateOrUpdate(null, reqVO.getKey()); | |
| 38 | + validateConfigForCreateOrUpdate(null, reqVO.getKey()); | |
| 39 | 39 | // 插入参数配置 |
| 40 | 40 | ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO); |
| 41 | 41 | config.setType(ConfigTypeEnum.CUSTOM.getType()); |
| ... | ... | @@ -46,19 +46,19 @@ public class ConfigServiceImpl implements ConfigService { |
| 46 | 46 | @Override |
| 47 | 47 | public void updateConfig(ConfigUpdateReqVO reqVO) { |
| 48 | 48 | // 校验正确性 |
| 49 | - checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key | |
| 49 | + validateConfigForCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key | |
| 50 | 50 | // 更新参数配置 |
| 51 | 51 | ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO); |
| 52 | - configMapper.updateById(updateObj);; | |
| 52 | + configMapper.updateById(updateObj); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | @Override |
| 56 | 56 | public void deleteConfig(Long id) { |
| 57 | 57 | // 校验配置存在 |
| 58 | - ConfigDO config = checkConfigExists(id); | |
| 58 | + ConfigDO config = validateConfigExists(id); | |
| 59 | 59 | // 内置配置,不允许删除 |
| 60 | 60 | if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) { |
| 61 | - throw exception(ErrorCodeConstants.CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE); | |
| 61 | + throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE); | |
| 62 | 62 | } |
| 63 | 63 | // 删除 |
| 64 | 64 | configMapper.deleteById(id); |
| ... | ... | @@ -84,39 +84,39 @@ public class ConfigServiceImpl implements ConfigService { |
| 84 | 84 | return configMapper.selectList(reqVO); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - private void checkCreateOrUpdate(Long id, String key) { | |
| 87 | + private void validateConfigForCreateOrUpdate(Long id, String key) { | |
| 88 | 88 | // 校验自己存在 |
| 89 | - checkConfigExists(id); | |
| 89 | + validateConfigExists(id); | |
| 90 | 90 | // 校验参数配置 key 的唯一性 |
| 91 | 91 | if (StrUtil.isNotEmpty(key)) { |
| 92 | - checkConfigKeyUnique(id, key); | |
| 92 | + validateConfigKeyUnique(id, key); | |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | @VisibleForTesting |
| 97 | - public ConfigDO checkConfigExists(Long id) { | |
| 97 | + public ConfigDO validateConfigExists(Long id) { | |
| 98 | 98 | if (id == null) { |
| 99 | 99 | return null; |
| 100 | 100 | } |
| 101 | 101 | ConfigDO config = configMapper.selectById(id); |
| 102 | 102 | if (config == null) { |
| 103 | - throw exception(ErrorCodeConstants.CONFIG_NOT_EXISTS); | |
| 103 | + throw exception(CONFIG_NOT_EXISTS); | |
| 104 | 104 | } |
| 105 | 105 | return config; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | @VisibleForTesting |
| 109 | - public void checkConfigKeyUnique(Long id, String key) { | |
| 109 | + public void validateConfigKeyUnique(Long id, String key) { | |
| 110 | 110 | ConfigDO config = configMapper.selectByKey(key); |
| 111 | 111 | if (config == null) { |
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | // 如果 id 为空,说明不用比较是否为相同 id 的参数配置 |
| 115 | 115 | if (id == null) { |
| 116 | - throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE); | |
| 116 | + throw exception(CONFIG_KEY_DUPLICATE); | |
| 117 | 117 | } |
| 118 | 118 | if (!config.getId().equals(id)) { |
| 119 | - throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE); | |
| 119 | + throw exception(CONFIG_KEY_DUPLICATE); | |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceTest.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.infra.service.config; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 5 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | |
| 6 | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | 6 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; |
| 8 | 7 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; |
| ... | ... | @@ -12,17 +11,17 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqV |
| 12 | 11 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 13 | 12 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; |
| 14 | 13 | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; |
| 15 | -import org.junit.jupiter.api.Assertions; | |
| 16 | 14 | import org.junit.jupiter.api.Test; |
| 17 | 15 | import org.springframework.context.annotation.Import; |
| 18 | 16 | |
| 19 | 17 | import javax.annotation.Resource; |
| 20 | -import java.time.LocalDateTime; | |
| 21 | 18 | import java.util.List; |
| 22 | 19 | import java.util.function.Consumer; |
| 23 | 20 | |
| 24 | 21 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 22 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | |
| 25 | 23 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 24 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | |
| 26 | 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 27 | 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 28 | 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| ... | ... | @@ -50,7 +49,7 @@ public class ConfigServiceTest extends BaseDbUnitTest { |
| 50 | 49 | // 校验记录的属性是否正确 |
| 51 | 50 | ConfigDO config = configMapper.selectById(configId); |
| 52 | 51 | assertPojoEquals(reqVO, config); |
| 53 | - Assertions.assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); | |
| 52 | + assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); | |
| 54 | 53 | } |
| 55 | 54 | |
| 56 | 55 | @Test |
| ... | ... | @@ -101,40 +100,40 @@ public class ConfigServiceTest extends BaseDbUnitTest { |
| 101 | 100 | } |
| 102 | 101 | |
| 103 | 102 | @Test |
| 104 | - public void testCheckConfigExists_success() { | |
| 103 | + public void testValidateConfigExists_success() { | |
| 105 | 104 | // mock 数据 |
| 106 | 105 | ConfigDO dbConfigDO = randomConfigDO(); |
| 107 | 106 | configMapper.insert(dbConfigDO);// @Sql: 先插入出一条存在的数据 |
| 108 | 107 | |
| 109 | 108 | // 调用成功 |
| 110 | - configService.checkConfigExists(dbConfigDO.getId()); | |
| 109 | + configService.validateConfigExists(dbConfigDO.getId()); | |
| 111 | 110 | } |
| 112 | 111 | |
| 113 | 112 | @Test |
| 114 | - public void testCheckConfigExist_notExists() { | |
| 115 | - assertServiceException(() -> configService.checkConfigExists(randomLongId()), CONFIG_NOT_EXISTS); | |
| 113 | + public void testValidateConfigExist_notExists() { | |
| 114 | + assertServiceException(() -> configService.validateConfigExists(randomLongId()), CONFIG_NOT_EXISTS); | |
| 116 | 115 | } |
| 117 | 116 | |
| 118 | 117 | @Test |
| 119 | - public void testCheckConfigKeyUnique_success() { | |
| 118 | + public void testValidateConfigKeyUnique_success() { | |
| 120 | 119 | // 调用,成功 |
| 121 | - configService.checkConfigKeyUnique(randomLongId(), randomString()); | |
| 120 | + configService.validateConfigKeyUnique(randomLongId(), randomString()); | |
| 122 | 121 | } |
| 123 | 122 | |
| 124 | 123 | @Test |
| 125 | - public void testCheckConfigKeyUnique_keyDuplicateForCreate() { | |
| 124 | + public void testValidateConfigKeyUnique_keyDuplicateForCreate() { | |
| 126 | 125 | // 准备参数 |
| 127 | 126 | String key = randomString(); |
| 128 | 127 | // mock 数据 |
| 129 | 128 | configMapper.insert(randomConfigDO(o -> o.setConfigKey(key))); |
| 130 | 129 | |
| 131 | 130 | // 调用,校验异常 |
| 132 | - assertServiceException(() -> configService.checkConfigKeyUnique(null, key), | |
| 131 | + assertServiceException(() -> configService.validateConfigKeyUnique(null, key), | |
| 133 | 132 | CONFIG_KEY_DUPLICATE); |
| 134 | 133 | } |
| 135 | 134 | |
| 136 | 135 | @Test |
| 137 | - public void testCheckConfigKeyUnique_keyDuplicateForUpdate() { | |
| 136 | + public void testValidateConfigKeyUnique_keyDuplicateForUpdate() { | |
| 138 | 137 | // 准备参数 |
| 139 | 138 | Long id = randomLongId(); |
| 140 | 139 | String key = randomString(); |
| ... | ... | @@ -142,7 +141,7 @@ public class ConfigServiceTest extends BaseDbUnitTest { |
| 142 | 141 | configMapper.insert(randomConfigDO(o -> o.setConfigKey(key))); |
| 143 | 142 | |
| 144 | 143 | // 调用,校验异常 |
| 145 | - assertServiceException(() -> configService.checkConfigKeyUnique(id, key), | |
| 144 | + assertServiceException(() -> configService.validateConfigKeyUnique(id, key), | |
| 146 | 145 | CONFIG_KEY_DUPLICATE); |
| 147 | 146 | } |
| 148 | 147 | |
| ... | ... | @@ -157,19 +156,19 @@ public class ConfigServiceTest extends BaseDbUnitTest { |
| 157 | 156 | }); |
| 158 | 157 | configMapper.insert(dbConfig); |
| 159 | 158 | // 测试 name 不匹配 |
| 160 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); | |
| 159 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); | |
| 161 | 160 | // 测试 key 不匹配 |
| 162 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); | |
| 161 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); | |
| 163 | 162 | // 测试 type 不匹配 |
| 164 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); | |
| 163 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); | |
| 165 | 164 | // 测试 createTime 不匹配 |
| 166 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | |
| 165 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | |
| 167 | 166 | // 准备参数 |
| 168 | 167 | ConfigPageReqVO reqVO = new ConfigPageReqVO(); |
| 169 | 168 | reqVO.setName("艿"); |
| 170 | 169 | reqVO.setKey("nai"); |
| 171 | 170 | reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); |
| 172 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 15),buildTime(2021, 2, 15)})); | |
| 171 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15)); | |
| 173 | 172 | |
| 174 | 173 | // 调用 |
| 175 | 174 | PageResult<ConfigDO> pageResult = configService.getConfigPage(reqVO); |
| ... | ... | @@ -190,19 +189,19 @@ public class ConfigServiceTest extends BaseDbUnitTest { |
| 190 | 189 | }); |
| 191 | 190 | configMapper.insert(dbConfig); |
| 192 | 191 | // 测试 name 不匹配 |
| 193 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); | |
| 192 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); | |
| 194 | 193 | // 测试 key 不匹配 |
| 195 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); | |
| 194 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); | |
| 196 | 195 | // 测试 type 不匹配 |
| 197 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); | |
| 196 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); | |
| 198 | 197 | // 测试 createTime 不匹配 |
| 199 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | |
| 198 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | |
| 200 | 199 | // 准备参数 |
| 201 | 200 | ConfigExportReqVO reqVO = new ConfigExportReqVO(); |
| 202 | 201 | reqVO.setName("艿"); |
| 203 | 202 | reqVO.setKey("nai"); |
| 204 | 203 | reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); |
| 205 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 15),buildTime(2021, 2, 15)})); | |
| 204 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15)); | |
| 206 | 205 | |
| 207 | 206 | // 调用 |
| 208 | 207 | List<ConfigDO> list = configService.getConfigList(reqVO); |
| ... | ... | @@ -212,6 +211,21 @@ public class ConfigServiceTest extends BaseDbUnitTest { |
| 212 | 211 | } |
| 213 | 212 | |
| 214 | 213 | @Test |
| 214 | + public void testGetConfig() { | |
| 215 | + // mock 数据 | |
| 216 | + ConfigDO dbConfig = randomConfigDO(); | |
| 217 | + configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 | |
| 218 | + // 准备参数 | |
| 219 | + Long id = dbConfig.getId(); | |
| 220 | + | |
| 221 | + // 调用 | |
| 222 | + ConfigDO config = configService.getConfig(id); | |
| 223 | + // 断言 | |
| 224 | + assertNotNull(config); | |
| 225 | + assertPojoEquals(dbConfig, config); | |
| 226 | + } | |
| 227 | + | |
| 228 | + @Test | |
| 215 | 229 | public void testGetConfigByKey() { |
| 216 | 230 | // mock 数据 |
| 217 | 231 | ConfigDO dbConfig = randomConfigDO(); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java
| ... | ... | @@ -89,7 +89,6 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { |
| 89 | 89 | o.setId(dbDataSourceConfig.getId()); // 设置更新的 ID |
| 90 | 90 | }); |
| 91 | 91 | // mock 方法 |
| 92 | -// when(stringEncryptor.encrypt(eq(reqVO.getPassword()))).thenReturn("123456"); | |
| 93 | 92 | databaseUtilsMock.when(() -> JdbcUtils.isConnectionOK(eq(reqVO.getUrl()), |
| 94 | 93 | eq(reqVO.getUsername()), eq(reqVO.getPassword()))).thenReturn(true); |
| 95 | 94 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.controller.admin.user; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 6 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 7 | 6 | import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; |
| 8 | 7 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO; |
| ... | ... | @@ -31,6 +30,7 @@ import javax.annotation.Resource; |
| 31 | 30 | import javax.validation.Valid; |
| 32 | 31 | import java.util.List; |
| 33 | 32 | |
| 33 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 34 | 34 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 35 | 35 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 36 | 36 | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY; |
| ... | ... | @@ -99,7 +99,7 @@ public class UserProfileController { |
| 99 | 99 | @ApiOperation("上传用户个人头像") |
| 100 | 100 | public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { |
| 101 | 101 | if (file.isEmpty()) { |
| 102 | - throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | |
| 102 | + throw exception(FILE_IS_EMPTY); | |
| 103 | 103 | } |
| 104 | 104 | String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream()); |
| 105 | 105 | return success(avatar); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.service.permission; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 6 | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
| ... | ... | @@ -31,6 +30,7 @@ import javax.annotation.Resource; |
| 31 | 30 | import java.util.*; |
| 32 | 31 | import java.util.stream.Collectors; |
| 33 | 32 | |
| 33 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 34 | 34 | import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT; |
| 35 | 35 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 36 | 36 | |
| ... | ... | @@ -118,7 +118,7 @@ public class MenuServiceImpl implements MenuService { |
| 118 | 118 | public void updateMenu(MenuUpdateReqVO reqVO) { |
| 119 | 119 | // 校验更新的菜单是否存在 |
| 120 | 120 | if (menuMapper.selectById(reqVO.getId()) == null) { |
| 121 | - throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS); | |
| 121 | + throw exception(MENU_NOT_EXISTS); | |
| 122 | 122 | } |
| 123 | 123 | // 校验父菜单存在 |
| 124 | 124 | validateParentMenu(reqVO.getParentId(), reqVO.getId()); |
| ... | ... | @@ -138,11 +138,11 @@ public class MenuServiceImpl implements MenuService { |
| 138 | 138 | public void deleteMenu(Long menuId) { |
| 139 | 139 | // 校验是否还有子菜单 |
| 140 | 140 | if (menuMapper.selectCountByParentId(menuId) > 0) { |
| 141 | - throw ServiceExceptionUtil.exception(MENU_EXISTS_CHILDREN); | |
| 141 | + throw exception(MENU_EXISTS_CHILDREN); | |
| 142 | 142 | } |
| 143 | 143 | // 校验删除的菜单是否存在 |
| 144 | 144 | if (menuMapper.selectById(menuId) == null) { |
| 145 | - throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS); | |
| 145 | + throw exception(MENU_NOT_EXISTS); | |
| 146 | 146 | } |
| 147 | 147 | // 标记删除 |
| 148 | 148 | menuMapper.deleteById(menuId); |
| ... | ... | @@ -229,17 +229,17 @@ public class MenuServiceImpl implements MenuService { |
| 229 | 229 | } |
| 230 | 230 | // 不能设置自己为父菜单 |
| 231 | 231 | if (parentId.equals(childId)) { |
| 232 | - throw ServiceExceptionUtil.exception(MENU_PARENT_ERROR); | |
| 232 | + throw exception(MENU_PARENT_ERROR); | |
| 233 | 233 | } |
| 234 | 234 | MenuDO menu = menuMapper.selectById(parentId); |
| 235 | 235 | // 父菜单不存在 |
| 236 | 236 | if (menu == null) { |
| 237 | - throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_EXISTS); | |
| 237 | + throw exception(MENU_PARENT_NOT_EXISTS); | |
| 238 | 238 | } |
| 239 | 239 | // 父菜单必须是目录或者菜单类型 |
| 240 | 240 | if (!MenuTypeEnum.DIR.getType().equals(menu.getType()) |
| 241 | 241 | && !MenuTypeEnum.MENU.getType().equals(menu.getType())) { |
| 242 | - throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_DIR_OR_MENU); | |
| 242 | + throw exception(MENU_PARENT_NOT_DIR_OR_MENU); | |
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| ... | ... | @@ -260,10 +260,10 @@ public class MenuServiceImpl implements MenuService { |
| 260 | 260 | } |
| 261 | 261 | // 如果 id 为空,说明不用比较是否为相同 id 的菜单 |
| 262 | 262 | if (id == null) { |
| 263 | - throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE); | |
| 263 | + throw exception(MENU_NAME_DUPLICATE); | |
| 264 | 264 | } |
| 265 | 265 | if (!menu.getId().equals(id)) { |
| 266 | - throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE); | |
| 266 | + throw exception(MENU_NAME_DUPLICATE); | |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java
| ... | ... | @@ -34,6 +34,7 @@ import java.util.Collections; |
| 34 | 34 | import java.util.List; |
| 35 | 35 | |
| 36 | 36 | import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; |
| 37 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | |
| 37 | 38 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 38 | 39 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 39 | 40 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| ... | ... | @@ -310,7 +311,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 310 | 311 | reqVO.setContactName("艿"); |
| 311 | 312 | reqVO.setContactMobile("1560"); |
| 312 | 313 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 313 | - reqVO.setCreateTime(new LocalDateTime[]{buildTime(2020, 12, 1),buildTime(2020, 12, 24)}); | |
| 314 | + reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); | |
| 314 | 315 | |
| 315 | 316 | // 调用 |
| 316 | 317 | PageResult<TenantDO> pageResult = tenantService.getTenantPage(reqVO); |
| ... | ... | @@ -347,7 +348,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 347 | 348 | reqVO.setContactName("艿"); |
| 348 | 349 | reqVO.setContactMobile("1560"); |
| 349 | 350 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 350 | - reqVO.setCreateTime(new LocalDateTime[]{buildTime(2020, 12, 1),buildTime(2020, 12, 24)}); | |
| 351 | + reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); | |
| 351 | 352 | |
| 352 | 353 | // 调用 |
| 353 | 354 | List<TenantDO> list = tenantService.getTenantList(reqVO); |
| ... | ... | @@ -356,7 +357,6 @@ public class TenantServiceImplTest extends BaseDbUnitTest { |
| 356 | 357 | assertPojoEquals(dbTenant, list.get(0)); |
| 357 | 358 | } |
| 358 | 359 | |
| 359 | - | |
| 360 | 360 | @Test |
| 361 | 361 | public void testGetTenantByName() { |
| 362 | 362 | // mock 数据 | ... | ... |