Commit 045c60fcd70c0da1185223a1a9fbd91d2316ef35
Committed by
Gitee
!392 完善 system 模块的单元测试,单测数量 423,方法行覆盖率 95%,行覆盖率 93%
Merge pull request !392 from 芋道源码/feature/dev-yunai
Showing
120 changed files
with
3175 additions
and
1707 deletions
Too many changes.
To preserve performance only 100 of 120 files are displayed.
pom.xml
| @@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
| 17 | <module>yudao-module-system</module> | 17 | <module>yudao-module-system</module> |
| 18 | <module>yudao-module-infra</module> | 18 | <module>yudao-module-infra</module> |
| 19 | <module>yudao-module-pay</module> | 19 | <module>yudao-module-pay</module> |
| 20 | -<!-- <module>yudao-module-bpm</module>--> | 20 | + <module>yudao-module-bpm</module> |
| 21 | <!-- <module>yudao-module-visualization</module>--> | 21 | <!-- <module>yudao-module-visualization</module>--> |
| 22 | <!-- <module>yudao-module-mp</module>--> | 22 | <!-- <module>yudao-module-mp</module>--> |
| 23 | <!-- <module>yudao-module-mall</module>--> | 23 | <!-- <module>yudao-module-mall</module>--> |
yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/util/DataPermissionUtils.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.datapermission.core.util; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; | ||
| 4 | +import cn.iocoder.yudao.framework.datapermission.core.aop.DataPermissionContextHolder; | ||
| 5 | +import lombok.SneakyThrows; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 数据权限 Util | ||
| 9 | + * | ||
| 10 | + * @author 芋道源码 | ||
| 11 | + */ | ||
| 12 | +public class DataPermissionUtils { | ||
| 13 | + | ||
| 14 | + private static DataPermission DATA_PERMISSION_DISABLE; | ||
| 15 | + | ||
| 16 | + @DataPermission(enable = false) | ||
| 17 | + @SneakyThrows | ||
| 18 | + private static DataPermission getDisableDataPermissionDisable() { | ||
| 19 | + if (DATA_PERMISSION_DISABLE == null) { | ||
| 20 | + DATA_PERMISSION_DISABLE = DataPermissionUtils.class | ||
| 21 | + .getDeclaredMethod("getDisableDataPermissionDisable") | ||
| 22 | + .getAnnotation(DataPermission.class); | ||
| 23 | + } | ||
| 24 | + return DATA_PERMISSION_DISABLE; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 忽略数据权限,执行对应的逻辑 | ||
| 29 | + * | ||
| 30 | + * @param runnable 逻辑 | ||
| 31 | + */ | ||
| 32 | + public static void executeIgnore(Runnable runnable) { | ||
| 33 | + DataPermission dataPermission = getDisableDataPermissionDisable(); | ||
| 34 | + DataPermissionContextHolder.add(dataPermission); | ||
| 35 | + try { | ||
| 36 | + // 执行 runnable | ||
| 37 | + runnable.run(); | ||
| 38 | + } finally { | ||
| 39 | + DataPermissionContextHolder.remove(); | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | +} |
yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/test/java/cn/iocoder/yudao/framework/datapermission/core/util/DataPermissionUtilsTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.datapermission.core.util; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.datapermission.core.aop.DataPermissionContextHolder; | ||
| 4 | +import org.junit.jupiter.api.Test; | ||
| 5 | + | ||
| 6 | +import static org.junit.jupiter.api.Assertions.*; | ||
| 7 | + | ||
| 8 | +public class DataPermissionUtilsTest { | ||
| 9 | + | ||
| 10 | + @Test | ||
| 11 | + public void testExecuteIgnore() { | ||
| 12 | + DataPermissionUtils.executeIgnore(() -> assertFalse(DataPermissionContextHolder.get().enable())); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | +} |
yudao-framework/yudao-spring-boot-starter-biz-error-code/src/main/java/cn/iocoder/yudao/framework/errorcode/core/generator/ErrorCodeAutoGeneratorImpl.java
| @@ -49,7 +49,7 @@ public class ErrorCodeAutoGeneratorImpl implements ErrorCodeAutoGenerator { | @@ -49,7 +49,7 @@ public class ErrorCodeAutoGeneratorImpl implements ErrorCodeAutoGenerator { | ||
| 49 | log.info("[execute][解析到错误码数量为 ({}) 个]", autoGenerateDTOs.size()); | 49 | log.info("[execute][解析到错误码数量为 ({}) 个]", autoGenerateDTOs.size()); |
| 50 | 50 | ||
| 51 | // 第二步,写入到 system 服务 | 51 | // 第二步,写入到 system 服务 |
| 52 | - errorCodeApi.autoGenerateErrorCodes(autoGenerateDTOs); | 52 | + errorCodeApi.autoGenerateErrorCodeList(autoGenerateDTOs); |
| 53 | log.info("[execute][写入到 system 组件完成]"); | 53 | log.info("[execute][写入到 system 组件完成]"); |
| 54 | } | 54 | } |
| 55 | 55 |
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/service/TenantFrameworkServiceImpl.java
| @@ -32,7 +32,7 @@ public class TenantFrameworkServiceImpl implements TenantFrameworkService { | @@ -32,7 +32,7 @@ public class TenantFrameworkServiceImpl implements TenantFrameworkService { | ||
| 32 | 32 | ||
| 33 | @Override | 33 | @Override |
| 34 | public List<Long> load(Object key) { | 34 | public List<Long> load(Object key) { |
| 35 | - return tenantApi.getTenantIds(); | 35 | + return tenantApi.getTenantIdList(); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | }); | 38 | }); |
| @@ -47,7 +47,7 @@ public class TenantFrameworkServiceImpl implements TenantFrameworkService { | @@ -47,7 +47,7 @@ public class TenantFrameworkServiceImpl implements TenantFrameworkService { | ||
| 47 | @Override | 47 | @Override |
| 48 | public ServiceException load(Long id) { | 48 | public ServiceException load(Long id) { |
| 49 | try { | 49 | try { |
| 50 | - tenantApi.validTenant(id); | 50 | + tenantApi.validateTenant(id); |
| 51 | return SERVICE_EXCEPTION_NULL; | 51 | return SERVICE_EXCEPTION_NULL; |
| 52 | } catch (ServiceException ex) { | 52 | } catch (ServiceException ex) { |
| 53 | return ex; | 53 | return ex; |
yudao-framework/yudao-spring-boot-starter-test/src/main/java/cn/iocoder/yudao/framework/test/core/util/RandomUtils.java
| @@ -50,7 +50,7 @@ public class RandomUtils { | @@ -50,7 +50,7 @@ public class RandomUtils { | ||
| 50 | } | 50 | } |
| 51 | // 如果是 type、status 结尾的字段,返回 tinyint 范围 | 51 | // 如果是 type、status 结尾的字段,返回 tinyint 范围 |
| 52 | if (StrUtil.endWithAnyIgnoreCase(attributeMetadata.getAttributeName(), | 52 | if (StrUtil.endWithAnyIgnoreCase(attributeMetadata.getAttributeName(), |
| 53 | - "type", "status", "category", "scope")) { | 53 | + "type", "status", "category", "scope", "result")) { |
| 54 | return RandomUtil.randomInt(0, TINYINT_MAX + 1); | 54 | return RandomUtil.randomInt(0, TINYINT_MAX + 1); |
| 55 | } | 55 | } |
| 56 | return RandomUtil.randomInt(); | 56 | return RandomUtil.randomInt(); |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmTaskAssignRuleServiceImpl.java
| @@ -213,18 +213,18 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | @@ -213,18 +213,18 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | ||
| 213 | 213 | ||
| 214 | private void validTaskAssignRuleOptions(Integer type, Set<Long> options) { | 214 | private void validTaskAssignRuleOptions(Integer type, Set<Long> options) { |
| 215 | if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) { | 215 | if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) { |
| 216 | - roleApi.validRoles(options); | 216 | + roleApi.validRoleList(options); |
| 217 | } else if (ObjectUtils.equalsAny(type, BpmTaskAssignRuleTypeEnum.DEPT_MEMBER.getType(), | 217 | } else if (ObjectUtils.equalsAny(type, BpmTaskAssignRuleTypeEnum.DEPT_MEMBER.getType(), |
| 218 | BpmTaskAssignRuleTypeEnum.DEPT_LEADER.getType())) { | 218 | BpmTaskAssignRuleTypeEnum.DEPT_LEADER.getType())) { |
| 219 | - deptApi.validDepts(options); | 219 | + deptApi.validateDeptList(options); |
| 220 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.POST.getType())) { | 220 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.POST.getType())) { |
| 221 | - postApi.validPosts(options); | 221 | + postApi.validPostList(options); |
| 222 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.USER.getType())) { | 222 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.USER.getType())) { |
| 223 | - adminUserApi.validUsers(options); | 223 | + adminUserApi.validateUserList(options); |
| 224 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.USER_GROUP.getType())) { | 224 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.USER_GROUP.getType())) { |
| 225 | userGroupService.validUserGroups(options); | 225 | userGroupService.validUserGroups(options); |
| 226 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.SCRIPT.getType())) { | 226 | } else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.SCRIPT.getType())) { |
| 227 | - dictDataApi.validDictDatas(DictTypeConstants.TASK_ASSIGN_SCRIPT, | 227 | + dictDataApi.validateDictDataList(DictTypeConstants.TASK_ASSIGN_SCRIPT, |
| 228 | CollectionUtils.convertSet(options, String::valueOf)); | 228 | CollectionUtils.convertSet(options, String::valueOf)); |
| 229 | } else { | 229 | } else { |
| 230 | throw new IllegalArgumentException(format("未知的规则类型({})", type)); | 230 | throw new IllegalArgumentException(format("未知的规则类型({})", type)); |
| @@ -288,12 +288,12 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | @@ -288,12 +288,12 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | ||
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | private Set<Long> calculateTaskCandidateUsersByDeptMember(BpmTaskAssignRuleDO rule) { | 290 | private Set<Long> calculateTaskCandidateUsersByDeptMember(BpmTaskAssignRuleDO rule) { |
| 291 | - List<AdminUserRespDTO> users = adminUserApi.getUsersByDeptIds(rule.getOptions()); | 291 | + List<AdminUserRespDTO> users = adminUserApi.getUserListByDeptIds(rule.getOptions()); |
| 292 | return convertSet(users, AdminUserRespDTO::getId); | 292 | return convertSet(users, AdminUserRespDTO::getId); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | private Set<Long> calculateTaskCandidateUsersByDeptLeader(BpmTaskAssignRuleDO rule) { | 295 | private Set<Long> calculateTaskCandidateUsersByDeptLeader(BpmTaskAssignRuleDO rule) { |
| 296 | - List<DeptRespDTO> depts = deptApi.getDepts(rule.getOptions()); | 296 | + List<DeptRespDTO> depts = deptApi.getDeptList(rule.getOptions()); |
| 297 | return convertSet(depts, DeptRespDTO::getLeaderUserId); | 297 | return convertSet(depts, DeptRespDTO::getLeaderUserId); |
| 298 | } | 298 | } |
| 299 | 299 |
yudao-module-bpm/yudao-module-bpm-biz/src/test/java/cn/iocoder/yudao/module/bpm/service/definition/BpmTaskAssignRuleServiceImplTest.java
| @@ -86,7 +86,7 @@ public class BpmTaskAssignRuleServiceImplTest extends BaseDbUnitTest { | @@ -86,7 +86,7 @@ public class BpmTaskAssignRuleServiceImplTest extends BaseDbUnitTest { | ||
| 86 | // mock 方法 | 86 | // mock 方法 |
| 87 | List<AdminUserRespDTO> users = CollectionUtils.convertList(asSet(11L, 22L), | 87 | List<AdminUserRespDTO> users = CollectionUtils.convertList(asSet(11L, 22L), |
| 88 | id -> new AdminUserRespDTO().setId(id)); | 88 | id -> new AdminUserRespDTO().setId(id)); |
| 89 | - when(adminUserApi.getUsersByDeptIds(eq(rule.getOptions()))).thenReturn(users); | 89 | + when(adminUserApi.getUserListByDeptIds(eq(rule.getOptions()))).thenReturn(users); |
| 90 | mockGetUserMap(asSet(11L, 22L)); | 90 | mockGetUserMap(asSet(11L, 22L)); |
| 91 | 91 | ||
| 92 | // 调用 | 92 | // 调用 |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java
| @@ -29,7 +29,7 @@ public interface DeptApi { | @@ -29,7 +29,7 @@ public interface DeptApi { | ||
| 29 | * @param ids 部门编号数组 | 29 | * @param ids 部门编号数组 |
| 30 | * @return 部门信息数组 | 30 | * @return 部门信息数组 |
| 31 | */ | 31 | */ |
| 32 | - List<DeptRespDTO> getDepts(Collection<Long> ids); | 32 | + List<DeptRespDTO> getDeptList(Collection<Long> ids); |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | * 校验部门们是否有效。如下情况,视为无效: | 35 | * 校验部门们是否有效。如下情况,视为无效: |
| @@ -38,7 +38,7 @@ public interface DeptApi { | @@ -38,7 +38,7 @@ public interface DeptApi { | ||
| 38 | * | 38 | * |
| 39 | * @param ids 角色编号数组 | 39 | * @param ids 角色编号数组 |
| 40 | */ | 40 | */ |
| 41 | - void validDepts(Collection<Long> ids); | 41 | + void validateDeptList(Collection<Long> ids); |
| 42 | 42 | ||
| 43 | /** | 43 | /** |
| 44 | * 获得指定编号的部门 Map | 44 | * 获得指定编号的部门 Map |
| @@ -47,7 +47,7 @@ public interface DeptApi { | @@ -47,7 +47,7 @@ public interface DeptApi { | ||
| 47 | * @return 部门 Map | 47 | * @return 部门 Map |
| 48 | */ | 48 | */ |
| 49 | default Map<Long, DeptRespDTO> getDeptMap(Set<Long> ids) { | 49 | default Map<Long, DeptRespDTO> getDeptMap(Set<Long> ids) { |
| 50 | - List<DeptRespDTO> list = getDepts(ids); | 50 | + List<DeptRespDTO> list = getDeptList(ids); |
| 51 | return CollectionUtils.convertMap(list, DeptRespDTO::getId); | 51 | return CollectionUtils.convertMap(list, DeptRespDTO::getId); |
| 52 | } | 52 | } |
| 53 | 53 |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApi.java
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java
| @@ -19,7 +19,7 @@ public interface DictDataApi { | @@ -19,7 +19,7 @@ public interface DictDataApi { | ||
| 19 | * @param dictType 字典类型 | 19 | * @param dictType 字典类型 |
| 20 | * @param values 字典数据值的数组 | 20 | * @param values 字典数据值的数组 |
| 21 | */ | 21 | */ |
| 22 | - void validDictDatas(String dictType, Collection<String> values); | 22 | + void validateDictDataList(String dictType, Collection<String> values); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * 获得指定的字典数据,从缓存中 | 25 | * 获得指定的字典数据,从缓存中 |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApi.java
| @@ -19,7 +19,7 @@ public interface ErrorCodeApi { | @@ -19,7 +19,7 @@ public interface ErrorCodeApi { | ||
| 19 | * | 19 | * |
| 20 | * @param autoGenerateDTOs 错误码信息 | 20 | * @param autoGenerateDTOs 错误码信息 |
| 21 | */ | 21 | */ |
| 22 | - void autoGenerateErrorCodes(@Valid List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs); | 22 | + void autoGenerateErrorCodeList(@Valid List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * 增量获得错误码数组 | 25 | * 增量获得错误码数组 |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApi.java
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/sms/SmsCodeApi.java
| 1 | package cn.iocoder.yudao.module.system.api.sms; | 1 | package cn.iocoder.yudao.module.system.api.sms; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.exception.ServiceException; | 3 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 4 | -import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO; | 4 | +import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeValidateReqDTO; |
| 5 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; | 5 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; |
| 6 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; | 6 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; |
| 7 | 7 | ||
| @@ -35,6 +35,6 @@ public interface SmsCodeApi { | @@ -35,6 +35,6 @@ public interface SmsCodeApi { | ||
| 35 | * | 35 | * |
| 36 | * @param reqDTO 校验请求 | 36 | * @param reqDTO 校验请求 |
| 37 | */ | 37 | */ |
| 38 | - void checkSmsCode(@Valid SmsCodeCheckReqDTO reqDTO); | 38 | + void validateSmsCode(@Valid SmsCodeValidateReqDTO reqDTO); |
| 39 | 39 | ||
| 40 | } | 40 | } |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/sms/dto/code/SmsCodeCheckReqDTO.java renamed to yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/sms/dto/code/SmsCodeValidateReqDTO.java
| @@ -14,7 +14,7 @@ import javax.validation.constraints.NotNull; | @@ -14,7 +14,7 @@ import javax.validation.constraints.NotNull; | ||
| 14 | * @author 芋道源码 | 14 | * @author 芋道源码 |
| 15 | */ | 15 | */ |
| 16 | @Data | 16 | @Data |
| 17 | -public class SmsCodeCheckReqDTO { | 17 | +public class SmsCodeValidateReqDTO { |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * 手机号 | 20 | * 手机号 |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApi.java
| @@ -14,13 +14,13 @@ public interface TenantApi { | @@ -14,13 +14,13 @@ public interface TenantApi { | ||
| 14 | * | 14 | * |
| 15 | * @return 租户编号数组 | 15 | * @return 租户编号数组 |
| 16 | */ | 16 | */ |
| 17 | - List<Long> getTenantIds(); | 17 | + List<Long> getTenantIdList(); |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * 校验租户是否合法 | 20 | * 校验租户是否合法 |
| 21 | * | 21 | * |
| 22 | * @param id 租户编号 | 22 | * @param id 租户编号 |
| 23 | */ | 23 | */ |
| 24 | - void validTenant(Long id); | 24 | + void validateTenant(Long id); |
| 25 | 25 | ||
| 26 | } | 26 | } |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java
| @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 6 | import java.util.Collection; | 6 | import java.util.Collection; |
| 7 | import java.util.List; | 7 | import java.util.List; |
| 8 | import java.util.Map; | 8 | import java.util.Map; |
| 9 | -import java.util.Set; | ||
| 10 | 9 | ||
| 11 | /** | 10 | /** |
| 12 | * Admin 用户 API 接口 | 11 | * Admin 用户 API 接口 |
| @@ -29,7 +28,7 @@ public interface AdminUserApi { | @@ -29,7 +28,7 @@ public interface AdminUserApi { | ||
| 29 | * @param ids 用户 ID 们 | 28 | * @param ids 用户 ID 们 |
| 30 | * @return 用户对象信息 | 29 | * @return 用户对象信息 |
| 31 | */ | 30 | */ |
| 32 | - List<AdminUserRespDTO> getUsers(Collection<Long> ids); | 31 | + List<AdminUserRespDTO> getUserList(Collection<Long> ids); |
| 33 | 32 | ||
| 34 | /** | 33 | /** |
| 35 | * 获得指定部门的用户数组 | 34 | * 获得指定部门的用户数组 |
| @@ -37,7 +36,7 @@ public interface AdminUserApi { | @@ -37,7 +36,7 @@ public interface AdminUserApi { | ||
| 37 | * @param deptIds 部门数组 | 36 | * @param deptIds 部门数组 |
| 38 | * @return 用户数组 | 37 | * @return 用户数组 |
| 39 | */ | 38 | */ |
| 40 | - List<AdminUserRespDTO> getUsersByDeptIds(Collection<Long> deptIds); | 39 | + List<AdminUserRespDTO> getUserListByDeptIds(Collection<Long> deptIds); |
| 41 | 40 | ||
| 42 | /** | 41 | /** |
| 43 | * 获得指定岗位的用户数组 | 42 | * 获得指定岗位的用户数组 |
| @@ -54,7 +53,7 @@ public interface AdminUserApi { | @@ -54,7 +53,7 @@ public interface AdminUserApi { | ||
| 54 | * @return 用户 Map | 53 | * @return 用户 Map |
| 55 | */ | 54 | */ |
| 56 | default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) { | 55 | default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) { |
| 57 | - List<AdminUserRespDTO> users = getUsers(ids); | 56 | + List<AdminUserRespDTO> users = getUserList(ids); |
| 58 | return CollectionUtils.convertMap(users, AdminUserRespDTO::getId); | 57 | return CollectionUtils.convertMap(users, AdminUserRespDTO::getId); |
| 59 | } | 58 | } |
| 60 | 59 | ||
| @@ -65,6 +64,6 @@ public interface AdminUserApi { | @@ -65,6 +64,6 @@ public interface AdminUserApi { | ||
| 65 | * | 64 | * |
| 66 | * @param ids 用户编号数组 | 65 | * @param ids 用户编号数组 |
| 67 | */ | 66 | */ |
| 68 | - void validUsers(Set<Long> ids); | 67 | + void validateUserList(Collection<Long> ids); |
| 69 | 68 | ||
| 70 | } | 69 | } |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
| @@ -50,7 +50,7 @@ public interface ErrorCodeConstants { | @@ -50,7 +50,7 @@ public interface ErrorCodeConstants { | ||
| 50 | ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1002004003, "存在子部门,无法删除"); | 50 | ErrorCode DEPT_EXITS_CHILDREN = new ErrorCode(1002004003, "存在子部门,无法删除"); |
| 51 | ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1002004004, "不能设置自己为父部门"); | 51 | ErrorCode DEPT_PARENT_ERROR = new ErrorCode(1002004004, "不能设置自己为父部门"); |
| 52 | ErrorCode DEPT_EXISTS_USER = new ErrorCode(1002004005, "部门中存在员工,无法删除"); | 52 | ErrorCode DEPT_EXISTS_USER = new ErrorCode(1002004005, "部门中存在员工,无法删除"); |
| 53 | - ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1002004006, "部门不处于开启状态,不允许选择"); | 53 | + ErrorCode DEPT_NOT_ENABLE = new ErrorCode(1002004006, "部门({})不处于开启状态,不允许选择"); |
| 54 | ErrorCode DEPT_PARENT_IS_CHILD = new ErrorCode(1002004007, "不能设置自己的子部门为父部门"); | 54 | ErrorCode DEPT_PARENT_IS_CHILD = new ErrorCode(1002004007, "不能设置自己的子部门为父部门"); |
| 55 | 55 | ||
| 56 | // ========== 岗位模块 1002005000 ========== | 56 | // ========== 岗位模块 1002005000 ========== |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/permission/MenuIdEnum.java deleted
| 1 | -package cn.iocoder.yudao.module.system.enums.permission; | ||
| 2 | - | ||
| 3 | -import lombok.AllArgsConstructor; | ||
| 4 | -import lombok.Getter; | ||
| 5 | - | ||
| 6 | -/** | ||
| 7 | - * Menu 编号枚举 | ||
| 8 | - */ | ||
| 9 | -@Getter | ||
| 10 | -@AllArgsConstructor | ||
| 11 | -public enum MenuIdEnum { | ||
| 12 | - | ||
| 13 | - /** | ||
| 14 | - * 根节点 | ||
| 15 | - */ | ||
| 16 | - ROOT(0L); | ||
| 17 | - | ||
| 18 | - private final Long id; | ||
| 19 | - | ||
| 20 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java
| @@ -28,14 +28,14 @@ public class DeptApiImpl implements DeptApi { | @@ -28,14 +28,14 @@ public class DeptApiImpl implements DeptApi { | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | @Override | 30 | @Override |
| 31 | - public List<DeptRespDTO> getDepts(Collection<Long> ids) { | ||
| 32 | - List<DeptDO> depts = deptService.getDepts(ids); | 31 | + public List<DeptRespDTO> getDeptList(Collection<Long> ids) { |
| 32 | + List<DeptDO> depts = deptService.getDeptList(ids); | ||
| 33 | return DeptConvert.INSTANCE.convertList03(depts); | 33 | return DeptConvert.INSTANCE.convertList03(depts); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | @Override | 36 | @Override |
| 37 | - public void validDepts(Collection<Long> ids) { | ||
| 38 | - deptService.validDepts(ids); | 37 | + public void validateDeptList(Collection<Long> ids) { |
| 38 | + deptService.validateDeptList(ids); | ||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | } | 41 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApiImpl.java
| @@ -18,7 +18,8 @@ public class PostApiImpl implements PostApi { | @@ -18,7 +18,8 @@ public class PostApiImpl implements PostApi { | ||
| 18 | private PostService postService; | 18 | private PostService postService; |
| 19 | 19 | ||
| 20 | @Override | 20 | @Override |
| 21 | - public void validPosts(Collection<Long> ids) { | ||
| 22 | - postService.validPosts(ids); | 21 | + public void validPostList(Collection<Long> ids) { |
| 22 | + postService.validatePostList(ids); | ||
| 23 | } | 23 | } |
| 24 | + | ||
| 24 | } | 25 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java
| @@ -21,8 +21,8 @@ public class DictDataApiImpl implements DictDataApi { | @@ -21,8 +21,8 @@ public class DictDataApiImpl implements DictDataApi { | ||
| 21 | private DictDataService dictDataService; | 21 | private DictDataService dictDataService; |
| 22 | 22 | ||
| 23 | @Override | 23 | @Override |
| 24 | - public void validDictDatas(String dictType, Collection<String> values) { | ||
| 25 | - dictDataService.validDictDatas(dictType, values); | 24 | + public void validateDictDataList(String dictType, Collection<String> values) { |
| 25 | + dictDataService.validateDictDataList(dictType, values); | ||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | @Override | 28 | @Override |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/errorcode/ErrorCodeApiImpl.java
| @@ -21,7 +21,7 @@ public class ErrorCodeApiImpl implements ErrorCodeApi { | @@ -21,7 +21,7 @@ public class ErrorCodeApiImpl implements ErrorCodeApi { | ||
| 21 | private ErrorCodeService errorCodeService; | 21 | private ErrorCodeService errorCodeService; |
| 22 | 22 | ||
| 23 | @Override | 23 | @Override |
| 24 | - public void autoGenerateErrorCodes(List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs) { | 24 | + public void autoGenerateErrorCodeList(List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs) { |
| 25 | errorCodeService.autoGenerateErrorCodes(autoGenerateDTOs); | 25 | errorCodeService.autoGenerateErrorCodes(autoGenerateDTOs); |
| 26 | } | 26 | } |
| 27 | 27 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/RoleApiImpl.java
| @@ -18,7 +18,7 @@ public class RoleApiImpl implements RoleApi { | @@ -18,7 +18,7 @@ public class RoleApiImpl implements RoleApi { | ||
| 18 | private RoleService roleService; | 18 | private RoleService roleService; |
| 19 | 19 | ||
| 20 | @Override | 20 | @Override |
| 21 | - public void validRoles(Collection<Long> ids) { | ||
| 22 | - roleService.validRoles(ids); | 21 | + public void validRoleList(Collection<Long> ids) { |
| 22 | + roleService.validateRoleList(ids); | ||
| 23 | } | 23 | } |
| 24 | } | 24 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/sms/SmsCodeApiImpl.java
| 1 | package cn.iocoder.yudao.module.system.api.sms; | 1 | package cn.iocoder.yudao.module.system.api.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO; | 3 | +import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeValidateReqDTO; |
| 4 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; | 4 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; |
| 5 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; | 5 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; |
| 6 | import cn.iocoder.yudao.module.system.service.sms.SmsCodeService; | 6 | import cn.iocoder.yudao.module.system.service.sms.SmsCodeService; |
| @@ -32,8 +32,8 @@ public class SmsCodeApiImpl implements SmsCodeApi { | @@ -32,8 +32,8 @@ public class SmsCodeApiImpl implements SmsCodeApi { | ||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | @Override | 34 | @Override |
| 35 | - public void checkSmsCode(SmsCodeCheckReqDTO reqDTO) { | ||
| 36 | - smsCodeService.checkSmsCode(reqDTO); | 35 | + public void validateSmsCode(SmsCodeValidateReqDTO reqDTO) { |
| 36 | + smsCodeService.validateSmsCode(reqDTO); | ||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | } | 39 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApiImpl.java
| @@ -18,12 +18,12 @@ public class TenantApiImpl implements TenantApi { | @@ -18,12 +18,12 @@ public class TenantApiImpl implements TenantApi { | ||
| 18 | private TenantService tenantService; | 18 | private TenantService tenantService; |
| 19 | 19 | ||
| 20 | @Override | 20 | @Override |
| 21 | - public List<Long> getTenantIds() { | ||
| 22 | - return tenantService.getTenantIds(); | 21 | + public List<Long> getTenantIdList() { |
| 22 | + return tenantService.getTenantIdList(); | ||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | @Override | 25 | @Override |
| 26 | - public void validTenant(Long id) { | 26 | + public void validateTenant(Long id) { |
| 27 | tenantService.validTenant(id); | 27 | tenantService.validTenant(id); |
| 28 | } | 28 | } |
| 29 | 29 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java
| @@ -9,7 +9,6 @@ import org.springframework.stereotype.Service; | @@ -9,7 +9,6 @@ import org.springframework.stereotype.Service; | ||
| 9 | import javax.annotation.Resource; | 9 | import javax.annotation.Resource; |
| 10 | import java.util.Collection; | 10 | import java.util.Collection; |
| 11 | import java.util.List; | 11 | import java.util.List; |
| 12 | -import java.util.Set; | ||
| 13 | 12 | ||
| 14 | /** | 13 | /** |
| 15 | * Admin 用户 API 实现类 | 14 | * Admin 用户 API 实现类 |
| @@ -29,26 +28,26 @@ public class AdminUserApiImpl implements AdminUserApi { | @@ -29,26 +28,26 @@ public class AdminUserApiImpl implements AdminUserApi { | ||
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | @Override | 30 | @Override |
| 32 | - public List<AdminUserRespDTO> getUsers(Collection<Long> ids) { | ||
| 33 | - List<AdminUserDO> users = userService.getUsers(ids); | 31 | + public List<AdminUserRespDTO> getUserList(Collection<Long> ids) { |
| 32 | + List<AdminUserDO> users = userService.getUserList(ids); | ||
| 34 | return UserConvert.INSTANCE.convertList4(users); | 33 | return UserConvert.INSTANCE.convertList4(users); |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | @Override | 36 | @Override |
| 38 | - public List<AdminUserRespDTO> getUsersByDeptIds(Collection<Long> deptIds) { | ||
| 39 | - List<AdminUserDO> users = userService.getUsersByDeptIds(deptIds); | 37 | + public List<AdminUserRespDTO> getUserListByDeptIds(Collection<Long> deptIds) { |
| 38 | + List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds); | ||
| 40 | return UserConvert.INSTANCE.convertList4(users); | 39 | return UserConvert.INSTANCE.convertList4(users); |
| 41 | } | 40 | } |
| 42 | 41 | ||
| 43 | @Override | 42 | @Override |
| 44 | public List<AdminUserRespDTO> getUsersByPostIds(Collection<Long> postIds) { | 43 | public List<AdminUserRespDTO> getUsersByPostIds(Collection<Long> postIds) { |
| 45 | - List<AdminUserDO> users = userService.getUsersByPostIds(postIds); | 44 | + List<AdminUserDO> users = userService.getUserListByPostIds(postIds); |
| 46 | return UserConvert.INSTANCE.convertList4(users); | 45 | return UserConvert.INSTANCE.convertList4(users); |
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | @Override | 48 | @Override |
| 50 | - public void validUsers(Set<Long> ids) { | ||
| 51 | - userService.validUsers(ids); | 49 | + public void validateUserList(Collection<Long> ids) { |
| 50 | + userService.validateUserList(ids); | ||
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | } | 53 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
| @@ -97,7 +97,7 @@ public class AuthController { | @@ -97,7 +97,7 @@ public class AuthController { | ||
| 97 | } | 97 | } |
| 98 | // 获得角色列表 | 98 | // 获得角色列表 |
| 99 | Set<Long> roleIds = permissionService.getUserRoleIdsFromCache(getLoginUserId(), singleton(CommonStatusEnum.ENABLE.getStatus())); | 99 | Set<Long> roleIds = permissionService.getUserRoleIdsFromCache(getLoginUserId(), singleton(CommonStatusEnum.ENABLE.getStatus())); |
| 100 | - List<RoleDO> roleList = roleService.getRolesFromCache(roleIds); | 100 | + List<RoleDO> roleList = roleService.getRoleListFromCache(roleIds); |
| 101 | // 获得菜单列表 | 101 | // 获得菜单列表 |
| 102 | List<MenuDO> menuList = permissionService.getRoleMenuListFromCache(roleIds, | 102 | List<MenuDO> menuList = permissionService.getRoleMenuListFromCache(roleIds, |
| 103 | SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()), | 103 | SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()), |
| @@ -108,7 +108,7 @@ public class AuthController { | @@ -108,7 +108,7 @@ public class AuthController { | ||
| 108 | 108 | ||
| 109 | @GetMapping("/list-menus") | 109 | @GetMapping("/list-menus") |
| 110 | @ApiOperation("获得登录用户的菜单列表") | 110 | @ApiOperation("获得登录用户的菜单列表") |
| 111 | - public CommonResult<List<AuthMenuRespVO>> getMenus() { | 111 | + public CommonResult<List<AuthMenuRespVO>> getMenuList() { |
| 112 | // 获得角色列表 | 112 | // 获得角色列表 |
| 113 | Set<Long> roleIds = permissionService.getUserRoleIdsFromCache(getLoginUserId(), singleton(CommonStatusEnum.ENABLE.getStatus())); | 113 | Set<Long> roleIds = permissionService.getUserRoleIdsFromCache(getLoginUserId(), singleton(CommonStatusEnum.ENABLE.getStatus())); |
| 114 | // 获得用户拥有的菜单列表 | 114 | // 获得用户拥有的菜单列表 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java
| @@ -57,19 +57,19 @@ public class DeptController { | @@ -57,19 +57,19 @@ public class DeptController { | ||
| 57 | @GetMapping("/list") | 57 | @GetMapping("/list") |
| 58 | @ApiOperation("获取部门列表") | 58 | @ApiOperation("获取部门列表") |
| 59 | @PreAuthorize("@ss.hasPermission('system:dept:query')") | 59 | @PreAuthorize("@ss.hasPermission('system:dept:query')") |
| 60 | - public CommonResult<List<DeptRespVO>> listDepts(DeptListReqVO reqVO) { | ||
| 61 | - List<DeptDO> list = deptService.getSimpleDepts(reqVO); | 60 | + public CommonResult<List<DeptRespVO>> getDeptList(DeptListReqVO reqVO) { |
| 61 | + List<DeptDO> list = deptService.getDeptList(reqVO); | ||
| 62 | list.sort(Comparator.comparing(DeptDO::getSort)); | 62 | list.sort(Comparator.comparing(DeptDO::getSort)); |
| 63 | return success(DeptConvert.INSTANCE.convertList(list)); | 63 | return success(DeptConvert.INSTANCE.convertList(list)); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | @GetMapping("/list-all-simple") | 66 | @GetMapping("/list-all-simple") |
| 67 | @ApiOperation(value = "获取部门精简信息列表", notes = "只包含被开启的部门,主要用于前端的下拉选项") | 67 | @ApiOperation(value = "获取部门精简信息列表", notes = "只包含被开启的部门,主要用于前端的下拉选项") |
| 68 | - public CommonResult<List<DeptSimpleRespVO>> getSimpleDepts() { | 68 | + public CommonResult<List<DeptSimpleRespVO>> getSimpleDeptList() { |
| 69 | // 获得部门列表,只要开启状态的 | 69 | // 获得部门列表,只要开启状态的 |
| 70 | DeptListReqVO reqVO = new DeptListReqVO(); | 70 | DeptListReqVO reqVO = new DeptListReqVO(); |
| 71 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 71 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 72 | - List<DeptDO> list = deptService.getSimpleDepts(reqVO); | 72 | + List<DeptDO> list = deptService.getDeptList(reqVO); |
| 73 | // 排序后,返回给前端 | 73 | // 排序后,返回给前端 |
| 74 | list.sort(Comparator.comparing(DeptDO::getSort)); | 74 | list.sort(Comparator.comparing(DeptDO::getSort)); |
| 75 | return success(DeptConvert.INSTANCE.convertList02(list)); | 75 | return success(DeptConvert.INSTANCE.convertList02(list)); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java
| @@ -70,9 +70,9 @@ public class PostController { | @@ -70,9 +70,9 @@ public class PostController { | ||
| 70 | 70 | ||
| 71 | @GetMapping("/list-all-simple") | 71 | @GetMapping("/list-all-simple") |
| 72 | @ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项") | 72 | @ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项") |
| 73 | - public CommonResult<List<PostSimpleRespVO>> getSimplePosts() { | 73 | + public CommonResult<List<PostSimpleRespVO>> getSimplePostList() { |
| 74 | // 获得岗位列表,只要开启状态的 | 74 | // 获得岗位列表,只要开启状态的 |
| 75 | - List<PostDO> list = postService.getPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); | 75 | + List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); |
| 76 | // 排序后,返回给前端 | 76 | // 排序后,返回给前端 |
| 77 | list.sort(Comparator.comparing(PostDO::getSort)); | 77 | list.sort(Comparator.comparing(PostDO::getSort)); |
| 78 | return success(PostConvert.INSTANCE.convertList02(list)); | 78 | return success(PostConvert.INSTANCE.convertList02(list)); |
| @@ -90,7 +90,7 @@ public class PostController { | @@ -90,7 +90,7 @@ public class PostController { | ||
| 90 | @PreAuthorize("@ss.hasPermission('system:post:export')") | 90 | @PreAuthorize("@ss.hasPermission('system:post:export')") |
| 91 | @OperateLog(type = EXPORT) | 91 | @OperateLog(type = EXPORT) |
| 92 | public void export(HttpServletResponse response, @Validated PostExportReqVO reqVO) throws IOException { | 92 | public void export(HttpServletResponse response, @Validated PostExportReqVO reqVO) throws IOException { |
| 93 | - List<PostDO> posts = postService.getPosts(reqVO); | 93 | + List<PostDO> posts = postService.getPostList(reqVO); |
| 94 | List<PostExcelVO> data = PostConvert.INSTANCE.convertList03(posts); | 94 | List<PostExcelVO> data = PostConvert.INSTANCE.convertList03(posts); |
| 95 | // 输出 | 95 | // 输出 |
| 96 | ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostExcelVO.class, data); | 96 | ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostExcelVO.class, data); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java
| @@ -61,8 +61,8 @@ public class DictDataController { | @@ -61,8 +61,8 @@ public class DictDataController { | ||
| 61 | @GetMapping("/list-all-simple") | 61 | @GetMapping("/list-all-simple") |
| 62 | @ApiOperation(value = "获得全部字典数据列表", notes = "一般用于管理后台缓存字典数据在本地") | 62 | @ApiOperation(value = "获得全部字典数据列表", notes = "一般用于管理后台缓存字典数据在本地") |
| 63 | // 无需添加权限认证,因为前端全局都需要 | 63 | // 无需添加权限认证,因为前端全局都需要 |
| 64 | - public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDatas() { | ||
| 65 | - List<DictDataDO> list = dictDataService.getDictDatas(); | 64 | + public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() { |
| 65 | + List<DictDataDO> list = dictDataService.getDictDataList(); | ||
| 66 | return success(DictDataConvert.INSTANCE.convertList(list)); | 66 | return success(DictDataConvert.INSTANCE.convertList(list)); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| @@ -86,7 +86,7 @@ public class DictDataController { | @@ -86,7 +86,7 @@ public class DictDataController { | ||
| 86 | @PreAuthorize("@ss.hasPermission('system:dict:export')") | 86 | @PreAuthorize("@ss.hasPermission('system:dict:export')") |
| 87 | @OperateLog(type = EXPORT) | 87 | @OperateLog(type = EXPORT) |
| 88 | public void export(HttpServletResponse response, @Valid DictDataExportReqVO reqVO) throws IOException { | 88 | public void export(HttpServletResponse response, @Valid DictDataExportReqVO reqVO) throws IOException { |
| 89 | - List<DictDataDO> list = dictDataService.getDictDatas(reqVO); | 89 | + List<DictDataDO> list = dictDataService.getDictDataList(reqVO); |
| 90 | List<DictDataExcelVO> data = DictDataConvert.INSTANCE.convertList02(list); | 90 | List<DictDataExcelVO> data = DictDataConvert.INSTANCE.convertList02(list); |
| 91 | // 输出 | 91 | // 输出 |
| 92 | ExcelUtils.write(response, "字典数据.xls", "数据列表", DictDataExcelVO.class, data); | 92 | ExcelUtils.write(response, "字典数据.xls", "数据列表", DictDataExcelVO.class, data); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictTypeController.java
| @@ -76,7 +76,7 @@ public class DictTypeController { | @@ -76,7 +76,7 @@ public class DictTypeController { | ||
| 76 | @GetMapping("/list-all-simple") | 76 | @GetMapping("/list-all-simple") |
| 77 | @ApiOperation(value = "获得全部字典类型列表", notes = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项") | 77 | @ApiOperation(value = "获得全部字典类型列表", notes = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项") |
| 78 | // 无需添加权限认证,因为前端全局都需要 | 78 | // 无需添加权限认证,因为前端全局都需要 |
| 79 | - public CommonResult<List<DictTypeSimpleRespVO>> listSimpleDictTypes() { | 79 | + public CommonResult<List<DictTypeSimpleRespVO>> getSimpleDictTypeList() { |
| 80 | List<DictTypeDO> list = dictTypeService.getDictTypeList(); | 80 | List<DictTypeDO> list = dictTypeService.getDictTypeList(); |
| 81 | return success(DictTypeConvert.INSTANCE.convertList(list)); | 81 | return success(DictTypeConvert.INSTANCE.convertList(list)); |
| 82 | } | 82 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java
| @@ -71,7 +71,7 @@ public class OperateLogController { | @@ -71,7 +71,7 @@ public class OperateLogController { | ||
| 71 | @PreAuthorize("@ss.hasPermission('system:operate-log:export')") | 71 | @PreAuthorize("@ss.hasPermission('system:operate-log:export')") |
| 72 | @OperateLog(type = EXPORT) | 72 | @OperateLog(type = EXPORT) |
| 73 | public void exportOperateLog(HttpServletResponse response, @Valid OperateLogExportReqVO reqVO) throws IOException { | 73 | public void exportOperateLog(HttpServletResponse response, @Valid OperateLogExportReqVO reqVO) throws IOException { |
| 74 | - List<OperateLogDO> list = operateLogService.getOperateLogs(reqVO); | 74 | + List<OperateLogDO> list = operateLogService.getOperateLogList(reqVO); |
| 75 | 75 | ||
| 76 | // 获得拼接需要的数据 | 76 | // 获得拼接需要的数据 |
| 77 | Collection<Long> userIds = CollectionUtils.convertList(list, OperateLogDO::getUserId); | 77 | Collection<Long> userIds = CollectionUtils.convertList(list, OperateLogDO::getUserId); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java
| @@ -57,8 +57,8 @@ public class NoticeController { | @@ -57,8 +57,8 @@ public class NoticeController { | ||
| 57 | @GetMapping("/page") | 57 | @GetMapping("/page") |
| 58 | @ApiOperation("获取通知公告列表") | 58 | @ApiOperation("获取通知公告列表") |
| 59 | @PreAuthorize("@ss.hasPermission('system:notice:query')") | 59 | @PreAuthorize("@ss.hasPermission('system:notice:query')") |
| 60 | - public CommonResult<PageResult<NoticeRespVO>> pageNotices(@Validated NoticePageReqVO reqVO) { | ||
| 61 | - return success(NoticeConvert.INSTANCE.convertPage(noticeService.pageNotices(reqVO))); | 60 | + public CommonResult<PageResult<NoticeRespVO>> getNoticePage(@Validated NoticePageReqVO reqVO) { |
| 61 | + return success(NoticeConvert.INSTANCE.convertPage(noticeService.getNoticePage(reqVO))); | ||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | @GetMapping("/get") | 64 | @GetMapping("/get") |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2UserController.java
| @@ -61,7 +61,7 @@ public class OAuth2UserController { | @@ -61,7 +61,7 @@ public class OAuth2UserController { | ||
| 61 | } | 61 | } |
| 62 | // 获得岗位信息 | 62 | // 获得岗位信息 |
| 63 | if (CollUtil.isNotEmpty(user.getPostIds())) { | 63 | if (CollUtil.isNotEmpty(user.getPostIds())) { |
| 64 | - List<PostDO> posts = postService.getPosts(user.getPostIds()); | 64 | + List<PostDO> posts = postService.getPostList(user.getPostIds()); |
| 65 | resp.setPosts(OAuth2UserConvert.INSTANCE.convertList(posts)); | 65 | resp.setPosts(OAuth2UserConvert.INSTANCE.convertList(posts)); |
| 66 | } | 66 | } |
| 67 | return success(resp); | 67 | return success(resp); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java
| @@ -57,8 +57,8 @@ public class MenuController { | @@ -57,8 +57,8 @@ public class MenuController { | ||
| 57 | @GetMapping("/list") | 57 | @GetMapping("/list") |
| 58 | @ApiOperation(value = "获取菜单列表", notes = "用于【菜单管理】界面") | 58 | @ApiOperation(value = "获取菜单列表", notes = "用于【菜单管理】界面") |
| 59 | @PreAuthorize("@ss.hasPermission('system:menu:query')") | 59 | @PreAuthorize("@ss.hasPermission('system:menu:query')") |
| 60 | - public CommonResult<List<MenuRespVO>> getMenus(MenuListReqVO reqVO) { | ||
| 61 | - List<MenuDO> list = menuService.getMenus(reqVO); | 60 | + public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) { |
| 61 | + List<MenuDO> list = menuService.getMenuList(reqVO); | ||
| 62 | list.sort(Comparator.comparing(MenuDO::getSort)); | 62 | list.sort(Comparator.comparing(MenuDO::getSort)); |
| 63 | return success(MenuConvert.INSTANCE.convertList(list)); | 63 | return success(MenuConvert.INSTANCE.convertList(list)); |
| 64 | } | 64 | } |
| @@ -66,11 +66,11 @@ public class MenuController { | @@ -66,11 +66,11 @@ public class MenuController { | ||
| 66 | @GetMapping("/list-all-simple") | 66 | @GetMapping("/list-all-simple") |
| 67 | @ApiOperation(value = "获取菜单精简信息列表", notes = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" + | 67 | @ApiOperation(value = "获取菜单精简信息列表", notes = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" + |
| 68 | "在多租户的场景下,会只返回租户所在套餐有的菜单") | 68 | "在多租户的场景下,会只返回租户所在套餐有的菜单") |
| 69 | - public CommonResult<List<MenuSimpleRespVO>> getSimpleMenus() { | 69 | + public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() { |
| 70 | // 获得菜单列表,只要开启状态的 | 70 | // 获得菜单列表,只要开启状态的 |
| 71 | MenuListReqVO reqVO = new MenuListReqVO(); | 71 | MenuListReqVO reqVO = new MenuListReqVO(); |
| 72 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 72 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 73 | - List<MenuDO> list = menuService.getTenantMenus(reqVO); | 73 | + List<MenuDO> list = menuService.getMenuListByTenant(reqVO); |
| 74 | // 排序后,返回给前端 | 74 | // 排序后,返回给前端 |
| 75 | list.sort(Comparator.comparing(MenuDO::getSort)); | 75 | list.sort(Comparator.comparing(MenuDO::getSort)); |
| 76 | return success(MenuConvert.INSTANCE.convertList02(list)); | 76 | return success(MenuConvert.INSTANCE.convertList02(list)); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java
| @@ -20,12 +20,12 @@ import javax.annotation.Resource; | @@ -20,12 +20,12 @@ import javax.annotation.Resource; | ||
| 20 | import javax.servlet.http.HttpServletResponse; | 20 | import javax.servlet.http.HttpServletResponse; |
| 21 | import javax.validation.Valid; | 21 | import javax.validation.Valid; |
| 22 | import java.io.IOException; | 22 | import java.io.IOException; |
| 23 | -import java.util.Collections; | ||
| 24 | import java.util.Comparator; | 23 | import java.util.Comparator; |
| 25 | import java.util.List; | 24 | import java.util.List; |
| 26 | 25 | ||
| 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 27 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 28 | +import static java.util.Collections.singleton; | ||
| 29 | 29 | ||
| 30 | @Api(tags = "管理后台 - 角色") | 30 | @Api(tags = "管理后台 - 角色") |
| 31 | @RestController | 31 | @RestController |
| @@ -85,9 +85,9 @@ public class RoleController { | @@ -85,9 +85,9 @@ public class RoleController { | ||
| 85 | 85 | ||
| 86 | @GetMapping("/list-all-simple") | 86 | @GetMapping("/list-all-simple") |
| 87 | @ApiOperation(value = "获取角色精简信息列表", notes = "只包含被开启的角色,主要用于前端的下拉选项") | 87 | @ApiOperation(value = "获取角色精简信息列表", notes = "只包含被开启的角色,主要用于前端的下拉选项") |
| 88 | - public CommonResult<List<RoleSimpleRespVO>> getSimpleRoles() { | 88 | + public CommonResult<List<RoleSimpleRespVO>> getSimpleRoleList() { |
| 89 | // 获得角色列表,只要开启状态的 | 89 | // 获得角色列表,只要开启状态的 |
| 90 | - List<RoleDO> list = roleService.getRoles(Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); | 90 | + List<RoleDO> list = roleService.getRoleListByStatus(singleton(CommonStatusEnum.ENABLE.getStatus())); |
| 91 | // 排序后,返回给前端 | 91 | // 排序后,返回给前端 |
| 92 | list.sort(Comparator.comparing(RoleDO::getSort)); | 92 | list.sort(Comparator.comparing(RoleDO::getSort)); |
| 93 | return success(RoleConvert.INSTANCE.convertList02(list)); | 93 | return success(RoleConvert.INSTANCE.convertList02(list)); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sensitiveword/SensitiveWordController.java
| @@ -90,8 +90,8 @@ public class SensitiveWordController { | @@ -90,8 +90,8 @@ public class SensitiveWordController { | ||
| 90 | @GetMapping("/get-tags") | 90 | @GetMapping("/get-tags") |
| 91 | @ApiOperation("获取所有敏感词的标签数组") | 91 | @ApiOperation("获取所有敏感词的标签数组") |
| 92 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") | 92 | @PreAuthorize("@ss.hasPermission('system:sensitive-word:query')") |
| 93 | - public CommonResult<Set<String>> getSensitiveWordTags() throws IOException { | ||
| 94 | - return success(sensitiveWordService.getSensitiveWordTags()); | 93 | + public CommonResult<Set<String>> getSensitiveWordTagSet() { |
| 94 | + return success(sensitiveWordService.getSensitiveWordTagSet()); | ||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | @GetMapping("/validate-text") | 97 | @GetMapping("/validate-text") |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsChannelController.java
| @@ -70,7 +70,7 @@ public class SmsChannelController { | @@ -70,7 +70,7 @@ public class SmsChannelController { | ||
| 70 | 70 | ||
| 71 | @GetMapping("/list-all-simple") | 71 | @GetMapping("/list-all-simple") |
| 72 | @ApiOperation(value = "获得短信渠道精简列表", notes = "包含被禁用的短信渠道") | 72 | @ApiOperation(value = "获得短信渠道精简列表", notes = "包含被禁用的短信渠道") |
| 73 | - public CommonResult<List<SmsChannelSimpleRespVO>> getSimpleSmsChannels() { | 73 | + public CommonResult<List<SmsChannelSimpleRespVO>> getSimpleSmsChannelList() { |
| 74 | List<SmsChannelDO> list = smsChannelService.getSmsChannelList(); | 74 | List<SmsChannelDO> list = smsChannelService.getSmsChannelList(); |
| 75 | // 排序后,返回给前端 | 75 | // 排序后,返回给前端 |
| 76 | list.sort(Comparator.comparing(SmsChannelDO::getId)); | 76 | list.sort(Comparator.comparing(SmsChannelDO::getId)); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
| @@ -111,9 +111,9 @@ public class UserController { | @@ -111,9 +111,9 @@ public class UserController { | ||
| 111 | 111 | ||
| 112 | @GetMapping("/list-all-simple") | 112 | @GetMapping("/list-all-simple") |
| 113 | @ApiOperation(value = "获取用户精简信息列表", notes = "只包含被开启的用户,主要用于前端的下拉选项") | 113 | @ApiOperation(value = "获取用户精简信息列表", notes = "只包含被开启的用户,主要用于前端的下拉选项") |
| 114 | - public CommonResult<List<UserSimpleRespVO>> getSimpleUsers() { | 114 | + public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() { |
| 115 | // 获用户列表,只要开启状态的 | 115 | // 获用户列表,只要开启状态的 |
| 116 | - List<AdminUserDO> list = userService.getUsersByStatus(CommonStatusEnum.ENABLE.getStatus()); | 116 | + List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 117 | // 排序后,返回给前端 | 117 | // 排序后,返回给前端 |
| 118 | return success(UserConvert.INSTANCE.convertList04(list)); | 118 | return success(UserConvert.INSTANCE.convertList04(list)); |
| 119 | } | 119 | } |
| @@ -122,7 +122,7 @@ public class UserController { | @@ -122,7 +122,7 @@ public class UserController { | ||
| 122 | @ApiOperation("获得用户详情") | 122 | @ApiOperation("获得用户详情") |
| 123 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | 123 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 124 | @PreAuthorize("@ss.hasPermission('system:user:query')") | 124 | @PreAuthorize("@ss.hasPermission('system:user:query')") |
| 125 | - public CommonResult<UserRespVO> getInfo(@RequestParam("id") Long id) { | 125 | + public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) { |
| 126 | return success(UserConvert.INSTANCE.convert(userService.getUser(id))); | 126 | return success(UserConvert.INSTANCE.convert(userService.getUser(id))); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| @@ -130,10 +130,10 @@ public class UserController { | @@ -130,10 +130,10 @@ public class UserController { | ||
| 130 | @ApiOperation("导出用户") | 130 | @ApiOperation("导出用户") |
| 131 | @PreAuthorize("@ss.hasPermission('system:user:export')") | 131 | @PreAuthorize("@ss.hasPermission('system:user:export')") |
| 132 | @OperateLog(type = EXPORT) | 132 | @OperateLog(type = EXPORT) |
| 133 | - public void exportUsers(@Validated UserExportReqVO reqVO, | ||
| 134 | - HttpServletResponse response) throws IOException { | 133 | + public void exportUserList(@Validated UserExportReqVO reqVO, |
| 134 | + HttpServletResponse response) throws IOException { | ||
| 135 | // 获得用户列表 | 135 | // 获得用户列表 |
| 136 | - List<AdminUserDO> users = userService.getUsers(reqVO); | 136 | + List<AdminUserDO> users = userService.getUserList(reqVO); |
| 137 | 137 | ||
| 138 | // 获得拼接需要的数据 | 138 | // 获得拼接需要的数据 |
| 139 | Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId); | 139 | Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId); |
| @@ -183,7 +183,7 @@ public class UserController { | @@ -183,7 +183,7 @@ public class UserController { | ||
| 183 | public CommonResult<UserImportRespVO> importExcel(@RequestParam("file") MultipartFile file, | 183 | public CommonResult<UserImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
| 184 | @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { | 184 | @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { |
| 185 | List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class); | 185 | List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class); |
| 186 | - return success(userService.importUsers(list, updateSupport)); | 186 | + return success(userService.importUserList(list, updateSupport)); |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | } | 189 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java
| @@ -63,7 +63,7 @@ public class UserProfileController { | @@ -63,7 +63,7 @@ public class UserProfileController { | ||
| 63 | AdminUserDO user = userService.getUser(getLoginUserId()); | 63 | AdminUserDO user = userService.getUser(getLoginUserId()); |
| 64 | UserProfileRespVO resp = UserConvert.INSTANCE.convert03(user); | 64 | UserProfileRespVO resp = UserConvert.INSTANCE.convert03(user); |
| 65 | // 获得用户角色 | 65 | // 获得用户角色 |
| 66 | - List<RoleDO> userRoles = roleService.getRolesFromCache(permissionService.getUserRoleIdListByUserId(user.getId())); | 66 | + List<RoleDO> userRoles = roleService.getRoleListFromCache(permissionService.getUserRoleIdListByUserId(user.getId())); |
| 67 | resp.setRoles(UserConvert.INSTANCE.convertList(userRoles)); | 67 | resp.setRoles(UserConvert.INSTANCE.convertList(userRoles)); |
| 68 | // 获得部门信息 | 68 | // 获得部门信息 |
| 69 | if (user.getDeptId() != null) { | 69 | if (user.getDeptId() != null) { |
| @@ -72,7 +72,7 @@ public class UserProfileController { | @@ -72,7 +72,7 @@ public class UserProfileController { | ||
| 72 | } | 72 | } |
| 73 | // 获得岗位信息 | 73 | // 获得岗位信息 |
| 74 | if (CollUtil.isNotEmpty(user.getPostIds())) { | 74 | if (CollUtil.isNotEmpty(user.getPostIds())) { |
| 75 | - List<PostDO> posts = postService.getPosts(user.getPostIds()); | 75 | + List<PostDO> posts = postService.getPostList(user.getPostIds()); |
| 76 | resp.setPosts(UserConvert.INSTANCE.convertList02(posts)); | 76 | resp.setPosts(UserConvert.INSTANCE.convertList02(posts)); |
| 77 | } | 77 | } |
| 78 | // 获得社交用户信息 | 78 | // 获得社交用户信息 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/AuthConvert.java
| @@ -9,13 +9,15 @@ import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; | @@ -9,13 +9,15 @@ import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 10 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 12 | -import cn.iocoder.yudao.module.system.enums.permission.MenuIdEnum; | ||
| 13 | import org.mapstruct.Mapper; | 12 | import org.mapstruct.Mapper; |
| 14 | import org.mapstruct.factory.Mappers; | 13 | import org.mapstruct.factory.Mappers; |
| 15 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| 16 | 15 | ||
| 17 | import java.util.*; | 16 | import java.util.*; |
| 18 | 17 | ||
| 18 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | ||
| 19 | +import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT; | ||
| 20 | + | ||
| 19 | @Mapper | 21 | @Mapper |
| 20 | public interface AuthConvert { | 22 | public interface AuthConvert { |
| 21 | 23 | ||
| @@ -47,7 +49,7 @@ public interface AuthConvert { | @@ -47,7 +49,7 @@ public interface AuthConvert { | ||
| 47 | Map<Long, AuthMenuRespVO> treeNodeMap = new LinkedHashMap<>(); | 49 | Map<Long, AuthMenuRespVO> treeNodeMap = new LinkedHashMap<>(); |
| 48 | menuList.forEach(menu -> treeNodeMap.put(menu.getId(), AuthConvert.INSTANCE.convertTreeNode(menu))); | 50 | menuList.forEach(menu -> treeNodeMap.put(menu.getId(), AuthConvert.INSTANCE.convertTreeNode(menu))); |
| 49 | // 处理父子关系 | 51 | // 处理父子关系 |
| 50 | - treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(MenuIdEnum.ROOT.getId())).forEach(childNode -> { | 52 | + treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(ID_ROOT)).forEach(childNode -> { |
| 51 | // 获得父节点 | 53 | // 获得父节点 |
| 52 | AuthMenuRespVO parentNode = treeNodeMap.get(childNode.getParentId()); | 54 | AuthMenuRespVO parentNode = treeNodeMap.get(childNode.getParentId()); |
| 53 | if (parentNode == null) { | 55 | if (parentNode == null) { |
| @@ -62,7 +64,7 @@ public interface AuthConvert { | @@ -62,7 +64,7 @@ public interface AuthConvert { | ||
| 62 | parentNode.getChildren().add(childNode); | 64 | parentNode.getChildren().add(childNode); |
| 63 | }); | 65 | }); |
| 64 | // 获得到所有的根节点 | 66 | // 获得到所有的根节点 |
| 65 | - return CollectionUtils.filterList(treeNodeMap.values(), node -> MenuIdEnum.ROOT.getId().equals(node.getParentId())); | 67 | + return filterList(treeNodeMap.values(), node -> ID_ROOT.equals(node.getParentId())); |
| 66 | } | 68 | } |
| 67 | 69 | ||
| 68 | SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO); | 70 | SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/permission/MenuDO.java
| @@ -21,7 +21,12 @@ import lombok.EqualsAndHashCode; | @@ -21,7 +21,12 @@ import lombok.EqualsAndHashCode; | ||
| 21 | public class MenuDO extends BaseDO { | 21 | public class MenuDO extends BaseDO { |
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| 24 | - * 菜单ID | 24 | + * 菜单编号 - 根节点 |
| 25 | + */ | ||
| 26 | + public static final Long ID_ROOT = 0L; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 菜单编号 | ||
| 25 | */ | 30 | */ |
| 26 | @TableId | 31 | @TableId |
| 27 | private Long id; | 32 | private Long id; |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java
| @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| 6 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 7 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 7 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 8 | ||
| 10 | import java.util.List; | 9 | import java.util.List; |
| @@ -19,9 +18,7 @@ public interface DeptMapper extends BaseMapperX<DeptDO> { | @@ -19,9 +18,7 @@ public interface DeptMapper extends BaseMapperX<DeptDO> { | ||
| 19 | } | 18 | } |
| 20 | 19 | ||
| 21 | default DeptDO selectByParentIdAndName(Long parentId, String name) { | 20 | default DeptDO selectByParentIdAndName(Long parentId, String name) { |
| 22 | - return selectOne(new LambdaQueryWrapper<DeptDO>() | ||
| 23 | - .eq(DeptDO::getParentId, parentId) | ||
| 24 | - .eq(DeptDO::getName, name)); | 21 | + return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name); |
| 25 | } | 22 | } |
| 26 | 23 | ||
| 27 | default Long selectCountByParentId(Long parentId) { | 24 | default Long selectCountByParentId(Long parentId) { |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java
| @@ -2,11 +2,10 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept; | @@ -2,11 +2,10 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 9 | -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 10 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 10 | ||
| 12 | import java.util.Collection; | 11 | import java.util.Collection; |
| @@ -16,31 +15,32 @@ import java.util.List; | @@ -16,31 +15,32 @@ import java.util.List; | ||
| 16 | public interface PostMapper extends BaseMapperX<PostDO> { | 15 | public interface PostMapper extends BaseMapperX<PostDO> { |
| 17 | 16 | ||
| 18 | default List<PostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) { | 17 | default List<PostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) { |
| 19 | - return selectList(new QueryWrapperX<PostDO>().inIfPresent("id", ids) | ||
| 20 | - .inIfPresent("status", statuses)); | 18 | + return selectList(new LambdaQueryWrapperX<PostDO>() |
| 19 | + .inIfPresent(PostDO::getId, ids) | ||
| 20 | + .inIfPresent(PostDO::getStatus, statuses)); | ||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | default PageResult<PostDO> selectPage(PostPageReqVO reqVO) { | 23 | default PageResult<PostDO> selectPage(PostPageReqVO reqVO) { |
| 24 | - return selectPage(reqVO, new QueryWrapperX<PostDO>() | ||
| 25 | - .likeIfPresent("code", reqVO.getCode()) | ||
| 26 | - .likeIfPresent("name", reqVO.getName()) | ||
| 27 | - .eqIfPresent("status", reqVO.getStatus()) | ||
| 28 | - .orderByDesc("id")); | 24 | + return selectPage(reqVO, new LambdaQueryWrapperX<PostDO>() |
| 25 | + .likeIfPresent(PostDO::getCode, reqVO.getCode()) | ||
| 26 | + .likeIfPresent(PostDO::getName, reqVO.getName()) | ||
| 27 | + .eqIfPresent(PostDO::getStatus, reqVO.getStatus()) | ||
| 28 | + .orderByDesc(PostDO::getId)); | ||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | default List<PostDO> selectList(PostExportReqVO reqVO) { | 31 | default List<PostDO> selectList(PostExportReqVO reqVO) { |
| 32 | - return selectList(new QueryWrapperX<PostDO>() | ||
| 33 | - .likeIfPresent("code", reqVO.getCode()) | ||
| 34 | - .likeIfPresent("name", reqVO.getName()) | ||
| 35 | - .eqIfPresent("status", reqVO.getStatus())); | 32 | + return selectList(new LambdaQueryWrapperX<PostDO>() |
| 33 | + .likeIfPresent(PostDO::getCode, reqVO.getCode()) | ||
| 34 | + .likeIfPresent(PostDO::getName, reqVO.getName()) | ||
| 35 | + .eqIfPresent(PostDO::getStatus, reqVO.getStatus())); | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | default PostDO selectByName(String name) { | 38 | default PostDO selectByName(String name) { |
| 39 | - return selectOne(new QueryWrapper<PostDO>().eq("name", name)); | 39 | + return selectOne(PostDO::getName, name); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | default PostDO selectByCode(String code) { | 42 | default PostDO selectByCode(String code) { |
| 43 | - return selectOne(new QueryWrapper<PostDO>().eq("code", code)); | 43 | + return selectOne(PostDO::getCode, code); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | } | 46 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java
| @@ -13,8 +13,7 @@ import java.util.List; | @@ -13,8 +13,7 @@ import java.util.List; | ||
| 13 | public interface UserPostMapper extends BaseMapperX<UserPostDO> { | 13 | public interface UserPostMapper extends BaseMapperX<UserPostDO> { |
| 14 | 14 | ||
| 15 | default List<UserPostDO> selectListByUserId(Long userId) { | 15 | default List<UserPostDO> selectListByUserId(Long userId) { |
| 16 | - return selectList(new LambdaQueryWrapperX<UserPostDO>() | ||
| 17 | - .eq(UserPostDO::getUserId, userId)); | 16 | + return selectList(UserPostDO::getUserId, userId); |
| 18 | } | 17 | } |
| 19 | 18 | ||
| 20 | default void deleteByUserIdAndPostId(Long userId, Collection<Long> postIds) { | 19 | default void deleteByUserIdAndPostId(Long userId, Collection<Long> postIds) { |
| @@ -24,11 +23,10 @@ public interface UserPostMapper extends BaseMapperX<UserPostDO> { | @@ -24,11 +23,10 @@ public interface UserPostMapper extends BaseMapperX<UserPostDO> { | ||
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | default List<UserPostDO> selectListByPostIds(Collection<Long> postIds) { | 25 | default List<UserPostDO> selectListByPostIds(Collection<Long> postIds) { |
| 27 | - return selectList(new LambdaQueryWrapperX<UserPostDO>() | ||
| 28 | - .in(UserPostDO::getPostId, postIds)); | 26 | + return selectList(UserPostDO::getPostId, postIds); |
| 29 | } | 27 | } |
| 30 | 28 | ||
| 31 | - default void deleteByUserId(Long userId){ | 29 | + default void deleteByUserId(Long userId) { |
| 32 | delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, userId)); | 30 | delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, userId)); |
| 33 | } | 31 | } |
| 34 | } | 32 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java
| @@ -17,13 +17,11 @@ import java.util.List; | @@ -17,13 +17,11 @@ import java.util.List; | ||
| 17 | public interface DictDataMapper extends BaseMapperX<DictDataDO> { | 17 | public interface DictDataMapper extends BaseMapperX<DictDataDO> { |
| 18 | 18 | ||
| 19 | default DictDataDO selectByDictTypeAndValue(String dictType, String value) { | 19 | default DictDataDO selectByDictTypeAndValue(String dictType, String value) { |
| 20 | - return selectOne(new LambdaQueryWrapper<DictDataDO>().eq(DictDataDO::getDictType, dictType) | ||
| 21 | - .eq(DictDataDO::getValue, value)); | 20 | + return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getValue, value); |
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | default DictDataDO selectByDictTypeAndLabel(String dictType, String label) { | 23 | default DictDataDO selectByDictTypeAndLabel(String dictType, String label) { |
| 25 | - return selectOne(new LambdaQueryWrapper<DictDataDO>().eq(DictDataDO::getDictType, dictType) | ||
| 26 | - .eq(DictDataDO::getLabel, label)); | 24 | + return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getLabel, label); |
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | default List<DictDataDO> selectByDictTypeAndValues(String dictType, Collection<String> values) { | 27 | default List<DictDataDO> selectByDictTypeAndValues(String dictType, Collection<String> values) { |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java
| @@ -36,11 +36,11 @@ public interface ErrorCodeMapper extends BaseMapperX<ErrorCodeDO> { | @@ -36,11 +36,11 @@ public interface ErrorCodeMapper extends BaseMapperX<ErrorCodeDO> { | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) { | 38 | default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) { |
| 39 | - return selectList(new LambdaQueryWrapperX<ErrorCodeDO>().in(ErrorCodeDO::getCode, codes)); | 39 | + return selectList(ErrorCodeDO::getCode, codes); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | default ErrorCodeDO selectByCode(Integer code) { | 42 | default ErrorCodeDO selectByCode(Integer code) { |
| 43 | - return selectOne(new LambdaQueryWrapperX<ErrorCodeDO>().eq(ErrorCodeDO::getCode, code)); | 43 | + return selectOne(ErrorCodeDO::getCode, code); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | default List<ErrorCodeDO> selectListByApplicationNameAndUpdateTimeGt(String applicationName, LocalDateTime minUpdateTime) { | 46 | default List<ErrorCodeDO> selectListByApplicationNameAndUpdateTimeGt(String applicationName, LocalDateTime minUpdateTime) { |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/MenuMapper.java
| @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
| 6 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 7 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 8 | import org.apache.ibatis.annotations.Mapper; | 7 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 8 | ||
| 10 | import java.util.List; | 9 | import java.util.List; |
| @@ -13,8 +12,7 @@ import java.util.List; | @@ -13,8 +12,7 @@ import java.util.List; | ||
| 13 | public interface MenuMapper extends BaseMapperX<MenuDO> { | 12 | public interface MenuMapper extends BaseMapperX<MenuDO> { |
| 14 | 13 | ||
| 15 | default MenuDO selectByParentIdAndName(Long parentId, String name) { | 14 | default MenuDO selectByParentIdAndName(Long parentId, String name) { |
| 16 | - return selectOne(new LambdaQueryWrapper<MenuDO>().eq(MenuDO::getParentId, parentId) | ||
| 17 | - .eq(MenuDO::getName, name)); | 15 | + return selectOne(MenuDO::getParentId, parentId, MenuDO::getName, name); |
| 18 | } | 16 | } |
| 19 | 17 | ||
| 20 | default Long selectCountByParentId(Long parentId) { | 18 | default Long selectCountByParentId(Long parentId) { |
| @@ -22,7 +20,8 @@ public interface MenuMapper extends BaseMapperX<MenuDO> { | @@ -22,7 +20,8 @@ public interface MenuMapper extends BaseMapperX<MenuDO> { | ||
| 22 | } | 20 | } |
| 23 | 21 | ||
| 24 | default List<MenuDO> selectList(MenuListReqVO reqVO) { | 22 | default List<MenuDO> selectList(MenuListReqVO reqVO) { |
| 25 | - return selectList(new LambdaQueryWrapperX<MenuDO>().likeIfPresent(MenuDO::getName, reqVO.getName()) | 23 | + return selectList(new LambdaQueryWrapperX<MenuDO>() |
| 24 | + .likeIfPresent(MenuDO::getName, reqVO.getName()) | ||
| 26 | .eqIfPresent(MenuDO::getStatus, reqVO.getStatus())); | 25 | .eqIfPresent(MenuDO::getStatus, reqVO.getStatus())); |
| 27 | } | 26 | } |
| 28 | 27 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserBindMapper.java
| @@ -24,9 +24,8 @@ public interface SocialUserBindMapper extends BaseMapperX<SocialUserBindDO> { | @@ -24,9 +24,8 @@ public interface SocialUserBindMapper extends BaseMapperX<SocialUserBindDO> { | ||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | default SocialUserBindDO selectByUserTypeAndSocialUserId(Integer userType, Long socialUserId) { | 26 | default SocialUserBindDO selectByUserTypeAndSocialUserId(Integer userType, Long socialUserId) { |
| 27 | - return selectOne(new LambdaQueryWrapperX<SocialUserBindDO>() | ||
| 28 | - .eq(SocialUserBindDO::getUserType, userType) | ||
| 29 | - .eq(SocialUserBindDO::getSocialUserId, socialUserId)); | 27 | + return selectOne(SocialUserBindDO::getUserType, userType, |
| 28 | + SocialUserBindDO::getSocialUserId, socialUserId); | ||
| 30 | } | 29 | } |
| 31 | 30 | ||
| 32 | default List<SocialUserBindDO> selectListByUserIdAndUserType(Long userId, Integer userType) { | 31 | default List<SocialUserBindDO> selectListByUserIdAndUserType(Long userId, Integer userType) { |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java
| @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 6 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; |
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 9 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 10 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| 11 | 10 | ||
| 12 | import java.util.Collection; | 11 | import java.util.Collection; |
| @@ -16,15 +15,15 @@ import java.util.List; | @@ -16,15 +15,15 @@ import java.util.List; | ||
| 16 | public interface AdminUserMapper extends BaseMapperX<AdminUserDO> { | 15 | public interface AdminUserMapper extends BaseMapperX<AdminUserDO> { |
| 17 | 16 | ||
| 18 | default AdminUserDO selectByUsername(String username) { | 17 | default AdminUserDO selectByUsername(String username) { |
| 19 | - return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getUsername, username)); | 18 | + return selectOne(AdminUserDO::getUsername, username); |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | default AdminUserDO selectByEmail(String email) { | 21 | default AdminUserDO selectByEmail(String email) { |
| 23 | - return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getEmail, email)); | 22 | + return selectOne(AdminUserDO::getEmail, email); |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | default AdminUserDO selectByMobile(String mobile) { | 25 | default AdminUserDO selectByMobile(String mobile) { |
| 27 | - return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getMobile, mobile)); | 26 | + return selectOne(AdminUserDO::getMobile, mobile); |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | default PageResult<AdminUserDO> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) { | 29 | default PageResult<AdminUserDO> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) { |
| @@ -50,10 +49,6 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> { | @@ -50,10 +49,6 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> { | ||
| 50 | return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname)); | 49 | return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname)); |
| 51 | } | 50 | } |
| 52 | 51 | ||
| 53 | - default List<AdminUserDO> selectListByUsername(String username) { | ||
| 54 | - return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getUsername, username)); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | default List<AdminUserDO> selectListByStatus(Integer status) { | 52 | default List<AdminUserDO> selectListByStatus(Integer status) { |
| 58 | return selectList(AdminUserDO::getStatus, status); | 53 | return selectList(AdminUserDO::getStatus, status); |
| 59 | } | 54 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
| @@ -94,7 +94,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { | @@ -94,7 +94,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { | ||
| 94 | @Override | 94 | @Override |
| 95 | public AuthLoginRespVO login(AuthLoginReqVO reqVO) { | 95 | public AuthLoginRespVO login(AuthLoginReqVO reqVO) { |
| 96 | // 校验验证码 | 96 | // 校验验证码 |
| 97 | - verifyCaptcha(reqVO); | 97 | + validateCaptcha(reqVO); |
| 98 | 98 | ||
| 99 | // 使用账号密码,进行登录 | 99 | // 使用账号密码,进行登录 |
| 100 | AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword()); | 100 | AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword()); |
| @@ -171,14 +171,8 @@ public class AdminAuthServiceImpl implements AdminAuthService { | @@ -171,14 +171,8 @@ public class AdminAuthServiceImpl implements AdminAuthService { | ||
| 171 | return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL); | 171 | return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | - @Override | ||
| 175 | - public AuthLoginRespVO refreshToken(String refreshToken) { | ||
| 176 | - OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, OAuth2ClientConstants.CLIENT_ID_DEFAULT); | ||
| 177 | - return AuthConvert.INSTANCE.convert(accessTokenDO); | ||
| 178 | - } | ||
| 179 | - | ||
| 180 | @VisibleForTesting | 174 | @VisibleForTesting |
| 181 | - void verifyCaptcha(AuthLoginReqVO reqVO) { | 175 | + void validateCaptcha(AuthLoginReqVO reqVO) { |
| 182 | // 如果验证码关闭,则不进行校验 | 176 | // 如果验证码关闭,则不进行校验 |
| 183 | if (!captchaEnable) { | 177 | if (!captchaEnable) { |
| 184 | return; | 178 | return; |
| @@ -207,6 +201,12 @@ public class AdminAuthServiceImpl implements AdminAuthService { | @@ -207,6 +201,12 @@ public class AdminAuthServiceImpl implements AdminAuthService { | ||
| 207 | } | 201 | } |
| 208 | 202 | ||
| 209 | @Override | 203 | @Override |
| 204 | + public AuthLoginRespVO refreshToken(String refreshToken) { | ||
| 205 | + OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, OAuth2ClientConstants.CLIENT_ID_DEFAULT); | ||
| 206 | + return AuthConvert.INSTANCE.convert(accessTokenDO); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + @Override | ||
| 210 | public void logout(String token, Integer logType) { | 210 | public void logout(String token, Integer logType) { |
| 211 | // 删除访问令牌 | 211 | // 删除访问令牌 |
| 212 | OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.removeAccessToken(token); | 212 | OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.removeAccessToken(token); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java
| @@ -52,7 +52,7 @@ public interface DeptService { | @@ -52,7 +52,7 @@ public interface DeptService { | ||
| 52 | * @param reqVO 筛选条件请求 VO | 52 | * @param reqVO 筛选条件请求 VO |
| 53 | * @return 部门列表 | 53 | * @return 部门列表 |
| 54 | */ | 54 | */ |
| 55 | - List<DeptDO> getSimpleDepts(DeptListReqVO reqVO); | 55 | + List<DeptDO> getDeptList(DeptListReqVO reqVO); |
| 56 | 56 | ||
| 57 | /** | 57 | /** |
| 58 | * 获得所有子部门,从缓存中 | 58 | * 获得所有子部门,从缓存中 |
| @@ -61,7 +61,7 @@ public interface DeptService { | @@ -61,7 +61,7 @@ public interface DeptService { | ||
| 61 | * @param recursive 是否递归获取所有 | 61 | * @param recursive 是否递归获取所有 |
| 62 | * @return 子部门列表 | 62 | * @return 子部门列表 |
| 63 | */ | 63 | */ |
| 64 | - List<DeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive); | 64 | + List<DeptDO> getDeptListByParentIdFromCache(Long parentId, boolean recursive); |
| 65 | 65 | ||
| 66 | /** | 66 | /** |
| 67 | * 获得部门信息数组 | 67 | * 获得部门信息数组 |
| @@ -69,7 +69,21 @@ public interface DeptService { | @@ -69,7 +69,21 @@ public interface DeptService { | ||
| 69 | * @param ids 部门编号数组 | 69 | * @param ids 部门编号数组 |
| 70 | * @return 部门信息数组 | 70 | * @return 部门信息数组 |
| 71 | */ | 71 | */ |
| 72 | - List<DeptDO> getDepts(Collection<Long> ids); | 72 | + List<DeptDO> getDeptList(Collection<Long> ids); |
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * 获得指定编号的部门 Map | ||
| 76 | + * | ||
| 77 | + * @param ids 部门编号数组 | ||
| 78 | + * @return 部门 Map | ||
| 79 | + */ | ||
| 80 | + default Map<Long, DeptDO> getDeptMap(Collection<Long> ids) { | ||
| 81 | + if (CollUtil.isEmpty(ids)) { | ||
| 82 | + return Collections.emptyMap(); | ||
| 83 | + } | ||
| 84 | + List<DeptDO> list = getDeptList(ids); | ||
| 85 | + return CollectionUtils.convertMap(list, DeptDO::getId); | ||
| 86 | + } | ||
| 73 | 87 | ||
| 74 | /** | 88 | /** |
| 75 | * 获得部门信息 | 89 | * 获得部门信息 |
| @@ -86,27 +100,6 @@ public interface DeptService { | @@ -86,27 +100,6 @@ public interface DeptService { | ||
| 86 | * | 100 | * |
| 87 | * @param ids 角色编号数组 | 101 | * @param ids 角色编号数组 |
| 88 | */ | 102 | */ |
| 89 | - void validDepts(Collection<Long> ids); | 103 | + void validateDeptList(Collection<Long> ids); |
| 90 | 104 | ||
| 91 | - /** | ||
| 92 | - * 获得指定编号的部门列表 | ||
| 93 | - * | ||
| 94 | - * @param ids 部门编号数组 | ||
| 95 | - * @return 部门列表 | ||
| 96 | - */ | ||
| 97 | - List<DeptDO> getSimpleDepts(Collection<Long> ids); | ||
| 98 | - | ||
| 99 | - /** | ||
| 100 | - * 获得指定编号的部门 Map | ||
| 101 | - * | ||
| 102 | - * @param ids 部门编号数组 | ||
| 103 | - * @return 部门 Map | ||
| 104 | - */ | ||
| 105 | - default Map<Long, DeptDO> getDeptMap(Collection<Long> ids) { | ||
| 106 | - if (CollUtil.isEmpty(ids)) { | ||
| 107 | - return Collections.emptyMap(); | ||
| 108 | - } | ||
| 109 | - List<DeptDO> list = getSimpleDepts(ids); | ||
| 110 | - return CollectionUtils.convertMap(list, DeptDO::getId); | ||
| 111 | - } | ||
| 112 | } | 105 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java
| @@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.system.service.dept; | @@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.system.service.dept; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 6 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 7 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; | 5 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 8 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | 6 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 9 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; |
| @@ -19,13 +17,11 @@ import com.google.common.collect.ImmutableMultimap; | @@ -19,13 +17,11 @@ import com.google.common.collect.ImmutableMultimap; | ||
| 19 | import com.google.common.collect.Multimap; | 17 | import com.google.common.collect.Multimap; |
| 20 | import lombok.Getter; | 18 | import lombok.Getter; |
| 21 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
| 22 | -import org.springframework.scheduling.annotation.Scheduled; | ||
| 23 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 24 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
| 25 | 22 | ||
| 26 | import javax.annotation.PostConstruct; | 23 | import javax.annotation.PostConstruct; |
| 27 | import javax.annotation.Resource; | 24 | import javax.annotation.Resource; |
| 28 | -import java.time.LocalDateTime; | ||
| 29 | import java.util.*; | 25 | import java.util.*; |
| 30 | 26 | ||
| 31 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -95,7 +91,7 @@ public class DeptServiceImpl implements DeptService { | @@ -95,7 +91,7 @@ public class DeptServiceImpl implements DeptService { | ||
| 95 | if (reqVO.getParentId() == null) { | 91 | if (reqVO.getParentId() == null) { |
| 96 | reqVO.setParentId(DeptIdEnum.ROOT.getId()); | 92 | reqVO.setParentId(DeptIdEnum.ROOT.getId()); |
| 97 | } | 93 | } |
| 98 | - checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); | 94 | + validateForCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName()); |
| 99 | // 插入部门 | 95 | // 插入部门 |
| 100 | DeptDO dept = DeptConvert.INSTANCE.convert(reqVO); | 96 | DeptDO dept = DeptConvert.INSTANCE.convert(reqVO); |
| 101 | deptMapper.insert(dept); | 97 | deptMapper.insert(dept); |
| @@ -110,7 +106,7 @@ public class DeptServiceImpl implements DeptService { | @@ -110,7 +106,7 @@ public class DeptServiceImpl implements DeptService { | ||
| 110 | if (reqVO.getParentId() == null) { | 106 | if (reqVO.getParentId() == null) { |
| 111 | reqVO.setParentId(DeptIdEnum.ROOT.getId()); | 107 | reqVO.setParentId(DeptIdEnum.ROOT.getId()); |
| 112 | } | 108 | } |
| 113 | - checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); | 109 | + validateForCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName()); |
| 114 | // 更新部门 | 110 | // 更新部门 |
| 115 | DeptDO updateObj = DeptConvert.INSTANCE.convert(reqVO); | 111 | DeptDO updateObj = DeptConvert.INSTANCE.convert(reqVO); |
| 116 | deptMapper.updateById(updateObj); | 112 | deptMapper.updateById(updateObj); |
| @@ -121,10 +117,10 @@ public class DeptServiceImpl implements DeptService { | @@ -121,10 +117,10 @@ public class DeptServiceImpl implements DeptService { | ||
| 121 | @Override | 117 | @Override |
| 122 | public void deleteDept(Long id) { | 118 | public void deleteDept(Long id) { |
| 123 | // 校验是否存在 | 119 | // 校验是否存在 |
| 124 | - checkDeptExists(id); | 120 | + validateDeptExists(id); |
| 125 | // 校验是否有子部门 | 121 | // 校验是否有子部门 |
| 126 | if (deptMapper.selectCountByParentId(id) > 0) { | 122 | if (deptMapper.selectCountByParentId(id) > 0) { |
| 127 | - throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN); | 123 | + throw exception(DEPT_EXITS_CHILDREN); |
| 128 | } | 124 | } |
| 129 | // 删除部门 | 125 | // 删除部门 |
| 130 | deptMapper.deleteById(id); | 126 | deptMapper.deleteById(id); |
| @@ -133,20 +129,20 @@ public class DeptServiceImpl implements DeptService { | @@ -133,20 +129,20 @@ public class DeptServiceImpl implements DeptService { | ||
| 133 | } | 129 | } |
| 134 | 130 | ||
| 135 | @Override | 131 | @Override |
| 136 | - public List<DeptDO> getSimpleDepts(DeptListReqVO reqVO) { | 132 | + public List<DeptDO> getDeptList(DeptListReqVO reqVO) { |
| 137 | return deptMapper.selectList(reqVO); | 133 | return deptMapper.selectList(reqVO); |
| 138 | } | 134 | } |
| 139 | 135 | ||
| 140 | @Override | 136 | @Override |
| 141 | - public List<DeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive) { | 137 | + public List<DeptDO> getDeptListByParentIdFromCache(Long parentId, boolean recursive) { |
| 142 | if (parentId == null) { | 138 | if (parentId == null) { |
| 143 | return Collections.emptyList(); | 139 | return Collections.emptyList(); |
| 144 | } | 140 | } |
| 145 | - List<DeptDO> result = new ArrayList<>(); // TODO 芋艿:待优化,新增缓存,避免每次遍历的计算 | 141 | + List<DeptDO> result = new ArrayList<>(); |
| 146 | // 递归,简单粗暴 | 142 | // 递归,简单粗暴 |
| 147 | - this.getDeptsByParentIdFromCache(result, parentId, | ||
| 148 | - recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次 | ||
| 149 | - parentDeptCache); | 143 | + getDeptsByParentIdFromCache(result, parentId, |
| 144 | + recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次 | ||
| 145 | + parentDeptCache); | ||
| 150 | return result; | 146 | return result; |
| 151 | } | 147 | } |
| 152 | 148 | ||
| @@ -182,65 +178,65 @@ public class DeptServiceImpl implements DeptService { | @@ -182,65 +178,65 @@ public class DeptServiceImpl implements DeptService { | ||
| 182 | recursiveCount - 1, parentDeptMap)); | 178 | recursiveCount - 1, parentDeptMap)); |
| 183 | } | 179 | } |
| 184 | 180 | ||
| 185 | - private void checkCreateOrUpdate(Long id, Long parentId, String name) { | 181 | + private void validateForCreateOrUpdate(Long id, Long parentId, String name) { |
| 186 | // 校验自己存在 | 182 | // 校验自己存在 |
| 187 | - checkDeptExists(id); | 183 | + validateDeptExists(id); |
| 188 | // 校验父部门的有效性 | 184 | // 校验父部门的有效性 |
| 189 | - checkParentDeptEnable(id, parentId); | 185 | + validateParentDeptEnable(id, parentId); |
| 190 | // 校验部门名的唯一性 | 186 | // 校验部门名的唯一性 |
| 191 | - checkDeptNameUnique(id, parentId, name); | 187 | + validateDeptNameUnique(id, parentId, name); |
| 192 | } | 188 | } |
| 193 | 189 | ||
| 194 | - private void checkParentDeptEnable(Long id, Long parentId) { | 190 | + private void validateParentDeptEnable(Long id, Long parentId) { |
| 195 | if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) { | 191 | if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) { |
| 196 | return; | 192 | return; |
| 197 | } | 193 | } |
| 198 | // 不能设置自己为父部门 | 194 | // 不能设置自己为父部门 |
| 199 | if (parentId.equals(id)) { | 195 | if (parentId.equals(id)) { |
| 200 | - throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR); | 196 | + throw exception(DEPT_PARENT_ERROR); |
| 201 | } | 197 | } |
| 202 | // 父岗位不存在 | 198 | // 父岗位不存在 |
| 203 | DeptDO dept = deptMapper.selectById(parentId); | 199 | DeptDO dept = deptMapper.selectById(parentId); |
| 204 | if (dept == null) { | 200 | if (dept == null) { |
| 205 | - throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS); | 201 | + throw exception(DEPT_PARENT_NOT_EXITS); |
| 206 | } | 202 | } |
| 207 | // 父部门被禁用 | 203 | // 父部门被禁用 |
| 208 | if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) { | 204 | if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) { |
| 209 | - throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE); | 205 | + throw exception(DEPT_NOT_ENABLE); |
| 210 | } | 206 | } |
| 211 | // 父部门不能是原来的子部门 | 207 | // 父部门不能是原来的子部门 |
| 212 | - List<DeptDO> children = this.getDeptsByParentIdFromCache(id, true); | 208 | + List<DeptDO> children = getDeptListByParentIdFromCache(id, true); |
| 213 | if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) { | 209 | if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) { |
| 214 | - throw ServiceExceptionUtil.exception(DEPT_PARENT_IS_CHILD); | 210 | + throw exception(DEPT_PARENT_IS_CHILD); |
| 215 | } | 211 | } |
| 216 | } | 212 | } |
| 217 | 213 | ||
| 218 | - private void checkDeptExists(Long id) { | 214 | + private void validateDeptExists(Long id) { |
| 219 | if (id == null) { | 215 | if (id == null) { |
| 220 | return; | 216 | return; |
| 221 | } | 217 | } |
| 222 | DeptDO dept = deptMapper.selectById(id); | 218 | DeptDO dept = deptMapper.selectById(id); |
| 223 | if (dept == null) { | 219 | if (dept == null) { |
| 224 | - throw ServiceExceptionUtil.exception(DEPT_NOT_FOUND); | 220 | + throw exception(DEPT_NOT_FOUND); |
| 225 | } | 221 | } |
| 226 | } | 222 | } |
| 227 | 223 | ||
| 228 | - private void checkDeptNameUnique(Long id, Long parentId, String name) { | 224 | + private void validateDeptNameUnique(Long id, Long parentId, String name) { |
| 229 | DeptDO menu = deptMapper.selectByParentIdAndName(parentId, name); | 225 | DeptDO menu = deptMapper.selectByParentIdAndName(parentId, name); |
| 230 | if (menu == null) { | 226 | if (menu == null) { |
| 231 | return; | 227 | return; |
| 232 | } | 228 | } |
| 233 | // 如果 id 为空,说明不用比较是否为相同 id 的岗位 | 229 | // 如果 id 为空,说明不用比较是否为相同 id 的岗位 |
| 234 | if (id == null) { | 230 | if (id == null) { |
| 235 | - throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE); | 231 | + throw exception(DEPT_NAME_DUPLICATE); |
| 236 | } | 232 | } |
| 237 | if (!menu.getId().equals(id)) { | 233 | if (!menu.getId().equals(id)) { |
| 238 | - throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE); | 234 | + throw exception(DEPT_NAME_DUPLICATE); |
| 239 | } | 235 | } |
| 240 | } | 236 | } |
| 241 | 237 | ||
| 242 | @Override | 238 | @Override |
| 243 | - public List<DeptDO> getDepts(Collection<Long> ids) { | 239 | + public List<DeptDO> getDeptList(Collection<Long> ids) { |
| 244 | return deptMapper.selectBatchIds(ids); | 240 | return deptMapper.selectBatchIds(ids); |
| 245 | } | 241 | } |
| 246 | 242 | ||
| @@ -250,13 +246,12 @@ public class DeptServiceImpl implements DeptService { | @@ -250,13 +246,12 @@ public class DeptServiceImpl implements DeptService { | ||
| 250 | } | 246 | } |
| 251 | 247 | ||
| 252 | @Override | 248 | @Override |
| 253 | - public void validDepts(Collection<Long> ids) { | 249 | + public void validateDeptList(Collection<Long> ids) { |
| 254 | if (CollUtil.isEmpty(ids)) { | 250 | if (CollUtil.isEmpty(ids)) { |
| 255 | return; | 251 | return; |
| 256 | } | 252 | } |
| 257 | // 获得科室信息 | 253 | // 获得科室信息 |
| 258 | - List<DeptDO> depts = deptMapper.selectBatchIds(ids); | ||
| 259 | - Map<Long, DeptDO> deptMap = CollectionUtils.convertMap(depts, DeptDO::getId); | 254 | + Map<Long, DeptDO> deptMap = getDeptMap(ids); |
| 260 | // 校验 | 255 | // 校验 |
| 261 | ids.forEach(id -> { | 256 | ids.forEach(id -> { |
| 262 | DeptDO dept = deptMap.get(id); | 257 | DeptDO dept = deptMap.get(id); |
| @@ -269,9 +264,4 @@ public class DeptServiceImpl implements DeptService { | @@ -269,9 +264,4 @@ public class DeptServiceImpl implements DeptService { | ||
| 269 | }); | 264 | }); |
| 270 | } | 265 | } |
| 271 | 266 | ||
| 272 | - @Override | ||
| 273 | - public List<DeptDO> getSimpleDepts(Collection<Long> ids) { | ||
| 274 | - return deptMapper.selectBatchIds(ids); | ||
| 275 | - } | ||
| 276 | - | ||
| 277 | } | 267 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java
| @@ -49,8 +49,8 @@ public interface PostService { | @@ -49,8 +49,8 @@ public interface PostService { | ||
| 49 | * @param ids 岗位编号数组。如果为空,不进行筛选 | 49 | * @param ids 岗位编号数组。如果为空,不进行筛选 |
| 50 | * @return 部门列表 | 50 | * @return 部门列表 |
| 51 | */ | 51 | */ |
| 52 | - default List<PostDO> getPosts(@Nullable Collection<Long> ids) { | ||
| 53 | - return getPosts(ids, asSet(CommonStatusEnum.ENABLE.getStatus(), CommonStatusEnum.DISABLE.getStatus())); | 52 | + default List<PostDO> getPostList(@Nullable Collection<Long> ids) { |
| 53 | + return getPostList(ids, asSet(CommonStatusEnum.ENABLE.getStatus(), CommonStatusEnum.DISABLE.getStatus())); | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| @@ -60,7 +60,7 @@ public interface PostService { | @@ -60,7 +60,7 @@ public interface PostService { | ||
| 60 | * @param statuses 状态数组。如果为空,不进行筛选 | 60 | * @param statuses 状态数组。如果为空,不进行筛选 |
| 61 | * @return 部门列表 | 61 | * @return 部门列表 |
| 62 | */ | 62 | */ |
| 63 | - List<PostDO> getPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses); | 63 | + List<PostDO> getPostList(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses); |
| 64 | 64 | ||
| 65 | /** | 65 | /** |
| 66 | * 获得岗位分页列表 | 66 | * 获得岗位分页列表 |
| @@ -76,7 +76,7 @@ public interface PostService { | @@ -76,7 +76,7 @@ public interface PostService { | ||
| 76 | * @param reqVO 查询条件 | 76 | * @param reqVO 查询条件 |
| 77 | * @return 部门列表 | 77 | * @return 部门列表 |
| 78 | */ | 78 | */ |
| 79 | - List<PostDO> getPosts(PostExportReqVO reqVO); | 79 | + List<PostDO> getPostList(PostExportReqVO reqVO); |
| 80 | 80 | ||
| 81 | /** | 81 | /** |
| 82 | * 获得岗位信息 | 82 | * 获得岗位信息 |
| @@ -93,6 +93,6 @@ public interface PostService { | @@ -93,6 +93,6 @@ public interface PostService { | ||
| 93 | * | 93 | * |
| 94 | * @param ids 岗位编号数组 | 94 | * @param ids 岗位编号数组 |
| 95 | */ | 95 | */ |
| 96 | - void validPosts(Collection<Long> ids); | 96 | + void validatePostList(Collection<Long> ids); |
| 97 | 97 | ||
| 98 | } | 98 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.service.dept; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.service.dept; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; |
| @@ -38,7 +37,8 @@ public class PostServiceImpl implements PostService { | @@ -38,7 +37,8 @@ public class PostServiceImpl implements PostService { | ||
| 38 | @Override | 37 | @Override |
| 39 | public Long createPost(PostCreateReqVO reqVO) { | 38 | public Long createPost(PostCreateReqVO reqVO) { |
| 40 | // 校验正确性 | 39 | // 校验正确性 |
| 41 | - this.checkCreateOrUpdate(null, reqVO.getName(), reqVO.getCode()); | 40 | + validatePostForCreateOrUpdate(null, reqVO.getName(), reqVO.getCode()); |
| 41 | + | ||
| 42 | // 插入岗位 | 42 | // 插入岗位 |
| 43 | PostDO post = PostConvert.INSTANCE.convert(reqVO); | 43 | PostDO post = PostConvert.INSTANCE.convert(reqVO); |
| 44 | postMapper.insert(post); | 44 | postMapper.insert(post); |
| @@ -48,7 +48,8 @@ public class PostServiceImpl implements PostService { | @@ -48,7 +48,8 @@ public class PostServiceImpl implements PostService { | ||
| 48 | @Override | 48 | @Override |
| 49 | public void updatePost(PostUpdateReqVO reqVO) { | 49 | public void updatePost(PostUpdateReqVO reqVO) { |
| 50 | // 校验正确性 | 50 | // 校验正确性 |
| 51 | - this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode()); | 51 | + validatePostForCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode()); |
| 52 | + | ||
| 52 | // 更新岗位 | 53 | // 更新岗位 |
| 53 | PostDO updateObj = PostConvert.INSTANCE.convert(reqVO); | 54 | PostDO updateObj = PostConvert.INSTANCE.convert(reqVO); |
| 54 | postMapper.updateById(updateObj); | 55 | postMapper.updateById(updateObj); |
| @@ -57,80 +58,79 @@ public class PostServiceImpl implements PostService { | @@ -57,80 +58,79 @@ public class PostServiceImpl implements PostService { | ||
| 57 | @Override | 58 | @Override |
| 58 | public void deletePost(Long id) { | 59 | public void deletePost(Long id) { |
| 59 | // 校验是否存在 | 60 | // 校验是否存在 |
| 60 | - this.checkPostExists(id); | 61 | + validatePostExists(id); |
| 61 | // 删除部门 | 62 | // 删除部门 |
| 62 | postMapper.deleteById(id); | 63 | postMapper.deleteById(id); |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | - @Override | ||
| 66 | - public List<PostDO> getPosts(Collection<Long> ids, Collection<Integer> statuses) { | ||
| 67 | - return postMapper.selectList(ids, statuses); | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - @Override | ||
| 71 | - public PageResult<PostDO> getPostPage(PostPageReqVO reqVO) { | ||
| 72 | - return postMapper.selectPage(reqVO); | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - @Override | ||
| 76 | - public List<PostDO> getPosts(PostExportReqVO reqVO) { | ||
| 77 | - return postMapper.selectList(reqVO); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - @Override | ||
| 81 | - public PostDO getPost(Long id) { | ||
| 82 | - return postMapper.selectById(id); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - private void checkCreateOrUpdate(Long id, String name, String code) { | 66 | + private void validatePostForCreateOrUpdate(Long id, String name, String code) { |
| 86 | // 校验自己存在 | 67 | // 校验自己存在 |
| 87 | - checkPostExists(id); | 68 | + validatePostExists(id); |
| 88 | // 校验岗位名的唯一性 | 69 | // 校验岗位名的唯一性 |
| 89 | - checkPostNameUnique(id, name); | 70 | + validatePostNameUnique(id, name); |
| 90 | // 校验岗位编码的唯一性 | 71 | // 校验岗位编码的唯一性 |
| 91 | - checkPostCodeUnique(id, code); | 72 | + validatePostCodeUnique(id, code); |
| 92 | } | 73 | } |
| 93 | 74 | ||
| 94 | - private void checkPostNameUnique(Long id, String name) { | 75 | + private void validatePostNameUnique(Long id, String name) { |
| 95 | PostDO post = postMapper.selectByName(name); | 76 | PostDO post = postMapper.selectByName(name); |
| 96 | if (post == null) { | 77 | if (post == null) { |
| 97 | return; | 78 | return; |
| 98 | } | 79 | } |
| 99 | // 如果 id 为空,说明不用比较是否为相同 id 的岗位 | 80 | // 如果 id 为空,说明不用比较是否为相同 id 的岗位 |
| 100 | if (id == null) { | 81 | if (id == null) { |
| 101 | - throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE); | 82 | + throw exception(POST_NAME_DUPLICATE); |
| 102 | } | 83 | } |
| 103 | if (!post.getId().equals(id)) { | 84 | if (!post.getId().equals(id)) { |
| 104 | - throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE); | 85 | + throw exception(POST_NAME_DUPLICATE); |
| 105 | } | 86 | } |
| 106 | } | 87 | } |
| 107 | 88 | ||
| 108 | - private void checkPostCodeUnique(Long id, String code) { | 89 | + private void validatePostCodeUnique(Long id, String code) { |
| 109 | PostDO post = postMapper.selectByCode(code); | 90 | PostDO post = postMapper.selectByCode(code); |
| 110 | if (post == null) { | 91 | if (post == null) { |
| 111 | return; | 92 | return; |
| 112 | } | 93 | } |
| 113 | // 如果 id 为空,说明不用比较是否为相同 id 的岗位 | 94 | // 如果 id 为空,说明不用比较是否为相同 id 的岗位 |
| 114 | if (id == null) { | 95 | if (id == null) { |
| 115 | - throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE); | 96 | + throw exception(POST_CODE_DUPLICATE); |
| 116 | } | 97 | } |
| 117 | if (!post.getId().equals(id)) { | 98 | if (!post.getId().equals(id)) { |
| 118 | - throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE); | 99 | + throw exception(POST_CODE_DUPLICATE); |
| 119 | } | 100 | } |
| 120 | } | 101 | } |
| 121 | 102 | ||
| 122 | - private void checkPostExists(Long id) { | 103 | + private void validatePostExists(Long id) { |
| 123 | if (id == null) { | 104 | if (id == null) { |
| 124 | return; | 105 | return; |
| 125 | } | 106 | } |
| 126 | - PostDO post = postMapper.selectById(id); | ||
| 127 | - if (post == null) { | ||
| 128 | - throw ServiceExceptionUtil.exception(POST_NOT_FOUND); | 107 | + if (postMapper.selectById(id) == null) { |
| 108 | + throw exception(POST_NOT_FOUND); | ||
| 129 | } | 109 | } |
| 130 | } | 110 | } |
| 131 | 111 | ||
| 132 | @Override | 112 | @Override |
| 133 | - public void validPosts(Collection<Long> ids) { | 113 | + public List<PostDO> getPostList(Collection<Long> ids, Collection<Integer> statuses) { |
| 114 | + return postMapper.selectList(ids, statuses); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + @Override | ||
| 118 | + public PageResult<PostDO> getPostPage(PostPageReqVO reqVO) { | ||
| 119 | + return postMapper.selectPage(reqVO); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + @Override | ||
| 123 | + public List<PostDO> getPostList(PostExportReqVO reqVO) { | ||
| 124 | + return postMapper.selectList(reqVO); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + @Override | ||
| 128 | + public PostDO getPost(Long id) { | ||
| 129 | + return postMapper.selectById(id); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public void validatePostList(Collection<Long> ids) { | ||
| 134 | if (CollUtil.isEmpty(ids)) { | 134 | if (CollUtil.isEmpty(ids)) { |
| 135 | return; | 135 | return; |
| 136 | } | 136 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java
| @@ -44,7 +44,7 @@ public interface DictDataService { | @@ -44,7 +44,7 @@ public interface DictDataService { | ||
| 44 | * | 44 | * |
| 45 | * @return 字典数据全列表 | 45 | * @return 字典数据全列表 |
| 46 | */ | 46 | */ |
| 47 | - List<DictDataDO> getDictDatas(); | 47 | + List<DictDataDO> getDictDataList(); |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * 获得字典数据分页列表 | 50 | * 获得字典数据分页列表 |
| @@ -60,7 +60,7 @@ public interface DictDataService { | @@ -60,7 +60,7 @@ public interface DictDataService { | ||
| 60 | * @param reqVO 列表请求 | 60 | * @param reqVO 列表请求 |
| 61 | * @return 字典数据列表 | 61 | * @return 字典数据列表 |
| 62 | */ | 62 | */ |
| 63 | - List<DictDataDO> getDictDatas(DictDataExportReqVO reqVO); | 63 | + List<DictDataDO> getDictDataList(DictDataExportReqVO reqVO); |
| 64 | 64 | ||
| 65 | /** | 65 | /** |
| 66 | * 获得字典数据详情 | 66 | * 获得字典数据详情 |
| @@ -86,7 +86,7 @@ public interface DictDataService { | @@ -86,7 +86,7 @@ public interface DictDataService { | ||
| 86 | * @param dictType 字典类型 | 86 | * @param dictType 字典类型 |
| 87 | * @param values 字典数据值的数组 | 87 | * @param values 字典数据值的数组 |
| 88 | */ | 88 | */ |
| 89 | - void validDictDatas(String dictType, Collection<String> values); | 89 | + void validateDictDataList(String dictType, Collection<String> values); |
| 90 | 90 | ||
| 91 | /** | 91 | /** |
| 92 | * 获得指定的字典数据 | 92 | * 获得指定的字典数据 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java
| @@ -48,7 +48,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -48,7 +48,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 48 | private DictDataMapper dictDataMapper; | 48 | private DictDataMapper dictDataMapper; |
| 49 | 49 | ||
| 50 | @Override | 50 | @Override |
| 51 | - public List<DictDataDO> getDictDatas() { | 51 | + public List<DictDataDO> getDictDataList() { |
| 52 | List<DictDataDO> list = dictDataMapper.selectList(); | 52 | List<DictDataDO> list = dictDataMapper.selectList(); |
| 53 | list.sort(COMPARATOR_TYPE_AND_SORT); | 53 | list.sort(COMPARATOR_TYPE_AND_SORT); |
| 54 | return list; | 54 | return list; |
| @@ -60,7 +60,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -60,7 +60,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | @Override | 62 | @Override |
| 63 | - public List<DictDataDO> getDictDatas(DictDataExportReqVO reqVO) { | 63 | + public List<DictDataDO> getDictDataList(DictDataExportReqVO reqVO) { |
| 64 | List<DictDataDO> list = dictDataMapper.selectList(reqVO); | 64 | List<DictDataDO> list = dictDataMapper.selectList(reqVO); |
| 65 | list.sort(COMPARATOR_TYPE_AND_SORT); | 65 | list.sort(COMPARATOR_TYPE_AND_SORT); |
| 66 | return list; | 66 | return list; |
| @@ -74,7 +74,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -74,7 +74,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 74 | @Override | 74 | @Override |
| 75 | public Long createDictData(DictDataCreateReqVO reqVO) { | 75 | public Long createDictData(DictDataCreateReqVO reqVO) { |
| 76 | // 校验正确性 | 76 | // 校验正确性 |
| 77 | - checkCreateOrUpdate(null, reqVO.getValue(), reqVO.getDictType()); | 77 | + validateDictDataForCreateOrUpdate(null, reqVO.getValue(), reqVO.getDictType()); |
| 78 | 78 | ||
| 79 | // 插入字典类型 | 79 | // 插入字典类型 |
| 80 | DictDataDO dictData = DictDataConvert.INSTANCE.convert(reqVO); | 80 | DictDataDO dictData = DictDataConvert.INSTANCE.convert(reqVO); |
| @@ -85,7 +85,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -85,7 +85,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 85 | @Override | 85 | @Override |
| 86 | public void updateDictData(DictDataUpdateReqVO reqVO) { | 86 | public void updateDictData(DictDataUpdateReqVO reqVO) { |
| 87 | // 校验正确性 | 87 | // 校验正确性 |
| 88 | - checkCreateOrUpdate(reqVO.getId(), reqVO.getValue(), reqVO.getDictType()); | 88 | + validateDictDataForCreateOrUpdate(reqVO.getId(), reqVO.getValue(), reqVO.getDictType()); |
| 89 | 89 | ||
| 90 | // 更新字典类型 | 90 | // 更新字典类型 |
| 91 | DictDataDO updateObj = DictDataConvert.INSTANCE.convert(reqVO); | 91 | DictDataDO updateObj = DictDataConvert.INSTANCE.convert(reqVO); |
| @@ -95,7 +95,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -95,7 +95,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 95 | @Override | 95 | @Override |
| 96 | public void deleteDictData(Long id) { | 96 | public void deleteDictData(Long id) { |
| 97 | // 校验是否存在 | 97 | // 校验是否存在 |
| 98 | - checkDictDataExists(id); | 98 | + validateDictDataExists(id); |
| 99 | 99 | ||
| 100 | // 删除字典数据 | 100 | // 删除字典数据 |
| 101 | dictDataMapper.deleteById(id); | 101 | dictDataMapper.deleteById(id); |
| @@ -106,18 +106,17 @@ public class DictDataServiceImpl implements DictDataService { | @@ -106,18 +106,17 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 106 | return dictDataMapper.selectCountByDictType(dictType); | 106 | return dictDataMapper.selectCountByDictType(dictType); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | - | ||
| 110 | - private void checkCreateOrUpdate(Long id, String value, String dictType) { | 109 | + private void validateDictDataForCreateOrUpdate(Long id, String value, String dictType) { |
| 111 | // 校验自己存在 | 110 | // 校验自己存在 |
| 112 | - checkDictDataExists(id); | 111 | + validateDictDataExists(id); |
| 113 | // 校验字典类型有效 | 112 | // 校验字典类型有效 |
| 114 | - checkDictTypeValid(dictType); | 113 | + validateDictTypeExists(dictType); |
| 115 | // 校验字典数据的值的唯一性 | 114 | // 校验字典数据的值的唯一性 |
| 116 | - checkDictDataValueUnique(id, dictType, value); | 115 | + validateDictDataValueUnique(id, dictType, value); |
| 117 | } | 116 | } |
| 118 | 117 | ||
| 119 | @VisibleForTesting | 118 | @VisibleForTesting |
| 120 | - public void checkDictDataValueUnique(Long id, String dictType, String value) { | 119 | + public void validateDictDataValueUnique(Long id, String dictType, String value) { |
| 121 | DictDataDO dictData = dictDataMapper.selectByDictTypeAndValue(dictType, value); | 120 | DictDataDO dictData = dictDataMapper.selectByDictTypeAndValue(dictType, value); |
| 122 | if (dictData == null) { | 121 | if (dictData == null) { |
| 123 | return; | 122 | return; |
| @@ -132,7 +131,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -132,7 +131,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 132 | } | 131 | } |
| 133 | 132 | ||
| 134 | @VisibleForTesting | 133 | @VisibleForTesting |
| 135 | - public void checkDictDataExists(Long id) { | 134 | + public void validateDictDataExists(Long id) { |
| 136 | if (id == null) { | 135 | if (id == null) { |
| 137 | return; | 136 | return; |
| 138 | } | 137 | } |
| @@ -143,7 +142,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -143,7 +142,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 143 | } | 142 | } |
| 144 | 143 | ||
| 145 | @VisibleForTesting | 144 | @VisibleForTesting |
| 146 | - public void checkDictTypeValid(String type) { | 145 | + public void validateDictTypeExists(String type) { |
| 147 | DictTypeDO dictType = dictTypeService.getDictType(type); | 146 | DictTypeDO dictType = dictTypeService.getDictType(type); |
| 148 | if (dictType == null) { | 147 | if (dictType == null) { |
| 149 | throw exception(DICT_TYPE_NOT_EXISTS); | 148 | throw exception(DICT_TYPE_NOT_EXISTS); |
| @@ -154,7 +153,7 @@ public class DictDataServiceImpl implements DictDataService { | @@ -154,7 +153,7 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 154 | } | 153 | } |
| 155 | 154 | ||
| 156 | @Override | 155 | @Override |
| 157 | - public void validDictDatas(String dictType, Collection<String> values) { | 156 | + public void validateDictDataList(String dictType, Collection<String> values) { |
| 158 | if (CollUtil.isEmpty(values)) { | 157 | if (CollUtil.isEmpty(values)) { |
| 159 | return; | 158 | return; |
| 160 | } | 159 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java
| @@ -57,7 +57,8 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -57,7 +57,8 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 57 | @Override | 57 | @Override |
| 58 | public Long createDictType(DictTypeCreateReqVO reqVO) { | 58 | public Long createDictType(DictTypeCreateReqVO reqVO) { |
| 59 | // 校验正确性 | 59 | // 校验正确性 |
| 60 | - checkCreateOrUpdate(null, reqVO.getName(), reqVO.getType()); | 60 | + validateDictTypeForCreateOrUpdate(null, reqVO.getName(), reqVO.getType()); |
| 61 | + | ||
| 61 | // 插入字典类型 | 62 | // 插入字典类型 |
| 62 | DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO) | 63 | DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO) |
| 63 | .setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值 | 64 | .setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值 |
| @@ -68,7 +69,8 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -68,7 +69,8 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 68 | @Override | 69 | @Override |
| 69 | public void updateDictType(DictTypeUpdateReqVO reqVO) { | 70 | public void updateDictType(DictTypeUpdateReqVO reqVO) { |
| 70 | // 校验正确性 | 71 | // 校验正确性 |
| 71 | - checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); | 72 | + validateDictTypeForCreateOrUpdate(reqVO.getId(), reqVO.getName(), null); |
| 73 | + | ||
| 72 | // 更新字典类型 | 74 | // 更新字典类型 |
| 73 | DictTypeDO updateObj = DictTypeConvert.INSTANCE.convert(reqVO); | 75 | DictTypeDO updateObj = DictTypeConvert.INSTANCE.convert(reqVO); |
| 74 | dictTypeMapper.updateById(updateObj); | 76 | dictTypeMapper.updateById(updateObj); |
| @@ -77,7 +79,7 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -77,7 +79,7 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 77 | @Override | 79 | @Override |
| 78 | public void deleteDictType(Long id) { | 80 | public void deleteDictType(Long id) { |
| 79 | // 校验是否存在 | 81 | // 校验是否存在 |
| 80 | - DictTypeDO dictType = checkDictTypeExists(id); | 82 | + DictTypeDO dictType = validateDictTypeExists(id); |
| 81 | // 校验是否有字典数据 | 83 | // 校验是否有字典数据 |
| 82 | if (dictDataService.countByDictType(dictType.getType()) > 0) { | 84 | if (dictDataService.countByDictType(dictType.getType()) > 0) { |
| 83 | throw exception(DICT_TYPE_HAS_CHILDREN); | 85 | throw exception(DICT_TYPE_HAS_CHILDREN); |
| @@ -91,17 +93,17 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -91,17 +93,17 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 91 | return dictTypeMapper.selectList(); | 93 | return dictTypeMapper.selectList(); |
| 92 | } | 94 | } |
| 93 | 95 | ||
| 94 | - private void checkCreateOrUpdate(Long id, String name, String type) { | 96 | + private void validateDictTypeForCreateOrUpdate(Long id, String name, String type) { |
| 95 | // 校验自己存在 | 97 | // 校验自己存在 |
| 96 | - checkDictTypeExists(id); | 98 | + validateDictTypeExists(id); |
| 97 | // 校验字典类型的名字的唯一性 | 99 | // 校验字典类型的名字的唯一性 |
| 98 | - checkDictTypeNameUnique(id, name); | 100 | + validateDictTypeNameUnique(id, name); |
| 99 | // 校验字典类型的类型的唯一性 | 101 | // 校验字典类型的类型的唯一性 |
| 100 | - checkDictTypeUnique(id, type); | 102 | + validateDictTypeUnique(id, type); |
| 101 | } | 103 | } |
| 102 | 104 | ||
| 103 | @VisibleForTesting | 105 | @VisibleForTesting |
| 104 | - public void checkDictTypeNameUnique(Long id, String name) { | 106 | + void validateDictTypeNameUnique(Long id, String name) { |
| 105 | DictTypeDO dictType = dictTypeMapper.selectByName(name); | 107 | DictTypeDO dictType = dictTypeMapper.selectByName(name); |
| 106 | if (dictType == null) { | 108 | if (dictType == null) { |
| 107 | return; | 109 | return; |
| @@ -116,7 +118,7 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -116,7 +118,7 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 116 | } | 118 | } |
| 117 | 119 | ||
| 118 | @VisibleForTesting | 120 | @VisibleForTesting |
| 119 | - public void checkDictTypeUnique(Long id, String type) { | 121 | + void validateDictTypeUnique(Long id, String type) { |
| 120 | if (StrUtil.isEmpty(type)) { | 122 | if (StrUtil.isEmpty(type)) { |
| 121 | return; | 123 | return; |
| 122 | } | 124 | } |
| @@ -134,7 +136,7 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -134,7 +136,7 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | @VisibleForTesting | 138 | @VisibleForTesting |
| 137 | - public DictTypeDO checkDictTypeExists(Long id) { | 139 | + DictTypeDO validateDictTypeExists(Long id) { |
| 138 | if (id == null) { | 140 | if (id == null) { |
| 139 | return null; | 141 | return null; |
| 140 | } | 142 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java
| @@ -58,7 +58,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { | @@ -58,7 +58,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { | ||
| 58 | @Override | 58 | @Override |
| 59 | public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) { | 59 | public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) { |
| 60 | // 校验存在 | 60 | // 校验存在 |
| 61 | - this.validateErrorCodeExists(updateReqVO.getId()); | 61 | + validateErrorCodeExists(updateReqVO.getId()); |
| 62 | // 校验 code 重复 | 62 | // 校验 code 重复 |
| 63 | validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId()); | 63 | validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId()); |
| 64 | 64 | ||
| @@ -71,7 +71,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { | @@ -71,7 +71,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { | ||
| 71 | @Override | 71 | @Override |
| 72 | public void deleteErrorCode(Long id) { | 72 | public void deleteErrorCode(Long id) { |
| 73 | // 校验存在 | 73 | // 校验存在 |
| 74 | - this.validateErrorCodeExists(id); | 74 | + validateErrorCodeExists(id); |
| 75 | // 删除 | 75 | // 删除 |
| 76 | errorCodeMapper.deleteById(id); | 76 | errorCodeMapper.deleteById(id); |
| 77 | } | 77 | } |
| @@ -100,7 +100,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { | @@ -100,7 +100,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { | ||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | @VisibleForTesting | 102 | @VisibleForTesting |
| 103 | - public void validateErrorCodeExists(Long id) { | 103 | + void validateErrorCodeExists(Long id) { |
| 104 | if (errorCodeMapper.selectById(id) == null) { | 104 | if (errorCodeMapper.selectById(id) == null) { |
| 105 | throw exception(ERROR_CODE_NOT_EXISTS); | 105 | throw exception(ERROR_CODE_NOT_EXISTS); |
| 106 | } | 106 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogService.java
| 1 | package cn.iocoder.yudao.module.system.service.logger; | 1 | package cn.iocoder.yudao.module.system.service.logger; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.operatelog.core.service.OperateLog; | ||
| 5 | -import cn.iocoder.yudao.framework.operatelog.core.service.OperateLogFrameworkService; | ||
| 6 | import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; | 4 | import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; |
| @@ -38,6 +36,6 @@ public interface OperateLogService { | @@ -38,6 +36,6 @@ public interface OperateLogService { | ||
| 38 | * @param reqVO 列表条件 | 36 | * @param reqVO 列表条件 |
| 39 | * @return 日志列表 | 37 | * @return 日志列表 |
| 40 | */ | 38 | */ |
| 41 | - List<OperateLogDO> getOperateLogs(OperateLogExportReqVO reqVO); | 39 | + List<OperateLogDO> getOperateLogList(OperateLogExportReqVO reqVO); |
| 42 | 40 | ||
| 43 | } | 41 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImpl.java
| @@ -49,7 +49,7 @@ public class OperateLogServiceImpl implements OperateLogService { | @@ -49,7 +49,7 @@ public class OperateLogServiceImpl implements OperateLogService { | ||
| 49 | // 处理基于用户昵称的查询 | 49 | // 处理基于用户昵称的查询 |
| 50 | Collection<Long> userIds = null; | 50 | Collection<Long> userIds = null; |
| 51 | if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { | 51 | if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { |
| 52 | - userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId); | 52 | + userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId); |
| 53 | if (CollUtil.isEmpty(userIds)) { | 53 | if (CollUtil.isEmpty(userIds)) { |
| 54 | return PageResult.empty(); | 54 | return PageResult.empty(); |
| 55 | } | 55 | } |
| @@ -59,11 +59,11 @@ public class OperateLogServiceImpl implements OperateLogService { | @@ -59,11 +59,11 @@ public class OperateLogServiceImpl implements OperateLogService { | ||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | @Override | 61 | @Override |
| 62 | - public List<OperateLogDO> getOperateLogs(OperateLogExportReqVO reqVO) { | 62 | + public List<OperateLogDO> getOperateLogList(OperateLogExportReqVO reqVO) { |
| 63 | // 处理基于用户昵称的查询 | 63 | // 处理基于用户昵称的查询 |
| 64 | Collection<Long> userIds = null; | 64 | Collection<Long> userIds = null; |
| 65 | if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { | 65 | if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { |
| 66 | - userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId); | 66 | + userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId); |
| 67 | if (CollUtil.isEmpty(userIds)) { | 67 | if (CollUtil.isEmpty(userIds)) { |
| 68 | return Collections.emptyList(); | 68 | return Collections.emptyList(); |
| 69 | } | 69 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.mail; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.mail; | ||
| 3 | import cn.hutool.core.util.StrUtil; | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.hutool.extra.mail.MailAccount; | 4 | import cn.hutool.extra.mail.MailAccount; |
| 5 | import cn.hutool.extra.mail.MailUtil; | 5 | import cn.hutool.extra.mail.MailUtil; |
| 6 | -import cn.iocoder.yudao.framework.common.core.KeyValue; | ||
| 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 7 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 9 | import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; | 8 | import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; |
| @@ -20,15 +19,13 @@ import org.springframework.stereotype.Service; | @@ -20,15 +19,13 @@ import org.springframework.stereotype.Service; | ||
| 20 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 21 | 20 | ||
| 22 | import javax.annotation.Resource; | 21 | import javax.annotation.Resource; |
| 23 | -import java.util.List; | ||
| 24 | import java.util.Map; | 22 | import java.util.Map; |
| 25 | -import java.util.stream.Collectors; | ||
| 26 | 23 | ||
| 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 24 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 28 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 25 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 29 | 26 | ||
| 30 | /** | 27 | /** |
| 31 | - * 邮箱模版 服务实现类 | 28 | + * 邮箱发送 Service 实现类 |
| 32 | * | 29 | * |
| 33 | * @author wangjingyi | 30 | * @author wangjingyi |
| 34 | * @since 2022-03-21 | 31 | * @since 2022-03-21 |
| @@ -82,13 +79,13 @@ public class MailSendServiceImpl implements MailSendService { | @@ -82,13 +79,13 @@ public class MailSendServiceImpl implements MailSendService { | ||
| 82 | public Long sendSingleMail(String mail, Long userId, Integer userType, | 79 | public Long sendSingleMail(String mail, Long userId, Integer userType, |
| 83 | String templateCode, Map<String, Object> templateParams) { | 80 | String templateCode, Map<String, Object> templateParams) { |
| 84 | // 校验邮箱模版是否合法 | 81 | // 校验邮箱模版是否合法 |
| 85 | - MailTemplateDO template = checkMailTemplateValid(templateCode); | 82 | + MailTemplateDO template = validateMailTemplate(templateCode); |
| 86 | // 校验邮箱账号是否合法 | 83 | // 校验邮箱账号是否合法 |
| 87 | - MailAccountDO account = checkMailAccountValid(template.getAccountId()); | 84 | + MailAccountDO account = validateMailAccount(template.getAccountId()); |
| 88 | 85 | ||
| 89 | // 校验邮箱是否存在 | 86 | // 校验邮箱是否存在 |
| 90 | - mail = checkMail(mail); | ||
| 91 | - checkTemplateParams(template, templateParams); | 87 | + mail = validateMail(mail); |
| 88 | + validateTemplateParams(template, templateParams); | ||
| 92 | 89 | ||
| 93 | // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 | 90 | // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 |
| 94 | Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()); | 91 | Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()); |
| @@ -106,7 +103,7 @@ public class MailSendServiceImpl implements MailSendService { | @@ -106,7 +103,7 @@ public class MailSendServiceImpl implements MailSendService { | ||
| 106 | @Override | 103 | @Override |
| 107 | public void doSendMail(MailSendMessage message) { | 104 | public void doSendMail(MailSendMessage message) { |
| 108 | // 1. 创建发送账号 | 105 | // 1. 创建发送账号 |
| 109 | - MailAccountDO account = checkMailAccountValid(message.getAccountId()); | 106 | + MailAccountDO account = validateMailAccount(message.getAccountId()); |
| 110 | MailAccount mailAccount = MailAccountConvert.INSTANCE.convert(account, message.getNickname()); | 107 | MailAccount mailAccount = MailAccountConvert.INSTANCE.convert(account, message.getNickname()); |
| 111 | // 2. 发送邮件 | 108 | // 2. 发送邮件 |
| 112 | try { | 109 | try { |
| @@ -121,7 +118,7 @@ public class MailSendServiceImpl implements MailSendService { | @@ -121,7 +118,7 @@ public class MailSendServiceImpl implements MailSendService { | ||
| 121 | } | 118 | } |
| 122 | 119 | ||
| 123 | @VisibleForTesting | 120 | @VisibleForTesting |
| 124 | - public MailTemplateDO checkMailTemplateValid(String templateCode) { | 121 | + MailTemplateDO validateMailTemplate(String templateCode) { |
| 125 | // 获得邮件模板。考虑到效率,从缓存中获取 | 122 | // 获得邮件模板。考虑到效率,从缓存中获取 |
| 126 | MailTemplateDO template = mailTemplateService.getMailTemplateByCodeFromCache(templateCode); | 123 | MailTemplateDO template = mailTemplateService.getMailTemplateByCodeFromCache(templateCode); |
| 127 | // 邮件模板不存在 | 124 | // 邮件模板不存在 |
| @@ -132,7 +129,7 @@ public class MailSendServiceImpl implements MailSendService { | @@ -132,7 +129,7 @@ public class MailSendServiceImpl implements MailSendService { | ||
| 132 | } | 129 | } |
| 133 | 130 | ||
| 134 | @VisibleForTesting | 131 | @VisibleForTesting |
| 135 | - public MailAccountDO checkMailAccountValid(Long accountId) { | 132 | + MailAccountDO validateMailAccount(Long accountId) { |
| 136 | // 获得邮箱账号。考虑到效率,从缓存中获取 | 133 | // 获得邮箱账号。考虑到效率,从缓存中获取 |
| 137 | MailAccountDO account = mailAccountService.getMailAccountFromCache(accountId); | 134 | MailAccountDO account = mailAccountService.getMailAccountFromCache(accountId); |
| 138 | // 邮箱账号不存在 | 135 | // 邮箱账号不存在 |
| @@ -143,7 +140,7 @@ public class MailSendServiceImpl implements MailSendService { | @@ -143,7 +140,7 @@ public class MailSendServiceImpl implements MailSendService { | ||
| 143 | } | 140 | } |
| 144 | 141 | ||
| 145 | @VisibleForTesting | 142 | @VisibleForTesting |
| 146 | - public String checkMail(String mail) { | 143 | + String validateMail(String mail) { |
| 147 | if (StrUtil.isEmpty(mail)) { | 144 | if (StrUtil.isEmpty(mail)) { |
| 148 | throw exception(MAIL_SEND_MAIL_NOT_EXISTS); | 145 | throw exception(MAIL_SEND_MAIL_NOT_EXISTS); |
| 149 | } | 146 | } |
| @@ -157,7 +154,7 @@ public class MailSendServiceImpl implements MailSendService { | @@ -157,7 +154,7 @@ public class MailSendServiceImpl implements MailSendService { | ||
| 157 | * @param templateParams 参数列表 | 154 | * @param templateParams 参数列表 |
| 158 | */ | 155 | */ |
| 159 | @VisibleForTesting | 156 | @VisibleForTesting |
| 160 | - public void checkTemplateParams(MailTemplateDO template, Map<String, Object> templateParams) { | 157 | + void validateTemplateParams(MailTemplateDO template, Map<String, Object> templateParams) { |
| 161 | template.getParams().forEach(key -> { | 158 | template.getParams().forEach(key -> { |
| 162 | Object value = templateParams.get(key); | 159 | Object value = templateParams.get(key); |
| 163 | if (value == null) { | 160 | if (value == null) { |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java
| @@ -39,7 +39,7 @@ public interface NoticeService { | @@ -39,7 +39,7 @@ public interface NoticeService { | ||
| 39 | * @param reqVO 分页条件 | 39 | * @param reqVO 分页条件 |
| 40 | * @return 部门分页列表 | 40 | * @return 部门分页列表 |
| 41 | */ | 41 | */ |
| 42 | - PageResult<NoticeDO> pageNotices(NoticePageReqVO reqVO); | 42 | + PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO); |
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | * 获得岗位公告公告信息 | 45 | * 获得岗位公告公告信息 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java
| 1 | package cn.iocoder.yudao.module.system.service.notice; | 1 | package cn.iocoder.yudao.module.system.service.notice; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; | 4 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; |
| 6 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; |
| 8 | import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; | 7 | import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; |
| 9 | -import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; | ||
| 10 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 9 | +import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; | ||
| 11 | import com.google.common.annotations.VisibleForTesting; | 10 | import com.google.common.annotations.VisibleForTesting; |
| 12 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 13 | 12 | ||
| 14 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 15 | 14 | ||
| 15 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 16 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; | 16 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; |
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| @@ -36,7 +36,7 @@ public class NoticeServiceImpl implements NoticeService { | @@ -36,7 +36,7 @@ public class NoticeServiceImpl implements NoticeService { | ||
| 36 | @Override | 36 | @Override |
| 37 | public void updateNotice(NoticeUpdateReqVO reqVO) { | 37 | public void updateNotice(NoticeUpdateReqVO reqVO) { |
| 38 | // 校验是否存在 | 38 | // 校验是否存在 |
| 39 | - this.checkNoticeExists(reqVO.getId()); | 39 | + validateNoticeExists(reqVO.getId()); |
| 40 | // 更新通知公告 | 40 | // 更新通知公告 |
| 41 | NoticeDO updateObj = NoticeConvert.INSTANCE.convert(reqVO); | 41 | NoticeDO updateObj = NoticeConvert.INSTANCE.convert(reqVO); |
| 42 | noticeMapper.updateById(updateObj); | 42 | noticeMapper.updateById(updateObj); |
| @@ -45,13 +45,13 @@ public class NoticeServiceImpl implements NoticeService { | @@ -45,13 +45,13 @@ public class NoticeServiceImpl implements NoticeService { | ||
| 45 | @Override | 45 | @Override |
| 46 | public void deleteNotice(Long id) { | 46 | public void deleteNotice(Long id) { |
| 47 | // 校验是否存在 | 47 | // 校验是否存在 |
| 48 | - this.checkNoticeExists(id); | 48 | + validateNoticeExists(id); |
| 49 | // 删除通知公告 | 49 | // 删除通知公告 |
| 50 | noticeMapper.deleteById(id); | 50 | noticeMapper.deleteById(id); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | @Override | 53 | @Override |
| 54 | - public PageResult<NoticeDO> pageNotices(NoticePageReqVO reqVO) { | 54 | + public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) { |
| 55 | return noticeMapper.selectPage(reqVO); | 55 | return noticeMapper.selectPage(reqVO); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| @@ -61,13 +61,13 @@ public class NoticeServiceImpl implements NoticeService { | @@ -61,13 +61,13 @@ public class NoticeServiceImpl implements NoticeService { | ||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | @VisibleForTesting | 63 | @VisibleForTesting |
| 64 | - public void checkNoticeExists(Long id) { | 64 | + public void validateNoticeExists(Long id) { |
| 65 | if (id == null) { | 65 | if (id == null) { |
| 66 | return; | 66 | return; |
| 67 | } | 67 | } |
| 68 | NoticeDO notice = noticeMapper.selectById(id); | 68 | NoticeDO notice = noticeMapper.selectById(id); |
| 69 | if (notice == null) { | 69 | if (notice == null) { |
| 70 | - throw ServiceExceptionUtil.exception(NOTICE_NOT_FOUND); | 70 | + throw exception(NOTICE_NOT_FOUND); |
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java
| @@ -44,13 +44,13 @@ public class NotifySendServiceImpl implements NotifySendService { | @@ -44,13 +44,13 @@ public class NotifySendServiceImpl implements NotifySendService { | ||
| 44 | @Override | 44 | @Override |
| 45 | public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams) { | 45 | public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams) { |
| 46 | // 校验模版 | 46 | // 校验模版 |
| 47 | - NotifyTemplateDO template = checkNotifyTemplateValid(templateCode); | 47 | + NotifyTemplateDO template = validateNotifyTemplate(templateCode); |
| 48 | if (Objects.equals(template.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { | 48 | if (Objects.equals(template.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { |
| 49 | log.info("[sendSingleNotify][模版({})已经关闭,无法给用户({}/{})发送]", templateCode, userId, userType); | 49 | log.info("[sendSingleNotify][模版({})已经关闭,无法给用户({}/{})发送]", templateCode, userId, userType); |
| 50 | return null; | 50 | return null; |
| 51 | } | 51 | } |
| 52 | // 校验参数 | 52 | // 校验参数 |
| 53 | - checkTemplateParams(template, templateParams); | 53 | + validateTemplateParams(template, templateParams); |
| 54 | 54 | ||
| 55 | // 发送站内信 | 55 | // 发送站内信 |
| 56 | String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams); | 56 | String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams); |
| @@ -58,7 +58,7 @@ public class NotifySendServiceImpl implements NotifySendService { | @@ -58,7 +58,7 @@ public class NotifySendServiceImpl implements NotifySendService { | ||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | @VisibleForTesting | 60 | @VisibleForTesting |
| 61 | - public NotifyTemplateDO checkNotifyTemplateValid(String templateCode) { | 61 | + public NotifyTemplateDO validateNotifyTemplate(String templateCode) { |
| 62 | // 获得站内信模板。考虑到效率,从缓存中获取 | 62 | // 获得站内信模板。考虑到效率,从缓存中获取 |
| 63 | NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode); | 63 | NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode); |
| 64 | // 站内信模板不存在 | 64 | // 站内信模板不存在 |
| @@ -75,7 +75,7 @@ public class NotifySendServiceImpl implements NotifySendService { | @@ -75,7 +75,7 @@ public class NotifySendServiceImpl implements NotifySendService { | ||
| 75 | * @param templateParams 参数列表 | 75 | * @param templateParams 参数列表 |
| 76 | */ | 76 | */ |
| 77 | @VisibleForTesting | 77 | @VisibleForTesting |
| 78 | - public void checkTemplateParams(NotifyTemplateDO template, Map<String, Object> templateParams) { | 78 | + public void validateTemplateParams(NotifyTemplateDO template, Map<String, Object> templateParams) { |
| 79 | template.getParams().forEach(key -> { | 79 | template.getParams().forEach(key -> { |
| 80 | Object value = templateParams.get(key); | 80 | Object value = templateParams.get(key); |
| 81 | if (value == null) { | 81 | if (value == null) { |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java
| @@ -76,7 +76,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | @@ -76,7 +76,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | ||
| 76 | @Override | 76 | @Override |
| 77 | public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) { | 77 | public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) { |
| 78 | // 校验站内信编码是否重复 | 78 | // 校验站内信编码是否重复 |
| 79 | - checkNotifyTemplateCodeDuplicate(null, createReqVO.getCode()); | 79 | + validateNotifyTemplateCodeDuplicate(null, createReqVO.getCode()); |
| 80 | 80 | ||
| 81 | // 插入 | 81 | // 插入 |
| 82 | NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO); | 82 | NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO); |
| @@ -93,7 +93,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | @@ -93,7 +93,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | ||
| 93 | // 校验存在 | 93 | // 校验存在 |
| 94 | validateNotifyTemplateExists(updateReqVO.getId()); | 94 | validateNotifyTemplateExists(updateReqVO.getId()); |
| 95 | // 校验站内信编码是否重复 | 95 | // 校验站内信编码是否重复 |
| 96 | - checkNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode()); | 96 | + validateNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode()); |
| 97 | 97 | ||
| 98 | // 更新 | 98 | // 更新 |
| 99 | NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO); | 99 | NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO); |
| @@ -136,7 +136,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | @@ -136,7 +136,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | ||
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | @VisibleForTesting | 138 | @VisibleForTesting |
| 139 | - public void checkNotifyTemplateCodeDuplicate(Long id, String code) { | 139 | + public void validateNotifyTemplateCodeDuplicate(Long id, String code) { |
| 140 | NotifyTemplateDO template = notifyTemplateMapper.selectByCode(code); | 140 | NotifyTemplateDO template = notifyTemplateMapper.selectByCode(code); |
| 141 | if (template == null) { | 141 | if (template == null) { |
| 142 | return; | 142 | return; |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuService.java
| @@ -47,7 +47,7 @@ public interface MenuService { | @@ -47,7 +47,7 @@ public interface MenuService { | ||
| 47 | * | 47 | * |
| 48 | * @return 菜单列表 | 48 | * @return 菜单列表 |
| 49 | */ | 49 | */ |
| 50 | - List<MenuDO> getMenus(); | 50 | + List<MenuDO> getMenuList(); |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * 基于租户,筛选菜单列表 | 53 | * 基于租户,筛选菜单列表 |
| @@ -56,7 +56,7 @@ public interface MenuService { | @@ -56,7 +56,7 @@ public interface MenuService { | ||
| 56 | * @param reqVO 筛选条件请求 VO | 56 | * @param reqVO 筛选条件请求 VO |
| 57 | * @return 菜单列表 | 57 | * @return 菜单列表 |
| 58 | */ | 58 | */ |
| 59 | - List<MenuDO> getTenantMenus(MenuListReqVO reqVO); | 59 | + List<MenuDO> getMenuListByTenant(MenuListReqVO reqVO); |
| 60 | 60 | ||
| 61 | /** | 61 | /** |
| 62 | * 筛选菜单列表 | 62 | * 筛选菜单列表 |
| @@ -64,7 +64,7 @@ public interface MenuService { | @@ -64,7 +64,7 @@ public interface MenuService { | ||
| 64 | * @param reqVO 筛选条件请求 VO | 64 | * @param reqVO 筛选条件请求 VO |
| 65 | * @return 菜单列表 | 65 | * @return 菜单列表 |
| 66 | */ | 66 | */ |
| 67 | - List<MenuDO> getMenus(MenuListReqVO reqVO); | 67 | + List<MenuDO> getMenuList(MenuListReqVO reqVO); |
| 68 | 68 | ||
| 69 | /** | 69 | /** |
| 70 | * 获得所有菜单,从缓存中 | 70 | * 获得所有菜单,从缓存中 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
| @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUp | @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUp | ||
| 10 | import cn.iocoder.yudao.module.system.convert.permission.MenuConvert; | 10 | import cn.iocoder.yudao.module.system.convert.permission.MenuConvert; |
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 12 | import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper; | 12 | import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper; |
| 13 | -import cn.iocoder.yudao.module.system.enums.permission.MenuIdEnum; | ||
| 14 | import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum; | 13 | import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum; |
| 15 | import cn.iocoder.yudao.module.system.mq.producer.permission.MenuProducer; | 14 | import cn.iocoder.yudao.module.system.mq.producer.permission.MenuProducer; |
| 16 | import cn.iocoder.yudao.module.system.service.tenant.TenantService; | 15 | import cn.iocoder.yudao.module.system.service.tenant.TenantService; |
| @@ -19,6 +18,7 @@ import com.google.common.collect.ImmutableMap; | @@ -19,6 +18,7 @@ import com.google.common.collect.ImmutableMap; | ||
| 19 | import com.google.common.collect.ImmutableMultimap; | 18 | import com.google.common.collect.ImmutableMultimap; |
| 20 | import com.google.common.collect.Multimap; | 19 | import com.google.common.collect.Multimap; |
| 21 | import lombok.Getter; | 20 | import lombok.Getter; |
| 21 | +import lombok.Setter; | ||
| 22 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
| 23 | import org.springframework.context.annotation.Lazy; | 23 | import org.springframework.context.annotation.Lazy; |
| 24 | import org.springframework.stereotype.Service; | 24 | import org.springframework.stereotype.Service; |
| @@ -31,6 +31,7 @@ import javax.annotation.Resource; | @@ -31,6 +31,7 @@ import javax.annotation.Resource; | ||
| 31 | import java.util.*; | 31 | import java.util.*; |
| 32 | import java.util.stream.Collectors; | 32 | import java.util.stream.Collectors; |
| 33 | 33 | ||
| 34 | +import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT; | ||
| 34 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 35 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 35 | 36 | ||
| 36 | /** | 37 | /** |
| @@ -49,6 +50,7 @@ public class MenuServiceImpl implements MenuService { | @@ -49,6 +50,7 @@ public class MenuServiceImpl implements MenuService { | ||
| 49 | * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 | 50 | * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 |
| 50 | */ | 51 | */ |
| 51 | @Getter | 52 | @Getter |
| 53 | + @Setter | ||
| 52 | private volatile Map<Long, MenuDO> menuCache; | 54 | private volatile Map<Long, MenuDO> menuCache; |
| 53 | /** | 55 | /** |
| 54 | * 权限与菜单缓存 | 56 | * 权限与菜单缓存 |
| @@ -58,6 +60,7 @@ public class MenuServiceImpl implements MenuService { | @@ -58,6 +60,7 @@ public class MenuServiceImpl implements MenuService { | ||
| 58 | * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 | 60 | * 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向 |
| 59 | */ | 61 | */ |
| 60 | @Getter | 62 | @Getter |
| 63 | + @Setter | ||
| 61 | private volatile Multimap<String, MenuDO> permissionMenuCache; | 64 | private volatile Multimap<String, MenuDO> permissionMenuCache; |
| 62 | 65 | ||
| 63 | @Resource | 66 | @Resource |
| @@ -97,9 +100,10 @@ public class MenuServiceImpl implements MenuService { | @@ -97,9 +100,10 @@ public class MenuServiceImpl implements MenuService { | ||
| 97 | @Override | 100 | @Override |
| 98 | public Long createMenu(MenuCreateReqVO reqVO) { | 101 | public Long createMenu(MenuCreateReqVO reqVO) { |
| 99 | // 校验父菜单存在 | 102 | // 校验父菜单存在 |
| 100 | - checkParentResource(reqVO.getParentId(), null); | 103 | + validateParentMenu(reqVO.getParentId(), null); |
| 101 | // 校验菜单(自己) | 104 | // 校验菜单(自己) |
| 102 | - checkResource(reqVO.getParentId(), reqVO.getName(), null); | 105 | + validateMenu(reqVO.getParentId(), reqVO.getName(), null); |
| 106 | + | ||
| 103 | // 插入数据库 | 107 | // 插入数据库 |
| 104 | MenuDO menu = MenuConvert.INSTANCE.convert(reqVO); | 108 | MenuDO menu = MenuConvert.INSTANCE.convert(reqVO); |
| 105 | initMenuProperty(menu); | 109 | initMenuProperty(menu); |
| @@ -117,9 +121,10 @@ public class MenuServiceImpl implements MenuService { | @@ -117,9 +121,10 @@ public class MenuServiceImpl implements MenuService { | ||
| 117 | throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS); | 121 | throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS); |
| 118 | } | 122 | } |
| 119 | // 校验父菜单存在 | 123 | // 校验父菜单存在 |
| 120 | - checkParentResource(reqVO.getParentId(), reqVO.getId()); | 124 | + validateParentMenu(reqVO.getParentId(), reqVO.getId()); |
| 121 | // 校验菜单(自己) | 125 | // 校验菜单(自己) |
| 122 | - checkResource(reqVO.getParentId(), reqVO.getName(), reqVO.getId()); | 126 | + validateMenu(reqVO.getParentId(), reqVO.getName(), reqVO.getId()); |
| 127 | + | ||
| 123 | // 更新到数据库 | 128 | // 更新到数据库 |
| 124 | MenuDO updateObject = MenuConvert.INSTANCE.convert(reqVO); | 129 | MenuDO updateObject = MenuConvert.INSTANCE.convert(reqVO); |
| 125 | initMenuProperty(updateObject); | 130 | initMenuProperty(updateObject); |
| @@ -128,13 +133,8 @@ public class MenuServiceImpl implements MenuService { | @@ -128,13 +133,8 @@ public class MenuServiceImpl implements MenuService { | ||
| 128 | menuProducer.sendMenuRefreshMessage(); | 133 | menuProducer.sendMenuRefreshMessage(); |
| 129 | } | 134 | } |
| 130 | 135 | ||
| 131 | - /** | ||
| 132 | - * 删除菜单 | ||
| 133 | - * | ||
| 134 | - * @param menuId 菜单编号 | ||
| 135 | - */ | ||
| 136 | - @Transactional(rollbackFor = Exception.class) | ||
| 137 | @Override | 136 | @Override |
| 137 | + @Transactional(rollbackFor = Exception.class) | ||
| 138 | public void deleteMenu(Long menuId) { | 138 | public void deleteMenu(Long menuId) { |
| 139 | // 校验是否还有子菜单 | 139 | // 校验是否还有子菜单 |
| 140 | if (menuMapper.selectCountByParentId(menuId) > 0) { | 140 | if (menuMapper.selectCountByParentId(menuId) > 0) { |
| @@ -160,20 +160,20 @@ public class MenuServiceImpl implements MenuService { | @@ -160,20 +160,20 @@ public class MenuServiceImpl implements MenuService { | ||
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | @Override | 162 | @Override |
| 163 | - public List<MenuDO> getMenus() { | 163 | + public List<MenuDO> getMenuList() { |
| 164 | return menuMapper.selectList(); | 164 | return menuMapper.selectList(); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | @Override | 167 | @Override |
| 168 | - public List<MenuDO> getTenantMenus(MenuListReqVO reqVO) { | ||
| 169 | - List<MenuDO> menus = getMenus(reqVO); | 168 | + public List<MenuDO> getMenuListByTenant(MenuListReqVO reqVO) { |
| 169 | + List<MenuDO> menus = getMenuList(reqVO); | ||
| 170 | // 开启多租户的情况下,需要过滤掉未开通的菜单 | 170 | // 开启多租户的情况下,需要过滤掉未开通的菜单 |
| 171 | tenantService.handleTenantMenu(menuIds -> menus.removeIf(menu -> !CollUtil.contains(menuIds, menu.getId()))); | 171 | tenantService.handleTenantMenu(menuIds -> menus.removeIf(menu -> !CollUtil.contains(menuIds, menu.getId()))); |
| 172 | return menus; | 172 | return menus; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | @Override | 175 | @Override |
| 176 | - public List<MenuDO> getMenus(MenuListReqVO reqVO) { | 176 | + public List<MenuDO> getMenuList(MenuListReqVO reqVO) { |
| 177 | return menuMapper.selectList(reqVO); | 177 | return menuMapper.selectList(reqVO); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| @@ -223,8 +223,8 @@ public class MenuServiceImpl implements MenuService { | @@ -223,8 +223,8 @@ public class MenuServiceImpl implements MenuService { | ||
| 223 | * @param childId 当前菜单编号 | 223 | * @param childId 当前菜单编号 |
| 224 | */ | 224 | */ |
| 225 | @VisibleForTesting | 225 | @VisibleForTesting |
| 226 | - public void checkParentResource(Long parentId, Long childId) { | ||
| 227 | - if (parentId == null || MenuIdEnum.ROOT.getId().equals(parentId)) { | 226 | + void validateParentMenu(Long parentId, Long childId) { |
| 227 | + if (parentId == null || ID_ROOT.equals(parentId)) { | ||
| 228 | return; | 228 | return; |
| 229 | } | 229 | } |
| 230 | // 不能设置自己为父菜单 | 230 | // 不能设置自己为父菜单 |
| @@ -253,7 +253,7 @@ public class MenuServiceImpl implements MenuService { | @@ -253,7 +253,7 @@ public class MenuServiceImpl implements MenuService { | ||
| 253 | * @param id 菜单编号 | 253 | * @param id 菜单编号 |
| 254 | */ | 254 | */ |
| 255 | @VisibleForTesting | 255 | @VisibleForTesting |
| 256 | - public void checkResource(Long parentId, String name, Long id) { | 256 | + void validateMenu(Long parentId, String name, Long id) { |
| 257 | MenuDO menu = menuMapper.selectByParentIdAndName(parentId, name); | 257 | MenuDO menu = menuMapper.selectByParentIdAndName(parentId, name); |
| 258 | if (menu == null) { | 258 | if (menu == null) { |
| 259 | return; | 259 | return; |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java
| @@ -158,7 +158,7 @@ public class PermissionServiceImpl implements PermissionService { | @@ -158,7 +158,7 @@ public class PermissionServiceImpl implements PermissionService { | ||
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | // 判断角色是否包含超级管理员。如果是超级管理员,获取到全部 | 160 | // 判断角色是否包含超级管理员。如果是超级管理员,获取到全部 |
| 161 | - List<RoleDO> roleList = roleService.getRolesFromCache(roleIds); | 161 | + List<RoleDO> roleList = roleService.getRoleListFromCache(roleIds); |
| 162 | if (roleService.hasAnySuperAdmin(roleList)) { | 162 | if (roleService.hasAnySuperAdmin(roleList)) { |
| 163 | return menuService.getMenuListFromCache(menuTypes, menusStatuses); | 163 | return menuService.getMenuListFromCache(menuTypes, menusStatuses); |
| 164 | } | 164 | } |
| @@ -190,7 +190,7 @@ public class PermissionServiceImpl implements PermissionService { | @@ -190,7 +190,7 @@ public class PermissionServiceImpl implements PermissionService { | ||
| 190 | public Set<Long> getRoleMenuIds(Long roleId) { | 190 | public Set<Long> getRoleMenuIds(Long roleId) { |
| 191 | // 如果是管理员的情况下,获取全部菜单编号 | 191 | // 如果是管理员的情况下,获取全部菜单编号 |
| 192 | if (roleService.hasAnySuperAdmin(Collections.singleton(roleId))) { | 192 | if (roleService.hasAnySuperAdmin(Collections.singleton(roleId))) { |
| 193 | - return convertSet(menuService.getMenus(), MenuDO::getId); | 193 | + return convertSet(menuService.getMenuList(), MenuDO::getId); |
| 194 | } | 194 | } |
| 195 | // 如果是非管理员的情况下,获得拥有的菜单编号 | 195 | // 如果是非管理员的情况下,获得拥有的菜单编号 |
| 196 | return convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId); | 196 | return convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId); |
| @@ -371,7 +371,7 @@ public class PermissionServiceImpl implements PermissionService { | @@ -371,7 +371,7 @@ public class PermissionServiceImpl implements PermissionService { | ||
| 371 | if (roleService.hasAnySuperAdmin(roleIds)) { | 371 | if (roleService.hasAnySuperAdmin(roleIds)) { |
| 372 | return true; | 372 | return true; |
| 373 | } | 373 | } |
| 374 | - Set<String> userRoles = convertSet(roleService.getRolesFromCache(roleIds), | 374 | + Set<String> userRoles = convertSet(roleService.getRoleListFromCache(roleIds), |
| 375 | RoleDO::getCode); | 375 | RoleDO::getCode); |
| 376 | return CollUtil.containsAny(userRoles, Sets.newHashSet(roles)); | 376 | return CollUtil.containsAny(userRoles, Sets.newHashSet(roles)); |
| 377 | } | 377 | } |
| @@ -388,7 +388,7 @@ public class PermissionServiceImpl implements PermissionService { | @@ -388,7 +388,7 @@ public class PermissionServiceImpl implements PermissionService { | ||
| 388 | result.setSelf(true); | 388 | result.setSelf(true); |
| 389 | return result; | 389 | return result; |
| 390 | } | 390 | } |
| 391 | - List<RoleDO> roles = roleService.getRolesFromCache(roleIds); | 391 | + List<RoleDO> roles = roleService.getRoleListFromCache(roleIds); |
| 392 | 392 | ||
| 393 | // 获得用户的部门编号的缓存,通过 Guava 的 Suppliers 惰性求值,即有且仅有第一次发起 DB 的查询 | 393 | // 获得用户的部门编号的缓存,通过 Guava 的 Suppliers 惰性求值,即有且仅有第一次发起 DB 的查询 |
| 394 | Supplier<Long> userDeptIdCache = Suppliers.memoize(() -> userService.getUser(userId).getDeptId()); | 394 | Supplier<Long> userDeptIdCache = Suppliers.memoize(() -> userService.getUser(userId).getDeptId()); |
| @@ -418,7 +418,7 @@ public class PermissionServiceImpl implements PermissionService { | @@ -418,7 +418,7 @@ public class PermissionServiceImpl implements PermissionService { | ||
| 418 | } | 418 | } |
| 419 | // 情况四,DEPT_DEPT_AND_CHILD | 419 | // 情况四,DEPT_DEPT_AND_CHILD |
| 420 | if (Objects.equals(role.getDataScope(), DataScopeEnum.DEPT_AND_CHILD.getScope())) { | 420 | if (Objects.equals(role.getDataScope(), DataScopeEnum.DEPT_AND_CHILD.getScope())) { |
| 421 | - List<DeptDO> depts = deptService.getDeptsByParentIdFromCache(userDeptIdCache.get(), true); | 421 | + List<DeptDO> depts = deptService.getDeptListByParentIdFromCache(userDeptIdCache.get(), true); |
| 422 | CollUtil.addAll(result.getDeptIds(), CollectionUtils.convertList(depts, DeptDO::getId)); | 422 | CollUtil.addAll(result.getDeptIds(), CollectionUtils.convertList(depts, DeptDO::getId)); |
| 423 | // 添加本身部门编号 | 423 | // 添加本身部门编号 |
| 424 | CollUtil.addAll(result.getDeptIds(), userDeptIdCache.get()); | 424 | CollUtil.addAll(result.getDeptIds(), userDeptIdCache.get()); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleService.java
| @@ -79,7 +79,7 @@ public interface RoleService { | @@ -79,7 +79,7 @@ public interface RoleService { | ||
| 79 | * @param statuses 筛选的状态。允许空,空时不筛选 | 79 | * @param statuses 筛选的状态。允许空,空时不筛选 |
| 80 | * @return 角色列表 | 80 | * @return 角色列表 |
| 81 | */ | 81 | */ |
| 82 | - List<RoleDO> getRoles(@Nullable Collection<Integer> statuses); | 82 | + List<RoleDO> getRoleListByStatus(@Nullable Collection<Integer> statuses); |
| 83 | 83 | ||
| 84 | /** | 84 | /** |
| 85 | * 获得角色数组,从缓存中 | 85 | * 获得角色数组,从缓存中 |
| @@ -87,7 +87,7 @@ public interface RoleService { | @@ -87,7 +87,7 @@ public interface RoleService { | ||
| 87 | * @param ids 角色编号数组 | 87 | * @param ids 角色编号数组 |
| 88 | * @return 角色数组 | 88 | * @return 角色数组 |
| 89 | */ | 89 | */ |
| 90 | - List<RoleDO> getRolesFromCache(Collection<Long> ids); | 90 | + List<RoleDO> getRoleListFromCache(Collection<Long> ids); |
| 91 | 91 | ||
| 92 | /** | 92 | /** |
| 93 | * 判断角色数组中,是否有超级管理员 | 93 | * 判断角色数组中,是否有超级管理员 |
| @@ -104,7 +104,7 @@ public interface RoleService { | @@ -104,7 +104,7 @@ public interface RoleService { | ||
| 104 | * @return 是否有管理员 | 104 | * @return 是否有管理员 |
| 105 | */ | 105 | */ |
| 106 | default boolean hasAnySuperAdmin(Set<Long> ids) { | 106 | default boolean hasAnySuperAdmin(Set<Long> ids) { |
| 107 | - return hasAnySuperAdmin(getRolesFromCache(ids)); | 107 | + return hasAnySuperAdmin(getRoleListFromCache(ids)); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | /** | 110 | /** |
| @@ -138,6 +138,6 @@ public interface RoleService { | @@ -138,6 +138,6 @@ public interface RoleService { | ||
| 138 | * | 138 | * |
| 139 | * @param ids 角色编号数组 | 139 | * @param ids 角色编号数组 |
| 140 | */ | 140 | */ |
| 141 | - void validRoles(Collection<Long> ids); | 141 | + void validateRoleList(Collection<Long> ids); |
| 142 | 142 | ||
| 143 | } | 143 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java
| @@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollectionUtil; | @@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollectionUtil; | ||
| 5 | import cn.hutool.core.util.ObjectUtil; | 5 | import cn.hutool.core.util.ObjectUtil; |
| 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 9 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | 8 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 10 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; |
| 11 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; | 10 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; |
| @@ -34,6 +33,7 @@ import java.util.*; | @@ -34,6 +33,7 @@ import java.util.*; | ||
| 34 | import java.util.stream.Collectors; | 33 | import java.util.stream.Collectors; |
| 35 | 34 | ||
| 36 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 35 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 36 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 37 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 37 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| @@ -76,7 +76,7 @@ public class RoleServiceImpl implements RoleService { | @@ -76,7 +76,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 76 | log.info("[initLocalCache][缓存角色,数量为:{}]", roleList.size()); | 76 | log.info("[initLocalCache][缓存角色,数量为:{}]", roleList.size()); |
| 77 | 77 | ||
| 78 | // 第二步:构建缓存 | 78 | // 第二步:构建缓存 |
| 79 | - roleCache = CollectionUtils.convertMap(roleList, RoleDO::getId); | 79 | + roleCache = convertMap(roleList, RoleDO::getId); |
| 80 | }); | 80 | }); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| @@ -84,7 +84,7 @@ public class RoleServiceImpl implements RoleService { | @@ -84,7 +84,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 84 | @Transactional | 84 | @Transactional |
| 85 | public Long createRole(RoleCreateReqVO reqVO, Integer type) { | 85 | public Long createRole(RoleCreateReqVO reqVO, Integer type) { |
| 86 | // 校验角色 | 86 | // 校验角色 |
| 87 | - checkDuplicateRole(reqVO.getName(), reqVO.getCode(), null); | 87 | + validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), null); |
| 88 | // 插入到数据库 | 88 | // 插入到数据库 |
| 89 | RoleDO role = RoleConvert.INSTANCE.convert(reqVO); | 89 | RoleDO role = RoleConvert.INSTANCE.convert(reqVO); |
| 90 | role.setType(ObjectUtil.defaultIfNull(type, RoleTypeEnum.CUSTOM.getType())); | 90 | role.setType(ObjectUtil.defaultIfNull(type, RoleTypeEnum.CUSTOM.getType())); |
| @@ -105,13 +105,13 @@ public class RoleServiceImpl implements RoleService { | @@ -105,13 +105,13 @@ public class RoleServiceImpl implements RoleService { | ||
| 105 | @Override | 105 | @Override |
| 106 | public void updateRole(RoleUpdateReqVO reqVO) { | 106 | public void updateRole(RoleUpdateReqVO reqVO) { |
| 107 | // 校验是否可以更新 | 107 | // 校验是否可以更新 |
| 108 | - checkUpdateRole(reqVO.getId()); | 108 | + validateRoleForUpdate(reqVO.getId()); |
| 109 | // 校验角色的唯一字段是否重复 | 109 | // 校验角色的唯一字段是否重复 |
| 110 | - checkDuplicateRole(reqVO.getName(), reqVO.getCode(), reqVO.getId()); | 110 | + validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), reqVO.getId()); |
| 111 | 111 | ||
| 112 | // 更新到数据库 | 112 | // 更新到数据库 |
| 113 | - RoleDO updateObject = RoleConvert.INSTANCE.convert(reqVO); | ||
| 114 | - roleMapper.updateById(updateObject); | 113 | + RoleDO updateObj = RoleConvert.INSTANCE.convert(reqVO); |
| 114 | + roleMapper.updateById(updateObj); | ||
| 115 | // 发送刷新消息 | 115 | // 发送刷新消息 |
| 116 | roleProducer.sendRoleRefreshMessage(); | 116 | roleProducer.sendRoleRefreshMessage(); |
| 117 | } | 117 | } |
| @@ -119,12 +119,11 @@ public class RoleServiceImpl implements RoleService { | @@ -119,12 +119,11 @@ public class RoleServiceImpl implements RoleService { | ||
| 119 | @Override | 119 | @Override |
| 120 | public void updateRoleStatus(Long id, Integer status) { | 120 | public void updateRoleStatus(Long id, Integer status) { |
| 121 | // 校验是否可以更新 | 121 | // 校验是否可以更新 |
| 122 | - checkUpdateRole(id); | 122 | + validateRoleForUpdate(id); |
| 123 | + | ||
| 123 | // 更新状态 | 124 | // 更新状态 |
| 124 | - RoleDO updateObject = new RoleDO(); | ||
| 125 | - updateObject.setId(id); | ||
| 126 | - updateObject.setStatus(status); | ||
| 127 | - roleMapper.updateById(updateObject); | 125 | + RoleDO updateObj = new RoleDO().setId(id).setStatus(status); |
| 126 | + roleMapper.updateById(updateObj); | ||
| 128 | // 发送刷新消息 | 127 | // 发送刷新消息 |
| 129 | roleProducer.sendRoleRefreshMessage(); | 128 | roleProducer.sendRoleRefreshMessage(); |
| 130 | } | 129 | } |
| @@ -132,7 +131,8 @@ public class RoleServiceImpl implements RoleService { | @@ -132,7 +131,8 @@ public class RoleServiceImpl implements RoleService { | ||
| 132 | @Override | 131 | @Override |
| 133 | public void updateRoleDataScope(Long id, Integer dataScope, Set<Long> dataScopeDeptIds) { | 132 | public void updateRoleDataScope(Long id, Integer dataScope, Set<Long> dataScopeDeptIds) { |
| 134 | // 校验是否可以更新 | 133 | // 校验是否可以更新 |
| 135 | - checkUpdateRole(id); | 134 | + validateRoleForUpdate(id); |
| 135 | + | ||
| 136 | // 更新数据范围 | 136 | // 更新数据范围 |
| 137 | RoleDO updateObject = new RoleDO(); | 137 | RoleDO updateObject = new RoleDO(); |
| 138 | updateObject.setId(id); | 138 | updateObject.setId(id); |
| @@ -147,7 +147,7 @@ public class RoleServiceImpl implements RoleService { | @@ -147,7 +147,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 147 | @Transactional(rollbackFor = Exception.class) | 147 | @Transactional(rollbackFor = Exception.class) |
| 148 | public void deleteRole(Long id) { | 148 | public void deleteRole(Long id) { |
| 149 | // 校验是否可以更新 | 149 | // 校验是否可以更新 |
| 150 | - this.checkUpdateRole(id); | 150 | + validateRoleForUpdate(id); |
| 151 | // 标记删除 | 151 | // 标记删除 |
| 152 | roleMapper.deleteById(id); | 152 | roleMapper.deleteById(id); |
| 153 | // 删除相关数据 | 153 | // 删除相关数据 |
| @@ -169,7 +169,7 @@ public class RoleServiceImpl implements RoleService { | @@ -169,7 +169,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | @Override | 171 | @Override |
| 172 | - public List<RoleDO> getRoles(@Nullable Collection<Integer> statuses) { | 172 | + public List<RoleDO> getRoleListByStatus(@Nullable Collection<Integer> statuses) { |
| 173 | if (CollUtil.isEmpty(statuses)) { | 173 | if (CollUtil.isEmpty(statuses)) { |
| 174 | return roleMapper.selectList(); | 174 | return roleMapper.selectList(); |
| 175 | } | 175 | } |
| @@ -177,7 +177,7 @@ public class RoleServiceImpl implements RoleService { | @@ -177,7 +177,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | @Override | 179 | @Override |
| 180 | - public List<RoleDO> getRolesFromCache(Collection<Long> ids) { | 180 | + public List<RoleDO> getRoleListFromCache(Collection<Long> ids) { |
| 181 | if (CollectionUtil.isEmpty(ids)) { | 181 | if (CollectionUtil.isEmpty(ids)) { |
| 182 | return Collections.emptyList(); | 182 | return Collections.emptyList(); |
| 183 | } | 183 | } |
| @@ -219,7 +219,7 @@ public class RoleServiceImpl implements RoleService { | @@ -219,7 +219,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 219 | * @param id 角色编号 | 219 | * @param id 角色编号 |
| 220 | */ | 220 | */ |
| 221 | @VisibleForTesting | 221 | @VisibleForTesting |
| 222 | - public void checkDuplicateRole(String name, String code, Long id) { | 222 | + void validateRoleDuplicate(String name, String code, Long id) { |
| 223 | // 0. 超级管理员,不允许创建 | 223 | // 0. 超级管理员,不允许创建 |
| 224 | if (RoleCodeEnum.isSuperAdmin(code)) { | 224 | if (RoleCodeEnum.isSuperAdmin(code)) { |
| 225 | throw exception(ROLE_ADMIN_CODE_ERROR, code); | 225 | throw exception(ROLE_ADMIN_CODE_ERROR, code); |
| @@ -246,7 +246,7 @@ public class RoleServiceImpl implements RoleService { | @@ -246,7 +246,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 246 | * @param id 角色编号 | 246 | * @param id 角色编号 |
| 247 | */ | 247 | */ |
| 248 | @VisibleForTesting | 248 | @VisibleForTesting |
| 249 | - public void checkUpdateRole(Long id) { | 249 | + void validateRoleForUpdate(Long id) { |
| 250 | RoleDO roleDO = roleMapper.selectById(id); | 250 | RoleDO roleDO = roleMapper.selectById(id); |
| 251 | if (roleDO == null) { | 251 | if (roleDO == null) { |
| 252 | throw exception(ROLE_NOT_EXISTS); | 252 | throw exception(ROLE_NOT_EXISTS); |
| @@ -258,13 +258,13 @@ public class RoleServiceImpl implements RoleService { | @@ -258,13 +258,13 @@ public class RoleServiceImpl implements RoleService { | ||
| 258 | } | 258 | } |
| 259 | 259 | ||
| 260 | @Override | 260 | @Override |
| 261 | - public void validRoles(Collection<Long> ids) { | 261 | + public void validateRoleList(Collection<Long> ids) { |
| 262 | if (CollUtil.isEmpty(ids)) { | 262 | if (CollUtil.isEmpty(ids)) { |
| 263 | return; | 263 | return; |
| 264 | } | 264 | } |
| 265 | // 获得角色信息 | 265 | // 获得角色信息 |
| 266 | List<RoleDO> roles = roleMapper.selectBatchIds(ids); | 266 | List<RoleDO> roles = roleMapper.selectBatchIds(ids); |
| 267 | - Map<Long, RoleDO> roleMap = CollectionUtils.convertMap(roles, RoleDO::getId); | 267 | + Map<Long, RoleDO> roleMap = convertMap(roles, RoleDO::getId); |
| 268 | // 校验 | 268 | // 校验 |
| 269 | ids.forEach(id -> { | 269 | ids.forEach(id -> { |
| 270 | RoleDO role = roleMap.get(id); | 270 | RoleDO role = roleMap.get(id); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordService.java
| @@ -81,7 +81,7 @@ public interface SensitiveWordService { | @@ -81,7 +81,7 @@ public interface SensitiveWordService { | ||
| 81 | * | 81 | * |
| 82 | * @return 标签数组 | 82 | * @return 标签数组 |
| 83 | */ | 83 | */ |
| 84 | - Set<String> getSensitiveWordTags(); | 84 | + Set<String> getSensitiveWordTagSet(); |
| 85 | 85 | ||
| 86 | /** | 86 | /** |
| 87 | * 获得文本所包含的不合法的敏感词数组 | 87 | * 获得文本所包含的不合法的敏感词数组 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sensitiveword/SensitiveWordServiceImpl.java
| @@ -25,6 +25,7 @@ import javax.annotation.Resource; | @@ -25,6 +25,7 @@ import javax.annotation.Resource; | ||
| 25 | import java.util.*; | 25 | import java.util.*; |
| 26 | 26 | ||
| 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 28 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | ||
| 28 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_EXISTS; | 29 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_EXISTS; |
| 29 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_NOT_EXISTS; | 30 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_NOT_EXISTS; |
| 30 | 31 | ||
| @@ -85,7 +86,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -85,7 +86,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 85 | 86 | ||
| 86 | private void initSensitiveWordTrie(List<SensitiveWordDO> wordDOs) { | 87 | private void initSensitiveWordTrie(List<SensitiveWordDO> wordDOs) { |
| 87 | // 过滤禁用的敏感词 | 88 | // 过滤禁用的敏感词 |
| 88 | - wordDOs = CollectionUtils.filterList(wordDOs, word -> word.getStatus().equals(CommonStatusEnum.ENABLE.getStatus())); | 89 | + wordDOs = filterList(wordDOs, word -> word.getStatus().equals(CommonStatusEnum.ENABLE.getStatus())); |
| 89 | 90 | ||
| 90 | // 初始化默认的 defaultSensitiveWordTrie | 91 | // 初始化默认的 defaultSensitiveWordTrie |
| 91 | this.defaultSensitiveWordTrie = new SimpleTrie(CollectionUtils.convertList(wordDOs, SensitiveWordDO::getName)); | 92 | this.defaultSensitiveWordTrie = new SimpleTrie(CollectionUtils.convertList(wordDOs, SensitiveWordDO::getName)); |
| @@ -107,7 +108,8 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -107,7 +108,8 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 107 | @Override | 108 | @Override |
| 108 | public Long createSensitiveWord(SensitiveWordCreateReqVO createReqVO) { | 109 | public Long createSensitiveWord(SensitiveWordCreateReqVO createReqVO) { |
| 109 | // 校验唯一性 | 110 | // 校验唯一性 |
| 110 | - checkSensitiveWordNameUnique(null, createReqVO.getName()); | 111 | + validateSensitiveWordNameUnique(null, createReqVO.getName()); |
| 112 | + | ||
| 111 | // 插入 | 113 | // 插入 |
| 112 | SensitiveWordDO sensitiveWord = SensitiveWordConvert.INSTANCE.convert(createReqVO); | 114 | SensitiveWordDO sensitiveWord = SensitiveWordConvert.INSTANCE.convert(createReqVO); |
| 113 | sensitiveWordMapper.insert(sensitiveWord); | 115 | sensitiveWordMapper.insert(sensitiveWord); |
| @@ -119,8 +121,9 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -119,8 +121,9 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 119 | @Override | 121 | @Override |
| 120 | public void updateSensitiveWord(SensitiveWordUpdateReqVO updateReqVO) { | 122 | public void updateSensitiveWord(SensitiveWordUpdateReqVO updateReqVO) { |
| 121 | // 校验唯一性 | 123 | // 校验唯一性 |
| 122 | - checkSensitiveWordExists(updateReqVO.getId()); | ||
| 123 | - checkSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName()); | 124 | + validateSensitiveWordExists(updateReqVO.getId()); |
| 125 | + validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName()); | ||
| 126 | + | ||
| 124 | // 更新 | 127 | // 更新 |
| 125 | SensitiveWordDO updateObj = SensitiveWordConvert.INSTANCE.convert(updateReqVO); | 128 | SensitiveWordDO updateObj = SensitiveWordConvert.INSTANCE.convert(updateReqVO); |
| 126 | sensitiveWordMapper.updateById(updateObj); | 129 | sensitiveWordMapper.updateById(updateObj); |
| @@ -131,14 +134,14 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -131,14 +134,14 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 131 | @Override | 134 | @Override |
| 132 | public void deleteSensitiveWord(Long id) { | 135 | public void deleteSensitiveWord(Long id) { |
| 133 | // 校验存在 | 136 | // 校验存在 |
| 134 | - checkSensitiveWordExists(id); | 137 | + validateSensitiveWordExists(id); |
| 135 | // 删除 | 138 | // 删除 |
| 136 | sensitiveWordMapper.deleteById(id); | 139 | sensitiveWordMapper.deleteById(id); |
| 137 | // 发送消息,刷新缓存 | 140 | // 发送消息,刷新缓存 |
| 138 | sensitiveWordProducer.sendSensitiveWordRefreshMessage(); | 141 | sensitiveWordProducer.sendSensitiveWordRefreshMessage(); |
| 139 | } | 142 | } |
| 140 | 143 | ||
| 141 | - private void checkSensitiveWordNameUnique(Long id, String name) { | 144 | + private void validateSensitiveWordNameUnique(Long id, String name) { |
| 142 | SensitiveWordDO word = sensitiveWordMapper.selectByName(name); | 145 | SensitiveWordDO word = sensitiveWordMapper.selectByName(name); |
| 143 | if (word == null) { | 146 | if (word == null) { |
| 144 | return; | 147 | return; |
| @@ -152,7 +155,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -152,7 +155,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 152 | } | 155 | } |
| 153 | } | 156 | } |
| 154 | 157 | ||
| 155 | - private void checkSensitiveWordExists(Long id) { | 158 | + private void validateSensitiveWordExists(Long id) { |
| 156 | if (sensitiveWordMapper.selectById(id) == null) { | 159 | if (sensitiveWordMapper.selectById(id) == null) { |
| 157 | throw exception(SENSITIVE_WORD_NOT_EXISTS); | 160 | throw exception(SENSITIVE_WORD_NOT_EXISTS); |
| 158 | } | 161 | } |
| @@ -179,7 +182,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | @@ -179,7 +182,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService { | ||
| 179 | } | 182 | } |
| 180 | 183 | ||
| 181 | @Override | 184 | @Override |
| 182 | - public Set<String> getSensitiveWordTags() { | 185 | + public Set<String> getSensitiveWordTagSet() { |
| 183 | return sensitiveWordTagsCache; | 186 | return sensitiveWordTagsCache; |
| 184 | } | 187 | } |
| 185 | 188 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelService.java
| 1 | package cn.iocoder.yudao.module.system.service.sms; | 1 | package cn.iocoder.yudao.module.system.service.sms; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; | 4 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO; |
| 6 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO; |
| 7 | +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; | ||
| 8 | 8 | ||
| 9 | import javax.validation.Valid; | 9 | import javax.validation.Valid; |
| 10 | -import java.util.Collection; | ||
| 11 | import java.util.List; | 10 | import java.util.List; |
| 12 | 11 | ||
| 13 | /** | 12 | /** |
| @@ -54,14 +53,6 @@ public interface SmsChannelService { | @@ -54,14 +53,6 @@ public interface SmsChannelService { | ||
| 54 | SmsChannelDO getSmsChannel(Long id); | 53 | SmsChannelDO getSmsChannel(Long id); |
| 55 | 54 | ||
| 56 | /** | 55 | /** |
| 57 | - * 获得短信渠道列表 | ||
| 58 | - * | ||
| 59 | - * @param ids 编号 | ||
| 60 | - * @return 短信渠道列表 | ||
| 61 | - */ | ||
| 62 | - List<SmsChannelDO> getSmsChannelList(Collection<Long> ids); | ||
| 63 | - | ||
| 64 | - /** | ||
| 65 | * 获得所有短信渠道列表 | 56 | * 获得所有短信渠道列表 |
| 66 | * | 57 | * |
| 67 | * @return 短信渠道列表 | 58 | * @return 短信渠道列表 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java
| @@ -15,7 +15,6 @@ import org.springframework.stereotype.Service; | @@ -15,7 +15,6 @@ import org.springframework.stereotype.Service; | ||
| 15 | 15 | ||
| 16 | import javax.annotation.PostConstruct; | 16 | import javax.annotation.PostConstruct; |
| 17 | import javax.annotation.Resource; | 17 | import javax.annotation.Resource; |
| 18 | -import java.util.Collection; | ||
| 19 | import java.util.List; | 18 | import java.util.List; |
| 20 | 19 | ||
| 21 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 20 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -69,7 +68,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { | @@ -69,7 +68,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { | ||
| 69 | @Override | 68 | @Override |
| 70 | public void updateSmsChannel(SmsChannelUpdateReqVO updateReqVO) { | 69 | public void updateSmsChannel(SmsChannelUpdateReqVO updateReqVO) { |
| 71 | // 校验存在 | 70 | // 校验存在 |
| 72 | - this.validateSmsChannelExists(updateReqVO.getId()); | 71 | + validateSmsChannelExists(updateReqVO.getId()); |
| 73 | // 更新 | 72 | // 更新 |
| 74 | SmsChannelDO updateObj = SmsChannelConvert.INSTANCE.convert(updateReqVO); | 73 | SmsChannelDO updateObj = SmsChannelConvert.INSTANCE.convert(updateReqVO); |
| 75 | smsChannelMapper.updateById(updateObj); | 74 | smsChannelMapper.updateById(updateObj); |
| @@ -80,7 +79,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { | @@ -80,7 +79,7 @@ public class SmsChannelServiceImpl implements SmsChannelService { | ||
| 80 | @Override | 79 | @Override |
| 81 | public void deleteSmsChannel(Long id) { | 80 | public void deleteSmsChannel(Long id) { |
| 82 | // 校验存在 | 81 | // 校验存在 |
| 83 | - this.validateSmsChannelExists(id); | 82 | + validateSmsChannelExists(id); |
| 84 | // 校验是否有在使用该账号的模版 | 83 | // 校验是否有在使用该账号的模版 |
| 85 | if (smsTemplateService.countByChannelId(id) > 0) { | 84 | if (smsTemplateService.countByChannelId(id) > 0) { |
| 86 | throw exception(SMS_CHANNEL_HAS_CHILDREN); | 85 | throw exception(SMS_CHANNEL_HAS_CHILDREN); |
| @@ -103,11 +102,6 @@ public class SmsChannelServiceImpl implements SmsChannelService { | @@ -103,11 +102,6 @@ public class SmsChannelServiceImpl implements SmsChannelService { | ||
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | @Override | 104 | @Override |
| 106 | - public List<SmsChannelDO> getSmsChannelList(Collection<Long> ids) { | ||
| 107 | - return smsChannelMapper.selectBatchIds(ids); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - @Override | ||
| 111 | public List<SmsChannelDO> getSmsChannelList() { | 105 | public List<SmsChannelDO> getSmsChannelList() { |
| 112 | return smsChannelMapper.selectList(); | 106 | return smsChannelMapper.selectList(); |
| 113 | } | 107 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsCodeService.java
| 1 | package cn.iocoder.yudao.module.system.service.sms; | 1 | package cn.iocoder.yudao.module.system.service.sms; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.exception.ServiceException; | 3 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 4 | -import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO; | 4 | +import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeValidateReqDTO; |
| 5 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; | 5 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; |
| 6 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; | 6 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; |
| 7 | 7 | ||
| @@ -35,6 +35,6 @@ public interface SmsCodeService { | @@ -35,6 +35,6 @@ public interface SmsCodeService { | ||
| 35 | * | 35 | * |
| 36 | * @param reqDTO 校验请求 | 36 | * @param reqDTO 校验请求 |
| 37 | */ | 37 | */ |
| 38 | - void checkSmsCode(@Valid SmsCodeCheckReqDTO reqDTO); | 38 | + void validateSmsCode(@Valid SmsCodeValidateReqDTO reqDTO); |
| 39 | 39 | ||
| 40 | } | 40 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsCodeServiceImpl.java
| @@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.system.service.sms; | @@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.system.service.sms; | ||
| 3 | import cn.hutool.core.date.LocalDateTimeUtil; | 3 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 5 | import cn.hutool.core.map.MapUtil; | 5 | import cn.hutool.core.map.MapUtil; |
| 6 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 7 | -import cn.iocoder.yudao.framework.common.util.date.DateUtils; | ||
| 8 | -import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO; | ||
| 9 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; | 6 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; |
| 10 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; | 7 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; |
| 8 | +import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeValidateReqDTO; | ||
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO; |
| 12 | import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsCodeMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsCodeMapper; |
| 13 | import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; | 11 | import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; |
| @@ -16,11 +14,11 @@ import org.springframework.stereotype.Service; | @@ -16,11 +14,11 @@ import org.springframework.stereotype.Service; | ||
| 16 | import org.springframework.validation.annotation.Validated; | 14 | import org.springframework.validation.annotation.Validated; |
| 17 | 15 | ||
| 18 | import javax.annotation.Resource; | 16 | import javax.annotation.Resource; |
| 19 | - | ||
| 20 | import java.time.LocalDateTime; | 17 | import java.time.LocalDateTime; |
| 21 | -import java.time.temporal.ChronoUnit; | ||
| 22 | 18 | ||
| 23 | import static cn.hutool.core.util.RandomUtil.randomInt; | 19 | import static cn.hutool.core.util.RandomUtil.randomInt; |
| 20 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 21 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.isToday; | ||
| 24 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 22 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 25 | 23 | ||
| 26 | /** | 24 | /** |
| @@ -58,11 +56,11 @@ public class SmsCodeServiceImpl implements SmsCodeService { | @@ -58,11 +56,11 @@ public class SmsCodeServiceImpl implements SmsCodeService { | ||
| 58 | if (lastSmsCode != null) { | 56 | if (lastSmsCode != null) { |
| 59 | if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis() | 57 | if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis() |
| 60 | < smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁 | 58 | < smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁 |
| 61 | - throw ServiceExceptionUtil.exception(SMS_CODE_SEND_TOO_FAST); | 59 | + throw exception(SMS_CODE_SEND_TOO_FAST); |
| 62 | } | 60 | } |
| 63 | - if (DateUtils.isToday(lastSmsCode.getCreateTime()) && // 必须是今天,才能计算超过当天的上限 | 61 | + if (isToday(lastSmsCode.getCreateTime()) && // 必须是今天,才能计算超过当天的上限 |
| 64 | lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 | 62 | lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 |
| 65 | - throw ServiceExceptionUtil.exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); | 63 | + throw exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); |
| 66 | } | 64 | } |
| 67 | // TODO 芋艿:提升,每个 IP 每天可发送数量 | 65 | // TODO 芋艿:提升,每个 IP 每天可发送数量 |
| 68 | // TODO 芋艿:提升,每个 IP 每小时可发送数量 | 66 | // TODO 芋艿:提升,每个 IP 每小时可发送数量 |
| @@ -71,7 +69,7 @@ public class SmsCodeServiceImpl implements SmsCodeService { | @@ -71,7 +69,7 @@ public class SmsCodeServiceImpl implements SmsCodeService { | ||
| 71 | // 创建验证码记录 | 69 | // 创建验证码记录 |
| 72 | String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1)); | 70 | String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1)); |
| 73 | SmsCodeDO newSmsCode = SmsCodeDO.builder().mobile(mobile).code(code).scene(scene) | 71 | SmsCodeDO newSmsCode = SmsCodeDO.builder().mobile(mobile).code(code).scene(scene) |
| 74 | - .todayIndex(lastSmsCode != null && DateUtils.isToday(lastSmsCode.getCreateTime()) ? lastSmsCode.getTodayIndex() + 1 : 1) | 72 | + .todayIndex(lastSmsCode != null && isToday(lastSmsCode.getCreateTime()) ? lastSmsCode.getTodayIndex() + 1 : 1) |
| 75 | .createIp(ip).used(false).build(); | 73 | .createIp(ip).used(false).build(); |
| 76 | smsCodeMapper.insert(newSmsCode); | 74 | smsCodeMapper.insert(newSmsCode); |
| 77 | return code; | 75 | return code; |
| @@ -80,32 +78,32 @@ public class SmsCodeServiceImpl implements SmsCodeService { | @@ -80,32 +78,32 @@ public class SmsCodeServiceImpl implements SmsCodeService { | ||
| 80 | @Override | 78 | @Override |
| 81 | public void useSmsCode(SmsCodeUseReqDTO reqDTO) { | 79 | public void useSmsCode(SmsCodeUseReqDTO reqDTO) { |
| 82 | // 检测验证码是否有效 | 80 | // 检测验证码是否有效 |
| 83 | - SmsCodeDO lastSmsCode = this.checkSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene()); | 81 | + SmsCodeDO lastSmsCode = validateSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene()); |
| 84 | // 使用验证码 | 82 | // 使用验证码 |
| 85 | smsCodeMapper.updateById(SmsCodeDO.builder().id(lastSmsCode.getId()) | 83 | smsCodeMapper.updateById(SmsCodeDO.builder().id(lastSmsCode.getId()) |
| 86 | .used(true).usedTime(LocalDateTime.now()).usedIp(reqDTO.getUsedIp()).build()); | 84 | .used(true).usedTime(LocalDateTime.now()).usedIp(reqDTO.getUsedIp()).build()); |
| 87 | } | 85 | } |
| 88 | 86 | ||
| 89 | @Override | 87 | @Override |
| 90 | - public void checkSmsCode(SmsCodeCheckReqDTO reqDTO) { | ||
| 91 | - checkSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene()); | 88 | + public void validateSmsCode(SmsCodeValidateReqDTO reqDTO) { |
| 89 | + validateSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene()); | ||
| 92 | } | 90 | } |
| 93 | 91 | ||
| 94 | - public SmsCodeDO checkSmsCode0(String mobile, String code, Integer scene) { | 92 | + private SmsCodeDO validateSmsCode0(String mobile, String code, Integer scene) { |
| 95 | // 校验验证码 | 93 | // 校验验证码 |
| 96 | SmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, code, scene); | 94 | SmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, code, scene); |
| 97 | // 若验证码不存在,抛出异常 | 95 | // 若验证码不存在,抛出异常 |
| 98 | if (lastSmsCode == null) { | 96 | if (lastSmsCode == null) { |
| 99 | - throw ServiceExceptionUtil.exception(SMS_CODE_NOT_FOUND); | 97 | + throw exception(SMS_CODE_NOT_FOUND); |
| 100 | } | 98 | } |
| 101 | // 超过时间 | 99 | // 超过时间 |
| 102 | if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis() | 100 | if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis() |
| 103 | >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 | 101 | >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 |
| 104 | - throw ServiceExceptionUtil.exception(SMS_CODE_EXPIRED); | 102 | + throw exception(SMS_CODE_EXPIRED); |
| 105 | } | 103 | } |
| 106 | // 判断验证码是否已被使用 | 104 | // 判断验证码是否已被使用 |
| 107 | if (Boolean.TRUE.equals(lastSmsCode.getUsed())) { | 105 | if (Boolean.TRUE.equals(lastSmsCode.getUsed())) { |
| 108 | - throw ServiceExceptionUtil.exception(SMS_CODE_USED); | 106 | + throw exception(SMS_CODE_USED); |
| 109 | } | 107 | } |
| 110 | return lastSmsCode; | 108 | return lastSmsCode; |
| 111 | } | 109 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsSendServiceImpl.java
| @@ -66,7 +66,7 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -66,7 +66,7 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | // 执行发送 | 68 | // 执行发送 |
| 69 | - return this.sendSingleSms(mobile, userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams); | 69 | + return sendSingleSms(mobile, userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | @Override | 72 | @Override |
| @@ -76,21 +76,21 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -76,21 +76,21 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 76 | mobile = memberService.getMemberUserMobile(userId); | 76 | mobile = memberService.getMemberUserMobile(userId); |
| 77 | } | 77 | } |
| 78 | // 执行发送 | 78 | // 执行发送 |
| 79 | - return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); | 79 | + return sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | @Override | 82 | @Override |
| 83 | public Long sendSingleSms(String mobile, Long userId, Integer userType, | 83 | public Long sendSingleSms(String mobile, Long userId, Integer userType, |
| 84 | String templateCode, Map<String, Object> templateParams) { | 84 | String templateCode, Map<String, Object> templateParams) { |
| 85 | // 校验短信模板是否合法 | 85 | // 校验短信模板是否合法 |
| 86 | - SmsTemplateDO template = this.checkSmsTemplateValid(templateCode); | 86 | + SmsTemplateDO template = validateSmsTemplate(templateCode); |
| 87 | // 校验短信渠道是否合法 | 87 | // 校验短信渠道是否合法 |
| 88 | - SmsChannelDO smsChannel = this.checkSmsChannelValid(template.getChannelId()); | 88 | + SmsChannelDO smsChannel = validateSmsChannel(template.getChannelId()); |
| 89 | 89 | ||
| 90 | // 校验手机号码是否存在 | 90 | // 校验手机号码是否存在 |
| 91 | - mobile = this.checkMobile(mobile); | 91 | + mobile = validateMobile(mobile); |
| 92 | // 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志 | 92 | // 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志 |
| 93 | - List<KeyValue<String, Object>> newTemplateParams = this.buildTemplateParams(template, templateParams); | 93 | + List<KeyValue<String, Object>> newTemplateParams = buildTemplateParams(template, templateParams); |
| 94 | 94 | ||
| 95 | // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 | 95 | // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 |
| 96 | Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()) | 96 | Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()) |
| @@ -108,7 +108,7 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -108,7 +108,7 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | @VisibleForTesting | 110 | @VisibleForTesting |
| 111 | - public SmsChannelDO checkSmsChannelValid(Long channelId) { | 111 | + SmsChannelDO validateSmsChannel(Long channelId) { |
| 112 | // 获得短信模板。考虑到效率,从缓存中获取 | 112 | // 获得短信模板。考虑到效率,从缓存中获取 |
| 113 | SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId); | 113 | SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId); |
| 114 | // 短信模板不存在 | 114 | // 短信模板不存在 |
| @@ -119,7 +119,7 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -119,7 +119,7 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | @VisibleForTesting | 121 | @VisibleForTesting |
| 122 | - public SmsTemplateDO checkSmsTemplateValid(String templateCode) { | 122 | + SmsTemplateDO validateSmsTemplate(String templateCode) { |
| 123 | // 获得短信模板。考虑到效率,从缓存中获取 | 123 | // 获得短信模板。考虑到效率,从缓存中获取 |
| 124 | SmsTemplateDO template = smsTemplateService.getSmsTemplateByCodeFromCache(templateCode); | 124 | SmsTemplateDO template = smsTemplateService.getSmsTemplateByCodeFromCache(templateCode); |
| 125 | // 短信模板不存在 | 125 | // 短信模板不存在 |
| @@ -139,7 +139,7 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -139,7 +139,7 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 139 | * @return 处理后的参数 | 139 | * @return 处理后的参数 |
| 140 | */ | 140 | */ |
| 141 | @VisibleForTesting | 141 | @VisibleForTesting |
| 142 | - public List<KeyValue<String, Object>> buildTemplateParams(SmsTemplateDO template, Map<String, Object> templateParams) { | 142 | + List<KeyValue<String, Object>> buildTemplateParams(SmsTemplateDO template, Map<String, Object> templateParams) { |
| 143 | return template.getParams().stream().map(key -> { | 143 | return template.getParams().stream().map(key -> { |
| 144 | Object value = templateParams.get(key); | 144 | Object value = templateParams.get(key); |
| 145 | if (value == null) { | 145 | if (value == null) { |
| @@ -150,7 +150,7 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -150,7 +150,7 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | @VisibleForTesting | 152 | @VisibleForTesting |
| 153 | - public String checkMobile(String mobile) { | 153 | + public String validateMobile(String mobile) { |
| 154 | if (StrUtil.isEmpty(mobile)) { | 154 | if (StrUtil.isEmpty(mobile)) { |
| 155 | throw exception(SMS_SEND_MOBILE_NOT_EXISTS); | 155 | throw exception(SMS_SEND_MOBILE_NOT_EXISTS); |
| 156 | } | 156 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java
| @@ -105,11 +105,11 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | @@ -105,11 +105,11 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | ||
| 105 | @Override | 105 | @Override |
| 106 | public Long createSmsTemplate(SmsTemplateCreateReqVO createReqVO) { | 106 | public Long createSmsTemplate(SmsTemplateCreateReqVO createReqVO) { |
| 107 | // 校验短信渠道 | 107 | // 校验短信渠道 |
| 108 | - SmsChannelDO channelDO = checkSmsChannel(createReqVO.getChannelId()); | 108 | + SmsChannelDO channelDO = validateSmsChannel(createReqVO.getChannelId()); |
| 109 | // 校验短信编码是否重复 | 109 | // 校验短信编码是否重复 |
| 110 | - checkSmsTemplateCodeDuplicate(null, createReqVO.getCode()); | 110 | + validateSmsTemplateCodeDuplicate(null, createReqVO.getCode()); |
| 111 | // 校验短信模板 | 111 | // 校验短信模板 |
| 112 | - checkApiTemplate(createReqVO.getChannelId(), createReqVO.getApiTemplateId()); | 112 | + validateApiTemplate(createReqVO.getChannelId(), createReqVO.getApiTemplateId()); |
| 113 | 113 | ||
| 114 | // 插入 | 114 | // 插入 |
| 115 | SmsTemplateDO template = SmsTemplateConvert.INSTANCE.convert(createReqVO); | 115 | SmsTemplateDO template = SmsTemplateConvert.INSTANCE.convert(createReqVO); |
| @@ -125,13 +125,13 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | @@ -125,13 +125,13 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | ||
| 125 | @Override | 125 | @Override |
| 126 | public void updateSmsTemplate(SmsTemplateUpdateReqVO updateReqVO) { | 126 | public void updateSmsTemplate(SmsTemplateUpdateReqVO updateReqVO) { |
| 127 | // 校验存在 | 127 | // 校验存在 |
| 128 | - this.validateSmsTemplateExists(updateReqVO.getId()); | 128 | + validateSmsTemplateExists(updateReqVO.getId()); |
| 129 | // 校验短信渠道 | 129 | // 校验短信渠道 |
| 130 | - SmsChannelDO channelDO = checkSmsChannel(updateReqVO.getChannelId()); | 130 | + SmsChannelDO channelDO = validateSmsChannel(updateReqVO.getChannelId()); |
| 131 | // 校验短信编码是否重复 | 131 | // 校验短信编码是否重复 |
| 132 | - checkSmsTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode()); | 132 | + validateSmsTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode()); |
| 133 | // 校验短信模板 | 133 | // 校验短信模板 |
| 134 | - checkApiTemplate(updateReqVO.getChannelId(), updateReqVO.getApiTemplateId()); | 134 | + validateApiTemplate(updateReqVO.getChannelId(), updateReqVO.getApiTemplateId()); |
| 135 | 135 | ||
| 136 | // 更新 | 136 | // 更新 |
| 137 | SmsTemplateDO updateObj = SmsTemplateConvert.INSTANCE.convert(updateReqVO); | 137 | SmsTemplateDO updateObj = SmsTemplateConvert.INSTANCE.convert(updateReqVO); |
| @@ -145,7 +145,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | @@ -145,7 +145,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | ||
| 145 | @Override | 145 | @Override |
| 146 | public void deleteSmsTemplate(Long id) { | 146 | public void deleteSmsTemplate(Long id) { |
| 147 | // 校验存在 | 147 | // 校验存在 |
| 148 | - this.validateSmsTemplateExists(id); | 148 | + validateSmsTemplateExists(id); |
| 149 | // 更新 | 149 | // 更新 |
| 150 | smsTemplateMapper.deleteById(id); | 150 | smsTemplateMapper.deleteById(id); |
| 151 | // 发送刷新消息 | 151 | // 发送刷新消息 |
| @@ -184,7 +184,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | @@ -184,7 +184,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | ||
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | @VisibleForTesting | 186 | @VisibleForTesting |
| 187 | - public SmsChannelDO checkSmsChannel(Long channelId) { | 187 | + public SmsChannelDO validateSmsChannel(Long channelId) { |
| 188 | SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId); | 188 | SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId); |
| 189 | if (channelDO == null) { | 189 | if (channelDO == null) { |
| 190 | throw exception(SMS_CHANNEL_NOT_EXISTS); | 190 | throw exception(SMS_CHANNEL_NOT_EXISTS); |
| @@ -196,7 +196,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | @@ -196,7 +196,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | ||
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | @VisibleForTesting | 198 | @VisibleForTesting |
| 199 | - public void checkSmsTemplateCodeDuplicate(Long id, String code) { | 199 | + public void validateSmsTemplateCodeDuplicate(Long id, String code) { |
| 200 | SmsTemplateDO template = smsTemplateMapper.selectByCode(code); | 200 | SmsTemplateDO template = smsTemplateMapper.selectByCode(code); |
| 201 | if (template == null) { | 201 | if (template == null) { |
| 202 | return; | 202 | return; |
| @@ -217,7 +217,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | @@ -217,7 +217,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { | ||
| 217 | * @param apiTemplateId API 模板编号 | 217 | * @param apiTemplateId API 模板编号 |
| 218 | */ | 218 | */ |
| 219 | @VisibleForTesting | 219 | @VisibleForTesting |
| 220 | - public void checkApiTemplate(Long channelId, String apiTemplateId) { | 220 | + public void validateApiTemplate(Long channelId, String apiTemplateId) { |
| 221 | // 获得短信模板 | 221 | // 获得短信模板 |
| 222 | SmsClient smsClient = smsClientFactory.getSmsClient(channelId); | 222 | SmsClient smsClient = smsClientFactory.getSmsClient(channelId); |
| 223 | Assert.notNull(smsClient, String.format("短信客户端(%d) 不存在", channelId)); | 223 | Assert.notNull(smsClient, String.format("短信客户端(%d) 不存在", channelId)); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java
| @@ -64,9 +64,9 @@ public class TenantPackageServiceImpl implements TenantPackageService { | @@ -64,9 +64,9 @@ public class TenantPackageServiceImpl implements TenantPackageService { | ||
| 64 | @Override | 64 | @Override |
| 65 | public void deleteTenantPackage(Long id) { | 65 | public void deleteTenantPackage(Long id) { |
| 66 | // 校验存在 | 66 | // 校验存在 |
| 67 | - this.validateTenantPackageExists(id); | 67 | + validateTenantPackageExists(id); |
| 68 | // 校验正在使用 | 68 | // 校验正在使用 |
| 69 | - this.validateTenantUsed(id); | 69 | + validateTenantUsed(id); |
| 70 | // 删除 | 70 | // 删除 |
| 71 | tenantPackageMapper.deleteById(id); | 71 | tenantPackageMapper.deleteById(id); |
| 72 | } | 72 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java
| @@ -75,7 +75,7 @@ public class TenantServiceImpl implements TenantService { | @@ -75,7 +75,7 @@ public class TenantServiceImpl implements TenantService { | ||
| 75 | private PermissionService permissionService; | 75 | private PermissionService permissionService; |
| 76 | 76 | ||
| 77 | @Override | 77 | @Override |
| 78 | - public List<Long> getTenantIds() { | 78 | + public List<Long> getTenantIdList() { |
| 79 | List<TenantDO> tenants = tenantMapper.selectList(); | 79 | List<TenantDO> tenants = tenantMapper.selectList(); |
| 80 | return CollectionUtils.convertList(tenants, TenantDO::getId); | 80 | return CollectionUtils.convertList(tenants, TenantDO::getId); |
| 81 | } | 81 | } |
| @@ -138,7 +138,7 @@ public class TenantServiceImpl implements TenantService { | @@ -138,7 +138,7 @@ public class TenantServiceImpl implements TenantService { | ||
| 138 | @Transactional(rollbackFor = Exception.class) | 138 | @Transactional(rollbackFor = Exception.class) |
| 139 | public void updateTenant(TenantUpdateReqVO updateReqVO) { | 139 | public void updateTenant(TenantUpdateReqVO updateReqVO) { |
| 140 | // 校验存在 | 140 | // 校验存在 |
| 141 | - TenantDO tenant = checkUpdateTenant(updateReqVO.getId()); | 141 | + TenantDO tenant = validateUpdateTenant(updateReqVO.getId()); |
| 142 | // 校验套餐被禁用 | 142 | // 校验套餐被禁用 |
| 143 | TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); | 143 | TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); |
| 144 | 144 | ||
| @@ -156,7 +156,7 @@ public class TenantServiceImpl implements TenantService { | @@ -156,7 +156,7 @@ public class TenantServiceImpl implements TenantService { | ||
| 156 | public void updateTenantRoleMenu(Long tenantId, Set<Long> menuIds) { | 156 | public void updateTenantRoleMenu(Long tenantId, Set<Long> menuIds) { |
| 157 | TenantUtils.execute(tenantId, () -> { | 157 | TenantUtils.execute(tenantId, () -> { |
| 158 | // 获得所有角色 | 158 | // 获得所有角色 |
| 159 | - List<RoleDO> roles = roleService.getRoles(null); | 159 | + List<RoleDO> roles = roleService.getRoleListByStatus(null); |
| 160 | roles.forEach(role -> Assert.isTrue(tenantId.equals(role.getTenantId()), "角色({}/{}) 租户不匹配", | 160 | roles.forEach(role -> Assert.isTrue(tenantId.equals(role.getTenantId()), "角色({}/{}) 租户不匹配", |
| 161 | role.getId(), role.getTenantId(), tenantId)); // 兜底校验 | 161 | role.getId(), role.getTenantId(), tenantId)); // 兜底校验 |
| 162 | // 重新分配每个角色的权限 | 162 | // 重新分配每个角色的权限 |
| @@ -179,12 +179,12 @@ public class TenantServiceImpl implements TenantService { | @@ -179,12 +179,12 @@ public class TenantServiceImpl implements TenantService { | ||
| 179 | @Override | 179 | @Override |
| 180 | public void deleteTenant(Long id) { | 180 | public void deleteTenant(Long id) { |
| 181 | // 校验存在 | 181 | // 校验存在 |
| 182 | - checkUpdateTenant(id); | 182 | + validateUpdateTenant(id); |
| 183 | // 删除 | 183 | // 删除 |
| 184 | tenantMapper.deleteById(id); | 184 | tenantMapper.deleteById(id); |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | - private TenantDO checkUpdateTenant(Long id) { | 187 | + private TenantDO validateUpdateTenant(Long id) { |
| 188 | TenantDO tenant = tenantMapper.selectById(id); | 188 | TenantDO tenant = tenantMapper.selectById(id); |
| 189 | if (tenant == null) { | 189 | if (tenant == null) { |
| 190 | throw exception(TENANT_NOT_EXISTS); | 190 | throw exception(TENANT_NOT_EXISTS); |
| @@ -248,7 +248,7 @@ public class TenantServiceImpl implements TenantService { | @@ -248,7 +248,7 @@ public class TenantServiceImpl implements TenantService { | ||
| 248 | TenantDO tenant = getTenant(TenantContextHolder.getRequiredTenantId()); | 248 | TenantDO tenant = getTenant(TenantContextHolder.getRequiredTenantId()); |
| 249 | Set<Long> menuIds; | 249 | Set<Long> menuIds; |
| 250 | if (isSystemTenant(tenant)) { // 系统租户,菜单是全量的 | 250 | if (isSystemTenant(tenant)) { // 系统租户,菜单是全量的 |
| 251 | - menuIds = CollectionUtils.convertSet(menuService.getMenus(), MenuDO::getId); | 251 | + menuIds = CollectionUtils.convertSet(menuService.getMenuList(), MenuDO::getId); |
| 252 | } else { | 252 | } else { |
| 253 | menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds(); | 253 | menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds(); |
| 254 | } | 254 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
| @@ -127,7 +127,7 @@ public interface AdminUserService { | @@ -127,7 +127,7 @@ public interface AdminUserService { | ||
| 127 | * @param deptIds 部门数组 | 127 | * @param deptIds 部门数组 |
| 128 | * @return 用户数组 | 128 | * @return 用户数组 |
| 129 | */ | 129 | */ |
| 130 | - List<AdminUserDO> getUsersByDeptIds(Collection<Long> deptIds); | 130 | + List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds); |
| 131 | 131 | ||
| 132 | /** | 132 | /** |
| 133 | * 获得指定岗位的用户数组 | 133 | * 获得指定岗位的用户数组 |
| @@ -135,7 +135,7 @@ public interface AdminUserService { | @@ -135,7 +135,7 @@ public interface AdminUserService { | ||
| 135 | * @param postIds 岗位数组 | 135 | * @param postIds 岗位数组 |
| 136 | * @return 用户数组 | 136 | * @return 用户数组 |
| 137 | */ | 137 | */ |
| 138 | - List<AdminUserDO> getUsersByPostIds(Collection<Long> postIds); | 138 | + List<AdminUserDO> getUserListByPostIds(Collection<Long> postIds); |
| 139 | 139 | ||
| 140 | /** | 140 | /** |
| 141 | * 获得用户列表 | 141 | * 获得用户列表 |
| @@ -143,7 +143,7 @@ public interface AdminUserService { | @@ -143,7 +143,7 @@ public interface AdminUserService { | ||
| 143 | * @param ids 用户编号数组 | 143 | * @param ids 用户编号数组 |
| 144 | * @return 用户列表 | 144 | * @return 用户列表 |
| 145 | */ | 145 | */ |
| 146 | - List<AdminUserDO> getUsers(Collection<Long> ids); | 146 | + List<AdminUserDO> getUserList(Collection<Long> ids); |
| 147 | 147 | ||
| 148 | /** | 148 | /** |
| 149 | * 校验用户们是否有效。如下情况,视为无效: | 149 | * 校验用户们是否有效。如下情况,视为无效: |
| @@ -152,7 +152,7 @@ public interface AdminUserService { | @@ -152,7 +152,7 @@ public interface AdminUserService { | ||
| 152 | * | 152 | * |
| 153 | * @param ids 用户编号数组 | 153 | * @param ids 用户编号数组 |
| 154 | */ | 154 | */ |
| 155 | - void validUsers(Set<Long> ids); | 155 | + void validateUserList(Collection<Long> ids); |
| 156 | 156 | ||
| 157 | /** | 157 | /** |
| 158 | * 获得用户 Map | 158 | * 获得用户 Map |
| @@ -164,7 +164,7 @@ public interface AdminUserService { | @@ -164,7 +164,7 @@ public interface AdminUserService { | ||
| 164 | if (CollUtil.isEmpty(ids)) { | 164 | if (CollUtil.isEmpty(ids)) { |
| 165 | return new HashMap<>(); | 165 | return new HashMap<>(); |
| 166 | } | 166 | } |
| 167 | - return CollectionUtils.convertMap(getUsers(ids), AdminUserDO::getId); | 167 | + return CollectionUtils.convertMap(getUserList(ids), AdminUserDO::getId); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | /** | 170 | /** |
| @@ -173,7 +173,7 @@ public interface AdminUserService { | @@ -173,7 +173,7 @@ public interface AdminUserService { | ||
| 173 | * @param reqVO 列表请求 | 173 | * @param reqVO 列表请求 |
| 174 | * @return 用户列表 | 174 | * @return 用户列表 |
| 175 | */ | 175 | */ |
| 176 | - List<AdminUserDO> getUsers(UserExportReqVO reqVO); | 176 | + List<AdminUserDO> getUserList(UserExportReqVO reqVO); |
| 177 | 177 | ||
| 178 | /** | 178 | /** |
| 179 | * 获得用户列表,基于昵称模糊匹配 | 179 | * 获得用户列表,基于昵称模糊匹配 |
| @@ -181,15 +181,7 @@ public interface AdminUserService { | @@ -181,15 +181,7 @@ public interface AdminUserService { | ||
| 181 | * @param nickname 昵称 | 181 | * @param nickname 昵称 |
| 182 | * @return 用户列表 | 182 | * @return 用户列表 |
| 183 | */ | 183 | */ |
| 184 | - List<AdminUserDO> getUsersByNickname(String nickname); | ||
| 185 | - | ||
| 186 | - /** | ||
| 187 | - * 获得用户列表,基于用户账号模糊匹配 | ||
| 188 | - * | ||
| 189 | - * @param username 用户账号 | ||
| 190 | - * @return 用户列表 | ||
| 191 | - */ | ||
| 192 | - List<AdminUserDO> getUsersByUsername(String username); | 184 | + List<AdminUserDO> getUserListByNickname(String nickname); |
| 193 | 185 | ||
| 194 | /** | 186 | /** |
| 195 | * 批量导入用户 | 187 | * 批量导入用户 |
| @@ -198,7 +190,7 @@ public interface AdminUserService { | @@ -198,7 +190,7 @@ public interface AdminUserService { | ||
| 198 | * @param isUpdateSupport 是否支持更新 | 190 | * @param isUpdateSupport 是否支持更新 |
| 199 | * @return 导入结果 | 191 | * @return 导入结果 |
| 200 | */ | 192 | */ |
| 201 | - UserImportRespVO importUsers(List<UserImportExcelVO> importUsers, boolean isUpdateSupport); | 193 | + UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport); |
| 202 | 194 | ||
| 203 | /** | 195 | /** |
| 204 | * 获得指定状态的用户们 | 196 | * 获得指定状态的用户们 |
| @@ -206,7 +198,7 @@ public interface AdminUserService { | @@ -206,7 +198,7 @@ public interface AdminUserService { | ||
| 206 | * @param status 状态 | 198 | * @param status 状态 |
| 207 | * @return 用户们 | 199 | * @return 用户们 |
| 208 | */ | 200 | */ |
| 209 | - List<AdminUserDO> getUsersByStatus(Integer status); | 201 | + List<AdminUserDO> getUserListByStatus(Integer status); |
| 210 | 202 | ||
| 211 | /** | 203 | /** |
| 212 | * 判断密码是否匹配 | 204 | * 判断密码是否匹配 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
| @@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | @@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 8 | import cn.iocoder.yudao.framework.common.exception.ServiceException; | 8 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 11 | -import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; | 11 | +import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils; |
| 12 | import cn.iocoder.yudao.module.infra.api.file.FileApi; | 12 | import cn.iocoder.yudao.module.infra.api.file.FileApi; |
| 13 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; | 13 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; |
| 14 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; | 14 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; |
| @@ -43,6 +43,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | @@ -43,6 +43,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | ||
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | * 后台用户 Service 实现类 | 45 | * 后台用户 Service 实现类 |
| 46 | + * | ||
| 46 | * @author 芋道源码 | 47 | * @author 芋道源码 |
| 47 | */ | 48 | */ |
| 48 | @Service("adminUserService") | 49 | @Service("adminUserService") |
| @@ -73,10 +74,6 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -73,10 +74,6 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 73 | @Resource | 74 | @Resource |
| 74 | private FileApi fileApi; | 75 | private FileApi fileApi; |
| 75 | 76 | ||
| 76 | - @Resource | ||
| 77 | - @Lazy // 循环依赖(自己依赖自己),避免报错 | ||
| 78 | - private AdminUserServiceImpl self; | ||
| 79 | - | ||
| 80 | @Override | 77 | @Override |
| 81 | @Transactional(rollbackFor = Exception.class) | 78 | @Transactional(rollbackFor = Exception.class) |
| 82 | public Long createUser(UserCreateReqVO reqVO) { | 79 | public Long createUser(UserCreateReqVO reqVO) { |
| @@ -88,7 +85,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -88,7 +85,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 88 | } | 85 | } |
| 89 | }); | 86 | }); |
| 90 | // 校验正确性 | 87 | // 校验正确性 |
| 91 | - self.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | 88 | + validateUserForCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), |
| 92 | reqVO.getDeptId(), reqVO.getPostIds()); | 89 | reqVO.getDeptId(), reqVO.getPostIds()); |
| 93 | // 插入用户 | 90 | // 插入用户 |
| 94 | AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); | 91 | AdminUserDO user = UserConvert.INSTANCE.convert(reqVO); |
| @@ -107,7 +104,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -107,7 +104,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 107 | @Transactional(rollbackFor = Exception.class) | 104 | @Transactional(rollbackFor = Exception.class) |
| 108 | public void updateUser(UserUpdateReqVO reqVO) { | 105 | public void updateUser(UserUpdateReqVO reqVO) { |
| 109 | // 校验正确性 | 106 | // 校验正确性 |
| 110 | - self.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | 107 | + validateUserForCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), |
| 111 | reqVO.getDeptId(), reqVO.getPostIds()); | 108 | reqVO.getDeptId(), reqVO.getPostIds()); |
| 112 | // 更新用户 | 109 | // 更新用户 |
| 113 | AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); | 110 | AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO); |
| @@ -141,9 +138,9 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -141,9 +138,9 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 141 | @Override | 138 | @Override |
| 142 | public void updateUserProfile(Long id, UserProfileUpdateReqVO reqVO) { | 139 | public void updateUserProfile(Long id, UserProfileUpdateReqVO reqVO) { |
| 143 | // 校验正确性 | 140 | // 校验正确性 |
| 144 | - checkUserExists(id); | ||
| 145 | - checkEmailUnique(id, reqVO.getEmail()); | ||
| 146 | - checkMobileUnique(id, reqVO.getMobile()); | 141 | + validateUserExists(id); |
| 142 | + validateEmailUnique(id, reqVO.getEmail()); | ||
| 143 | + validateMobileUnique(id, reqVO.getMobile()); | ||
| 147 | // 执行更新 | 144 | // 执行更新 |
| 148 | userMapper.updateById(UserConvert.INSTANCE.convert(reqVO).setId(id)); | 145 | userMapper.updateById(UserConvert.INSTANCE.convert(reqVO).setId(id)); |
| 149 | } | 146 | } |
| @@ -151,7 +148,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -151,7 +148,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 151 | @Override | 148 | @Override |
| 152 | public void updateUserPassword(Long id, UserProfileUpdatePasswordReqVO reqVO) { | 149 | public void updateUserPassword(Long id, UserProfileUpdatePasswordReqVO reqVO) { |
| 153 | // 校验旧密码密码 | 150 | // 校验旧密码密码 |
| 154 | - checkOldPassword(id, reqVO.getOldPassword()); | 151 | + validateOldPassword(id, reqVO.getOldPassword()); |
| 155 | // 执行更新 | 152 | // 执行更新 |
| 156 | AdminUserDO updateObj = new AdminUserDO().setId(id); | 153 | AdminUserDO updateObj = new AdminUserDO().setId(id); |
| 157 | updateObj.setPassword(encodePassword(reqVO.getNewPassword())); // 加密密码 | 154 | updateObj.setPassword(encodePassword(reqVO.getNewPassword())); // 加密密码 |
| @@ -160,7 +157,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -160,7 +157,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 160 | 157 | ||
| 161 | @Override | 158 | @Override |
| 162 | public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception { | 159 | public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception { |
| 163 | - checkUserExists(id); | 160 | + validateUserExists(id); |
| 164 | // 存储文件 | 161 | // 存储文件 |
| 165 | String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile)); | 162 | String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile)); |
| 166 | // 更新路径 | 163 | // 更新路径 |
| @@ -174,7 +171,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -174,7 +171,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 174 | @Override | 171 | @Override |
| 175 | public void updateUserPassword(Long id, String password) { | 172 | public void updateUserPassword(Long id, String password) { |
| 176 | // 校验用户存在 | 173 | // 校验用户存在 |
| 177 | - checkUserExists(id); | 174 | + validateUserExists(id); |
| 178 | // 更新密码 | 175 | // 更新密码 |
| 179 | AdminUserDO updateObj = new AdminUserDO(); | 176 | AdminUserDO updateObj = new AdminUserDO(); |
| 180 | updateObj.setId(id); | 177 | updateObj.setId(id); |
| @@ -185,7 +182,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -185,7 +182,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 185 | @Override | 182 | @Override |
| 186 | public void updateUserStatus(Long id, Integer status) { | 183 | public void updateUserStatus(Long id, Integer status) { |
| 187 | // 校验用户存在 | 184 | // 校验用户存在 |
| 188 | - checkUserExists(id); | 185 | + validateUserExists(id); |
| 189 | // 更新状态 | 186 | // 更新状态 |
| 190 | AdminUserDO updateObj = new AdminUserDO(); | 187 | AdminUserDO updateObj = new AdminUserDO(); |
| 191 | updateObj.setId(id); | 188 | updateObj.setId(id); |
| @@ -197,7 +194,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -197,7 +194,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 197 | @Transactional(rollbackFor = Exception.class) | 194 | @Transactional(rollbackFor = Exception.class) |
| 198 | public void deleteUser(Long id) { | 195 | public void deleteUser(Long id) { |
| 199 | // 校验用户存在 | 196 | // 校验用户存在 |
| 200 | - checkUserExists(id); | 197 | + validateUserExists(id); |
| 201 | // 删除用户 | 198 | // 删除用户 |
| 202 | userMapper.deleteById(id); | 199 | userMapper.deleteById(id); |
| 203 | // 删除用户关联数据 | 200 | // 删除用户关联数据 |
| @@ -227,7 +224,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -227,7 +224,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 227 | } | 224 | } |
| 228 | 225 | ||
| 229 | @Override | 226 | @Override |
| 230 | - public List<AdminUserDO> getUsersByDeptIds(Collection<Long> deptIds) { | 227 | + public List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds) { |
| 231 | if (CollUtil.isEmpty(deptIds)) { | 228 | if (CollUtil.isEmpty(deptIds)) { |
| 232 | return Collections.emptyList(); | 229 | return Collections.emptyList(); |
| 233 | } | 230 | } |
| @@ -235,7 +232,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -235,7 +232,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 235 | } | 232 | } |
| 236 | 233 | ||
| 237 | @Override | 234 | @Override |
| 238 | - public List<AdminUserDO> getUsersByPostIds(Collection<Long> postIds) { | 235 | + public List<AdminUserDO> getUserListByPostIds(Collection<Long> postIds) { |
| 239 | if (CollUtil.isEmpty(postIds)) { | 236 | if (CollUtil.isEmpty(postIds)) { |
| 240 | return Collections.emptyList(); | 237 | return Collections.emptyList(); |
| 241 | } | 238 | } |
| @@ -247,7 +244,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -247,7 +244,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 247 | } | 244 | } |
| 248 | 245 | ||
| 249 | @Override | 246 | @Override |
| 250 | - public List<AdminUserDO> getUsers(Collection<Long> ids) { | 247 | + public List<AdminUserDO> getUserList(Collection<Long> ids) { |
| 251 | if (CollUtil.isEmpty(ids)) { | 248 | if (CollUtil.isEmpty(ids)) { |
| 252 | return Collections.emptyList(); | 249 | return Collections.emptyList(); |
| 253 | } | 250 | } |
| @@ -255,7 +252,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -255,7 +252,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 255 | } | 252 | } |
| 256 | 253 | ||
| 257 | @Override | 254 | @Override |
| 258 | - public void validUsers(Set<Long> ids) { | 255 | + public void validateUserList(Collection<Long> ids) { |
| 259 | if (CollUtil.isEmpty(ids)) { | 256 | if (CollUtil.isEmpty(ids)) { |
| 260 | return; | 257 | return; |
| 261 | } | 258 | } |
| @@ -275,20 +272,15 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -275,20 +272,15 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 275 | } | 272 | } |
| 276 | 273 | ||
| 277 | @Override | 274 | @Override |
| 278 | - public List<AdminUserDO> getUsers(UserExportReqVO reqVO) { | 275 | + public List<AdminUserDO> getUserList(UserExportReqVO reqVO) { |
| 279 | return userMapper.selectList(reqVO, getDeptCondition(reqVO.getDeptId())); | 276 | return userMapper.selectList(reqVO, getDeptCondition(reqVO.getDeptId())); |
| 280 | } | 277 | } |
| 281 | 278 | ||
| 282 | @Override | 279 | @Override |
| 283 | - public List<AdminUserDO> getUsersByNickname(String nickname) { | 280 | + public List<AdminUserDO> getUserListByNickname(String nickname) { |
| 284 | return userMapper.selectListByNickname(nickname); | 281 | return userMapper.selectListByNickname(nickname); |
| 285 | } | 282 | } |
| 286 | 283 | ||
| 287 | - @Override | ||
| 288 | - public List<AdminUserDO> getUsersByUsername(String username) { | ||
| 289 | - return userMapper.selectListByUsername(username); | ||
| 290 | - } | ||
| 291 | - | ||
| 292 | /** | 284 | /** |
| 293 | * 获得部门条件:查询指定部门的子部门编号们,包括自身 | 285 | * 获得部门条件:查询指定部门的子部门编号们,包括自身 |
| 294 | * @param deptId 部门编号 | 286 | * @param deptId 部门编号 |
| @@ -298,31 +290,33 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -298,31 +290,33 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 298 | if (deptId == null) { | 290 | if (deptId == null) { |
| 299 | return Collections.emptySet(); | 291 | return Collections.emptySet(); |
| 300 | } | 292 | } |
| 301 | - Set<Long> deptIds = convertSet(deptService.getDeptsByParentIdFromCache( | 293 | + Set<Long> deptIds = convertSet(deptService.getDeptListByParentIdFromCache( |
| 302 | deptId, true), DeptDO::getId); | 294 | deptId, true), DeptDO::getId); |
| 303 | deptIds.add(deptId); // 包括自身 | 295 | deptIds.add(deptId); // 包括自身 |
| 304 | return deptIds; | 296 | return deptIds; |
| 305 | } | 297 | } |
| 306 | 298 | ||
| 307 | - @DataPermission(enable = false) // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确 | ||
| 308 | - public void checkCreateOrUpdate(Long id, String username, String mobile, String email, | ||
| 309 | - Long deptId, Set<Long> postIds) { | ||
| 310 | - // 校验用户存在 | ||
| 311 | - checkUserExists(id); | ||
| 312 | - // 校验用户名唯一 | ||
| 313 | - checkUsernameUnique(id, username); | ||
| 314 | - // 校验手机号唯一 | ||
| 315 | - checkMobileUnique(id, mobile); | ||
| 316 | - // 校验邮箱唯一 | ||
| 317 | - checkEmailUnique(id, email); | ||
| 318 | - // 校验部门处于开启状态 | ||
| 319 | - deptService.validDepts(CollectionUtils.singleton(deptId)); | ||
| 320 | - // 校验岗位处于开启状态 | ||
| 321 | - postService.validPosts(postIds); | 299 | + private void validateUserForCreateOrUpdate(Long id, String username, String mobile, String email, |
| 300 | + Long deptId, Set<Long> postIds) { | ||
| 301 | + // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确 | ||
| 302 | + DataPermissionUtils.executeIgnore(() -> { | ||
| 303 | + // 校验用户存在 | ||
| 304 | + validateUserExists(id); | ||
| 305 | + // 校验用户名唯一 | ||
| 306 | + validateUsernameUnique(id, username); | ||
| 307 | + // 校验手机号唯一 | ||
| 308 | + validateMobileUnique(id, mobile); | ||
| 309 | + // 校验邮箱唯一 | ||
| 310 | + validateEmailUnique(id, email); | ||
| 311 | + // 校验部门处于开启状态 | ||
| 312 | + deptService.validateDeptList(CollectionUtils.singleton(deptId)); | ||
| 313 | + // 校验岗位处于开启状态 | ||
| 314 | + postService.validatePostList(postIds); | ||
| 315 | + }); | ||
| 322 | } | 316 | } |
| 323 | 317 | ||
| 324 | @VisibleForTesting | 318 | @VisibleForTesting |
| 325 | - public void checkUserExists(Long id) { | 319 | + void validateUserExists(Long id) { |
| 326 | if (id == null) { | 320 | if (id == null) { |
| 327 | return; | 321 | return; |
| 328 | } | 322 | } |
| @@ -333,7 +327,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -333,7 +327,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 333 | } | 327 | } |
| 334 | 328 | ||
| 335 | @VisibleForTesting | 329 | @VisibleForTesting |
| 336 | - public void checkUsernameUnique(Long id, String username) { | 330 | + void validateUsernameUnique(Long id, String username) { |
| 337 | if (StrUtil.isBlank(username)) { | 331 | if (StrUtil.isBlank(username)) { |
| 338 | return; | 332 | return; |
| 339 | } | 333 | } |
| @@ -351,7 +345,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -351,7 +345,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 351 | } | 345 | } |
| 352 | 346 | ||
| 353 | @VisibleForTesting | 347 | @VisibleForTesting |
| 354 | - public void checkEmailUnique(Long id, String email) { | 348 | + void validateEmailUnique(Long id, String email) { |
| 355 | if (StrUtil.isBlank(email)) { | 349 | if (StrUtil.isBlank(email)) { |
| 356 | return; | 350 | return; |
| 357 | } | 351 | } |
| @@ -369,7 +363,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -369,7 +363,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 369 | } | 363 | } |
| 370 | 364 | ||
| 371 | @VisibleForTesting | 365 | @VisibleForTesting |
| 372 | - public void checkMobileUnique(Long id, String mobile) { | 366 | + void validateMobileUnique(Long id, String mobile) { |
| 373 | if (StrUtil.isBlank(mobile)) { | 367 | if (StrUtil.isBlank(mobile)) { |
| 374 | return; | 368 | return; |
| 375 | } | 369 | } |
| @@ -392,7 +386,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -392,7 +386,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 392 | * @param oldPassword 旧密码 | 386 | * @param oldPassword 旧密码 |
| 393 | */ | 387 | */ |
| 394 | @VisibleForTesting | 388 | @VisibleForTesting |
| 395 | - public void checkOldPassword(Long id, String oldPassword) { | 389 | + void validateOldPassword(Long id, String oldPassword) { |
| 396 | AdminUserDO user = userMapper.selectById(id); | 390 | AdminUserDO user = userMapper.selectById(id); |
| 397 | if (user == null) { | 391 | if (user == null) { |
| 398 | throw exception(USER_NOT_EXISTS); | 392 | throw exception(USER_NOT_EXISTS); |
| @@ -404,7 +398,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -404,7 +398,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 404 | 398 | ||
| 405 | @Override | 399 | @Override |
| 406 | @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入 | 400 | @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入 |
| 407 | - public UserImportRespVO importUsers(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) { | 401 | + public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) { |
| 408 | if (CollUtil.isEmpty(importUsers)) { | 402 | if (CollUtil.isEmpty(importUsers)) { |
| 409 | throw exception(USER_IMPORT_LIST_IS_EMPTY); | 403 | throw exception(USER_IMPORT_LIST_IS_EMPTY); |
| 410 | } | 404 | } |
| @@ -413,7 +407,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -413,7 +407,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 413 | importUsers.forEach(importUser -> { | 407 | importUsers.forEach(importUser -> { |
| 414 | // 校验,判断是否有不符合的原因 | 408 | // 校验,判断是否有不符合的原因 |
| 415 | try { | 409 | try { |
| 416 | - checkCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(), | 410 | + validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(), |
| 417 | importUser.getDeptId(), null); | 411 | importUser.getDeptId(), null); |
| 418 | } catch (ServiceException ex) { | 412 | } catch (ServiceException ex) { |
| 419 | respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage()); | 413 | respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage()); |
| @@ -441,7 +435,7 @@ public class AdminUserServiceImpl implements AdminUserService { | @@ -441,7 +435,7 @@ public class AdminUserServiceImpl implements AdminUserService { | ||
| 441 | } | 435 | } |
| 442 | 436 | ||
| 443 | @Override | 437 | @Override |
| 444 | - public List<AdminUserDO> getUsersByStatus(Integer status) { | 438 | + public List<AdminUserDO> getUserListByStatus(Integer status) { |
| 445 | return userMapper.selectListByStatus(status); | 439 | return userMapper.selectListByStatus(status); |
| 446 | } | 440 | } |
| 447 | 441 |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java
| 1 | package cn.iocoder.yudao.module.system.service.auth; | 1 | package cn.iocoder.yudao.module.system.service.auth; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ReflectUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 6 | -import cn.iocoder.yudao.framework.test.core.util.AssertUtils; | ||
| 7 | import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; | 7 | import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; |
| 8 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | ||
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*; | ||
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; |
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 10 | import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; | 12 | import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; |
| 11 | import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; | 13 | import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; |
| 14 | +import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; | ||
| 15 | +import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | ||
| 12 | import cn.iocoder.yudao.module.system.service.logger.LoginLogService; | 16 | import cn.iocoder.yudao.module.system.service.logger.LoginLogService; |
| 13 | import cn.iocoder.yudao.module.system.service.member.MemberService; | 17 | import cn.iocoder.yudao.module.system.service.member.MemberService; |
| 14 | import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; | 18 | import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; |
| 15 | import cn.iocoder.yudao.module.system.service.social.SocialUserService; | 19 | import cn.iocoder.yudao.module.system.service.social.SocialUserService; |
| 16 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; | 20 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 21 | +import com.xingyuv.captcha.model.common.ResponseModel; | ||
| 17 | import com.xingyuv.captcha.service.CaptchaService; | 22 | import com.xingyuv.captcha.service.CaptchaService; |
| 23 | +import org.junit.jupiter.api.BeforeEach; | ||
| 18 | import org.junit.jupiter.api.Test; | 24 | import org.junit.jupiter.api.Test; |
| 19 | import org.springframework.boot.test.mock.mockito.MockBean; | 25 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 20 | import org.springframework.context.annotation.Import; | 26 | import org.springframework.context.annotation.Import; |
| 21 | 27 | ||
| 22 | import javax.annotation.Resource; | 28 | import javax.annotation.Resource; |
| 29 | +import javax.validation.ConstraintViolationException; | ||
| 30 | +import javax.validation.Validation; | ||
| 23 | import javax.validation.Validator; | 31 | import javax.validation.Validator; |
| 24 | 32 | ||
| 33 | +import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 34 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 35 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | ||
| 26 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 36 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | 37 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; |
| 28 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 38 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 39 | +import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 40 | +import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| 29 | import static org.mockito.ArgumentMatchers.eq; | 41 | import static org.mockito.ArgumentMatchers.eq; |
| 30 | import static org.mockito.Mockito.*; | 42 | import static org.mockito.Mockito.*; |
| 31 | 43 | ||
| @@ -42,17 +54,24 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | @@ -42,17 +54,24 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | ||
| 42 | @MockBean | 54 | @MockBean |
| 43 | private LoginLogService loginLogService; | 55 | private LoginLogService loginLogService; |
| 44 | @MockBean | 56 | @MockBean |
| 45 | - private SocialUserService socialService; | 57 | + private SocialUserService socialUserService; |
| 46 | @MockBean | 58 | @MockBean |
| 47 | private SmsCodeApi smsCodeApi; | 59 | private SmsCodeApi smsCodeApi; |
| 48 | @MockBean | 60 | @MockBean |
| 49 | private OAuth2TokenService oauth2TokenService; | 61 | private OAuth2TokenService oauth2TokenService; |
| 50 | @MockBean | 62 | @MockBean |
| 51 | private MemberService memberService; | 63 | private MemberService memberService; |
| 52 | - | ||
| 53 | @MockBean | 64 | @MockBean |
| 54 | private Validator validator; | 65 | private Validator validator; |
| 55 | 66 | ||
| 67 | + @BeforeEach | ||
| 68 | + public void setUp() { | ||
| 69 | + ReflectUtil.setFieldValue(authService, "captchaEnable", true); | ||
| 70 | + // 注入一个 Validator 对象 | ||
| 71 | + ReflectUtil.setFieldValue(authService, "validator", | ||
| 72 | + Validation.buildDefaultValidatorFactory().getValidator()); | ||
| 73 | + } | ||
| 74 | + | ||
| 56 | @Test | 75 | @Test |
| 57 | public void testAuthenticate_success() { | 76 | public void testAuthenticate_success() { |
| 58 | // 准备参数 | 77 | // 准备参数 |
| @@ -78,7 +97,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | @@ -78,7 +97,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | ||
| 78 | String password = randomString(); | 97 | String password = randomString(); |
| 79 | 98 | ||
| 80 | // 调用, 并断言异常 | 99 | // 调用, 并断言异常 |
| 81 | - AssertUtils.assertServiceException(() -> authService.authenticate(username, password), | 100 | + assertServiceException(() -> authService.authenticate(username, password), |
| 82 | AUTH_LOGIN_BAD_CREDENTIALS); | 101 | AUTH_LOGIN_BAD_CREDENTIALS); |
| 83 | verify(loginLogService).createLoginLog( | 102 | verify(loginLogService).createLoginLog( |
| 84 | argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | 103 | argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| @@ -98,7 +117,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | @@ -98,7 +117,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | ||
| 98 | when(userService.getUserByUsername(eq(username))).thenReturn(user); | 117 | when(userService.getUserByUsername(eq(username))).thenReturn(user); |
| 99 | 118 | ||
| 100 | // 调用, 并断言异常 | 119 | // 调用, 并断言异常 |
| 101 | - AssertUtils.assertServiceException(() -> authService.authenticate(username, password), | 120 | + assertServiceException(() -> authService.authenticate(username, password), |
| 102 | AUTH_LOGIN_BAD_CREDENTIALS); | 121 | AUTH_LOGIN_BAD_CREDENTIALS); |
| 103 | verify(loginLogService).createLoginLog( | 122 | verify(loginLogService).createLoginLog( |
| 104 | argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | 123 | argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| @@ -120,7 +139,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | @@ -120,7 +139,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | ||
| 120 | when(userService.isPasswordMatch(eq(password), eq(user.getPassword()))).thenReturn(true); | 139 | when(userService.isPasswordMatch(eq(password), eq(user.getPassword()))).thenReturn(true); |
| 121 | 140 | ||
| 122 | // 调用, 并断言异常 | 141 | // 调用, 并断言异常 |
| 123 | - AssertUtils.assertServiceException(() -> authService.authenticate(username, password), | 142 | + assertServiceException(() -> authService.authenticate(username, password), |
| 124 | AUTH_LOGIN_USER_DISABLED); | 143 | AUTH_LOGIN_USER_DISABLED); |
| 125 | verify(loginLogService).createLoginLog( | 144 | verify(loginLogService).createLoginLog( |
| 126 | argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | 145 | argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) |
| @@ -129,82 +148,194 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | @@ -129,82 +148,194 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | ||
| 129 | ); | 148 | ); |
| 130 | } | 149 | } |
| 131 | 150 | ||
| 132 | -// @Test | ||
| 133 | -// public void testCaptcha_success() { | ||
| 134 | -// // 准备参数 | ||
| 135 | -// AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class); | ||
| 136 | -// | ||
| 137 | -// // mock 验证码正确 | ||
| 138 | -// when(captchaService.getCaptchaCode(reqVO.getUuid())).thenReturn(reqVO.getCode()); | ||
| 139 | -// | ||
| 140 | -// // 调用 | ||
| 141 | -// authService.verifyCaptcha(reqVO); | ||
| 142 | -// // 断言 | ||
| 143 | -// verify(captchaService).deleteCaptchaCode(reqVO.getUuid()); | ||
| 144 | -// } | ||
| 145 | -// | ||
| 146 | -// @Test | ||
| 147 | -// public void testCaptcha_notFound() { | ||
| 148 | -// // 准备参数 | ||
| 149 | -// AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class); | ||
| 150 | -// | ||
| 151 | -// // 调用, 并断言异常 | ||
| 152 | -// assertServiceException(() -> authService.verifyCaptcha(reqVO), AUTH_LOGIN_CAPTCHA_NOT_FOUND); | ||
| 153 | -// // 校验调用参数 | ||
| 154 | -// verify(loginLogService, times(1)).createLoginLog( | ||
| 155 | -// argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | ||
| 156 | -// && o.getResult().equals(LoginResultEnum.CAPTCHA_NOT_FOUND.getResult())) | ||
| 157 | -// ); | ||
| 158 | -// } | ||
| 159 | - | ||
| 160 | -// @Test | ||
| 161 | -// public void testCaptcha_codeError() { | ||
| 162 | -// // 准备参数 | ||
| 163 | -// AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class); | ||
| 164 | -// | ||
| 165 | -// // mock 验证码不正确 | ||
| 166 | -// String code = randomString(); | ||
| 167 | -// when(captchaService.getCaptchaCode(reqVO.getUuid())).thenReturn(code); | ||
| 168 | -// | ||
| 169 | -// // 调用, 并断言异常 | ||
| 170 | -// assertServiceException(() -> authService.verifyCaptcha(reqVO), AUTH_LOGIN_CAPTCHA_CODE_ERROR); | ||
| 171 | -// // 校验调用参数 | ||
| 172 | -// verify(loginLogService).createLoginLog( | ||
| 173 | -// argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | ||
| 174 | -// && o.getResult().equals(LoginResultEnum.CAPTCHA_CODE_ERROR.getResult())) | ||
| 175 | -// ); | ||
| 176 | -// } | ||
| 177 | - | ||
| 178 | -// @Test | ||
| 179 | -// public void testLogin_success() { | ||
| 180 | -// // 准备参数 | ||
| 181 | -// AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class, o -> | ||
| 182 | -// o.setUsername("test_username").setPassword("test_password")); | ||
| 183 | -// | ||
| 184 | -// // mock 验证码正确 | ||
| 185 | -// when(captchaService.getCaptchaCode(reqVO.getUuid())).thenReturn(reqVO.getCode()); | ||
| 186 | -// // mock user 数据 | ||
| 187 | -// AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(1L).setUsername("test_username") | ||
| 188 | -// .setPassword("test_password").setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 189 | -// when(userService.getUserByUsername(eq("test_username"))).thenReturn(user); | ||
| 190 | -// // mock password 匹配 | ||
| 191 | -// when(userService.isPasswordMatch(eq("test_password"), eq(user.getPassword()))).thenReturn(true); | ||
| 192 | -// // mock 缓存登录用户到 Redis | ||
| 193 | -// OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class, o -> o.setUserId(1L) | ||
| 194 | -// .setUserType(UserTypeEnum.ADMIN.getValue())); | ||
| 195 | -// when(oauth2TokenService.createAccessToken(eq(1L), eq(UserTypeEnum.ADMIN.getValue()), eq("default"), isNull())) | ||
| 196 | -// .thenReturn(accessTokenDO); | ||
| 197 | -// | ||
| 198 | -// // 调用, 并断言异常 | ||
| 199 | -// AuthLoginRespVO loginRespVO = authService.login(reqVO); | ||
| 200 | -// assertPojoEquals(accessTokenDO, loginRespVO); | ||
| 201 | -// // 校验调用参数 | ||
| 202 | -// verify(loginLogService).createLoginLog( | ||
| 203 | -// argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | ||
| 204 | -// && o.getResult().equals(LoginResultEnum.SUCCESS.getResult()) | ||
| 205 | -// && o.getUserId().equals(user.getId())) | ||
| 206 | -// ); | ||
| 207 | -// } | 151 | + @Test |
| 152 | + public void testLogin_success() { | ||
| 153 | + // 准备参数 | ||
| 154 | + AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class, o -> | ||
| 155 | + o.setUsername("test_username").setPassword("test_password") | ||
| 156 | + .setSocialType(randomEle(SocialTypeEnum.values()).getType())); | ||
| 157 | + | ||
| 158 | + // mock 验证码正确 | ||
| 159 | + ReflectUtil.setFieldValue(authService, "captchaEnable", false); | ||
| 160 | + // mock user 数据 | ||
| 161 | + AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(1L).setUsername("test_username") | ||
| 162 | + .setPassword("test_password").setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 163 | + when(userService.getUserByUsername(eq("test_username"))).thenReturn(user); | ||
| 164 | + // mock password 匹配 | ||
| 165 | + when(userService.isPasswordMatch(eq("test_password"), eq(user.getPassword()))).thenReturn(true); | ||
| 166 | + // mock 缓存登录用户到 Redis | ||
| 167 | + OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class, o -> o.setUserId(1L) | ||
| 168 | + .setUserType(UserTypeEnum.ADMIN.getValue())); | ||
| 169 | + when(oauth2TokenService.createAccessToken(eq(1L), eq(UserTypeEnum.ADMIN.getValue()), eq("default"), isNull())) | ||
| 170 | + .thenReturn(accessTokenDO); | ||
| 171 | + | ||
| 172 | + // 调用,并校验 | ||
| 173 | + AuthLoginRespVO loginRespVO = authService.login(reqVO); | ||
| 174 | + assertPojoEquals(accessTokenDO, loginRespVO); | ||
| 175 | + // 校验调用参数 | ||
| 176 | + verify(loginLogService).createLoginLog( | ||
| 177 | + argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | ||
| 178 | + && o.getResult().equals(LoginResultEnum.SUCCESS.getResult()) | ||
| 179 | + && o.getUserId().equals(user.getId())) | ||
| 180 | + ); | ||
| 181 | + verify(socialUserService).bindSocialUser(eq(new SocialUserBindReqDTO( | ||
| 182 | + user.getId(), UserTypeEnum.ADMIN.getValue(), | ||
| 183 | + reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()))); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + @Test | ||
| 187 | + public void testSendSmsCode() { | ||
| 188 | + // 准备参数 | ||
| 189 | + String mobile = randomString(); | ||
| 190 | + Integer scene = randomEle(SmsSceneEnum.values()).getScene(); | ||
| 191 | + AuthSmsSendReqVO reqVO = new AuthSmsSendReqVO(mobile, scene); | ||
| 192 | + // mock 方法(用户信息) | ||
| 193 | + AdminUserDO user = randomPojo(AdminUserDO.class); | ||
| 194 | + when(userService.getUserByMobile(eq(mobile))).thenReturn(user); | ||
| 195 | + | ||
| 196 | + // 调用 | ||
| 197 | + authService.sendSmsCode(reqVO); | ||
| 198 | + // 断言 | ||
| 199 | + verify(smsCodeApi).sendSmsCode(argThat(sendReqDTO -> { | ||
| 200 | + assertEquals(mobile, sendReqDTO.getMobile()); | ||
| 201 | + assertEquals(scene, sendReqDTO.getScene()); | ||
| 202 | + return true; | ||
| 203 | + })); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + @Test | ||
| 207 | + public void testSmsLogin_success() { | ||
| 208 | + // 准备参数 | ||
| 209 | + String mobile = randomString(); | ||
| 210 | + String scene = randomString(); | ||
| 211 | + AuthSmsLoginReqVO reqVO = new AuthSmsLoginReqVO(mobile, scene); | ||
| 212 | + // mock 方法(用户信息) | ||
| 213 | + AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(1L)); | ||
| 214 | + when(userService.getUserByMobile(eq(mobile))).thenReturn(user); | ||
| 215 | + // mock 缓存登录用户到 Redis | ||
| 216 | + OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class, o -> o.setUserId(1L) | ||
| 217 | + .setUserType(UserTypeEnum.ADMIN.getValue())); | ||
| 218 | + when(oauth2TokenService.createAccessToken(eq(1L), eq(UserTypeEnum.ADMIN.getValue()), eq("default"), isNull())) | ||
| 219 | + .thenReturn(accessTokenDO); | ||
| 220 | + | ||
| 221 | + // 调用,并断言 | ||
| 222 | + AuthLoginRespVO loginRespVO = authService.smsLogin(reqVO); | ||
| 223 | + assertPojoEquals(accessTokenDO, loginRespVO); | ||
| 224 | + // 断言调用 | ||
| 225 | + verify(loginLogService).createLoginLog( | ||
| 226 | + argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_MOBILE.getType()) | ||
| 227 | + && o.getResult().equals(LoginResultEnum.SUCCESS.getResult()) | ||
| 228 | + && o.getUserId().equals(user.getId())) | ||
| 229 | + ); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + @Test | ||
| 233 | + public void testSocialLogin_success() { | ||
| 234 | + // 准备参数 | ||
| 235 | + AuthSocialLoginReqVO reqVO = randomPojo(AuthSocialLoginReqVO.class); | ||
| 236 | + // mock 方法(绑定的用户编号) | ||
| 237 | + Long userId = 1L; | ||
| 238 | + when(socialUserService.getBindUserId(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()), | ||
| 239 | + eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(userId); | ||
| 240 | + // mock(用户) | ||
| 241 | + AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(userId)); | ||
| 242 | + when(userService.getUser(eq(userId))).thenReturn(user); | ||
| 243 | + // mock 缓存登录用户到 Redis | ||
| 244 | + OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class, o -> o.setUserId(1L) | ||
| 245 | + .setUserType(UserTypeEnum.ADMIN.getValue())); | ||
| 246 | + when(oauth2TokenService.createAccessToken(eq(1L), eq(UserTypeEnum.ADMIN.getValue()), eq("default"), isNull())) | ||
| 247 | + .thenReturn(accessTokenDO); | ||
| 248 | + | ||
| 249 | + // 调用,并断言 | ||
| 250 | + AuthLoginRespVO loginRespVO = authService.socialLogin(reqVO); | ||
| 251 | + assertPojoEquals(accessTokenDO, loginRespVO); | ||
| 252 | + // 断言调用 | ||
| 253 | + verify(loginLogService).createLoginLog( | ||
| 254 | + argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_SOCIAL.getType()) | ||
| 255 | + && o.getResult().equals(LoginResultEnum.SUCCESS.getResult()) | ||
| 256 | + && o.getUserId().equals(user.getId())) | ||
| 257 | + ); | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + @Test | ||
| 261 | + public void testValidateCaptcha_successWithEnable() { | ||
| 262 | + // 准备参数 | ||
| 263 | + AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class); | ||
| 264 | + | ||
| 265 | + // mock 验证码打开 | ||
| 266 | + ReflectUtil.setFieldValue(authService, "captchaEnable", true); | ||
| 267 | + // mock 验证通过 | ||
| 268 | + when(captchaService.verification(argThat(captchaVO -> { | ||
| 269 | + assertEquals(reqVO.getCaptchaVerification(), captchaVO.getCaptchaVerification()); | ||
| 270 | + return true; | ||
| 271 | + }))).thenReturn(ResponseModel.success()); | ||
| 272 | + | ||
| 273 | + // 调用,无需断言 | ||
| 274 | + authService.validateCaptcha(reqVO); | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + @Test | ||
| 278 | + public void testValidateCaptcha_successWithDisable() { | ||
| 279 | + // 准备参数 | ||
| 280 | + AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class); | ||
| 281 | + | ||
| 282 | + // mock 验证码关闭 | ||
| 283 | + ReflectUtil.setFieldValue(authService, "captchaEnable", false); | ||
| 284 | + | ||
| 285 | + // 调用,无需断言 | ||
| 286 | + authService.validateCaptcha(reqVO); | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + @Test | ||
| 290 | + public void testValidateCaptcha_constraintViolationException() { | ||
| 291 | + // 准备参数 | ||
| 292 | + AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class).setCaptchaVerification(null); | ||
| 293 | + | ||
| 294 | + // mock 验证码打开 | ||
| 295 | + ReflectUtil.setFieldValue(authService, "captchaEnable", true); | ||
| 296 | + | ||
| 297 | + // 调用,并断言异常 | ||
| 298 | + assertThrows(ConstraintViolationException.class, () -> authService.validateCaptcha(reqVO), | ||
| 299 | + "验证码不能为空"); | ||
| 300 | + } | ||
| 301 | + | ||
| 302 | + | ||
| 303 | + @Test | ||
| 304 | + public void testCaptcha_fail() { | ||
| 305 | + // 准备参数 | ||
| 306 | + AuthLoginReqVO reqVO = randomPojo(AuthLoginReqVO.class); | ||
| 307 | + | ||
| 308 | + // mock 验证码打开 | ||
| 309 | + ReflectUtil.setFieldValue(authService, "captchaEnable", true); | ||
| 310 | + // mock 验证通过 | ||
| 311 | + when(captchaService.verification(argThat(captchaVO -> { | ||
| 312 | + assertEquals(reqVO.getCaptchaVerification(), captchaVO.getCaptchaVerification()); | ||
| 313 | + return true; | ||
| 314 | + }))).thenReturn(ResponseModel.errorMsg("就是不对")); | ||
| 315 | + | ||
| 316 | + // 调用, 并断言异常 | ||
| 317 | + assertServiceException(() -> authService.validateCaptcha(reqVO), AUTH_LOGIN_CAPTCHA_CODE_ERROR, "就是不对"); | ||
| 318 | + // 校验调用参数 | ||
| 319 | + verify(loginLogService).createLoginLog( | ||
| 320 | + argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGIN_USERNAME.getType()) | ||
| 321 | + && o.getResult().equals(LoginResultEnum.CAPTCHA_CODE_ERROR.getResult())) | ||
| 322 | + ); | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | + @Test | ||
| 326 | + public void testRefreshToken() { | ||
| 327 | + // 准备参数 | ||
| 328 | + String refreshToken = randomString(); | ||
| 329 | + // mock 方法 | ||
| 330 | + OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class); | ||
| 331 | + when(oauth2TokenService.refreshAccessToken(eq(refreshToken), eq("default"))) | ||
| 332 | + .thenReturn(accessTokenDO); | ||
| 333 | + | ||
| 334 | + // 调用 | ||
| 335 | + AuthLoginRespVO loginRespVO = authService.refreshToken(refreshToken); | ||
| 336 | + // 断言 | ||
| 337 | + assertPojoEquals(accessTokenDO, loginRespVO); | ||
| 338 | + } | ||
| 208 | 339 | ||
| 209 | @Test | 340 | @Test |
| 210 | public void testLogout_success() { | 341 | public void testLogout_success() { |
| @@ -221,6 +352,8 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | @@ -221,6 +352,8 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { | ||
| 221 | verify(loginLogService).createLoginLog(argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGOUT_SELF.getType()) | 352 | verify(loginLogService).createLoginLog(argThat(o -> o.getLogType().equals(LoginLogTypeEnum.LOGOUT_SELF.getType()) |
| 222 | && o.getResult().equals(LoginResultEnum.SUCCESS.getResult())) | 353 | && o.getResult().equals(LoginResultEnum.SUCCESS.getResult())) |
| 223 | ); | 354 | ); |
| 355 | + // 调用,并校验 | ||
| 356 | + | ||
| 224 | } | 357 | } |
| 225 | 358 | ||
| 226 | @Test | 359 | @Test |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceTest.java renamed to yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java
| @@ -19,6 +19,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; | @@ -19,6 +19,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 19 | import org.springframework.context.annotation.Import; | 19 | import org.springframework.context.annotation.Import; |
| 20 | 20 | ||
| 21 | import javax.annotation.Resource; | 21 | import javax.annotation.Resource; |
| 22 | +import java.util.Arrays; | ||
| 22 | import java.util.List; | 23 | import java.util.List; |
| 23 | import java.util.Map; | 24 | import java.util.Map; |
| 24 | import java.util.function.Consumer; | 25 | import java.util.function.Consumer; |
| @@ -28,8 +29,8 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq | @@ -28,8 +29,8 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq | ||
| 28 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 29 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 29 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 30 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 30 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 31 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 32 | +import static java.util.Collections.singletonList; | ||
| 31 | import static org.junit.jupiter.api.Assertions.*; | 33 | import static org.junit.jupiter.api.Assertions.*; |
| 32 | -import static org.mockito.Mockito.times; | ||
| 33 | import static org.mockito.Mockito.verify; | 34 | import static org.mockito.Mockito.verify; |
| 34 | 35 | ||
| 35 | /** | 36 | /** |
| @@ -38,7 +39,7 @@ import static org.mockito.Mockito.verify; | @@ -38,7 +39,7 @@ import static org.mockito.Mockito.verify; | ||
| 38 | * @author niudehua | 39 | * @author niudehua |
| 39 | */ | 40 | */ |
| 40 | @Import(DeptServiceImpl.class) | 41 | @Import(DeptServiceImpl.class) |
| 41 | -public class DeptServiceTest extends BaseDbUnitTest { | 42 | +public class DeptServiceImplTest extends BaseDbUnitTest { |
| 42 | 43 | ||
| 43 | @Resource | 44 | @Resource |
| 44 | private DeptServiceImpl deptService; | 45 | private DeptServiceImpl deptService; |
| @@ -76,7 +77,7 @@ public class DeptServiceTest extends BaseDbUnitTest { | @@ -76,7 +77,7 @@ public class DeptServiceTest extends BaseDbUnitTest { | ||
| 76 | } | 77 | } |
| 77 | 78 | ||
| 78 | @Test | 79 | @Test |
| 79 | - void testListDepts() { | 80 | + public void testListDepts() { |
| 80 | // mock 数据 | 81 | // mock 数据 |
| 81 | DeptDO dept = randomPojo(DeptDO.class, o -> { // 等会查询到 | 82 | DeptDO dept = randomPojo(DeptDO.class, o -> { // 等会查询到 |
| 82 | o.setName("开发部"); | 83 | o.setName("开发部"); |
| @@ -91,21 +92,22 @@ public class DeptServiceTest extends BaseDbUnitTest { | @@ -91,21 +92,22 @@ public class DeptServiceTest extends BaseDbUnitTest { | ||
| 91 | DeptListReqVO reqVO = new DeptListReqVO(); | 92 | DeptListReqVO reqVO = new DeptListReqVO(); |
| 92 | reqVO.setName("开"); | 93 | reqVO.setName("开"); |
| 93 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 94 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 95 | + | ||
| 94 | // 调用 | 96 | // 调用 |
| 95 | - List<DeptDO> sysDeptDOS = deptService.getSimpleDepts(reqVO); | 97 | + List<DeptDO> sysDeptDOS = deptService.getDeptList(reqVO); |
| 96 | // 断言 | 98 | // 断言 |
| 97 | assertEquals(1, sysDeptDOS.size()); | 99 | assertEquals(1, sysDeptDOS.size()); |
| 98 | assertPojoEquals(dept, sysDeptDOS.get(0)); | 100 | assertPojoEquals(dept, sysDeptDOS.get(0)); |
| 99 | } | 101 | } |
| 100 | 102 | ||
| 101 | @Test | 103 | @Test |
| 102 | - void testCreateDept_success() { | 104 | + public void testCreateDept_success() { |
| 103 | // 准备参数 | 105 | // 准备参数 |
| 104 | - DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, | ||
| 105 | - o -> { | ||
| 106 | - o.setParentId(DeptIdEnum.ROOT.getId()); | ||
| 107 | - o.setStatus(randomCommonStatus()); | ||
| 108 | - }); | 106 | + DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> { |
| 107 | + o.setParentId(DeptIdEnum.ROOT.getId()); | ||
| 108 | + o.setStatus(randomCommonStatus()); | ||
| 109 | + }); | ||
| 110 | + | ||
| 109 | // 调用 | 111 | // 调用 |
| 110 | Long deptId = deptService.createDept(reqVO); | 112 | Long deptId = deptService.createDept(reqVO); |
| 111 | // 断言 | 113 | // 断言 |
| @@ -114,11 +116,11 @@ public class DeptServiceTest extends BaseDbUnitTest { | @@ -114,11 +116,11 @@ public class DeptServiceTest extends BaseDbUnitTest { | ||
| 114 | DeptDO deptDO = deptMapper.selectById(deptId); | 116 | DeptDO deptDO = deptMapper.selectById(deptId); |
| 115 | assertPojoEquals(reqVO, deptDO); | 117 | assertPojoEquals(reqVO, deptDO); |
| 116 | // 校验调用 | 118 | // 校验调用 |
| 117 | - verify(deptProducer, times(1)).sendDeptRefreshMessage(); | 119 | + verify(deptProducer).sendDeptRefreshMessage(); |
| 118 | } | 120 | } |
| 119 | 121 | ||
| 120 | @Test | 122 | @Test |
| 121 | - void testUpdateDept_success() { | 123 | + public void testUpdateDept_success() { |
| 122 | // mock 数据 | 124 | // mock 数据 |
| 123 | DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); | 125 | DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); |
| 124 | deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 | 126 | deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 |
| @@ -129,28 +131,34 @@ public class DeptServiceTest extends BaseDbUnitTest { | @@ -129,28 +131,34 @@ public class DeptServiceTest extends BaseDbUnitTest { | ||
| 129 | o.setId(dbDeptDO.getId()); | 131 | o.setId(dbDeptDO.getId()); |
| 130 | o.setStatus(randomCommonStatus()); | 132 | o.setStatus(randomCommonStatus()); |
| 131 | }); | 133 | }); |
| 134 | + | ||
| 132 | // 调用 | 135 | // 调用 |
| 133 | deptService.updateDept(reqVO); | 136 | deptService.updateDept(reqVO); |
| 134 | // 校验是否更新正确 | 137 | // 校验是否更新正确 |
| 135 | DeptDO deptDO = deptMapper.selectById(reqVO.getId()); // 获取最新的 | 138 | DeptDO deptDO = deptMapper.selectById(reqVO.getId()); // 获取最新的 |
| 136 | assertPojoEquals(reqVO, deptDO); | 139 | assertPojoEquals(reqVO, deptDO); |
| 140 | + // 校验调用 | ||
| 141 | + verify(deptProducer).sendDeptRefreshMessage(); | ||
| 137 | } | 142 | } |
| 138 | 143 | ||
| 139 | @Test | 144 | @Test |
| 140 | - void testDeleteDept_success() { | 145 | + public void testDeleteDept_success() { |
| 141 | // mock 数据 | 146 | // mock 数据 |
| 142 | DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); | 147 | DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); |
| 143 | deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 | 148 | deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 |
| 144 | // 准备参数 | 149 | // 准备参数 |
| 145 | Long id = dbDeptDO.getId(); | 150 | Long id = dbDeptDO.getId(); |
| 151 | + | ||
| 146 | // 调用 | 152 | // 调用 |
| 147 | deptService.deleteDept(id); | 153 | deptService.deleteDept(id); |
| 148 | // 校验数据不存在了 | 154 | // 校验数据不存在了 |
| 149 | assertNull(deptMapper.selectById(id)); | 155 | assertNull(deptMapper.selectById(id)); |
| 156 | + // 校验调用 | ||
| 157 | + verify(deptProducer).sendDeptRefreshMessage(); | ||
| 150 | } | 158 | } |
| 151 | 159 | ||
| 152 | @Test | 160 | @Test |
| 153 | - void testCheckDept_nameDuplicateForUpdate() { | 161 | + public void testValidateDept_nameDuplicateForUpdate() { |
| 154 | // mock 数据 | 162 | // mock 数据 |
| 155 | DeptDO deptDO = randomDeptDO(); | 163 | DeptDO deptDO = randomDeptDO(); |
| 156 | // 设置根节点部门 | 164 | // 设置根节点部门 |
| @@ -162,37 +170,40 @@ public class DeptServiceTest extends BaseDbUnitTest { | @@ -162,37 +170,40 @@ public class DeptServiceTest extends BaseDbUnitTest { | ||
| 162 | nameDeptDO.setParentId(DeptIdEnum.ROOT.getId()); | 170 | nameDeptDO.setParentId(DeptIdEnum.ROOT.getId()); |
| 163 | deptMapper.insert(nameDeptDO); | 171 | deptMapper.insert(nameDeptDO); |
| 164 | // 准备参数 | 172 | // 准备参数 |
| 165 | - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, | ||
| 166 | - o -> { | ||
| 167 | - // 设置根节点部门 | ||
| 168 | - o.setParentId(DeptIdEnum.ROOT.getId()); | ||
| 169 | - // 设置更新的 ID | ||
| 170 | - o.setId(deptDO.getId()); | ||
| 171 | - // 模拟 name 重复 | ||
| 172 | - o.setName(nameDeptDO.getName()); | ||
| 173 | - }); | 173 | + DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { |
| 174 | + // 设置根节点部门 | ||
| 175 | + o.setParentId(DeptIdEnum.ROOT.getId()); | ||
| 176 | + // 设置更新的 ID | ||
| 177 | + o.setId(deptDO.getId()); | ||
| 178 | + // 模拟 name 重复 | ||
| 179 | + o.setName(nameDeptDO.getName()); | ||
| 180 | + }); | ||
| 181 | + | ||
| 174 | // 调用, 并断言异常 | 182 | // 调用, 并断言异常 |
| 175 | assertServiceException(() -> deptService.updateDept(reqVO), DEPT_NAME_DUPLICATE); | 183 | assertServiceException(() -> deptService.updateDept(reqVO), DEPT_NAME_DUPLICATE); |
| 176 | } | 184 | } |
| 177 | 185 | ||
| 178 | @Test | 186 | @Test |
| 179 | - void testCheckDept_parentNotExitsForCreate() { | 187 | + public void testValidateDept_parentNotExitsForCreate() { |
| 188 | + // 准备参数 | ||
| 180 | DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, | 189 | DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, |
| 181 | o -> o.setStatus(randomCommonStatus())); | 190 | o -> o.setStatus(randomCommonStatus())); |
| 191 | + | ||
| 182 | // 调用,并断言异常 | 192 | // 调用,并断言异常 |
| 183 | assertServiceException(() -> deptService.createDept(reqVO), DEPT_PARENT_NOT_EXITS); | 193 | assertServiceException(() -> deptService.createDept(reqVO), DEPT_PARENT_NOT_EXITS); |
| 184 | } | 194 | } |
| 185 | 195 | ||
| 186 | @Test | 196 | @Test |
| 187 | - void testCheckDept_notFoundForDelete() { | 197 | + public void testValidateDept_notFoundForDelete() { |
| 188 | // 准备参数 | 198 | // 准备参数 |
| 189 | Long id = randomLongId(); | 199 | Long id = randomLongId(); |
| 200 | + | ||
| 190 | // 调用, 并断言异常 | 201 | // 调用, 并断言异常 |
| 191 | assertServiceException(() -> deptService.deleteDept(id), DEPT_NOT_FOUND); | 202 | assertServiceException(() -> deptService.deleteDept(id), DEPT_NOT_FOUND); |
| 192 | } | 203 | } |
| 193 | 204 | ||
| 194 | @Test | 205 | @Test |
| 195 | - void testCheckDept_exitsChildrenForDelete() { | 206 | + public void testValidateDept_exitsChildrenForDelete() { |
| 196 | // mock 数据 | 207 | // mock 数据 |
| 197 | DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); | 208 | DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); |
| 198 | deptMapper.insert(parentDept);// @Sql: 先插入出一条存在的数据 | 209 | deptMapper.insert(parentDept);// @Sql: 先插入出一条存在的数据 |
| @@ -208,39 +219,39 @@ public class DeptServiceTest extends BaseDbUnitTest { | @@ -208,39 +219,39 @@ public class DeptServiceTest extends BaseDbUnitTest { | ||
| 208 | } | 219 | } |
| 209 | 220 | ||
| 210 | @Test | 221 | @Test |
| 211 | - void testCheckDept_parentErrorForUpdate() { | 222 | + public void testValidateDept_parentErrorForUpdate() { |
| 212 | // mock 数据 | 223 | // mock 数据 |
| 213 | DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); | 224 | DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); |
| 214 | deptMapper.insert(dbDeptDO); | 225 | deptMapper.insert(dbDeptDO); |
| 215 | // 准备参数 | 226 | // 准备参数 |
| 216 | - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, | ||
| 217 | - o -> { | ||
| 218 | - // 设置自己为父部门 | ||
| 219 | - o.setParentId(dbDeptDO.getId()); | ||
| 220 | - // 设置更新的 ID | ||
| 221 | - o.setId(dbDeptDO.getId()); | ||
| 222 | - }); | 227 | + DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { |
| 228 | + // 设置自己为父部门 | ||
| 229 | + o.setParentId(dbDeptDO.getId()); | ||
| 230 | + // 设置更新的 ID | ||
| 231 | + o.setId(dbDeptDO.getId()); | ||
| 232 | + }); | ||
| 233 | + | ||
| 223 | // 调用, 并断言异常 | 234 | // 调用, 并断言异常 |
| 224 | assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_ERROR); | 235 | assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_ERROR); |
| 225 | } | 236 | } |
| 226 | 237 | ||
| 227 | @Test | 238 | @Test |
| 228 | - void testCheckDept_notEnableForCreate() { | 239 | + public void testValidateDept_notEnableForCreate() { |
| 229 | // mock 数据 | 240 | // mock 数据 |
| 230 | DeptDO deptDO = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())); | 241 | DeptDO deptDO = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())); |
| 231 | deptMapper.insert(deptDO); | 242 | deptMapper.insert(deptDO); |
| 232 | // 准备参数 | 243 | // 准备参数 |
| 233 | - DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, | ||
| 234 | - o -> { | ||
| 235 | - // 设置未启用的部门为副部门 | ||
| 236 | - o.setParentId(deptDO.getId()); | ||
| 237 | - }); | 244 | + DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> { |
| 245 | + // 设置未启用的部门为父部门 | ||
| 246 | + o.setParentId(deptDO.getId()); | ||
| 247 | + }); | ||
| 248 | + | ||
| 238 | // 调用, 并断言异常 | 249 | // 调用, 并断言异常 |
| 239 | assertServiceException(() -> deptService.createDept(reqVO), DEPT_NOT_ENABLE); | 250 | assertServiceException(() -> deptService.createDept(reqVO), DEPT_NOT_ENABLE); |
| 240 | } | 251 | } |
| 241 | 252 | ||
| 242 | @Test | 253 | @Test |
| 243 | - void testCheckDept_parentIsChildForUpdate() { | 254 | + public void testCheckDept_parentIsChildForUpdate() { |
| 244 | // mock 数据 | 255 | // mock 数据 |
| 245 | DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); | 256 | DeptDO parentDept = randomPojo(DeptDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); |
| 246 | deptMapper.insert(parentDept); | 257 | deptMapper.insert(parentDept); |
| @@ -251,18 +262,84 @@ public class DeptServiceTest extends BaseDbUnitTest { | @@ -251,18 +262,84 @@ public class DeptServiceTest extends BaseDbUnitTest { | ||
| 251 | deptMapper.insert(childDept); | 262 | deptMapper.insert(childDept); |
| 252 | // 初始化本地缓存 | 263 | // 初始化本地缓存 |
| 253 | deptService.initLocalCache(); | 264 | deptService.initLocalCache(); |
| 265 | + | ||
| 254 | // 准备参数 | 266 | // 准备参数 |
| 255 | - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, | ||
| 256 | - o -> { | ||
| 257 | - // 设置自己的子部门为父部门 | ||
| 258 | - o.setParentId(childDept.getId()); | ||
| 259 | - // 设置更新的 ID | ||
| 260 | - o.setId(parentDept.getId()); | ||
| 261 | - }); | 267 | + DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { |
| 268 | + // 设置自己的子部门为父部门 | ||
| 269 | + o.setParentId(childDept.getId()); | ||
| 270 | + // 设置更新的 ID | ||
| 271 | + o.setId(parentDept.getId()); | ||
| 272 | + }); | ||
| 273 | + | ||
| 262 | // 调用, 并断言异常 | 274 | // 调用, 并断言异常 |
| 263 | assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_IS_CHILD); | 275 | assertServiceException(() -> deptService.updateDept(reqVO), DEPT_PARENT_IS_CHILD); |
| 264 | } | 276 | } |
| 265 | 277 | ||
| 278 | + @Test | ||
| 279 | + public void testGetDeptList() { | ||
| 280 | + // mock 数据 | ||
| 281 | + DeptDO deptDO01 = randomDeptDO(); | ||
| 282 | + deptMapper.insert(deptDO01); | ||
| 283 | + DeptDO deptDO02 = randomDeptDO(); | ||
| 284 | + deptMapper.insert(deptDO02); | ||
| 285 | + // 准备参数 | ||
| 286 | + List<Long> ids = Arrays.asList(deptDO01.getId(), deptDO02.getId()); | ||
| 287 | + | ||
| 288 | + // 调用 | ||
| 289 | + List<DeptDO> deptDOList = deptService.getDeptList(ids); | ||
| 290 | + // 断言 | ||
| 291 | + assertEquals(2, deptDOList.size()); | ||
| 292 | + assertEquals(deptDO01, deptDOList.get(0)); | ||
| 293 | + assertEquals(deptDO02, deptDOList.get(1)); | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + @Test | ||
| 297 | + public void testGetDept() { | ||
| 298 | + // mock 数据 | ||
| 299 | + DeptDO deptDO = randomDeptDO(); | ||
| 300 | + deptMapper.insert(deptDO); | ||
| 301 | + // 准备参数 | ||
| 302 | + Long id = deptDO.getId(); | ||
| 303 | + | ||
| 304 | + // 调用 | ||
| 305 | + DeptDO dbDept = deptService.getDept(id); | ||
| 306 | + // 断言 | ||
| 307 | + assertEquals(deptDO, dbDept); | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + @Test | ||
| 311 | + public void testValidateDeptList_success() { | ||
| 312 | + // mock 数据 | ||
| 313 | + DeptDO deptDO = randomDeptDO().setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 314 | + deptMapper.insert(deptDO); | ||
| 315 | + // 准备参数 | ||
| 316 | + List<Long> ids = singletonList(deptDO.getId()); | ||
| 317 | + | ||
| 318 | + // 调用,无需断言 | ||
| 319 | + deptService.validateDeptList(ids); | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + @Test | ||
| 323 | + public void testValidateDeptList_notFound() { | ||
| 324 | + // 准备参数 | ||
| 325 | + List<Long> ids = singletonList(randomLongId()); | ||
| 326 | + | ||
| 327 | + // 调用, 并断言异常 | ||
| 328 | + assertServiceException(() -> deptService.validateDeptList(ids), DEPT_NOT_FOUND); | ||
| 329 | + } | ||
| 330 | + | ||
| 331 | + @Test | ||
| 332 | + public void testValidateDeptList_notEnable() { | ||
| 333 | + // mock 数据 | ||
| 334 | + DeptDO deptDO = randomDeptDO().setStatus(CommonStatusEnum.DISABLE.getStatus()); | ||
| 335 | + deptMapper.insert(deptDO); | ||
| 336 | + // 准备参数 | ||
| 337 | + List<Long> ids = singletonList(deptDO.getId()); | ||
| 338 | + | ||
| 339 | + // 调用, 并断言异常 | ||
| 340 | + assertServiceException(() -> deptService.validateDeptList(ids), DEPT_NOT_ENABLE, deptDO.getName()); | ||
| 341 | + } | ||
| 342 | + | ||
| 266 | @SafeVarargs | 343 | @SafeVarargs |
| 267 | private static DeptDO randomDeptDO(Consumer<DeptDO>... consumers) { | 344 | private static DeptDO randomDeptDO(Consumer<DeptDO>... consumers) { |
| 268 | Consumer<DeptDO> consumer = (o) -> { | 345 | Consumer<DeptDO> consumer = (o) -> { |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceTest.java renamed to yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java
| 1 | package cn.iocoder.yudao.module.system.service.dept; | 1 | package cn.iocoder.yudao.module.system.service.dept; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 7 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 6 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO; |
| 9 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; |
| 10 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
| 11 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO; | 10 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO; |
| 11 | +import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | ||
| 12 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; | 12 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; |
| 13 | -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 14 | import org.junit.jupiter.api.Test; | 13 | import org.junit.jupiter.api.Test; |
| 15 | import org.springframework.context.annotation.Import; | 14 | import org.springframework.context.annotation.Import; |
| 16 | 15 | ||
| 17 | import javax.annotation.Resource; | 16 | import javax.annotation.Resource; |
| 17 | +import java.util.Arrays; | ||
| 18 | import java.util.List; | 18 | import java.util.List; |
| 19 | import java.util.function.Consumer; | 19 | import java.util.function.Consumer; |
| 20 | 20 | ||
| 21 | import static cn.hutool.core.util.RandomUtil.randomEle; | 21 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 22 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 22 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 23 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 23 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 24 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 24 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | ||
| 25 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 25 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 26 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 26 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 27 | +import static java.util.Collections.singletonList; | ||
| 27 | import static org.junit.jupiter.api.Assertions.*; | 28 | import static org.junit.jupiter.api.Assertions.*; |
| 28 | 29 | ||
| 30 | +/** | ||
| 31 | + * {@link PostServiceImpl} 的单元测试类 | ||
| 32 | + * | ||
| 33 | + * @author niudehua | ||
| 34 | + */ | ||
| 29 | @Import(PostServiceImpl.class) | 35 | @Import(PostServiceImpl.class) |
| 30 | -public class PostServiceTest extends BaseDbUnitTest { | 36 | +public class PostServiceImplTest extends BaseDbUnitTest { |
| 31 | 37 | ||
| 32 | @Resource | 38 | @Resource |
| 33 | private PostServiceImpl postService; | 39 | private PostServiceImpl postService; |
| 40 | + | ||
| 34 | @Resource | 41 | @Resource |
| 35 | private PostMapper postMapper; | 42 | private PostMapper postMapper; |
| 36 | 43 | ||
| 37 | @Test | 44 | @Test |
| 38 | - void testPagePosts() { | 45 | + public void testCreatePost_success() { |
| 46 | + // 准备参数 | ||
| 47 | + PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class, | ||
| 48 | + o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); | ||
| 49 | + // 调用 | ||
| 50 | + Long postId = postService.createPost(reqVO); | ||
| 51 | + | ||
| 52 | + // 断言 | ||
| 53 | + assertNotNull(postId); | ||
| 54 | + // 校验记录的属性是否正确 | ||
| 55 | + PostDO post = postMapper.selectById(postId); | ||
| 56 | + assertPojoEquals(reqVO, post); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Test | ||
| 60 | + public void testUpdatePost_success() { | ||
| 61 | + // mock 数据 | ||
| 62 | + PostDO postDO = randomPostDO(); | ||
| 63 | + postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 | ||
| 64 | + // 准备参数 | ||
| 65 | + PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> { | ||
| 66 | + // 设置更新的 ID | ||
| 67 | + o.setId(postDO.getId()); | ||
| 68 | + o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); | ||
| 69 | + }); | ||
| 70 | + | ||
| 71 | + // 调用 | ||
| 72 | + postService.updatePost(reqVO); | ||
| 73 | + // 校验是否更新正确 | ||
| 74 | + PostDO post = postMapper.selectById(reqVO.getId()); | ||
| 75 | + assertPojoEquals(reqVO, post); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Test | ||
| 79 | + public void testDeletePost_success() { | ||
| 80 | + // mock 数据 | ||
| 81 | + PostDO postDO = randomPostDO(); | ||
| 82 | + postMapper.insert(postDO); | ||
| 83 | + // 准备参数 | ||
| 84 | + Long id = postDO.getId(); | ||
| 85 | + | ||
| 86 | + // 调用 | ||
| 87 | + postService.deletePost(id); | ||
| 88 | + assertNull(postMapper.selectById(id)); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @Test | ||
| 92 | + public void testValidatePost_notFoundForDelete() { | ||
| 93 | + // 准备参数 | ||
| 94 | + Long id = randomLongId(); | ||
| 95 | + | ||
| 96 | + // 调用, 并断言异常 | ||
| 97 | + assertServiceException(() -> postService.deletePost(id), POST_NOT_FOUND); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Test | ||
| 101 | + public void testValidatePost_nameDuplicateForCreate() { | ||
| 102 | + // mock 数据 | ||
| 103 | + PostDO postDO = randomPostDO(); | ||
| 104 | + postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 | ||
| 105 | + // 准备参数 | ||
| 106 | + PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class, | ||
| 107 | + // 模拟 name 重复 | ||
| 108 | + o -> o.setName(postDO.getName())); | ||
| 109 | + assertServiceException(() -> postService.createPost(reqVO), POST_NAME_DUPLICATE); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @Test | ||
| 113 | + public void testValidatePost_codeDuplicateForUpdate() { | ||
| 114 | + // mock 数据 | ||
| 115 | + PostDO postDO = randomPostDO(); | ||
| 116 | + postMapper.insert(postDO); | ||
| 117 | + // mock 数据:稍后模拟重复它的 code | ||
| 118 | + PostDO codePostDO = randomPostDO(); | ||
| 119 | + postMapper.insert(codePostDO); | ||
| 120 | + // 准备参数 | ||
| 121 | + PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> { | ||
| 122 | + // 设置更新的 ID | ||
| 123 | + o.setId(postDO.getId()); | ||
| 124 | + // 模拟 code 重复 | ||
| 125 | + o.setCode(codePostDO.getCode()); | ||
| 126 | + }); | ||
| 127 | + | ||
| 128 | + // 调用, 并断言异常 | ||
| 129 | + assertServiceException(() -> postService.updatePost(reqVO), POST_CODE_DUPLICATE); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Test | ||
| 133 | + public void testGetPostPage() { | ||
| 39 | // mock 数据 | 134 | // mock 数据 |
| 40 | PostDO postDO = randomPojo(PostDO.class, o -> { | 135 | PostDO postDO = randomPojo(PostDO.class, o -> { |
| 41 | o.setName("码仔"); | 136 | o.setName("码仔"); |
| @@ -43,10 +138,9 @@ public class PostServiceTest extends BaseDbUnitTest { | @@ -43,10 +138,9 @@ public class PostServiceTest extends BaseDbUnitTest { | ||
| 43 | }); | 138 | }); |
| 44 | postMapper.insert(postDO); | 139 | postMapper.insert(postDO); |
| 45 | // 测试 name 不匹配 | 140 | // 测试 name 不匹配 |
| 46 | - postMapper.insert(ObjectUtils.cloneIgnoreId(postDO, o -> o.setName("程序员"))); | 141 | + postMapper.insert(cloneIgnoreId(postDO, o -> o.setName("程序员"))); |
| 47 | // 测试 status 不匹配 | 142 | // 测试 status 不匹配 |
| 48 | - postMapper.insert(ObjectUtils.cloneIgnoreId(postDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | ||
| 49 | - | 143 | + postMapper.insert(cloneIgnoreId(postDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 50 | // 准备参数 | 144 | // 准备参数 |
| 51 | PostPageReqVO reqVO = new PostPageReqVO(); | 145 | PostPageReqVO reqVO = new PostPageReqVO(); |
| 52 | reqVO.setName("码"); | 146 | reqVO.setName("码"); |
| @@ -54,7 +148,6 @@ public class PostServiceTest extends BaseDbUnitTest { | @@ -54,7 +148,6 @@ public class PostServiceTest extends BaseDbUnitTest { | ||
| 54 | 148 | ||
| 55 | // 调用 | 149 | // 调用 |
| 56 | PageResult<PostDO> pageResult = postService.getPostPage(reqVO); | 150 | PageResult<PostDO> pageResult = postService.getPostPage(reqVO); |
| 57 | - | ||
| 58 | // 断言 | 151 | // 断言 |
| 59 | assertEquals(1, pageResult.getTotal()); | 152 | assertEquals(1, pageResult.getTotal()); |
| 60 | assertEquals(1, pageResult.getList().size()); | 153 | assertEquals(1, pageResult.getList().size()); |
| @@ -62,7 +155,7 @@ public class PostServiceTest extends BaseDbUnitTest { | @@ -62,7 +155,7 @@ public class PostServiceTest extends BaseDbUnitTest { | ||
| 62 | } | 155 | } |
| 63 | 156 | ||
| 64 | @Test | 157 | @Test |
| 65 | - void testListPosts() { | 158 | + public void testGetPostList_export() { |
| 66 | // mock 数据 | 159 | // mock 数据 |
| 67 | PostDO postDO = randomPojo(PostDO.class, o -> { | 160 | PostDO postDO = randomPojo(PostDO.class, o -> { |
| 68 | o.setName("码仔"); | 161 | o.setName("码仔"); |
| @@ -70,124 +163,91 @@ public class PostServiceTest extends BaseDbUnitTest { | @@ -70,124 +163,91 @@ public class PostServiceTest extends BaseDbUnitTest { | ||
| 70 | }); | 163 | }); |
| 71 | postMapper.insert(postDO); | 164 | postMapper.insert(postDO); |
| 72 | // 测试 name 不匹配 | 165 | // 测试 name 不匹配 |
| 73 | - postMapper.insert(ObjectUtils.cloneIgnoreId(postDO, o -> o.setName("程序员"))); | 166 | + postMapper.insert(cloneIgnoreId(postDO, o -> o.setName("程序员"))); |
| 74 | // 测试 status 不匹配 | 167 | // 测试 status 不匹配 |
| 75 | - postMapper.insert(ObjectUtils.cloneIgnoreId(postDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 168 | + postMapper.insert(cloneIgnoreId(postDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 76 | // 准备参数 | 169 | // 准备参数 |
| 77 | PostExportReqVO reqVO = new PostExportReqVO(); | 170 | PostExportReqVO reqVO = new PostExportReqVO(); |
| 78 | reqVO.setName("码"); | 171 | reqVO.setName("码"); |
| 79 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 172 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 80 | 173 | ||
| 81 | // 调用 | 174 | // 调用 |
| 82 | - List<PostDO> list = postService.getPosts(reqVO); | 175 | + List<PostDO> list = postService.getPostList(reqVO); |
| 83 | // 断言 | 176 | // 断言 |
| 84 | assertEquals(1, list.size()); | 177 | assertEquals(1, list.size()); |
| 85 | assertPojoEquals(postDO, list.get(0)); | 178 | assertPojoEquals(postDO, list.get(0)); |
| 86 | } | 179 | } |
| 87 | 180 | ||
| 88 | @Test | 181 | @Test |
| 89 | - void testGetPost() { | 182 | + public void testGetPostList() { |
| 90 | // mock 数据 | 183 | // mock 数据 |
| 91 | - PostDO dbPostDO = randomPostDO(); | ||
| 92 | - postMapper.insert(dbPostDO); | 184 | + PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); |
| 185 | + postMapper.insert(postDO01); | ||
| 186 | + // 测试 status 不匹配 | ||
| 187 | + PostDO postDO02 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())); | ||
| 188 | + postMapper.insert(postDO02); | ||
| 93 | // 准备参数 | 189 | // 准备参数 |
| 94 | - Long id = dbPostDO.getId(); | ||
| 95 | - // 调用 | ||
| 96 | - PostDO post = postService.getPost(id); | ||
| 97 | - // 断言 | ||
| 98 | - assertNotNull(post); | ||
| 99 | - assertPojoEquals(dbPostDO, post); | ||
| 100 | - } | 190 | + List<Long> ids = Arrays.asList(postDO01.getId(), postDO02.getId()); |
| 101 | 191 | ||
| 102 | - @Test | ||
| 103 | - void testCreatePost_success() { | ||
| 104 | - // 准备参数 | ||
| 105 | - PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class, | ||
| 106 | - o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); | ||
| 107 | // 调用 | 192 | // 调用 |
| 108 | - Long postId = postService.createPost(reqVO); | 193 | + List<PostDO> list = postService.getPostList(ids, singletonList(CommonStatusEnum.ENABLE.getStatus())); |
| 109 | // 断言 | 194 | // 断言 |
| 110 | - assertNotNull(postId); | ||
| 111 | - // 校验记录的属性是否正确 | ||
| 112 | - PostDO post = postMapper.selectById(postId); | ||
| 113 | - assertPojoEquals(reqVO, post); | 195 | + assertEquals(1, list.size()); |
| 196 | + assertPojoEquals(postDO01, list.get(0)); | ||
| 114 | } | 197 | } |
| 115 | 198 | ||
| 116 | @Test | 199 | @Test |
| 117 | - void testUpdatePost_success() { | 200 | + public void testGetPost() { |
| 118 | // mock 数据 | 201 | // mock 数据 |
| 119 | - PostDO postDO = randomPostDO(); | ||
| 120 | - postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 | 202 | + PostDO dbPostDO = randomPostDO(); |
| 203 | + postMapper.insert(dbPostDO); | ||
| 121 | // 准备参数 | 204 | // 准备参数 |
| 122 | - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, | ||
| 123 | - o -> { | ||
| 124 | - // 设置更新的 ID | ||
| 125 | - o.setId(postDO.getId()); | ||
| 126 | - o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); | ||
| 127 | - }); | 205 | + Long id = dbPostDO.getId(); |
| 128 | // 调用 | 206 | // 调用 |
| 129 | - postService.updatePost(reqVO); | ||
| 130 | - // 校验是否更新正确 | ||
| 131 | - PostDO post = postMapper.selectById(reqVO.getId());// 获取最新的 | ||
| 132 | - assertPojoEquals(reqVO, post); | 207 | + PostDO post = postService.getPost(id); |
| 208 | + // 断言 | ||
| 209 | + assertNotNull(post); | ||
| 210 | + assertPojoEquals(dbPostDO, post); | ||
| 133 | } | 211 | } |
| 134 | 212 | ||
| 135 | @Test | 213 | @Test |
| 136 | - void testDeletePost_success() { | 214 | + public void testValidatePostList_success() { |
| 137 | // mock 数据 | 215 | // mock 数据 |
| 138 | - PostDO postDO = randomPostDO(); | 216 | + PostDO postDO = randomPostDO().setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 139 | postMapper.insert(postDO); | 217 | postMapper.insert(postDO); |
| 140 | // 准备参数 | 218 | // 准备参数 |
| 141 | - Long id = postDO.getId(); | ||
| 142 | - // 调用 | ||
| 143 | - postService.deletePost(id); | ||
| 144 | - assertNull(postMapper.selectById(id)); | ||
| 145 | - } | 219 | + List<Long> ids = singletonList(postDO.getId()); |
| 146 | 220 | ||
| 147 | - @Test | ||
| 148 | - void testCheckPost_notFoundForDelete() { | ||
| 149 | - // 准备参数 | ||
| 150 | - Long id = randomLongId(); | ||
| 151 | - // 调用, 并断言异常 | ||
| 152 | - assertServiceException(() -> postService.deletePost(id), POST_NOT_FOUND); | 221 | + // 调用,无需断言 |
| 222 | + postService.validatePostList(ids); | ||
| 153 | } | 223 | } |
| 154 | 224 | ||
| 155 | @Test | 225 | @Test |
| 156 | - void testCheckPost_nameDuplicateForCreate() { | ||
| 157 | - // mock 数据 | ||
| 158 | - PostDO postDO = randomPostDO(); | ||
| 159 | - postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 | 226 | + public void testValidatePostList_notFound() { |
| 160 | // 准备参数 | 227 | // 准备参数 |
| 161 | - PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class, | ||
| 162 | - // 模拟 name 重复 | ||
| 163 | - o -> o.setName(postDO.getName())); | ||
| 164 | - assertServiceException(() -> postService.createPost(reqVO), POST_NAME_DUPLICATE); | 228 | + List<Long> ids = singletonList(randomLongId()); |
| 229 | + | ||
| 230 | + // 调用, 并断言异常 | ||
| 231 | + assertServiceException(() -> postService.validatePostList(ids), POST_NOT_FOUND); | ||
| 165 | } | 232 | } |
| 166 | 233 | ||
| 167 | @Test | 234 | @Test |
| 168 | - void testCheckPost_codeDuplicateForUpdate() { | 235 | + public void testValidatePostList_notEnable() { |
| 169 | // mock 数据 | 236 | // mock 数据 |
| 170 | - PostDO postDO = randomPostDO(); | 237 | + PostDO postDO = randomPostDO().setStatus(CommonStatusEnum.DISABLE.getStatus()); |
| 171 | postMapper.insert(postDO); | 238 | postMapper.insert(postDO); |
| 172 | - // mock 数据 稍后模拟重复它的 code | ||
| 173 | - PostDO codePostDO = randomPostDO(); | ||
| 174 | - postMapper.insert(codePostDO); | ||
| 175 | // 准备参数 | 239 | // 准备参数 |
| 176 | - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, | ||
| 177 | - o -> { | ||
| 178 | - // 设置更新的 ID | ||
| 179 | - o.setId(postDO.getId()); | ||
| 180 | - // 模拟 code 重复 | ||
| 181 | - o.setCode(codePostDO.getCode()); | ||
| 182 | - }); | 240 | + List<Long> ids = singletonList(postDO.getId()); |
| 241 | + | ||
| 183 | // 调用, 并断言异常 | 242 | // 调用, 并断言异常 |
| 184 | - assertServiceException(() -> postService.updatePost(reqVO), POST_CODE_DUPLICATE); | 243 | + assertServiceException(() -> postService.validatePostList(ids), POST_NOT_ENABLE, |
| 244 | + postDO.getName()); | ||
| 185 | } | 245 | } |
| 186 | 246 | ||
| 187 | @SafeVarargs | 247 | @SafeVarargs |
| 188 | private static PostDO randomPostDO(Consumer<PostDO>... consumers) { | 248 | private static PostDO randomPostDO(Consumer<PostDO>... consumers) { |
| 189 | Consumer<PostDO> consumer = (o) -> { | 249 | Consumer<PostDO> consumer = (o) -> { |
| 190 | - o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 | 250 | + o.setStatus(randomCommonStatus()); // 保证 status 的范围 |
| 191 | }; | 251 | }; |
| 192 | return randomPojo(PostDO.class, ArrayUtils.append(consumer, consumers)); | 252 | return randomPojo(PostDO.class, ArrayUtils.append(consumer, consumers)); |
| 193 | } | 253 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceTest.java renamed to yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.dict; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.dict; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 6 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 7 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataCreateReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataCreateReqVO; |
| 9 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; |
| @@ -20,16 +19,18 @@ import javax.annotation.Resource; | @@ -20,16 +19,18 @@ import javax.annotation.Resource; | ||
| 20 | import java.util.List; | 19 | import java.util.List; |
| 21 | import java.util.function.Consumer; | 20 | import java.util.function.Consumer; |
| 22 | 21 | ||
| 22 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 23 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 23 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 24 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 24 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 25 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 25 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 26 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 26 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 27 | +import static java.util.Collections.singletonList; | ||
| 27 | import static org.junit.jupiter.api.Assertions.*; | 28 | import static org.junit.jupiter.api.Assertions.*; |
| 28 | import static org.mockito.ArgumentMatchers.eq; | 29 | import static org.mockito.ArgumentMatchers.eq; |
| 29 | import static org.mockito.Mockito.when; | 30 | import static org.mockito.Mockito.when; |
| 30 | 31 | ||
| 31 | @Import(DictDataServiceImpl.class) | 32 | @Import(DictDataServiceImpl.class) |
| 32 | -public class DictDataServiceTest extends BaseDbUnitTest { | 33 | +public class DictDataServiceImplTest extends BaseDbUnitTest { |
| 33 | 34 | ||
| 34 | @Resource | 35 | @Resource |
| 35 | private DictDataServiceImpl dictDataService; | 36 | private DictDataServiceImpl dictDataService; |
| @@ -40,6 +41,23 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -40,6 +41,23 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 40 | private DictTypeService dictTypeService; | 41 | private DictTypeService dictTypeService; |
| 41 | 42 | ||
| 42 | @Test | 43 | @Test |
| 44 | + public void testGetDictDataList() { | ||
| 45 | + // mock 数据 | ||
| 46 | + DictDataDO dictDataDO01 = randomDictDataDO().setDictType("yunai").setSort(2); | ||
| 47 | + dictDataMapper.insert(dictDataDO01); | ||
| 48 | + DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setSort(1); | ||
| 49 | + dictDataMapper.insert(dictDataDO02); | ||
| 50 | + // 准备参数 | ||
| 51 | + | ||
| 52 | + // 调用 | ||
| 53 | + List<DictDataDO> dictDataDOList = dictDataService.getDictDataList(); | ||
| 54 | + // 断言 | ||
| 55 | + assertEquals(2, dictDataDOList.size()); | ||
| 56 | + assertPojoEquals(dictDataDO02, dictDataDOList.get(0)); | ||
| 57 | + assertPojoEquals(dictDataDO01, dictDataDOList.get(1)); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Test | ||
| 43 | public void testGetDictDataPage() { | 61 | public void testGetDictDataPage() { |
| 44 | // mock 数据 | 62 | // mock 数据 |
| 45 | DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到 | 63 | DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到 |
| @@ -49,11 +67,11 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -49,11 +67,11 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 49 | }); | 67 | }); |
| 50 | dictDataMapper.insert(dbDictData); | 68 | dictDataMapper.insert(dbDictData); |
| 51 | // 测试 label 不匹配 | 69 | // 测试 label 不匹配 |
| 52 | - dictDataMapper.insert(ObjectUtils.cloneIgnoreId(dbDictData, o -> o.setLabel("艿"))); | 70 | + dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setLabel("艿"))); |
| 53 | // 测试 dictType 不匹配 | 71 | // 测试 dictType 不匹配 |
| 54 | - dictDataMapper.insert(ObjectUtils.cloneIgnoreId(dbDictData, o -> o.setDictType("nai"))); | 72 | + dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setDictType("nai"))); |
| 55 | // 测试 status 不匹配 | 73 | // 测试 status 不匹配 |
| 56 | - dictDataMapper.insert(ObjectUtils.cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 74 | + dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 57 | // 准备参数 | 75 | // 准备参数 |
| 58 | DictDataPageReqVO reqVO = new DictDataPageReqVO(); | 76 | DictDataPageReqVO reqVO = new DictDataPageReqVO(); |
| 59 | reqVO.setLabel("芋"); | 77 | reqVO.setLabel("芋"); |
| @@ -69,7 +87,7 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -69,7 +87,7 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 69 | } | 87 | } |
| 70 | 88 | ||
| 71 | @Test | 89 | @Test |
| 72 | - public void testGetDictDataList() { | 90 | + public void testGetDictDataList_export() { |
| 73 | // mock 数据 | 91 | // mock 数据 |
| 74 | DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到 | 92 | DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到 |
| 75 | o.setLabel("芋艿"); | 93 | o.setLabel("芋艿"); |
| @@ -78,11 +96,11 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -78,11 +96,11 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 78 | }); | 96 | }); |
| 79 | dictDataMapper.insert(dbDictData); | 97 | dictDataMapper.insert(dbDictData); |
| 80 | // 测试 label 不匹配 | 98 | // 测试 label 不匹配 |
| 81 | - dictDataMapper.insert(ObjectUtils.cloneIgnoreId(dbDictData, o -> o.setLabel("艿"))); | 99 | + dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setLabel("艿"))); |
| 82 | // 测试 dictType 不匹配 | 100 | // 测试 dictType 不匹配 |
| 83 | - dictDataMapper.insert(ObjectUtils.cloneIgnoreId(dbDictData, o -> o.setDictType("nai"))); | 101 | + dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setDictType("nai"))); |
| 84 | // 测试 status 不匹配 | 102 | // 测试 status 不匹配 |
| 85 | - dictDataMapper.insert(ObjectUtils.cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 103 | + dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 86 | // 准备参数 | 104 | // 准备参数 |
| 87 | DictDataExportReqVO reqVO = new DictDataExportReqVO(); | 105 | DictDataExportReqVO reqVO = new DictDataExportReqVO(); |
| 88 | reqVO.setLabel("芋"); | 106 | reqVO.setLabel("芋"); |
| @@ -90,13 +108,27 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -90,13 +108,27 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 90 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 108 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 91 | 109 | ||
| 92 | // 调用 | 110 | // 调用 |
| 93 | - List<DictDataDO> list = dictDataService.getDictDatas(reqVO); | 111 | + List<DictDataDO> list = dictDataService.getDictDataList(reqVO); |
| 94 | // 断言 | 112 | // 断言 |
| 95 | assertEquals(1, list.size()); | 113 | assertEquals(1, list.size()); |
| 96 | assertPojoEquals(dbDictData, list.get(0)); | 114 | assertPojoEquals(dbDictData, list.get(0)); |
| 97 | } | 115 | } |
| 98 | 116 | ||
| 99 | @Test | 117 | @Test |
| 118 | + public void testGetDictData() { | ||
| 119 | + // mock 数据 | ||
| 120 | + DictDataDO dbDictData = randomDictDataDO(); | ||
| 121 | + dictDataMapper.insert(dbDictData); | ||
| 122 | + // 准备参数 | ||
| 123 | + Long id = dbDictData.getId(); | ||
| 124 | + | ||
| 125 | + // 调用 | ||
| 126 | + DictDataDO dictData = dictDataService.getDictData(id); | ||
| 127 | + // 断言 | ||
| 128 | + assertPojoEquals(dbDictData, dictData); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Test | ||
| 100 | public void testCreateDictData_success() { | 132 | public void testCreateDictData_success() { |
| 101 | // 准备参数 | 133 | // 准备参数 |
| 102 | DictDataCreateReqVO reqVO = randomPojo(DictDataCreateReqVO.class, | 134 | DictDataCreateReqVO reqVO = randomPojo(DictDataCreateReqVO.class, |
| @@ -148,54 +180,54 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -148,54 +180,54 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 148 | } | 180 | } |
| 149 | 181 | ||
| 150 | @Test | 182 | @Test |
| 151 | - public void testCheckDictDataExists_success() { | 183 | + public void testValidateDictDataExists_success() { |
| 152 | // mock 数据 | 184 | // mock 数据 |
| 153 | DictDataDO dbDictData = randomDictDataDO(); | 185 | DictDataDO dbDictData = randomDictDataDO(); |
| 154 | dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据 | 186 | dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据 |
| 155 | 187 | ||
| 156 | // 调用成功 | 188 | // 调用成功 |
| 157 | - dictDataService.checkDictDataExists(dbDictData.getId()); | 189 | + dictDataService.validateDictDataExists(dbDictData.getId()); |
| 158 | } | 190 | } |
| 159 | 191 | ||
| 160 | @Test | 192 | @Test |
| 161 | - public void testCheckDictDataExists_notExists() { | ||
| 162 | - assertServiceException(() -> dictDataService.checkDictDataExists(randomLongId()), DICT_DATA_NOT_EXISTS); | 193 | + public void testValidateDictDataExists_notExists() { |
| 194 | + assertServiceException(() -> dictDataService.validateDictDataExists(randomLongId()), DICT_DATA_NOT_EXISTS); | ||
| 163 | } | 195 | } |
| 164 | 196 | ||
| 165 | @Test | 197 | @Test |
| 166 | - public void testCheckDictTypeValid_success() { | 198 | + public void testValidateDictTypeExists_success() { |
| 167 | // mock 方法,数据类型被禁用 | 199 | // mock 方法,数据类型被禁用 |
| 168 | String type = randomString(); | 200 | String type = randomString(); |
| 169 | when(dictTypeService.getDictType(eq(type))).thenReturn(randomDictTypeDO(type)); | 201 | when(dictTypeService.getDictType(eq(type))).thenReturn(randomDictTypeDO(type)); |
| 170 | 202 | ||
| 171 | // 调用, 成功 | 203 | // 调用, 成功 |
| 172 | - dictDataService.checkDictTypeValid(type); | 204 | + dictDataService.validateDictTypeExists(type); |
| 173 | } | 205 | } |
| 174 | 206 | ||
| 175 | @Test | 207 | @Test |
| 176 | - public void testCheckDictTypeValid_notExists() { | ||
| 177 | - assertServiceException(() -> dictDataService.checkDictTypeValid(randomString()), DICT_TYPE_NOT_EXISTS); | 208 | + public void testValidateDictTypeExists_notExists() { |
| 209 | + assertServiceException(() -> dictDataService.validateDictTypeExists(randomString()), DICT_TYPE_NOT_EXISTS); | ||
| 178 | } | 210 | } |
| 179 | 211 | ||
| 180 | @Test | 212 | @Test |
| 181 | - public void testCheckDictTypeValid_notEnable() { | 213 | + public void testValidateDictTypeExists_notEnable() { |
| 182 | // mock 方法,数据类型被禁用 | 214 | // mock 方法,数据类型被禁用 |
| 183 | String dictType = randomString(); | 215 | String dictType = randomString(); |
| 184 | when(dictTypeService.getDictType(eq(dictType))).thenReturn( | 216 | when(dictTypeService.getDictType(eq(dictType))).thenReturn( |
| 185 | randomPojo(DictTypeDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 217 | randomPojo(DictTypeDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 186 | 218 | ||
| 187 | // 调用, 并断言异常 | 219 | // 调用, 并断言异常 |
| 188 | - assertServiceException(() -> dictDataService.checkDictTypeValid(dictType), DICT_TYPE_NOT_ENABLE); | 220 | + assertServiceException(() -> dictDataService.validateDictTypeExists(dictType), DICT_TYPE_NOT_ENABLE); |
| 189 | } | 221 | } |
| 190 | 222 | ||
| 191 | @Test | 223 | @Test |
| 192 | - public void testCheckDictDataValueUnique_success() { | 224 | + public void testValidateDictDataValueUnique_success() { |
| 193 | // 调用,成功 | 225 | // 调用,成功 |
| 194 | - dictDataService.checkDictDataValueUnique(randomLongId(), randomString(), randomString()); | 226 | + dictDataService.validateDictDataValueUnique(randomLongId(), randomString(), randomString()); |
| 195 | } | 227 | } |
| 196 | 228 | ||
| 197 | @Test | 229 | @Test |
| 198 | - public void testCheckDictDataValueUnique_valueDuplicateForCreate() { | 230 | + public void testValidateDictDataValueUnique_valueDuplicateForCreate() { |
| 199 | // 准备参数 | 231 | // 准备参数 |
| 200 | String dictType = randomString(); | 232 | String dictType = randomString(); |
| 201 | String value = randomString(); | 233 | String value = randomString(); |
| @@ -206,12 +238,12 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -206,12 +238,12 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 206 | })); | 238 | })); |
| 207 | 239 | ||
| 208 | // 调用,校验异常 | 240 | // 调用,校验异常 |
| 209 | - assertServiceException(() -> dictDataService.checkDictDataValueUnique(null, dictType, value), | 241 | + assertServiceException(() -> dictDataService.validateDictDataValueUnique(null, dictType, value), |
| 210 | DICT_DATA_VALUE_DUPLICATE); | 242 | DICT_DATA_VALUE_DUPLICATE); |
| 211 | } | 243 | } |
| 212 | 244 | ||
| 213 | @Test | 245 | @Test |
| 214 | - public void testCheckDictDataValueUnique_valueDuplicateForUpdate() { | 246 | + public void testValidateDictDataValueUnique_valueDuplicateForUpdate() { |
| 215 | // 准备参数 | 247 | // 准备参数 |
| 216 | Long id = randomLongId(); | 248 | Long id = randomLongId(); |
| 217 | String dictType = randomString(); | 249 | String dictType = randomString(); |
| @@ -223,10 +255,96 @@ public class DictDataServiceTest extends BaseDbUnitTest { | @@ -223,10 +255,96 @@ public class DictDataServiceTest extends BaseDbUnitTest { | ||
| 223 | })); | 255 | })); |
| 224 | 256 | ||
| 225 | // 调用,校验异常 | 257 | // 调用,校验异常 |
| 226 | - assertServiceException(() -> dictDataService.checkDictDataValueUnique(id, dictType, value), | 258 | + assertServiceException(() -> dictDataService.validateDictDataValueUnique(id, dictType, value), |
| 227 | DICT_DATA_VALUE_DUPLICATE); | 259 | DICT_DATA_VALUE_DUPLICATE); |
| 228 | } | 260 | } |
| 229 | 261 | ||
| 262 | + @Test | ||
| 263 | + public void testCountByDictType() { | ||
| 264 | + // mock 数据 | ||
| 265 | + dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("yunai"))); | ||
| 266 | + dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("tudou"))); | ||
| 267 | + dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("yunai"))); | ||
| 268 | + // 准备参数 | ||
| 269 | + String dictType = "yunai"; | ||
| 270 | + | ||
| 271 | + // 调用 | ||
| 272 | + long count = dictDataService.countByDictType(dictType); | ||
| 273 | + // 校验 | ||
| 274 | + assertEquals(2L, count); | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + @Test | ||
| 278 | + public void testValidateDictDataList_success() { | ||
| 279 | + // mock 数据 | ||
| 280 | + DictDataDO dictDataDO = randomDictDataDO().setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 281 | + dictDataMapper.insert(dictDataDO); | ||
| 282 | + // 准备参数 | ||
| 283 | + String dictType = dictDataDO.getDictType(); | ||
| 284 | + List<String> values = singletonList(dictDataDO.getValue()); | ||
| 285 | + | ||
| 286 | + // 调用,无需断言 | ||
| 287 | + dictDataService.validateDictDataList(dictType, values); | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + @Test | ||
| 291 | + public void testValidateDictDataList_notFound() { | ||
| 292 | + // 准备参数 | ||
| 293 | + String dictType = randomString(); | ||
| 294 | + List<String> values = singletonList(randomString()); | ||
| 295 | + | ||
| 296 | + // 调用, 并断言异常 | ||
| 297 | + assertServiceException(() -> dictDataService.validateDictDataList(dictType, values), DICT_DATA_NOT_EXISTS); | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + @Test | ||
| 301 | + public void testValidateDictDataList_notEnable() { | ||
| 302 | + // mock 数据 | ||
| 303 | + DictDataDO dictDataDO = randomDictDataDO().setStatus(CommonStatusEnum.DISABLE.getStatus()); | ||
| 304 | + dictDataMapper.insert(dictDataDO); | ||
| 305 | + // 准备参数 | ||
| 306 | + String dictType = dictDataDO.getDictType(); | ||
| 307 | + List<String> values = singletonList(dictDataDO.getValue()); | ||
| 308 | + | ||
| 309 | + // 调用, 并断言异常 | ||
| 310 | + assertServiceException(() -> dictDataService.validateDictDataList(dictType, values), | ||
| 311 | + DICT_DATA_NOT_ENABLE, dictDataDO.getLabel()); | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + @Test | ||
| 315 | + public void testGetDictData_dictType() { | ||
| 316 | + // mock 数据 | ||
| 317 | + DictDataDO dictDataDO = randomDictDataDO().setDictType("yunai").setValue("1"); | ||
| 318 | + dictDataMapper.insert(dictDataDO); | ||
| 319 | + DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setValue("2"); | ||
| 320 | + dictDataMapper.insert(dictDataDO02); | ||
| 321 | + // 准备参数 | ||
| 322 | + String dictType = "yunai"; | ||
| 323 | + String value = "1"; | ||
| 324 | + | ||
| 325 | + // 调用 | ||
| 326 | + DictDataDO dbDictData = dictDataService.getDictData(dictType, value); | ||
| 327 | + // 断言 | ||
| 328 | + assertEquals(dictDataDO, dbDictData); | ||
| 329 | + } | ||
| 330 | + | ||
| 331 | + @Test | ||
| 332 | + public void testParseDictData() { | ||
| 333 | + // mock 数据 | ||
| 334 | + DictDataDO dictDataDO = randomDictDataDO().setDictType("yunai").setLabel("1"); | ||
| 335 | + dictDataMapper.insert(dictDataDO); | ||
| 336 | + DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setLabel("2"); | ||
| 337 | + dictDataMapper.insert(dictDataDO02); | ||
| 338 | + // 准备参数 | ||
| 339 | + String dictType = "yunai"; | ||
| 340 | + String label = "1"; | ||
| 341 | + | ||
| 342 | + // 调用 | ||
| 343 | + DictDataDO dbDictData = dictDataService.parseDictData(dictType, label); | ||
| 344 | + // 断言 | ||
| 345 | + assertEquals(dictDataDO, dbDictData); | ||
| 346 | + } | ||
| 347 | + | ||
| 230 | // ========== 随机对象 ========== | 348 | // ========== 随机对象 ========== |
| 231 | 349 | ||
| 232 | @SafeVarargs | 350 | @SafeVarargs |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceTest.java renamed to yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java
| @@ -2,36 +2,36 @@ package cn.iocoder.yudao.module.system.service.dict; | @@ -2,36 +2,36 @@ package cn.iocoder.yudao.module.system.service.dict; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||
| 6 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 5 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO; | ||
| 7 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO; |
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeUpdateReqVO; | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; |
| 10 | import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; | 12 | import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; |
| 11 | -import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | ||
| 12 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 13 | -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 14 | import org.junit.jupiter.api.Test; | 13 | import org.junit.jupiter.api.Test; |
| 15 | import org.springframework.boot.test.mock.mockito.MockBean; | 14 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 16 | import org.springframework.context.annotation.Import; | 15 | import org.springframework.context.annotation.Import; |
| 17 | 16 | ||
| 18 | import javax.annotation.Resource; | 17 | import javax.annotation.Resource; |
| 19 | -import java.time.LocalDateTime; | ||
| 20 | import java.util.List; | 18 | import java.util.List; |
| 21 | import java.util.function.Consumer; | 19 | import java.util.function.Consumer; |
| 22 | 20 | ||
| 23 | import static cn.hutool.core.util.RandomUtil.randomEle; | 21 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 24 | -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 22 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| 23 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | ||
| 24 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 27 | -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | ||
| 28 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 28 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | ||
| 29 | import static org.junit.jupiter.api.Assertions.*; | 29 | import static org.junit.jupiter.api.Assertions.*; |
| 30 | import static org.mockito.ArgumentMatchers.eq; | 30 | import static org.mockito.ArgumentMatchers.eq; |
| 31 | import static org.mockito.Mockito.when; | 31 | import static org.mockito.Mockito.when; |
| 32 | 32 | ||
| 33 | @Import(DictTypeServiceImpl.class) | 33 | @Import(DictTypeServiceImpl.class) |
| 34 | -public class DictTypeServiceTest extends BaseDbUnitTest { | 34 | +public class DictTypeServiceImplTest extends BaseDbUnitTest { |
| 35 | 35 | ||
| 36 | @Resource | 36 | @Resource |
| 37 | private DictTypeServiceImpl dictTypeService; | 37 | private DictTypeServiceImpl dictTypeService; |
| @@ -52,19 +52,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -52,19 +52,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 52 | }); | 52 | }); |
| 53 | dictTypeMapper.insert(dbDictType); | 53 | dictTypeMapper.insert(dbDictType); |
| 54 | // 测试 name 不匹配 | 54 | // 测试 name 不匹配 |
| 55 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); | 55 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); |
| 56 | // 测试 type 不匹配 | 56 | // 测试 type 不匹配 |
| 57 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); | 57 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); |
| 58 | // 测试 status 不匹配 | 58 | // 测试 status 不匹配 |
| 59 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 59 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 60 | // 测试 createTime 不匹配 | 60 | // 测试 createTime 不匹配 |
| 61 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | 61 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); |
| 62 | // 准备参数 | 62 | // 准备参数 |
| 63 | DictTypePageReqVO reqVO = new DictTypePageReqVO(); | 63 | DictTypePageReqVO reqVO = new DictTypePageReqVO(); |
| 64 | reqVO.setName("nai"); | 64 | reqVO.setName("nai"); |
| 65 | reqVO.setType("艿"); | 65 | reqVO.setType("艿"); |
| 66 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 66 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 67 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 10),buildTime(2021, 1, 20)})); | 67 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20)); |
| 68 | 68 | ||
| 69 | // 调用 | 69 | // 调用 |
| 70 | PageResult<DictTypeDO> pageResult = dictTypeService.getDictTypePage(reqVO); | 70 | PageResult<DictTypeDO> pageResult = dictTypeService.getDictTypePage(reqVO); |
| @@ -75,7 +75,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -75,7 +75,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | @Test | 77 | @Test |
| 78 | - public void testGetDictTypeList() { | 78 | + public void testGetDictTypeList_export() { |
| 79 | // mock 数据 | 79 | // mock 数据 |
| 80 | DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到 | 80 | DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到 |
| 81 | o.setName("yunai"); | 81 | o.setName("yunai"); |
| @@ -85,19 +85,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -85,19 +85,19 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 85 | }); | 85 | }); |
| 86 | dictTypeMapper.insert(dbDictType); | 86 | dictTypeMapper.insert(dbDictType); |
| 87 | // 测试 name 不匹配 | 87 | // 测试 name 不匹配 |
| 88 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); | 88 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou"))); |
| 89 | // 测试 type 不匹配 | 89 | // 测试 type 不匹配 |
| 90 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); | 90 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆"))); |
| 91 | // 测试 status 不匹配 | 91 | // 测试 status 不匹配 |
| 92 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | 92 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 93 | // 测试 createTime 不匹配 | 93 | // 测试 createTime 不匹配 |
| 94 | - dictTypeMapper.insert(ObjectUtils.cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | 94 | + dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1)))); |
| 95 | // 准备参数 | 95 | // 准备参数 |
| 96 | DictTypeExportReqVO reqVO = new DictTypeExportReqVO(); | 96 | DictTypeExportReqVO reqVO = new DictTypeExportReqVO(); |
| 97 | reqVO.setName("nai"); | 97 | reqVO.setName("nai"); |
| 98 | reqVO.setType("艿"); | 98 | reqVO.setType("艿"); |
| 99 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 99 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 100 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 10),buildTime(2021, 1, 20)})); | 100 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20)); |
| 101 | 101 | ||
| 102 | // 调用 | 102 | // 调用 |
| 103 | List<DictTypeDO> list = dictTypeService.getDictTypeList(reqVO); | 103 | List<DictTypeDO> list = dictTypeService.getDictTypeList(reqVO); |
| @@ -107,7 +107,22 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -107,7 +107,22 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | @Test | 109 | @Test |
| 110 | - public void testGetDictType() { | 110 | + public void testGetDictType_id() { |
| 111 | + // mock 数据 | ||
| 112 | + DictTypeDO dbDictType = randomDictTypeDO(); | ||
| 113 | + dictTypeMapper.insert(dbDictType); | ||
| 114 | + // 准备参数 | ||
| 115 | + Long id = dbDictType.getId(); | ||
| 116 | + | ||
| 117 | + // 调用 | ||
| 118 | + DictTypeDO dictType = dictTypeService.getDictType(id); | ||
| 119 | + // 断言 | ||
| 120 | + assertNotNull(dictType); | ||
| 121 | + assertPojoEquals(dbDictType, dictType); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @Test | ||
| 125 | + public void testGetDictType_type() { | ||
| 111 | // mock 数据 | 126 | // mock 数据 |
| 112 | DictTypeDO dbDictType = randomDictTypeDO(); | 127 | DictTypeDO dbDictType = randomDictTypeDO(); |
| 113 | dictTypeMapper.insert(dbDictType); | 128 | dictTypeMapper.insert(dbDictType); |
| @@ -183,40 +198,57 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -183,40 +198,57 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 183 | } | 198 | } |
| 184 | 199 | ||
| 185 | @Test | 200 | @Test |
| 186 | - public void testCheckDictDataExists_success() { | 201 | + public void testGetDictTypeList() { |
| 202 | + // 准备参数 | ||
| 203 | + DictTypeDO dictTypeDO01 = randomDictTypeDO(); | ||
| 204 | + dictTypeMapper.insert(dictTypeDO01); | ||
| 205 | + DictTypeDO dictTypeDO02 = randomDictTypeDO(); | ||
| 206 | + dictTypeMapper.insert(dictTypeDO02); | ||
| 207 | + // mock 方法 | ||
| 208 | + | ||
| 209 | + // 调用 | ||
| 210 | + List<DictTypeDO> dictTypeDOList = dictTypeService.getDictTypeList(); | ||
| 211 | + // 断言 | ||
| 212 | + assertEquals(2, dictTypeDOList.size()); | ||
| 213 | + assertPojoEquals(dictTypeDO01, dictTypeDOList.get(0)); | ||
| 214 | + assertPojoEquals(dictTypeDO02, dictTypeDOList.get(1)); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + @Test | ||
| 218 | + public void testValidateDictDataExists_success() { | ||
| 187 | // mock 数据 | 219 | // mock 数据 |
| 188 | DictTypeDO dbDictType = randomDictTypeDO(); | 220 | DictTypeDO dbDictType = randomDictTypeDO(); |
| 189 | dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据 | 221 | dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据 |
| 190 | 222 | ||
| 191 | // 调用成功 | 223 | // 调用成功 |
| 192 | - dictTypeService.checkDictTypeExists(dbDictType.getId()); | 224 | + dictTypeService.validateDictTypeExists(dbDictType.getId()); |
| 193 | } | 225 | } |
| 194 | 226 | ||
| 195 | @Test | 227 | @Test |
| 196 | - public void testCheckDictDataExists_notExists() { | ||
| 197 | - assertServiceException(() -> dictTypeService.checkDictTypeExists(randomLongId()), DICT_TYPE_NOT_EXISTS); | 228 | + public void testValidateDictDataExists_notExists() { |
| 229 | + assertServiceException(() -> dictTypeService.validateDictTypeExists(randomLongId()), DICT_TYPE_NOT_EXISTS); | ||
| 198 | } | 230 | } |
| 199 | 231 | ||
| 200 | @Test | 232 | @Test |
| 201 | - public void testCheckDictTypeUnique_success() { | 233 | + public void testValidateDictTypeUnique_success() { |
| 202 | // 调用,成功 | 234 | // 调用,成功 |
| 203 | - dictTypeService.checkDictTypeUnique(randomLongId(), randomString()); | 235 | + dictTypeService.validateDictTypeUnique(randomLongId(), randomString()); |
| 204 | } | 236 | } |
| 205 | 237 | ||
| 206 | @Test | 238 | @Test |
| 207 | - public void testCheckDictTypeUnique_valueDuplicateForCreate() { | 239 | + public void testValidateDictTypeUnique_valueDuplicateForCreate() { |
| 208 | // 准备参数 | 240 | // 准备参数 |
| 209 | String type = randomString(); | 241 | String type = randomString(); |
| 210 | // mock 数据 | 242 | // mock 数据 |
| 211 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); | 243 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); |
| 212 | 244 | ||
| 213 | // 调用,校验异常 | 245 | // 调用,校验异常 |
| 214 | - assertServiceException(() -> dictTypeService.checkDictTypeUnique(null, type), | 246 | + assertServiceException(() -> dictTypeService.validateDictTypeUnique(null, type), |
| 215 | DICT_TYPE_TYPE_DUPLICATE); | 247 | DICT_TYPE_TYPE_DUPLICATE); |
| 216 | } | 248 | } |
| 217 | 249 | ||
| 218 | @Test | 250 | @Test |
| 219 | - public void testCheckDictTypeUnique_valueDuplicateForUpdate() { | 251 | + public void testValidateDictTypeUnique_valueDuplicateForUpdate() { |
| 220 | // 准备参数 | 252 | // 准备参数 |
| 221 | Long id = randomLongId(); | 253 | Long id = randomLongId(); |
| 222 | String type = randomString(); | 254 | String type = randomString(); |
| @@ -224,30 +256,30 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -224,30 +256,30 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 224 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); | 256 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type))); |
| 225 | 257 | ||
| 226 | // 调用,校验异常 | 258 | // 调用,校验异常 |
| 227 | - assertServiceException(() -> dictTypeService.checkDictTypeUnique(id, type), | 259 | + assertServiceException(() -> dictTypeService.validateDictTypeUnique(id, type), |
| 228 | DICT_TYPE_TYPE_DUPLICATE); | 260 | DICT_TYPE_TYPE_DUPLICATE); |
| 229 | } | 261 | } |
| 230 | 262 | ||
| 231 | @Test | 263 | @Test |
| 232 | - public void testCheckDictTypNameUnique_success() { | 264 | + public void testValidateDictTypNameUnique_success() { |
| 233 | // 调用,成功 | 265 | // 调用,成功 |
| 234 | - dictTypeService.checkDictTypeNameUnique(randomLongId(), randomString()); | 266 | + dictTypeService.validateDictTypeNameUnique(randomLongId(), randomString()); |
| 235 | } | 267 | } |
| 236 | 268 | ||
| 237 | @Test | 269 | @Test |
| 238 | - public void testCheckDictTypeNameUnique_nameDuplicateForCreate() { | 270 | + public void testValidateDictTypeNameUnique_nameDuplicateForCreate() { |
| 239 | // 准备参数 | 271 | // 准备参数 |
| 240 | String name = randomString(); | 272 | String name = randomString(); |
| 241 | // mock 数据 | 273 | // mock 数据 |
| 242 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); | 274 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); |
| 243 | 275 | ||
| 244 | // 调用,校验异常 | 276 | // 调用,校验异常 |
| 245 | - assertServiceException(() -> dictTypeService.checkDictTypeNameUnique(null, name), | 277 | + assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(null, name), |
| 246 | DICT_TYPE_NAME_DUPLICATE); | 278 | DICT_TYPE_NAME_DUPLICATE); |
| 247 | } | 279 | } |
| 248 | 280 | ||
| 249 | @Test | 281 | @Test |
| 250 | - public void testCheckDictTypeNameUnique_nameDuplicateForUpdate() { | 282 | + public void testValidateDictTypeNameUnique_nameDuplicateForUpdate() { |
| 251 | // 准备参数 | 283 | // 准备参数 |
| 252 | Long id = randomLongId(); | 284 | Long id = randomLongId(); |
| 253 | String name = randomString(); | 285 | String name = randomString(); |
| @@ -255,7 +287,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | @@ -255,7 +287,7 @@ public class DictTypeServiceTest extends BaseDbUnitTest { | ||
| 255 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); | 287 | dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name))); |
| 256 | 288 | ||
| 257 | // 调用,校验异常 | 289 | // 调用,校验异常 |
| 258 | - assertServiceException(() -> dictTypeService.checkDictTypeNameUnique(id, name), | 290 | + assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(id, name), |
| 259 | DICT_TYPE_NAME_DUPLICATE); | 291 | DICT_TYPE_NAME_DUPLICATE); |
| 260 | } | 292 | } |
| 261 | 293 |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java
| @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.system.service.errorcode; | @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.system.service.errorcode; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 4 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 5 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; | 6 | import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; |
| 7 | +import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; | ||
| 8 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; |
| 9 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; |
| 10 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; | 10 | import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; |
| @@ -22,7 +22,9 @@ import java.util.List; | @@ -22,7 +22,9 @@ import java.util.List; | ||
| 22 | import java.util.function.Consumer; | 22 | import java.util.function.Consumer; |
| 23 | 23 | ||
| 24 | import static cn.hutool.core.util.RandomUtil.randomEle; | 24 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | ||
| 25 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | 26 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 27 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 28 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 27 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 29 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 28 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 30 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| @@ -57,7 +59,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -57,7 +59,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 57 | @Test | 59 | @Test |
| 58 | public void testUpdateErrorCode_success() { | 60 | public void testUpdateErrorCode_success() { |
| 59 | // mock 数据 | 61 | // mock 数据 |
| 60 | - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(); | 62 | + ErrorCodeDO dbErrorCode = randomErrorCodeDO(); |
| 61 | errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 | 63 | errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 |
| 62 | // 准备参数 | 64 | // 准备参数 |
| 63 | ErrorCodeUpdateReqVO reqVO = randomPojo(ErrorCodeUpdateReqVO.class, o -> { | 65 | ErrorCodeUpdateReqVO reqVO = randomPojo(ErrorCodeUpdateReqVO.class, o -> { |
| @@ -75,7 +77,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -75,7 +77,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 75 | @Test | 77 | @Test |
| 76 | public void testDeleteErrorCode_success() { | 78 | public void testDeleteErrorCode_success() { |
| 77 | // mock 数据 | 79 | // mock 数据 |
| 78 | - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(); | 80 | + ErrorCodeDO dbErrorCode = randomErrorCodeDO(); |
| 79 | errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 | 81 | errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 |
| 80 | // 准备参数 | 82 | // 准备参数 |
| 81 | Long id = dbErrorCode.getId(); | 83 | Long id = dbErrorCode.getId(); |
| @@ -96,7 +98,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -96,7 +98,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 96 | reqVO.setApplicationName("tu"); | 98 | reqVO.setApplicationName("tu"); |
| 97 | reqVO.setCode(1); | 99 | reqVO.setCode(1); |
| 98 | reqVO.setMessage("ma"); | 100 | reqVO.setMessage("ma"); |
| 99 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 11, 1),buildTime(2020, 11, 30)})); | 101 | + reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); |
| 100 | 102 | ||
| 101 | // 调用 | 103 | // 调用 |
| 102 | PageResult<ErrorCodeDO> pageResult = errorCodeService.getErrorCodePage(reqVO); | 104 | PageResult<ErrorCodeDO> pageResult = errorCodeService.getErrorCodePage(reqVO); |
| @@ -110,7 +112,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -110,7 +112,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 110 | * 初始化 getErrorCodePage 方法的测试数据 | 112 | * 初始化 getErrorCodePage 方法的测试数据 |
| 111 | */ | 113 | */ |
| 112 | private ErrorCodeDO initGetErrorCodePage() { | 114 | private ErrorCodeDO initGetErrorCodePage() { |
| 113 | - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> { // 等会查询到 | 115 | + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> { // 等会查询到 |
| 114 | o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); | 116 | o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); |
| 115 | o.setApplicationName("tudou"); | 117 | o.setApplicationName("tudou"); |
| 116 | o.setCode(1); | 118 | o.setCode(1); |
| @@ -119,20 +121,20 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -119,20 +121,20 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 119 | }); | 121 | }); |
| 120 | errorCodeMapper.insert(dbErrorCode); | 122 | errorCodeMapper.insert(dbErrorCode); |
| 121 | // 测试 type 不匹配 | 123 | // 测试 type 不匹配 |
| 122 | - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); | 124 | + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); |
| 123 | // 测试 applicationName 不匹配 | 125 | // 测试 applicationName 不匹配 |
| 124 | - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); | 126 | + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); |
| 125 | // 测试 code 不匹配 | 127 | // 测试 code 不匹配 |
| 126 | - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); | 128 | + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); |
| 127 | // 测试 message 不匹配 | 129 | // 测试 message 不匹配 |
| 128 | - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setMessage("nai"))); | 130 | + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setMessage("nai"))); |
| 129 | // 测试 createTime 不匹配 | 131 | // 测试 createTime 不匹配 |
| 130 | - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCreateTime(buildTime(2020, 12, 12)))); | 132 | + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCreateTime(buildTime(2020, 12, 12)))); |
| 131 | return dbErrorCode; | 133 | return dbErrorCode; |
| 132 | } | 134 | } |
| 133 | 135 | ||
| 134 | @Test | 136 | @Test |
| 135 | - public void testGetErrorCodeList() { | 137 | + public void testGetErrorCodeList_export() { |
| 136 | // mock 数据 | 138 | // mock 数据 |
| 137 | ErrorCodeDO dbErrorCode = initGetErrorCodePage(); | 139 | ErrorCodeDO dbErrorCode = initGetErrorCodePage(); |
| 138 | // 准备参数 | 140 | // 准备参数 |
| @@ -141,7 +143,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -141,7 +143,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 141 | reqVO.setApplicationName("tu"); | 143 | reqVO.setApplicationName("tu"); |
| 142 | reqVO.setCode(1); | 144 | reqVO.setCode(1); |
| 143 | reqVO.setMessage("ma"); | 145 | reqVO.setMessage("ma"); |
| 144 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 11, 1),buildTime(2020, 11, 30)})); | 146 | + reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); |
| 145 | 147 | ||
| 146 | // 调用 | 148 | // 调用 |
| 147 | List<ErrorCodeDO> list = errorCodeService.getErrorCodeList(reqVO); | 149 | List<ErrorCodeDO> list = errorCodeService.getErrorCodeList(reqVO); |
| @@ -155,7 +157,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -155,7 +157,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 155 | // 准备参数 | 157 | // 准备参数 |
| 156 | Integer code = randomInteger(); | 158 | Integer code = randomInteger(); |
| 157 | // mock 数据 | 159 | // mock 数据 |
| 158 | - errorCodeMapper.insert(randomInfErrorCodeDO(o -> o.setCode(code))); | 160 | + errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code))); |
| 159 | 161 | ||
| 160 | // 调用,校验异常 | 162 | // 调用,校验异常 |
| 161 | assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, null), | 163 | assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, null), |
| @@ -168,7 +170,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -168,7 +170,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 168 | Long id = randomLongId(); | 170 | Long id = randomLongId(); |
| 169 | Integer code = randomInteger(); | 171 | Integer code = randomInteger(); |
| 170 | // mock 数据 | 172 | // mock 数据 |
| 171 | - errorCodeMapper.insert(randomInfErrorCodeDO(o -> o.setCode(code))); | 173 | + errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code))); |
| 172 | 174 | ||
| 173 | // 调用,校验异常 | 175 | // 调用,校验异常 |
| 174 | assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, id), | 176 | assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, id), |
| @@ -204,7 +206,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -204,7 +206,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 204 | @Test | 206 | @Test |
| 205 | public void testAutoGenerateErrorCodes_021() { | 207 | public void testAutoGenerateErrorCodes_021() { |
| 206 | // mock 数据 | 208 | // mock 数据 |
| 207 | - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType())); | 209 | + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType())); |
| 208 | errorCodeMapper.insert(dbErrorCode); | 210 | errorCodeMapper.insert(dbErrorCode); |
| 209 | // 准备参数 | 211 | // 准备参数 |
| 210 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, | 212 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, |
| @@ -224,7 +226,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -224,7 +226,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 224 | @Test | 226 | @Test |
| 225 | public void testAutoGenerateErrorCodes_022() { | 227 | public void testAutoGenerateErrorCodes_022() { |
| 226 | // mock 数据 | 228 | // mock 数据 |
| 227 | - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); | 229 | + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); |
| 228 | errorCodeMapper.insert(dbErrorCode); | 230 | errorCodeMapper.insert(dbErrorCode); |
| 229 | // 准备参数 | 231 | // 准备参数 |
| 230 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, | 232 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, |
| @@ -244,7 +246,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -244,7 +246,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 244 | @Test | 246 | @Test |
| 245 | public void testAutoGenerateErrorCodes_023() { | 247 | public void testAutoGenerateErrorCodes_023() { |
| 246 | // mock 数据 | 248 | // mock 数据 |
| 247 | - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); | 249 | + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); |
| 248 | errorCodeMapper.insert(dbErrorCode); | 250 | errorCodeMapper.insert(dbErrorCode); |
| 249 | // 准备参数 | 251 | // 准备参数 |
| 250 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, | 252 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, |
| @@ -265,7 +267,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -265,7 +267,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 265 | @Test | 267 | @Test |
| 266 | public void testAutoGenerateErrorCodes_024() { | 268 | public void testAutoGenerateErrorCodes_024() { |
| 267 | // mock 数据 | 269 | // mock 数据 |
| 268 | - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); | 270 | + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); |
| 269 | errorCodeMapper.insert(dbErrorCode); | 271 | errorCodeMapper.insert(dbErrorCode); |
| 270 | // 准备参数 | 272 | // 准备参数 |
| 271 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, | 273 | ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, |
| @@ -279,10 +281,44 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | @@ -279,10 +281,44 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { | ||
| 279 | assertPojoEquals(generateReqDTO, errorCode); | 281 | assertPojoEquals(generateReqDTO, errorCode); |
| 280 | } | 282 | } |
| 281 | 283 | ||
| 284 | + @Test | ||
| 285 | + public void testGetErrorCode() { | ||
| 286 | + // 准备参数 | ||
| 287 | + ErrorCodeDO errorCodeDO = randomErrorCodeDO(); | ||
| 288 | + errorCodeMapper.insert(errorCodeDO); | ||
| 289 | + // mock 方法 | ||
| 290 | + Long id = errorCodeDO.getId(); | ||
| 291 | + | ||
| 292 | + // 调用 | ||
| 293 | + ErrorCodeDO dbErrorCode = errorCodeService.getErrorCode(id); | ||
| 294 | + // 断言 | ||
| 295 | + assertPojoEquals(errorCodeDO, dbErrorCode); | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + @Test | ||
| 299 | + public void testGetErrorCodeList() { | ||
| 300 | + // 准备参数 | ||
| 301 | + ErrorCodeDO errorCodeDO01 = randomErrorCodeDO( | ||
| 302 | + o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 10))); | ||
| 303 | + errorCodeMapper.insert(errorCodeDO01); | ||
| 304 | + ErrorCodeDO errorCodeDO02 = randomErrorCodeDO( | ||
| 305 | + o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 12))); | ||
| 306 | + errorCodeMapper.insert(errorCodeDO02); | ||
| 307 | + // mock 方法 | ||
| 308 | + String applicationName = "yunai_server"; | ||
| 309 | + LocalDateTime minUpdateTime = buildTime(2022, 1, 11); | ||
| 310 | + | ||
| 311 | + // 调用 | ||
| 312 | + List<ErrorCodeRespDTO> errorCodeList = errorCodeService.getErrorCodeList(applicationName, minUpdateTime); | ||
| 313 | + // 断言 | ||
| 314 | + assertEquals(1, errorCodeList.size()); | ||
| 315 | + assertPojoEquals(errorCodeDO02, errorCodeList.get(0)); | ||
| 316 | + } | ||
| 317 | + | ||
| 282 | // ========== 随机对象 ========== | 318 | // ========== 随机对象 ========== |
| 283 | 319 | ||
| 284 | @SafeVarargs | 320 | @SafeVarargs |
| 285 | - private static ErrorCodeDO randomInfErrorCodeDO(Consumer<ErrorCodeDO>... consumers) { | 321 | + private static ErrorCodeDO randomErrorCodeDO(Consumer<ErrorCodeDO>... consumers) { |
| 286 | Consumer<ErrorCodeDO> consumer = (o) -> { | 322 | Consumer<ErrorCodeDO> consumer = (o) -> { |
| 287 | o.setType(randomEle(ErrorCodeTypeEnum.values()).getType()); // 保证 key 的范围 | 323 | o.setType(randomEle(ErrorCodeTypeEnum.values()).getType()); // 保证 key 的范围 |
| 288 | }; | 324 | }; |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/LoginLogServiceImplTest.java
| 1 | package cn.iocoder.yudao.module.system.service.logger; | 1 | package cn.iocoder.yudao.module.system.service.logger; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.RandomUtil; | ||
| 4 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 7 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 8 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 9 | -import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||
| 10 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; | 5 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; |
| 11 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO; |
| 12 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO; |
| 13 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO; |
| 14 | import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper; | 9 | import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper; |
| 15 | -import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; | ||
| 16 | import org.junit.jupiter.api.Test; | 10 | import org.junit.jupiter.api.Test; |
| 17 | import org.springframework.context.annotation.Import; | 11 | import org.springframework.context.annotation.Import; |
| 18 | 12 | ||
| 19 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 20 | -import java.time.LocalDateTime; | ||
| 21 | import java.util.List; | 14 | import java.util.List; |
| 22 | 15 | ||
| 23 | -import static cn.hutool.core.util.RandomUtil.randomEle; | 16 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| 24 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | 17 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 18 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 19 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 26 | -import static cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.*; | 20 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 21 | +import static cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.CAPTCHA_CODE_ERROR; | ||
| 22 | +import static cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.SUCCESS; | ||
| 27 | import static org.junit.jupiter.api.Assertions.assertEquals; | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 28 | 24 | ||
| 29 | @Import(LoginLogServiceImpl.class) | 25 | @Import(LoginLogServiceImpl.class) |
| @@ -37,42 +33,31 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest { | @@ -37,42 +33,31 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest { | ||
| 37 | 33 | ||
| 38 | @Test | 34 | @Test |
| 39 | public void testGetLoginLogPage() { | 35 | public void testGetLoginLogPage() { |
| 40 | - // 构造测试数据 | ||
| 41 | - // 登录成功的 | ||
| 42 | - LoginLogDO loginLogDO = RandomUtils.randomPojo(LoginLogDO.class, logDO -> { | ||
| 43 | - logDO.setLogType(RandomUtil.randomEle(cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum.values()).getType()); | ||
| 44 | - logDO.setTraceId(TracerUtils.getTraceId()); | ||
| 45 | - logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()); | ||
| 46 | - | ||
| 47 | - logDO.setUserIp("192.168.199.16"); | ||
| 48 | - logDO.setUsername("wangkai"); | ||
| 49 | - logDO.setCreateTime(buildTime(2021, 3, 6)); | ||
| 50 | - logDO.setResult(SUCCESS.getResult()); | 36 | + // mock 数据 |
| 37 | + LoginLogDO loginLogDO = randomPojo(LoginLogDO.class, o -> { | ||
| 38 | + o.setUserIp("192.168.199.16"); | ||
| 39 | + o.setUsername("wang"); | ||
| 40 | + o.setResult(SUCCESS.getResult()); | ||
| 41 | + o.setCreateTime(buildTime(2021, 3, 6)); | ||
| 51 | }); | 42 | }); |
| 52 | loginLogMapper.insert(loginLogDO); | 43 | loginLogMapper.insert(loginLogDO); |
| 53 | - | ||
| 54 | - // 下面几个都是不匹配的数据 | ||
| 55 | - // 登录失败的 | ||
| 56 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setResult(CAPTCHA_CODE_ERROR.getResult()))); | ||
| 57 | - // 不同ip段的 | ||
| 58 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setUserIp("192.168.128.18"))); | ||
| 59 | - // 不同username | ||
| 60 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setUsername("yunai"))); | ||
| 61 | - // 构造一个早期时间 2021-02-06 00:00:00 | ||
| 62 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setCreateTime(buildTime(2021, 2, 6)))); | ||
| 63 | - | ||
| 64 | - | 44 | + // 测试 status 不匹配 |
| 45 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setResult(CAPTCHA_CODE_ERROR.getResult()))); | ||
| 46 | + // 测试 ip 不匹配 | ||
| 47 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUserIp("192.168.128.18"))); | ||
| 48 | + // 测试 username 不匹配 | ||
| 49 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUsername("yunai"))); | ||
| 50 | + // 测试 createTime 不匹配 | ||
| 51 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setCreateTime(buildTime(2021, 2, 6)))); | ||
| 65 | // 构造调用参数 | 52 | // 构造调用参数 |
| 66 | LoginLogPageReqVO reqVO = new LoginLogPageReqVO(); | 53 | LoginLogPageReqVO reqVO = new LoginLogPageReqVO(); |
| 67 | - reqVO.setUsername("wangkai"); | 54 | + reqVO.setUsername("wang"); |
| 68 | reqVO.setUserIp("192.168.199"); | 55 | reqVO.setUserIp("192.168.199"); |
| 69 | reqVO.setStatus(true); | 56 | reqVO.setStatus(true); |
| 70 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 3, 5), | ||
| 71 | - buildTime(2021, 3, 7)})); | 57 | + reqVO.setCreateTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); |
| 72 | 58 | ||
| 73 | - // 调用service方法 | 59 | + // 调用 |
| 74 | PageResult<LoginLogDO> pageResult = loginLogService.getLoginLogPage(reqVO); | 60 | PageResult<LoginLogDO> pageResult = loginLogService.getLoginLogPage(reqVO); |
| 75 | - | ||
| 76 | // 断言,只查到了一条符合条件的 | 61 | // 断言,只查到了一条符合条件的 |
| 77 | assertEquals(1, pageResult.getTotal()); | 62 | assertEquals(1, pageResult.getTotal()); |
| 78 | assertEquals(1, pageResult.getList().size()); | 63 | assertEquals(1, pageResult.getList().size()); |
| @@ -81,62 +66,45 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest { | @@ -81,62 +66,45 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest { | ||
| 81 | 66 | ||
| 82 | @Test | 67 | @Test |
| 83 | public void testGetLoginLogList() { | 68 | public void testGetLoginLogList() { |
| 84 | - // 构造测试数据 | ||
| 85 | - | ||
| 86 | - // 登录成功的 | ||
| 87 | - LoginLogDO loginLogDO = RandomUtils.randomPojo(LoginLogDO.class, logDO -> { | ||
| 88 | - logDO.setLogType(RandomUtil.randomEle(cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum.values()).getType()); | ||
| 89 | - logDO.setTraceId(TracerUtils.getTraceId()); | ||
| 90 | - logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()); | ||
| 91 | - | ||
| 92 | - logDO.setUserIp("192.168.111.16"); | ||
| 93 | - logDO.setUsername("wangxiaokai"); | ||
| 94 | - logDO.setCreateTime(buildTime(2021, 3, 6)); | ||
| 95 | - logDO.setResult(SUCCESS.getResult()); | 69 | + // mock 数据 |
| 70 | + LoginLogDO loginLogDO = randomPojo(LoginLogDO.class, o -> { | ||
| 71 | + o.setUserIp("192.168.199.16"); | ||
| 72 | + o.setUsername("wang"); | ||
| 73 | + o.setResult(SUCCESS.getResult()); | ||
| 74 | + o.setCreateTime(buildTime(2021, 3, 6)); | ||
| 96 | }); | 75 | }); |
| 97 | loginLogMapper.insert(loginLogDO); | 76 | loginLogMapper.insert(loginLogDO); |
| 98 | - | ||
| 99 | - // 下面几个都是不匹配的数据 | ||
| 100 | - // 登录失败的 | ||
| 101 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setResult(CAPTCHA_CODE_ERROR.getResult()))); | ||
| 102 | - // 不同ip段的 | ||
| 103 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setUserIp("192.168.128.18"))); | ||
| 104 | - // 不同username | ||
| 105 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setUsername("yunai"))); | ||
| 106 | - // 构造一个早期时间 2021-02-06 00:00:00 | ||
| 107 | - loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setCreateTime(buildTime(2021, 2, 6)))); | ||
| 108 | - | 77 | + // 测试 status 不匹配 |
| 78 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setResult(CAPTCHA_CODE_ERROR.getResult()))); | ||
| 79 | + // 测试 ip 不匹配 | ||
| 80 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUserIp("192.168.128.18"))); | ||
| 81 | + // 测试 username 不匹配 | ||
| 82 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setUsername("yunai"))); | ||
| 83 | + // 测试 createTime 不匹配 | ||
| 84 | + loginLogMapper.insert(cloneIgnoreId(loginLogDO, o -> o.setCreateTime(buildTime(2021, 2, 6)))); | ||
| 109 | // 构造调用参数 | 85 | // 构造调用参数 |
| 110 | LoginLogExportReqVO reqVO = new LoginLogExportReqVO(); | 86 | LoginLogExportReqVO reqVO = new LoginLogExportReqVO(); |
| 111 | - reqVO.setUsername("wangxiaokai"); | ||
| 112 | - reqVO.setUserIp("192.168.111"); | 87 | + reqVO.setUsername("wang"); |
| 88 | + reqVO.setUserIp("192.168.199"); | ||
| 113 | reqVO.setStatus(true); | 89 | reqVO.setStatus(true); |
| 114 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 3, 5), | ||
| 115 | - buildTime(2021, 3, 7)})); | 90 | + reqVO.setCreateTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); |
| 116 | 91 | ||
| 117 | // 调用service方法 | 92 | // 调用service方法 |
| 118 | - List<LoginLogDO> loginLogList = loginLogService.getLoginLogList(reqVO); | ||
| 119 | - | 93 | + List<LoginLogDO> list = loginLogService.getLoginLogList(reqVO); |
| 120 | // 断言 | 94 | // 断言 |
| 121 | - assertEquals(1, loginLogList.size()); | ||
| 122 | - assertPojoEquals(loginLogDO, loginLogList.get(0)); | 95 | + assertEquals(1, list.size()); |
| 96 | + assertPojoEquals(loginLogDO, list.get(0)); | ||
| 123 | } | 97 | } |
| 124 | 98 | ||
| 125 | @Test | 99 | @Test |
| 126 | public void testCreateLoginLog() { | 100 | public void testCreateLoginLog() { |
| 127 | - LoginLogCreateReqDTO reqDTO = RandomUtils.randomPojo(LoginLogCreateReqDTO.class, vo -> { | ||
| 128 | - // 指定随机的范围,避免超出范围入库失败 | ||
| 129 | - vo.setUserType(randomEle(UserTypeEnum.values()).getValue()); | ||
| 130 | - vo.setLogType(randomEle(LoginLogTypeEnum.values()).getType()); | ||
| 131 | - vo.setResult(randomEle(values()).getResult()); | ||
| 132 | - vo.setTraceId(TracerUtils.getTraceId()); | ||
| 133 | - }); | 101 | + LoginLogCreateReqDTO reqDTO = randomPojo(LoginLogCreateReqDTO.class); |
| 134 | 102 | ||
| 135 | // 调用 | 103 | // 调用 |
| 136 | loginLogService.createLoginLog(reqDTO); | 104 | loginLogService.createLoginLog(reqDTO); |
| 137 | - // 断言,忽略基本字段 | ||
| 138 | - LoginLogDO sysLoginLogDO = loginLogMapper.selectOne(null); | ||
| 139 | - assertPojoEquals(reqDTO, sysLoginLogDO); | 105 | + // 断言 |
| 106 | + LoginLogDO loginLogDO = loginLogMapper.selectOne(null); | ||
| 107 | + assertPojoEquals(reqDTO, loginLogDO); | ||
| 140 | } | 108 | } |
| 141 | 109 | ||
| 142 | } | 110 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImplTest.java
| @@ -5,8 +5,6 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | @@ -5,8 +5,6 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 6 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | 6 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||
| 9 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 10 | import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; | 8 | import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; |
| 11 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 9 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 12 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | 10 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; |
| @@ -16,20 +14,20 @@ import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.Oper | @@ -16,20 +14,20 @@ import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.Oper | ||
| 16 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; | 14 | import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 17 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | 15 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 18 | import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogMapper; | 16 | import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogMapper; |
| 19 | -import cn.iocoder.yudao.module.system.enums.common.SexEnum; | ||
| 20 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; | 17 | import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 21 | import org.junit.jupiter.api.Test; | 18 | import org.junit.jupiter.api.Test; |
| 22 | import org.springframework.boot.test.mock.mockito.MockBean; | 19 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 23 | import org.springframework.context.annotation.Import; | 20 | import org.springframework.context.annotation.Import; |
| 24 | 21 | ||
| 25 | import javax.annotation.Resource; | 22 | import javax.annotation.Resource; |
| 26 | -import java.time.LocalDateTime; | ||
| 27 | import java.util.Collections; | 23 | import java.util.Collections; |
| 28 | import java.util.List; | 24 | import java.util.List; |
| 29 | 25 | ||
| 30 | import static cn.hutool.core.util.RandomUtil.randomEle; | 26 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 31 | import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; | 27 | import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; |
| 28 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | ||
| 32 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | 29 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 30 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 33 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 31 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 34 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | 32 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| 35 | import static org.junit.jupiter.api.Assertions.assertEquals; | 33 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| @@ -49,34 +47,28 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { | @@ -49,34 +47,28 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { | ||
| 49 | 47 | ||
| 50 | @Test | 48 | @Test |
| 51 | public void testCreateOperateLogAsync() { | 49 | public void testCreateOperateLogAsync() { |
| 52 | - String traceId = TracerUtils.getTraceId(); | ||
| 53 | - OperateLogCreateReqDTO reqVO = RandomUtils.randomPojo(OperateLogCreateReqDTO.class, o -> { | ||
| 54 | - o.setTraceId(traceId); | ||
| 55 | - o.setUserId(randomLongId()); | ||
| 56 | - o.setUserType(randomEle(UserTypeEnum.values()).getValue()); | ||
| 57 | - o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build()); | ||
| 58 | - }); | 50 | + OperateLogCreateReqDTO reqVO = RandomUtils.randomPojo(OperateLogCreateReqDTO.class, |
| 51 | + o -> o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build())); | ||
| 59 | 52 | ||
| 60 | - // 执行service方法 | 53 | + // 调研 |
| 61 | operateLogServiceImpl.createOperateLog(reqVO); | 54 | operateLogServiceImpl.createOperateLog(reqVO); |
| 62 | - // 断言插入是否正确 | ||
| 63 | - OperateLogDO sysOperateLogDO = operateLogMapper.selectOne("trace_id", traceId); | ||
| 64 | - assertPojoEquals(reqVO, sysOperateLogDO); | 55 | + // 断言 |
| 56 | + OperateLogDO operateLogDO = operateLogMapper.selectOne(null); | ||
| 57 | + assertPojoEquals(reqVO, operateLogDO); | ||
| 65 | } | 58 | } |
| 66 | 59 | ||
| 67 | @Test | 60 | @Test |
| 68 | public void testGetOperateLogPage() { | 61 | public void testGetOperateLogPage() { |
| 69 | - // 构造测试数据 | ||
| 70 | - // 先构造用户 | 62 | + // mock(用户信息) |
| 71 | AdminUserDO user = RandomUtils.randomPojo(AdminUserDO.class, o -> { | 63 | AdminUserDO user = RandomUtils.randomPojo(AdminUserDO.class, o -> { |
| 72 | - o.setNickname("wangkai"); | ||
| 73 | - o.setSex(SexEnum.MALE.getSex()); | 64 | + o.setNickname("wang"); |
| 74 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 65 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 75 | }); | 66 | }); |
| 76 | - when(userService.getUsersByNickname("wangkai")).thenReturn(Collections.singletonList(user)); | 67 | + when(userService.getUserListByNickname("wang")).thenReturn(Collections.singletonList(user)); |
| 77 | Long userId = user.getId(); | 68 | Long userId = user.getId(); |
| 69 | + | ||
| 78 | // 构造操作日志 | 70 | // 构造操作日志 |
| 79 | - OperateLogDO sysOperateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { | 71 | + OperateLogDO operateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { |
| 80 | o.setUserId(userId); | 72 | o.setUserId(userId); |
| 81 | o.setUserType(randomEle(UserTypeEnum.values()).getValue()); | 73 | o.setUserType(randomEle(UserTypeEnum.values()).getValue()); |
| 82 | o.setModule("order"); | 74 | o.setModule("order"); |
| @@ -85,50 +77,46 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { | @@ -85,50 +77,46 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { | ||
| 85 | o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); | 77 | o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); |
| 86 | o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build()); | 78 | o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build()); |
| 87 | }); | 79 | }); |
| 88 | - operateLogMapper.insert(sysOperateLogDO); | ||
| 89 | - | ||
| 90 | - // 下面几个是不匹配的数据 | ||
| 91 | - // 随机 userId | ||
| 92 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setUserId(userId + 1))); | ||
| 93 | - // module 不同 | ||
| 94 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setModule("user"))); | ||
| 95 | - // type 不同 | ||
| 96 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setType(OperateTypeEnum.IMPORT.getType()))); | ||
| 97 | - // createTime 不同 | ||
| 98 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setStartTime(buildTime(2021, 2, 6)))); | ||
| 99 | - // resultCode 不同 | ||
| 100 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setResultCode(BAD_REQUEST.getCode()))); | 80 | + operateLogMapper.insert(operateLogDO); |
| 81 | + // 测试 userId 不匹配 | ||
| 82 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setUserId(userId + 1))); | ||
| 83 | + // 测试 module 不匹配 | ||
| 84 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setModule("user"))); | ||
| 85 | + // 测试 type 不匹配 | ||
| 86 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setType(OperateTypeEnum.IMPORT.getType()))); | ||
| 87 | + // 测试 createTime 不匹配 | ||
| 88 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setStartTime(buildTime(2021, 2, 6)))); | ||
| 89 | + // 测试 resultCode 不匹配 | ||
| 90 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setResultCode(BAD_REQUEST.getCode()))); | ||
| 101 | 91 | ||
| 102 | // 构造调用参数 | 92 | // 构造调用参数 |
| 103 | OperateLogPageReqVO reqVO = new OperateLogPageReqVO(); | 93 | OperateLogPageReqVO reqVO = new OperateLogPageReqVO(); |
| 104 | - reqVO.setUserNickname("wangkai"); | 94 | + reqVO.setUserNickname("wang"); |
| 105 | reqVO.setModule("order"); | 95 | reqVO.setModule("order"); |
| 106 | reqVO.setType(OperateTypeEnum.CREATE.getType()); | 96 | reqVO.setType(OperateTypeEnum.CREATE.getType()); |
| 107 | - reqVO.setStartTime((new LocalDateTime[]{buildTime(2021, 3, 5), | ||
| 108 | - buildTime(2021, 3, 7)})); | 97 | + reqVO.setStartTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); |
| 109 | reqVO.setSuccess(true); | 98 | reqVO.setSuccess(true); |
| 110 | 99 | ||
| 111 | - // 调用service方法 | 100 | + // 调用 |
| 112 | PageResult<OperateLogDO> pageResult = operateLogServiceImpl.getOperateLogPage(reqVO); | 101 | PageResult<OperateLogDO> pageResult = operateLogServiceImpl.getOperateLogPage(reqVO); |
| 113 | // 断言,只查到了一条符合条件的 | 102 | // 断言,只查到了一条符合条件的 |
| 114 | assertEquals(1, pageResult.getTotal()); | 103 | assertEquals(1, pageResult.getTotal()); |
| 115 | assertEquals(1, pageResult.getList().size()); | 104 | assertEquals(1, pageResult.getList().size()); |
| 116 | - assertPojoEquals(sysOperateLogDO, pageResult.getList().get(0)); | 105 | + assertPojoEquals(operateLogDO, pageResult.getList().get(0)); |
| 117 | } | 106 | } |
| 118 | 107 | ||
| 119 | @Test | 108 | @Test |
| 120 | public void testGetOperateLogs() { | 109 | public void testGetOperateLogs() { |
| 121 | - // 构造测试数据 | ||
| 122 | - // 先构造用户 | 110 | + // mock(用户信息) |
| 123 | AdminUserDO user = RandomUtils.randomPojo(AdminUserDO.class, o -> { | 111 | AdminUserDO user = RandomUtils.randomPojo(AdminUserDO.class, o -> { |
| 124 | - o.setNickname("wangkai"); | ||
| 125 | - o.setSex(SexEnum.MALE.getSex()); | 112 | + o.setNickname("wang"); |
| 126 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 113 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 127 | }); | 114 | }); |
| 128 | - when(userService.getUsersByNickname("wangkai")).thenReturn(Collections.singletonList(user)); | 115 | + when(userService.getUserListByNickname("wang")).thenReturn(Collections.singletonList(user)); |
| 129 | Long userId = user.getId(); | 116 | Long userId = user.getId(); |
| 117 | + | ||
| 130 | // 构造操作日志 | 118 | // 构造操作日志 |
| 131 | - OperateLogDO sysOperateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { | 119 | + OperateLogDO operateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { |
| 132 | o.setUserId(userId); | 120 | o.setUserId(userId); |
| 133 | o.setUserType(randomEle(UserTypeEnum.values()).getValue()); | 121 | o.setUserType(randomEle(UserTypeEnum.values()).getValue()); |
| 134 | o.setModule("order"); | 122 | o.setModule("order"); |
| @@ -137,33 +125,31 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { | @@ -137,33 +125,31 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest { | ||
| 137 | o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); | 125 | o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); |
| 138 | o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build()); | 126 | o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build()); |
| 139 | }); | 127 | }); |
| 140 | - operateLogMapper.insert(sysOperateLogDO); | ||
| 141 | - | ||
| 142 | - // 下面几个是不匹配的数据 | ||
| 143 | - // 随机 userId | ||
| 144 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setUserId(userId + 1))); | ||
| 145 | - // module 不同 | ||
| 146 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setModule("user"))); | ||
| 147 | - // type 不同 | ||
| 148 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setType(OperateTypeEnum.IMPORT.getType()))); | ||
| 149 | - // createTime 不同 | ||
| 150 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setStartTime(buildTime(2021, 2, 6)))); | ||
| 151 | - // resultCode 不同 | ||
| 152 | - operateLogMapper.insert(ObjectUtils.cloneIgnoreId(sysOperateLogDO, logDO -> logDO.setResultCode(BAD_REQUEST.getCode()))); | 128 | + operateLogMapper.insert(operateLogDO); |
| 129 | + // 测试 userId 不匹配 | ||
| 130 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setUserId(userId + 1))); | ||
| 131 | + // 测试 module 不匹配 | ||
| 132 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setModule("user"))); | ||
| 133 | + // 测试 type 不匹配 | ||
| 134 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setType(OperateTypeEnum.IMPORT.getType()))); | ||
| 135 | + // 测试 createTime 不匹配 | ||
| 136 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setStartTime(buildTime(2021, 2, 6)))); | ||
| 137 | + // 测试 resultCode 不匹配 | ||
| 138 | + operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setResultCode(BAD_REQUEST.getCode()))); | ||
| 153 | 139 | ||
| 154 | // 构造调用参数 | 140 | // 构造调用参数 |
| 155 | OperateLogExportReqVO reqVO = new OperateLogExportReqVO(); | 141 | OperateLogExportReqVO reqVO = new OperateLogExportReqVO(); |
| 156 | - reqVO.setUserNickname("wangkai"); | 142 | + reqVO.setUserNickname("wang"); |
| 157 | reqVO.setModule("order"); | 143 | reqVO.setModule("order"); |
| 158 | reqVO.setType(OperateTypeEnum.CREATE.getType()); | 144 | reqVO.setType(OperateTypeEnum.CREATE.getType()); |
| 159 | - reqVO.setStartTime((new LocalDateTime[]{buildTime(2021, 3, 5),buildTime(2021, 3, 7)})); | 145 | + reqVO.setStartTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); |
| 160 | reqVO.setSuccess(true); | 146 | reqVO.setSuccess(true); |
| 161 | 147 | ||
| 162 | // 调用 service 方法 | 148 | // 调用 service 方法 |
| 163 | - List<OperateLogDO> list = operateLogServiceImpl.getOperateLogs(reqVO); | 149 | + List<OperateLogDO> list = operateLogServiceImpl.getOperateLogList(reqVO); |
| 164 | // 断言,只查到了一条符合条件的 | 150 | // 断言,只查到了一条符合条件的 |
| 165 | assertEquals(1, list.size()); | 151 | assertEquals(1, list.size()); |
| 166 | - assertPojoEquals(sysOperateLogDO, list.get(0)); | 152 | + assertPojoEquals(operateLogDO, list.get(0)); |
| 167 | } | 153 | } |
| 168 | 154 | ||
| 169 | } | 155 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImplTest.java
| @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou | ||
| 6 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; |
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; |
| 9 | -import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; | ||
| 10 | import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; | 9 | import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; |
| 11 | import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; | 10 | import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; |
| 12 | import org.junit.jupiter.api.Test; | 11 | import org.junit.jupiter.api.Test; |
| @@ -14,7 +13,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; | @@ -14,7 +13,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 14 | import org.springframework.context.annotation.Import; | 13 | import org.springframework.context.annotation.Import; |
| 15 | 14 | ||
| 16 | import javax.annotation.Resource; | 15 | import javax.annotation.Resource; |
| 17 | - | 16 | +import java.util.List; |
| 18 | import java.util.Map; | 17 | import java.util.Map; |
| 19 | 18 | ||
| 20 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | 19 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| @@ -23,7 +22,9 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic | @@ -23,7 +22,9 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic | ||
| 23 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 22 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 24 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; | 23 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS; |
| 25 | import static org.junit.jupiter.api.Assertions.*; | 24 | import static org.junit.jupiter.api.Assertions.*; |
| 25 | +import static org.mockito.ArgumentMatchers.eq; | ||
| 26 | import static org.mockito.Mockito.verify; | 26 | import static org.mockito.Mockito.verify; |
| 27 | +import static org.mockito.Mockito.when; | ||
| 27 | 28 | ||
| 28 | /** | 29 | /** |
| 29 | * {@link MailAccountServiceImpl} 的单元测试类 | 30 | * {@link MailAccountServiceImpl} 的单元测试类 |
| @@ -109,6 +110,8 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { | @@ -109,6 +110,8 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { | ||
| 109 | mailAccountMapper.insert(dbMailAccount);// @Sql: 先插入出一条存在的数据 | 110 | mailAccountMapper.insert(dbMailAccount);// @Sql: 先插入出一条存在的数据 |
| 110 | // 准备参数 | 111 | // 准备参数 |
| 111 | Long id = dbMailAccount.getId(); | 112 | Long id = dbMailAccount.getId(); |
| 113 | + // mock 方法(无关联模版) | ||
| 114 | + when(mailTemplateService.countByAccountId(eq(id))).thenReturn(0L); | ||
| 112 | 115 | ||
| 113 | // 调用 | 116 | // 调用 |
| 114 | mailAccountService.deleteMailAccount(id); | 117 | mailAccountService.deleteMailAccount(id); |
| @@ -118,6 +121,21 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { | @@ -118,6 +121,21 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { | ||
| 118 | } | 121 | } |
| 119 | 122 | ||
| 120 | @Test | 123 | @Test |
| 124 | + public void testGetMailAccountFromCache() { | ||
| 125 | + // mock 数据 | ||
| 126 | + MailAccountDO dbMailAccount = randomPojo(MailAccountDO.class); | ||
| 127 | + mailAccountMapper.insert(dbMailAccount);// @Sql: 先插入出一条存在的数据 | ||
| 128 | + mailAccountService.initLocalCache(); | ||
| 129 | + // 准备参数 | ||
| 130 | + Long id = dbMailAccount.getId(); | ||
| 131 | + | ||
| 132 | + // 调用 | ||
| 133 | + MailAccountDO mailAccount = mailAccountService.getMailAccountFromCache(id); | ||
| 134 | + // 断言 | ||
| 135 | + assertPojoEquals(dbMailAccount, mailAccount); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + @Test | ||
| 121 | public void testDeleteMailAccount_notExists() { | 139 | public void testDeleteMailAccount_notExists() { |
| 122 | // 准备参数 | 140 | // 准备参数 |
| 123 | Long id = randomLongId(); | 141 | Long id = randomLongId(); |
| @@ -151,4 +169,35 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { | @@ -151,4 +169,35 @@ public class MailAccountServiceImplTest extends BaseDbUnitTest { | ||
| 151 | assertPojoEquals(dbMailAccount, pageResult.getList().get(0)); | 169 | assertPojoEquals(dbMailAccount, pageResult.getList().get(0)); |
| 152 | } | 170 | } |
| 153 | 171 | ||
| 172 | + @Test | ||
| 173 | + public void testGetMailAccount() { | ||
| 174 | + // mock 数据 | ||
| 175 | + MailAccountDO dbMailAccount = randomPojo(MailAccountDO.class); | ||
| 176 | + mailAccountMapper.insert(dbMailAccount);// @Sql: 先插入出一条存在的数据 | ||
| 177 | + // 准备参数 | ||
| 178 | + Long id = dbMailAccount.getId(); | ||
| 179 | + | ||
| 180 | + // 调用 | ||
| 181 | + MailAccountDO mailAccount = mailAccountService.getMailAccount(id); | ||
| 182 | + // 断言 | ||
| 183 | + assertPojoEquals(dbMailAccount, mailAccount); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + @Test | ||
| 187 | + public void testGetMailAccountList() { | ||
| 188 | + // mock 数据 | ||
| 189 | + MailAccountDO dbMailAccount01 = randomPojo(MailAccountDO.class); | ||
| 190 | + mailAccountMapper.insert(dbMailAccount01); | ||
| 191 | + MailAccountDO dbMailAccount02 = randomPojo(MailAccountDO.class); | ||
| 192 | + mailAccountMapper.insert(dbMailAccount02); | ||
| 193 | + // 准备参数 | ||
| 194 | + | ||
| 195 | + // 调用 | ||
| 196 | + List<MailAccountDO> list = mailAccountService.getMailAccountList(); | ||
| 197 | + // 断言 | ||
| 198 | + assertEquals(2, list.size()); | ||
| 199 | + assertPojoEquals(dbMailAccount01, list.get(0)); | ||
| 200 | + assertPojoEquals(dbMailAccount02, list.get(1)); | ||
| 201 | + } | ||
| 202 | + | ||
| 154 | } | 203 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailLogServiceImplTest.java
| @@ -117,6 +117,20 @@ public class MailLogServiceImplTest extends BaseDbUnitTest { | @@ -117,6 +117,20 @@ public class MailLogServiceImplTest extends BaseDbUnitTest { | ||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | @Test | 119 | @Test |
| 120 | + public void testGetMailLog() { | ||
| 121 | + // mock 数据 | ||
| 122 | + MailLogDO dbMailLog = randomPojo(MailLogDO.class, o -> o.setTemplateParams(randomTemplateParams())); | ||
| 123 | + mailLogMapper.insert(dbMailLog); | ||
| 124 | + // 准备参数 | ||
| 125 | + Long id = dbMailLog.getId(); | ||
| 126 | + | ||
| 127 | + // 调用 | ||
| 128 | + MailLogDO mailLog = mailLogService.getMailLog(id); | ||
| 129 | + // 断言 | ||
| 130 | + assertPojoEquals(dbMailLog, mailLog); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + @Test | ||
| 120 | public void testGetMailLogPage() { | 134 | public void testGetMailLogPage() { |
| 121 | // mock 数据 | 135 | // mock 数据 |
| 122 | MailLogDO dbMailLog = randomPojo(MailLogDO.class, o -> { // 等会查询到 | 136 | MailLogDO dbMailLog = randomPojo(MailLogDO.class, o -> { // 等会查询到 |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImplTest.java
| @@ -6,14 +6,20 @@ import cn.hutool.extra.mail.MailUtil; | @@ -6,14 +6,20 @@ import cn.hutool.extra.mail.MailUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 7 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 8 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | 8 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 9 | +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; |
| 10 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; |
| 12 | +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | ||
| 13 | +import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage; | ||
| 11 | import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; | 14 | import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; |
| 15 | +import cn.iocoder.yudao.module.system.service.member.MemberService; | ||
| 16 | +import cn.iocoder.yudao.module.system.service.user.AdminUserService; | ||
| 12 | import org.assertj.core.util.Lists; | 17 | import org.assertj.core.util.Lists; |
| 13 | import org.junit.jupiter.api.Disabled; | 18 | import org.junit.jupiter.api.Disabled; |
| 14 | import org.junit.jupiter.api.Test; | 19 | import org.junit.jupiter.api.Test; |
| 15 | import org.mockito.InjectMocks; | 20 | import org.mockito.InjectMocks; |
| 16 | import org.mockito.Mock; | 21 | import org.mockito.Mock; |
| 22 | +import org.mockito.MockedStatic; | ||
| 17 | 23 | ||
| 18 | import java.util.HashMap; | 24 | import java.util.HashMap; |
| 19 | import java.util.Map; | 25 | import java.util.Map; |
| @@ -23,6 +29,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic | @@ -23,6 +29,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic | ||
| 23 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 29 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 24 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 30 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 25 | import static org.junit.jupiter.api.Assertions.assertEquals; | 31 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 32 | +import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| 26 | import static org.mockito.ArgumentMatchers.eq; | 33 | import static org.mockito.ArgumentMatchers.eq; |
| 27 | import static org.mockito.Mockito.*; | 34 | import static org.mockito.Mockito.*; |
| 28 | 35 | ||
| @@ -32,6 +39,10 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -32,6 +39,10 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 32 | private MailSendServiceImpl mailSendService; | 39 | private MailSendServiceImpl mailSendService; |
| 33 | 40 | ||
| 34 | @Mock | 41 | @Mock |
| 42 | + private AdminUserService adminUserService; | ||
| 43 | + @Mock | ||
| 44 | + private MemberService memberService; | ||
| 45 | + @Mock | ||
| 35 | private MailAccountService mailAccountService; | 46 | private MailAccountService mailAccountService; |
| 36 | @Mock | 47 | @Mock |
| 37 | private MailTemplateService mailTemplateService; | 48 | private MailTemplateService mailTemplateService; |
| @@ -55,6 +66,82 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -55,6 +66,82 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 55 | System.out.println("发送结果:" + messageId); | 66 | System.out.println("发送结果:" + messageId); |
| 56 | } | 67 | } |
| 57 | 68 | ||
| 69 | + @Test | ||
| 70 | + public void testSendSingleMailToAdmin() { | ||
| 71 | + // 准备参数 | ||
| 72 | + Long userId = randomLongId(); | ||
| 73 | + String templateCode = RandomUtils.randomString(); | ||
| 74 | + Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") | ||
| 75 | + .put("op", "login").build(); | ||
| 76 | + // mock adminUserService 的方法 | ||
| 77 | + AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setMobile("15601691300")); | ||
| 78 | + when(adminUserService.getUser(eq(userId))).thenReturn(user); | ||
| 79 | + | ||
| 80 | + // mock MailTemplateService 的方法 | ||
| 81 | + MailTemplateDO template = randomPojo(MailTemplateDO.class, o -> { | ||
| 82 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 83 | + o.setContent("验证码为{code}, 操作为{op}"); | ||
| 84 | + o.setParams(Lists.newArrayList("code", "op")); | ||
| 85 | + }); | ||
| 86 | + when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | ||
| 87 | + String content = RandomUtils.randomString(); | ||
| 88 | + when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) | ||
| 89 | + .thenReturn(content); | ||
| 90 | + // mock MailAccountService 的方法 | ||
| 91 | + MailAccountDO account = randomPojo(MailAccountDO.class); | ||
| 92 | + when(mailAccountService.getMailAccountFromCache(eq(template.getAccountId()))).thenReturn(account); | ||
| 93 | + // mock MailLogService 的方法 | ||
| 94 | + Long mailLogId = randomLongId(); | ||
| 95 | + when(mailLogService.createMailLog(eq(userId), eq(UserTypeEnum.ADMIN.getValue()), eq(user.getEmail()), | ||
| 96 | + eq(account), eq(template), eq(content), eq(templateParams), eq(true))).thenReturn(mailLogId); | ||
| 97 | + | ||
| 98 | + // 调用 | ||
| 99 | + Long resultMailLogId = mailSendService.sendSingleMailToAdmin(null, userId, templateCode, templateParams); | ||
| 100 | + // 断言 | ||
| 101 | + assertEquals(mailLogId, resultMailLogId); | ||
| 102 | + // 断言调用 | ||
| 103 | + verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(user.getEmail()), | ||
| 104 | + eq(account.getId()), eq(template.getNickname()), eq(template.getTitle()), eq(content)); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Test | ||
| 108 | + public void testSendSingleMailToMember() { | ||
| 109 | + // 准备参数 | ||
| 110 | + Long userId = randomLongId(); | ||
| 111 | + String templateCode = RandomUtils.randomString(); | ||
| 112 | + Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") | ||
| 113 | + .put("op", "login").build(); | ||
| 114 | + // mock memberService 的方法 | ||
| 115 | + String mail = randomEmail(); | ||
| 116 | + when(memberService.getMemberUserEmail(eq(userId))).thenReturn(mail); | ||
| 117 | + | ||
| 118 | + // mock MailTemplateService 的方法 | ||
| 119 | + MailTemplateDO template = randomPojo(MailTemplateDO.class, o -> { | ||
| 120 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 121 | + o.setContent("验证码为{code}, 操作为{op}"); | ||
| 122 | + o.setParams(Lists.newArrayList("code", "op")); | ||
| 123 | + }); | ||
| 124 | + when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | ||
| 125 | + String content = RandomUtils.randomString(); | ||
| 126 | + when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) | ||
| 127 | + .thenReturn(content); | ||
| 128 | + // mock MailAccountService 的方法 | ||
| 129 | + MailAccountDO account = randomPojo(MailAccountDO.class); | ||
| 130 | + when(mailAccountService.getMailAccountFromCache(eq(template.getAccountId()))).thenReturn(account); | ||
| 131 | + // mock MailLogService 的方法 | ||
| 132 | + Long mailLogId = randomLongId(); | ||
| 133 | + when(mailLogService.createMailLog(eq(userId), eq(UserTypeEnum.MEMBER.getValue()), eq(mail), | ||
| 134 | + eq(account), eq(template), eq(content), eq(templateParams), eq(true))).thenReturn(mailLogId); | ||
| 135 | + | ||
| 136 | + // 调用 | ||
| 137 | + Long resultMailLogId = mailSendService.sendSingleMailToMember(null, userId, templateCode, templateParams); | ||
| 138 | + // 断言 | ||
| 139 | + assertEquals(mailLogId, resultMailLogId); | ||
| 140 | + // 断言调用 | ||
| 141 | + verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(mail), | ||
| 142 | + eq(account.getId()), eq(template.getNickname()), eq(template.getTitle()), eq(content)); | ||
| 143 | + } | ||
| 144 | + | ||
| 58 | /** | 145 | /** |
| 59 | * 发送成功,当短信模板开启时 | 146 | * 发送成功,当短信模板开启时 |
| 60 | */ | 147 | */ |
| @@ -64,7 +151,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -64,7 +151,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 64 | String mail = randomEmail(); | 151 | String mail = randomEmail(); |
| 65 | Long userId = randomLongId(); | 152 | Long userId = randomLongId(); |
| 66 | Integer userType = randomEle(UserTypeEnum.values()).getValue(); | 153 | Integer userType = randomEle(UserTypeEnum.values()).getValue(); |
| 67 | - String templateCode = randomString(); | 154 | + String templateCode = RandomUtils.randomString(); |
| 68 | Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") | 155 | Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") |
| 69 | .put("op", "login").build(); | 156 | .put("op", "login").build(); |
| 70 | // mock MailTemplateService 的方法 | 157 | // mock MailTemplateService 的方法 |
| @@ -74,7 +161,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -74,7 +161,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 74 | o.setParams(Lists.newArrayList("code", "op")); | 161 | o.setParams(Lists.newArrayList("code", "op")); |
| 75 | }); | 162 | }); |
| 76 | when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | 163 | when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); |
| 77 | - String content = randomString(); | 164 | + String content = RandomUtils.randomString(); |
| 78 | when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) | 165 | when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) |
| 79 | .thenReturn(content); | 166 | .thenReturn(content); |
| 80 | // mock MailAccountService 的方法 | 167 | // mock MailAccountService 的方法 |
| @@ -103,7 +190,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -103,7 +190,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 103 | String mail = randomEmail(); | 190 | String mail = randomEmail(); |
| 104 | Long userId = randomLongId(); | 191 | Long userId = randomLongId(); |
| 105 | Integer userType = randomEle(UserTypeEnum.values()).getValue(); | 192 | Integer userType = randomEle(UserTypeEnum.values()).getValue(); |
| 106 | - String templateCode = randomString(); | 193 | + String templateCode = RandomUtils.randomString(); |
| 107 | Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") | 194 | Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") |
| 108 | .put("op", "login").build(); | 195 | .put("op", "login").build(); |
| 109 | // mock MailTemplateService 的方法 | 196 | // mock MailTemplateService 的方法 |
| @@ -113,7 +200,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -113,7 +200,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 113 | o.setParams(Lists.newArrayList("code", "op")); | 200 | o.setParams(Lists.newArrayList("code", "op")); |
| 114 | }); | 201 | }); |
| 115 | when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | 202 | when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); |
| 116 | - String content = randomString(); | 203 | + String content = RandomUtils.randomString(); |
| 117 | when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) | 204 | when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) |
| 118 | .thenReturn(content); | 205 | .thenReturn(content); |
| 119 | // mock MailAccountService 的方法 | 206 | // mock MailAccountService 的方法 |
| @@ -134,18 +221,18 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -134,18 +221,18 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 134 | } | 221 | } |
| 135 | 222 | ||
| 136 | @Test | 223 | @Test |
| 137 | - public void testCheckMailTemplateValid_notExists() { | 224 | + public void testValidateMailTemplateValid_notExists() { |
| 138 | // 准备参数 | 225 | // 准备参数 |
| 139 | - String templateCode = randomString(); | 226 | + String templateCode = RandomUtils.randomString(); |
| 140 | // mock 方法 | 227 | // mock 方法 |
| 141 | 228 | ||
| 142 | // 调用,并断言异常 | 229 | // 调用,并断言异常 |
| 143 | - assertServiceException(() -> mailSendService.checkMailTemplateValid(templateCode), | 230 | + assertServiceException(() -> mailSendService.validateMailTemplate(templateCode), |
| 144 | MAIL_TEMPLATE_NOT_EXISTS); | 231 | MAIL_TEMPLATE_NOT_EXISTS); |
| 145 | } | 232 | } |
| 146 | 233 | ||
| 147 | @Test | 234 | @Test |
| 148 | - public void testCheckTemplateParams_paramMiss() { | 235 | + public void testValidateTemplateParams_paramMiss() { |
| 149 | // 准备参数 | 236 | // 准备参数 |
| 150 | MailTemplateDO template = randomPojo(MailTemplateDO.class, | 237 | MailTemplateDO template = randomPojo(MailTemplateDO.class, |
| 151 | o -> o.setParams(Lists.newArrayList("code"))); | 238 | o -> o.setParams(Lists.newArrayList("code"))); |
| @@ -153,18 +240,80 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | @@ -153,18 +240,80 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { | ||
| 153 | // mock 方法 | 240 | // mock 方法 |
| 154 | 241 | ||
| 155 | // 调用,并断言异常 | 242 | // 调用,并断言异常 |
| 156 | - assertServiceException(() -> mailSendService.checkTemplateParams(template, templateParams), | 243 | + assertServiceException(() -> mailSendService.validateTemplateParams(template, templateParams), |
| 157 | MAIL_SEND_TEMPLATE_PARAM_MISS, "code"); | 244 | MAIL_SEND_TEMPLATE_PARAM_MISS, "code"); |
| 158 | } | 245 | } |
| 159 | 246 | ||
| 160 | @Test | 247 | @Test |
| 161 | - public void testCheckMail_notExists() { | 248 | + public void testValidateMail_notExists() { |
| 162 | // 准备参数 | 249 | // 准备参数 |
| 163 | // mock 方法 | 250 | // mock 方法 |
| 164 | 251 | ||
| 165 | // 调用,并断言异常 | 252 | // 调用,并断言异常 |
| 166 | - assertServiceException(() -> mailSendService.checkMail(null), | 253 | + assertServiceException(() -> mailSendService.validateMail(null), |
| 167 | MAIL_SEND_MAIL_NOT_EXISTS); | 254 | MAIL_SEND_MAIL_NOT_EXISTS); |
| 168 | } | 255 | } |
| 169 | 256 | ||
| 257 | + @Test | ||
| 258 | + public void testDoSendMail_success() { | ||
| 259 | + try (MockedStatic<MailUtil> mailUtilMock = mockStatic(MailUtil.class)) { | ||
| 260 | + // 准备参数 | ||
| 261 | + MailSendMessage message = randomPojo(MailSendMessage.class, o -> o.setNickname("芋艿")); | ||
| 262 | + // mock 方法(获得邮箱账号) | ||
| 263 | + MailAccountDO account = randomPojo(MailAccountDO.class, o -> o.setMail("7685@qq.com")); | ||
| 264 | + when(mailAccountService.getMailAccountFromCache(eq(message.getAccountId()))) | ||
| 265 | + .thenReturn(account); | ||
| 266 | + | ||
| 267 | + // mock 方法(发送邮件) | ||
| 268 | + String messageId = randomString(); | ||
| 269 | + mailUtilMock.when(() -> MailUtil.send(argThat(mailAccount -> { | ||
| 270 | + assertEquals("芋艿 <7685@qq.com>", mailAccount.getFrom()); | ||
| 271 | + assertTrue(mailAccount.isAuth()); | ||
| 272 | + assertEquals(account.getUsername(), mailAccount.getUser()); | ||
| 273 | + assertEquals(account.getPassword(), mailAccount.getPass()); | ||
| 274 | + assertEquals(account.getHost(), mailAccount.getHost()); | ||
| 275 | + assertEquals(account.getPort(), mailAccount.getPort()); | ||
| 276 | + assertEquals(account.getSslEnable(), mailAccount.isSslEnable()); | ||
| 277 | + return true; | ||
| 278 | + }), eq(message.getMail()), eq(message.getTitle()), eq(message.getContent()), eq(true))) | ||
| 279 | + .thenReturn(messageId); | ||
| 280 | + | ||
| 281 | + // 调用 | ||
| 282 | + mailSendService.doSendMail(message); | ||
| 283 | + // 断言 | ||
| 284 | + verify(mailLogService).updateMailSendResult(eq(message.getLogId()), eq(messageId), isNull()); | ||
| 285 | + } | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + @Test | ||
| 289 | + public void testDoSendMail_exception() { | ||
| 290 | + try (MockedStatic<MailUtil> mailUtilMock = mockStatic(MailUtil.class)) { | ||
| 291 | + // 准备参数 | ||
| 292 | + MailSendMessage message = randomPojo(MailSendMessage.class, o -> o.setNickname("芋艿")); | ||
| 293 | + // mock 方法(获得邮箱账号) | ||
| 294 | + MailAccountDO account = randomPojo(MailAccountDO.class, o -> o.setMail("7685@qq.com")); | ||
| 295 | + when(mailAccountService.getMailAccountFromCache(eq(message.getAccountId()))) | ||
| 296 | + .thenReturn(account); | ||
| 297 | + | ||
| 298 | + // mock 方法(发送邮件) | ||
| 299 | + Exception e = new NullPointerException("啦啦啦"); | ||
| 300 | + mailUtilMock.when(() -> MailUtil.send(argThat(mailAccount -> { | ||
| 301 | + assertEquals("芋艿 <7685@qq.com>", mailAccount.getFrom()); | ||
| 302 | + assertTrue(mailAccount.isAuth()); | ||
| 303 | + assertEquals(account.getUsername(), mailAccount.getUser()); | ||
| 304 | + assertEquals(account.getPassword(), mailAccount.getPass()); | ||
| 305 | + assertEquals(account.getHost(), mailAccount.getHost()); | ||
| 306 | + assertEquals(account.getPort(), mailAccount.getPort()); | ||
| 307 | + assertEquals(account.getSslEnable(), mailAccount.isSslEnable()); | ||
| 308 | + return true; | ||
| 309 | + }), eq(message.getMail()), eq(message.getTitle()), eq(message.getContent()), eq(true))) | ||
| 310 | + .thenThrow(e); | ||
| 311 | + | ||
| 312 | + // 调用 | ||
| 313 | + mailSendService.doSendMail(message); | ||
| 314 | + // 断言 | ||
| 315 | + verify(mailLogService).updateMailSendResult(eq(message.getLogId()), isNull(), same(e)); | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | + | ||
| 170 | } | 319 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImplTest.java
| @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 6 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO; |
| 9 | -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | ||
| 10 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; |
| 11 | import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; |
| 12 | import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; | 11 | import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer; |
| @@ -15,7 +14,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; | @@ -15,7 +14,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 15 | import org.springframework.context.annotation.Import; | 14 | import org.springframework.context.annotation.Import; |
| 16 | 15 | ||
| 17 | import javax.annotation.Resource; | 16 | import javax.annotation.Resource; |
| 18 | - | 17 | +import java.util.HashMap; |
| 18 | +import java.util.List; | ||
| 19 | import java.util.Map; | 19 | import java.util.Map; |
| 20 | 20 | ||
| 21 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | 21 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
| @@ -27,6 +27,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId | @@ -27,6 +27,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId | ||
| 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 28 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; | 28 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS; |
| 29 | import static org.junit.jupiter.api.Assertions.*; | 29 | import static org.junit.jupiter.api.Assertions.*; |
| 30 | +import static org.mockito.Mockito.verify; | ||
| 30 | 31 | ||
| 31 | /** | 32 | /** |
| 32 | * {@link MailTemplateServiceImpl} 的单元测试类 | 33 | * {@link MailTemplateServiceImpl} 的单元测试类 |
| @@ -72,6 +73,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | @@ -72,6 +73,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 72 | // 校验记录的属性是否正确 | 73 | // 校验记录的属性是否正确 |
| 73 | MailTemplateDO mailTemplate = mailTemplateMapper.selectById(mailTemplateId); | 74 | MailTemplateDO mailTemplate = mailTemplateMapper.selectById(mailTemplateId); |
| 74 | assertPojoEquals(reqVO, mailTemplate); | 75 | assertPojoEquals(reqVO, mailTemplate); |
| 76 | + verify(mailProducer).sendMailTemplateRefreshMessage(); | ||
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | @Test | 79 | @Test |
| @@ -89,6 +91,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | @@ -89,6 +91,7 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 89 | // 校验是否更新正确 | 91 | // 校验是否更新正确 |
| 90 | MailTemplateDO mailTemplate = mailTemplateMapper.selectById(reqVO.getId()); // 获取最新的 | 92 | MailTemplateDO mailTemplate = mailTemplateMapper.selectById(reqVO.getId()); // 获取最新的 |
| 91 | assertPojoEquals(reqVO, mailTemplate); | 93 | assertPojoEquals(reqVO, mailTemplate); |
| 94 | + verify(mailProducer).sendMailTemplateRefreshMessage(); | ||
| 92 | } | 95 | } |
| 93 | 96 | ||
| 94 | @Test | 97 | @Test |
| @@ -110,8 +113,9 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | @@ -110,8 +113,9 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 110 | 113 | ||
| 111 | // 调用 | 114 | // 调用 |
| 112 | mailTemplateService.deleteMailTemplate(id); | 115 | mailTemplateService.deleteMailTemplate(id); |
| 113 | - // 校验数据不存在了 | ||
| 114 | - assertNull(mailTemplateMapper.selectById(id)); | 116 | + // 校验数据不存在了 |
| 117 | + assertNull(mailTemplateMapper.selectById(id)); | ||
| 118 | + verify(mailProducer).sendMailTemplateRefreshMessage(); | ||
| 115 | } | 119 | } |
| 116 | 120 | ||
| 117 | @Test | 121 | @Test |
| @@ -160,4 +164,77 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | @@ -160,4 +164,77 @@ public class MailTemplateServiceImplTest extends BaseDbUnitTest { | ||
| 160 | assertPojoEquals(dbMailTemplate, pageResult.getList().get(0)); | 164 | assertPojoEquals(dbMailTemplate, pageResult.getList().get(0)); |
| 161 | } | 165 | } |
| 162 | 166 | ||
| 167 | + @Test | ||
| 168 | + public void testGetMailTemplateList() { | ||
| 169 | + // mock 数据 | ||
| 170 | + MailTemplateDO dbMailTemplate01 = randomPojo(MailTemplateDO.class); | ||
| 171 | + mailTemplateMapper.insert(dbMailTemplate01); | ||
| 172 | + MailTemplateDO dbMailTemplate02 = randomPojo(MailTemplateDO.class); | ||
| 173 | + mailTemplateMapper.insert(dbMailTemplate02); | ||
| 174 | + | ||
| 175 | + // 调用 | ||
| 176 | + List<MailTemplateDO> list = mailTemplateService.getMailTemplateList(); | ||
| 177 | + // 断言 | ||
| 178 | + assertEquals(2, list.size()); | ||
| 179 | + assertEquals(dbMailTemplate01, list.get(0)); | ||
| 180 | + assertEquals(dbMailTemplate02, list.get(1)); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + @Test | ||
| 184 | + public void testGetMailTemplate() { | ||
| 185 | + // mock 数据 | ||
| 186 | + MailTemplateDO dbMailTemplate = randomPojo(MailTemplateDO.class); | ||
| 187 | + mailTemplateMapper.insert(dbMailTemplate); | ||
| 188 | + // 准备参数 | ||
| 189 | + Long id = dbMailTemplate.getId(); | ||
| 190 | + | ||
| 191 | + // 调用 | ||
| 192 | + MailTemplateDO mailTemplate = mailTemplateService.getMailTemplate(id); | ||
| 193 | + // 断言 | ||
| 194 | + assertPojoEquals(dbMailTemplate, mailTemplate); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + @Test | ||
| 198 | + public void testGetMailTemplateByCodeFromCache() { | ||
| 199 | + // mock 数据 | ||
| 200 | + MailTemplateDO dbMailTemplate = randomPojo(MailTemplateDO.class); | ||
| 201 | + mailTemplateMapper.insert(dbMailTemplate); | ||
| 202 | + mailTemplateService.initLocalCache(); | ||
| 203 | + // 准备参数 | ||
| 204 | + String code = dbMailTemplate.getCode(); | ||
| 205 | + | ||
| 206 | + // 调用 | ||
| 207 | + MailTemplateDO mailTemplate = mailTemplateService.getMailTemplateByCodeFromCache(code); | ||
| 208 | + // 断言 | ||
| 209 | + assertPojoEquals(dbMailTemplate, mailTemplate); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + @Test | ||
| 213 | + public void testFormatMailTemplateContent() { | ||
| 214 | + // 准备参数 | ||
| 215 | + Map<String, Object> params = new HashMap<>(); | ||
| 216 | + params.put("name", "小红"); | ||
| 217 | + params.put("what", "饭"); | ||
| 218 | + | ||
| 219 | + // 调用,并断言 | ||
| 220 | + assertEquals("小红,你好,饭吃了吗?", | ||
| 221 | + mailTemplateService.formatMailTemplateContent("{name},你好,{what}吃了吗?", params)); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + @Test | ||
| 225 | + public void testCountByAccountId() { | ||
| 226 | + // mock 数据 | ||
| 227 | + MailTemplateDO dbMailTemplate = randomPojo(MailTemplateDO.class); | ||
| 228 | + mailTemplateMapper.insert(dbMailTemplate); | ||
| 229 | + // 测试 accountId 不匹配 | ||
| 230 | + mailTemplateMapper.insert(cloneIgnoreId(dbMailTemplate, o -> o.setAccountId(2L))); | ||
| 231 | + // 准备参数 | ||
| 232 | + Long accountId = dbMailTemplate.getAccountId(); | ||
| 233 | + | ||
| 234 | + // 调用 | ||
| 235 | + long count = mailTemplateService.countByAccountId(accountId); | ||
| 236 | + // 断言 | ||
| 237 | + assertEquals(1, count); | ||
| 238 | + } | ||
| 239 | + | ||
| 163 | } | 240 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java
| @@ -2,75 +2,67 @@ package cn.iocoder.yudao.module.system.service.notice; | @@ -2,75 +2,67 @@ package cn.iocoder.yudao.module.system.service.notice; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 5 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; |
| 6 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; |
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 9 | import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; |
| 10 | -import cn.iocoder.yudao.module.system.enums.notice.NoticeTypeEnum; | ||
| 11 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 12 | -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | ||
| 13 | import org.junit.jupiter.api.Test; | 11 | import org.junit.jupiter.api.Test; |
| 14 | import org.springframework.context.annotation.Import; | 12 | import org.springframework.context.annotation.Import; |
| 15 | 13 | ||
| 16 | import javax.annotation.Resource; | 14 | import javax.annotation.Resource; |
| 17 | 15 | ||
| 18 | -import java.util.function.Consumer; | ||
| 19 | - | ||
| 20 | -import static cn.hutool.core.util.RandomUtil.randomEle; | ||
| 21 | -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; | 16 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 22 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 17 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 23 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 24 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | 19 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; |
| 25 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 20 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 21 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; | ||
| 26 | import static org.junit.jupiter.api.Assertions.*; | 22 | import static org.junit.jupiter.api.Assertions.*; |
| 27 | 23 | ||
| 28 | @Import(NoticeServiceImpl.class) | 24 | @Import(NoticeServiceImpl.class) |
| 29 | class NoticeServiceImplTest extends BaseDbUnitTest { | 25 | class NoticeServiceImplTest extends BaseDbUnitTest { |
| 30 | 26 | ||
| 31 | @Resource | 27 | @Resource |
| 32 | - private NoticeServiceImpl sysNoticeService; | 28 | + private NoticeServiceImpl noticeService; |
| 33 | 29 | ||
| 34 | @Resource | 30 | @Resource |
| 35 | - private NoticeMapper sysNoticeMapper; | 31 | + private NoticeMapper noticeMapper; |
| 36 | 32 | ||
| 37 | @Test | 33 | @Test |
| 38 | - public void testPageNotices_success() { | 34 | + public void testGetNoticePage_success() { |
| 39 | // 插入前置数据 | 35 | // 插入前置数据 |
| 40 | NoticeDO dbNotice = randomPojo(NoticeDO.class, o -> { | 36 | NoticeDO dbNotice = randomPojo(NoticeDO.class, o -> { |
| 41 | o.setTitle("尼古拉斯赵四来啦!"); | 37 | o.setTitle("尼古拉斯赵四来啦!"); |
| 42 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 38 | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 43 | - o.setType(randomEle(NoticeTypeEnum.values()).getType()); | ||
| 44 | }); | 39 | }); |
| 45 | - sysNoticeMapper.insert(dbNotice); | ||
| 46 | - | 40 | + noticeMapper.insert(dbNotice); |
| 47 | // 测试 title 不匹配 | 41 | // 测试 title 不匹配 |
| 48 | - sysNoticeMapper.insert(ObjectUtils.cloneIgnoreId(dbNotice, o -> o.setTitle("尼古拉斯凯奇也来啦!"))); | 42 | + noticeMapper.insert(cloneIgnoreId(dbNotice, o -> o.setTitle("尼古拉斯凯奇也来啦!"))); |
| 49 | // 测试 status 不匹配 | 43 | // 测试 status 不匹配 |
| 50 | - sysNoticeMapper.insert(ObjectUtils.cloneIgnoreId(dbNotice, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - // 查询 | 44 | + noticeMapper.insert(cloneIgnoreId(dbNotice, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); |
| 45 | + // 准备参数 | ||
| 54 | NoticePageReqVO reqVO = new NoticePageReqVO(); | 46 | NoticePageReqVO reqVO = new NoticePageReqVO(); |
| 55 | reqVO.setTitle("尼古拉斯赵四来啦!"); | 47 | reqVO.setTitle("尼古拉斯赵四来啦!"); |
| 56 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 48 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 57 | - PageResult<NoticeDO> pageResult = sysNoticeService.pageNotices(reqVO); | ||
| 58 | 49 | ||
| 50 | + // 调用 | ||
| 51 | + PageResult<NoticeDO> pageResult = noticeService.getNoticePage(reqVO); | ||
| 59 | // 验证查询结果经过筛选 | 52 | // 验证查询结果经过筛选 |
| 60 | assertEquals(1, pageResult.getTotal()); | 53 | assertEquals(1, pageResult.getTotal()); |
| 61 | assertEquals(1, pageResult.getList().size()); | 54 | assertEquals(1, pageResult.getList().size()); |
| 62 | assertPojoEquals(dbNotice, pageResult.getList().get(0)); | 55 | assertPojoEquals(dbNotice, pageResult.getList().get(0)); |
| 63 | - | ||
| 64 | } | 56 | } |
| 65 | 57 | ||
| 66 | @Test | 58 | @Test |
| 67 | public void testGetNotice_success() { | 59 | public void testGetNotice_success() { |
| 68 | // 插入前置数据 | 60 | // 插入前置数据 |
| 69 | - NoticeDO dbNotice = randomNoticeDO(); | ||
| 70 | - sysNoticeMapper.insert(dbNotice); | 61 | + NoticeDO dbNotice = randomPojo(NoticeDO.class); |
| 62 | + noticeMapper.insert(dbNotice); | ||
| 71 | 63 | ||
| 72 | // 查询 | 64 | // 查询 |
| 73 | - NoticeDO notice = sysNoticeService.getNotice(dbNotice.getId()); | 65 | + NoticeDO notice = noticeService.getNotice(dbNotice.getId()); |
| 74 | 66 | ||
| 75 | // 验证插入与读取对象是否一致 | 67 | // 验证插入与读取对象是否一致 |
| 76 | assertNotNull(notice); | 68 | assertNotNull(notice); |
| @@ -80,84 +72,59 @@ class NoticeServiceImplTest extends BaseDbUnitTest { | @@ -80,84 +72,59 @@ class NoticeServiceImplTest extends BaseDbUnitTest { | ||
| 80 | @Test | 72 | @Test |
| 81 | public void testCreateNotice_success() { | 73 | public void testCreateNotice_success() { |
| 82 | // 准备参数 | 74 | // 准备参数 |
| 83 | - NoticeCreateReqVO reqVO = randomNoticeCreateReqVO(); | ||
| 84 | - | ||
| 85 | - // 校验插入是否成功 | ||
| 86 | - Long noticeId = sysNoticeService.createNotice(reqVO); | ||
| 87 | - assertNotNull(noticeId); | 75 | + NoticeCreateReqVO reqVO = randomPojo(NoticeCreateReqVO.class); |
| 88 | 76 | ||
| 77 | + // 调用 | ||
| 78 | + Long noticeId = noticeService.createNotice(reqVO); | ||
| 89 | // 校验插入属性是否正确 | 79 | // 校验插入属性是否正确 |
| 90 | - NoticeDO notice = sysNoticeMapper.selectById(noticeId); | 80 | + assertNotNull(noticeId); |
| 81 | + NoticeDO notice = noticeMapper.selectById(noticeId); | ||
| 91 | assertPojoEquals(reqVO, notice); | 82 | assertPojoEquals(reqVO, notice); |
| 92 | } | 83 | } |
| 93 | 84 | ||
| 94 | @Test | 85 | @Test |
| 95 | public void testUpdateNotice_success() { | 86 | public void testUpdateNotice_success() { |
| 96 | // 插入前置数据 | 87 | // 插入前置数据 |
| 97 | - NoticeDO dbNoticeDO = randomNoticeDO(); | ||
| 98 | - sysNoticeMapper.insert(dbNoticeDO); | 88 | + NoticeDO dbNoticeDO = randomPojo(NoticeDO.class); |
| 89 | + noticeMapper.insert(dbNoticeDO); | ||
| 99 | 90 | ||
| 100 | // 准备更新参数 | 91 | // 准备更新参数 |
| 101 | - NoticeUpdateReqVO reqVO = randomNoticeUpdateReqVO(o -> o.setId(dbNoticeDO.getId())); | 92 | + NoticeUpdateReqVO reqVO = randomPojo(NoticeUpdateReqVO.class, o -> o.setId(dbNoticeDO.getId())); |
| 102 | 93 | ||
| 103 | // 更新 | 94 | // 更新 |
| 104 | - sysNoticeService.updateNotice(reqVO); | ||
| 105 | - | 95 | + noticeService.updateNotice(reqVO); |
| 106 | // 检验是否更新成功 | 96 | // 检验是否更新成功 |
| 107 | - NoticeDO notice = sysNoticeMapper.selectById(reqVO.getId()); | 97 | + NoticeDO notice = noticeMapper.selectById(reqVO.getId()); |
| 108 | assertPojoEquals(reqVO, notice); | 98 | assertPojoEquals(reqVO, notice); |
| 109 | } | 99 | } |
| 110 | 100 | ||
| 111 | @Test | 101 | @Test |
| 112 | public void testDeleteNotice_success() { | 102 | public void testDeleteNotice_success() { |
| 113 | // 插入前置数据 | 103 | // 插入前置数据 |
| 114 | - NoticeDO dbNotice = randomNoticeDO(); | ||
| 115 | - sysNoticeMapper.insert(dbNotice); | 104 | + NoticeDO dbNotice = randomPojo(NoticeDO.class); |
| 105 | + noticeMapper.insert(dbNotice); | ||
| 116 | 106 | ||
| 117 | // 删除 | 107 | // 删除 |
| 118 | - sysNoticeService.deleteNotice(dbNotice.getId()); | 108 | + noticeService.deleteNotice(dbNotice.getId()); |
| 119 | 109 | ||
| 120 | // 检查是否删除成功 | 110 | // 检查是否删除成功 |
| 121 | - assertNull(sysNoticeMapper.selectById(dbNotice.getId())); | 111 | + assertNull(noticeMapper.selectById(dbNotice.getId())); |
| 122 | } | 112 | } |
| 123 | 113 | ||
| 124 | @Test | 114 | @Test |
| 125 | - public void checkNoticeExists_success() { | 115 | + public void testValidateNoticeExists_success() { |
| 126 | // 插入前置数据 | 116 | // 插入前置数据 |
| 127 | - NoticeDO dbNotice = randomNoticeDO(); | ||
| 128 | - sysNoticeMapper.insert(dbNotice); | 117 | + NoticeDO dbNotice = randomPojo(NoticeDO.class); |
| 118 | + noticeMapper.insert(dbNotice); | ||
| 129 | 119 | ||
| 130 | // 成功调用 | 120 | // 成功调用 |
| 131 | - sysNoticeService.checkNoticeExists(dbNotice.getId()); | 121 | + noticeService.validateNoticeExists(dbNotice.getId()); |
| 132 | } | 122 | } |
| 133 | 123 | ||
| 134 | @Test | 124 | @Test |
| 135 | - public void checkNoticeExists_noExists() { | ||
| 136 | - assertServiceException(() -> sysNoticeService.checkNoticeExists(randomLongId()), NOTICE_NOT_FOUND); | 125 | + public void testValidateNoticeExists_noExists() { |
| 126 | + assertServiceException(() -> | ||
| 127 | + noticeService.validateNoticeExists(randomLongId()), NOTICE_NOT_FOUND); | ||
| 137 | } | 128 | } |
| 138 | 129 | ||
| 139 | - @SafeVarargs | ||
| 140 | - private static NoticeDO randomNoticeDO(Consumer<NoticeDO>... consumers) { | ||
| 141 | - NoticeDO notice = randomPojo(NoticeDO.class, consumers); | ||
| 142 | - notice.setType(randomEle(NoticeTypeEnum.values()).getType()); | ||
| 143 | - notice.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 144 | - return notice; | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - @SafeVarargs | ||
| 148 | - private static NoticeUpdateReqVO randomNoticeUpdateReqVO(Consumer<NoticeUpdateReqVO>... consumers) { | ||
| 149 | - NoticeUpdateReqVO reqVO = randomPojo(NoticeUpdateReqVO.class, consumers); | ||
| 150 | - reqVO.setType(randomEle(NoticeTypeEnum.values()).getType()); | ||
| 151 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 152 | - return reqVO; | ||
| 153 | - } | ||
| 154 | - | ||
| 155 | - private static NoticeCreateReqVO randomNoticeCreateReqVO() { | ||
| 156 | - NoticeCreateReqVO reqVO = randomPojo(NoticeCreateReqVO.class); | ||
| 157 | - reqVO.setType(randomEle(NoticeTypeEnum.values()).getType()); | ||
| 158 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 159 | - return reqVO; | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | - | ||
| 163 | } | 130 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImplTest.java
| @@ -109,6 +109,20 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest { | @@ -109,6 +109,20 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest { | ||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | @Test | 111 | @Test |
| 112 | + public void testGetNotifyMessage() { | ||
| 113 | + // mock 数据 | ||
| 114 | + NotifyMessageDO dbNotifyMessage = randomPojo(NotifyMessageDO.class, | ||
| 115 | + o -> o.setTemplateParams(randomTemplateParams())); | ||
| 116 | + notifyMessageMapper.insert(dbNotifyMessage); | ||
| 117 | + // 准备参数 | ||
| 118 | + Long id = dbNotifyMessage.getId(); | ||
| 119 | + | ||
| 120 | + // 调用 | ||
| 121 | + NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id); | ||
| 122 | + assertPojoEquals(dbNotifyMessage, notifyMessage); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Test | ||
| 112 | public void testGetMyNotifyMessagePage() { | 126 | public void testGetMyNotifyMessagePage() { |
| 113 | // mock 数据 | 127 | // mock 数据 |
| 114 | NotifyMessageDO dbNotifyMessage = randomPojo(NotifyMessageDO.class, o -> { // 等会查询到 | 128 | NotifyMessageDO dbNotifyMessage = randomPojo(NotifyMessageDO.class, o -> { // 等会查询到 |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImplTest.java
| @@ -4,8 +4,6 @@ import cn.hutool.core.map.MapUtil; | @@ -4,8 +4,6 @@ import cn.hutool.core.map.MapUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 7 | -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | ||
| 8 | -import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; |
| 10 | import org.assertj.core.util.Lists; | 8 | import org.assertj.core.util.Lists; |
| 11 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
| @@ -18,7 +16,8 @@ import java.util.Map; | @@ -18,7 +16,8 @@ import java.util.Map; | ||
| 18 | import static cn.hutool.core.util.RandomUtil.randomEle; | 16 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 19 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 17 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 20 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 18 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 21 | -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 19 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; |
| 20 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_SEND_TEMPLATE_PARAM_MISS; | ||
| 22 | import static org.junit.jupiter.api.Assertions.assertEquals; | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 23 | import static org.junit.jupiter.api.Assertions.assertNull; | 22 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 24 | import static org.mockito.ArgumentMatchers.eq; | 23 | import static org.mockito.ArgumentMatchers.eq; |
| @@ -34,6 +33,62 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest { | @@ -34,6 +33,62 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest { | ||
| 34 | @Mock | 33 | @Mock |
| 35 | private NotifyMessageService notifyMessageService; | 34 | private NotifyMessageService notifyMessageService; |
| 36 | 35 | ||
| 36 | + @Test | ||
| 37 | + public void testSendSingleNotifyToAdmin() { | ||
| 38 | + // 准备参数 | ||
| 39 | + Long userId = randomLongId(); | ||
| 40 | + String templateCode = randomString(); | ||
| 41 | + Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") | ||
| 42 | + .put("op", "login").build(); | ||
| 43 | + // mock NotifyTemplateService 的方法 | ||
| 44 | + NotifyTemplateDO template = randomPojo(NotifyTemplateDO.class, o -> { | ||
| 45 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 46 | + o.setContent("验证码为{code}, 操作为{op}"); | ||
| 47 | + o.setParams(Lists.newArrayList("code", "op")); | ||
| 48 | + }); | ||
| 49 | + when(notifyTemplateService.getNotifyTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | ||
| 50 | + String content = randomString(); | ||
| 51 | + when(notifyTemplateService.formatNotifyTemplateContent(eq(template.getContent()), eq(templateParams))) | ||
| 52 | + .thenReturn(content); | ||
| 53 | + // mock NotifyMessageService 的方法 | ||
| 54 | + Long messageId = randomLongId(); | ||
| 55 | + when(notifyMessageService.createNotifyMessage(eq(userId), eq(UserTypeEnum.ADMIN.getValue()), | ||
| 56 | + eq(template), eq(content), eq(templateParams))).thenReturn(messageId); | ||
| 57 | + | ||
| 58 | + // 调用 | ||
| 59 | + Long resultMessageId = notifySendService.sendSingleNotifyToAdmin(userId, templateCode, templateParams); | ||
| 60 | + // 断言 | ||
| 61 | + assertEquals(messageId, resultMessageId); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Test | ||
| 65 | + public void testSendSingleNotifyToMember() { | ||
| 66 | + // 准备参数 | ||
| 67 | + Long userId = randomLongId(); | ||
| 68 | + String templateCode = randomString(); | ||
| 69 | + Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") | ||
| 70 | + .put("op", "login").build(); | ||
| 71 | + // mock NotifyTemplateService 的方法 | ||
| 72 | + NotifyTemplateDO template = randomPojo(NotifyTemplateDO.class, o -> { | ||
| 73 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 74 | + o.setContent("验证码为{code}, 操作为{op}"); | ||
| 75 | + o.setParams(Lists.newArrayList("code", "op")); | ||
| 76 | + }); | ||
| 77 | + when(notifyTemplateService.getNotifyTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); | ||
| 78 | + String content = randomString(); | ||
| 79 | + when(notifyTemplateService.formatNotifyTemplateContent(eq(template.getContent()), eq(templateParams))) | ||
| 80 | + .thenReturn(content); | ||
| 81 | + // mock NotifyMessageService 的方法 | ||
| 82 | + Long messageId = randomLongId(); | ||
| 83 | + when(notifyMessageService.createNotifyMessage(eq(userId), eq(UserTypeEnum.MEMBER.getValue()), | ||
| 84 | + eq(template), eq(content), eq(templateParams))).thenReturn(messageId); | ||
| 85 | + | ||
| 86 | + // 调用 | ||
| 87 | + Long resultMessageId = notifySendService.sendSingleNotifyToMember(userId, templateCode, templateParams); | ||
| 88 | + // 断言 | ||
| 89 | + assertEquals(messageId, resultMessageId); | ||
| 90 | + } | ||
| 91 | + | ||
| 37 | /** | 92 | /** |
| 38 | * 发送成功,当短信模板开启时 | 93 | * 发送成功,当短信模板开启时 |
| 39 | */ | 94 | */ |
| @@ -100,7 +155,7 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest { | @@ -100,7 +155,7 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest { | ||
| 100 | // mock 方法 | 155 | // mock 方法 |
| 101 | 156 | ||
| 102 | // 调用,并断言异常 | 157 | // 调用,并断言异常 |
| 103 | - assertServiceException(() -> notifySendService.checkNotifyTemplateValid(templateCode), | 158 | + assertServiceException(() -> notifySendService.validateNotifyTemplate(templateCode), |
| 104 | NOTICE_NOT_FOUND); | 159 | NOTICE_NOT_FOUND); |
| 105 | } | 160 | } |
| 106 | 161 | ||
| @@ -113,7 +168,7 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest { | @@ -113,7 +168,7 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest { | ||
| 113 | // mock 方法 | 168 | // mock 方法 |
| 114 | 169 | ||
| 115 | // 调用,并断言异常 | 170 | // 调用,并断言异常 |
| 116 | - assertServiceException(() -> notifySendService.checkTemplateParams(template, templateParams), | 171 | + assertServiceException(() -> notifySendService.validateTemplateParams(template, templateParams), |
| 117 | NOTIFY_SEND_TEMPLATE_PARAM_MISS, "code"); | 172 | NOTIFY_SEND_TEMPLATE_PARAM_MISS, "code"); |
| 118 | } | 173 | } |
| 119 | 174 |