Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/springdoc
# Conflicts: # yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java # yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/clean.sql # yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsChannelController.java # yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java # yudao-server/pom.xml
This commit is contained in:
@@ -28,14 +28,14 @@ public class DeptApiImpl implements DeptApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptRespDTO> getDepts(Collection<Long> ids) {
|
||||
List<DeptDO> depts = deptService.getDepts(ids);
|
||||
public List<DeptRespDTO> getDeptList(Collection<Long> ids) {
|
||||
List<DeptDO> depts = deptService.getDeptList(ids);
|
||||
return DeptConvert.INSTANCE.convertList03(depts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validDepts(Collection<Long> ids) {
|
||||
deptService.validDepts(ids);
|
||||
public void validateDeptList(Collection<Long> ids) {
|
||||
deptService.validateDeptList(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ public class PostApiImpl implements PostApi {
|
||||
private PostService postService;
|
||||
|
||||
@Override
|
||||
public void validPosts(Collection<Long> ids) {
|
||||
postService.validPosts(ids);
|
||||
public void validPostList(Collection<Long> ids) {
|
||||
postService.validatePostList(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public class DictDataApiImpl implements DictDataApi {
|
||||
private DictDataService dictDataService;
|
||||
|
||||
@Override
|
||||
public void validDictDatas(String dictType, Collection<String> values) {
|
||||
dictDataService.validDictDatas(dictType, values);
|
||||
public void validateDictDataList(String dictType, Collection<String> values) {
|
||||
dictDataService.validateDictDataList(dictType, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ErrorCodeApiImpl implements ErrorCodeApi {
|
||||
private ErrorCodeService errorCodeService;
|
||||
|
||||
@Override
|
||||
public void autoGenerateErrorCodes(List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs) {
|
||||
public void autoGenerateErrorCodeList(List<ErrorCodeAutoGenerateReqDTO> autoGenerateDTOs) {
|
||||
errorCodeService.autoGenerateErrorCodes(autoGenerateDTOs);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class RoleApiImpl implements RoleApi {
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
public void validRoles(Collection<Long> ids) {
|
||||
roleService.validRoles(ids);
|
||||
public void validRoleList(Collection<Long> ids) {
|
||||
roleService.validateRoleList(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.api.sms;
|
||||
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeValidateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
|
||||
import cn.iocoder.yudao.module.system.service.sms.SmsCodeService;
|
||||
@@ -32,8 +32,8 @@ public class SmsCodeApiImpl implements SmsCodeApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSmsCode(SmsCodeCheckReqDTO reqDTO) {
|
||||
smsCodeService.checkSmsCode(reqDTO);
|
||||
public void validateSmsCode(SmsCodeValidateReqDTO reqDTO) {
|
||||
smsCodeService.validateSmsCode(reqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ public class TenantApiImpl implements TenantApi {
|
||||
private TenantService tenantService;
|
||||
|
||||
@Override
|
||||
public List<Long> getTenantIds() {
|
||||
return tenantService.getTenantIds();
|
||||
public List<Long> getTenantIdList() {
|
||||
return tenantService.getTenantIdList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validTenant(Long id) {
|
||||
public void validateTenant(Long id) {
|
||||
tenantService.validTenant(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Admin 用户 API 实现类
|
||||
@@ -29,26 +28,26 @@ public class AdminUserApiImpl implements AdminUserApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserRespDTO> getUsers(Collection<Long> ids) {
|
||||
List<AdminUserDO> users = userService.getUsers(ids);
|
||||
public List<AdminUserRespDTO> getUserList(Collection<Long> ids) {
|
||||
List<AdminUserDO> users = userService.getUserList(ids);
|
||||
return UserConvert.INSTANCE.convertList4(users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserRespDTO> getUsersByDeptIds(Collection<Long> deptIds) {
|
||||
List<AdminUserDO> users = userService.getUsersByDeptIds(deptIds);
|
||||
public List<AdminUserRespDTO> getUserListByDeptIds(Collection<Long> deptIds) {
|
||||
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds);
|
||||
return UserConvert.INSTANCE.convertList4(users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserRespDTO> getUsersByPostIds(Collection<Long> postIds) {
|
||||
List<AdminUserDO> users = userService.getUsersByPostIds(postIds);
|
||||
List<AdminUserDO> users = userService.getUserListByPostIds(postIds);
|
||||
return UserConvert.INSTANCE.convertList4(users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validUsers(Set<Long> ids) {
|
||||
userService.validUsers(ids);
|
||||
public void validateUserList(Collection<Long> ids) {
|
||||
userService.validateUserList(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class AuthController {
|
||||
}
|
||||
// 获得角色列表
|
||||
Set<Long> roleIds = permissionService.getUserRoleIdsFromCache(getLoginUserId(), singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
List<RoleDO> roleList = roleService.getRolesFromCache(roleIds);
|
||||
List<RoleDO> roleList = roleService.getRoleListFromCache(roleIds);
|
||||
// 获得菜单列表
|
||||
List<MenuDO> menuList = permissionService.getRoleMenuListFromCache(roleIds,
|
||||
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()),
|
||||
@@ -108,7 +108,7 @@ public class AuthController {
|
||||
|
||||
@GetMapping("/list-menus")
|
||||
@Operation(summary = "获得登录用户的菜单列表")
|
||||
public CommonResult<List<AuthMenuRespVO>> getMenus() {
|
||||
public CommonResult<List<AuthMenuRespVO>> getMenuList() {
|
||||
// 获得角色列表
|
||||
Set<Long> roleIds = permissionService.getUserRoleIdsFromCache(getLoginUserId(), singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 获得用户拥有的菜单列表
|
||||
|
||||
@@ -57,19 +57,19 @@ public class DeptController {
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取部门列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:query')")
|
||||
public CommonResult<List<DeptRespVO>> listDepts(DeptListReqVO reqVO) {
|
||||
List<DeptDO> list = deptService.getSimpleDepts(reqVO);
|
||||
public CommonResult<List<DeptRespVO>> getDeptList(DeptListReqVO reqVO) {
|
||||
List<DeptDO> list = deptService.getDeptList(reqVO);
|
||||
list.sort(Comparator.comparing(DeptDO::getSort));
|
||||
return success(DeptConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获取部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项")
|
||||
public CommonResult<List<DeptSimpleRespVO>> getSimpleDepts() {
|
||||
public CommonResult<List<DeptSimpleRespVO>> getSimpleDeptList() {
|
||||
// 获得部门列表,只要开启状态的
|
||||
DeptListReqVO reqVO = new DeptListReqVO();
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<DeptDO> list = deptService.getSimpleDepts(reqVO);
|
||||
List<DeptDO> list = deptService.getDeptList(reqVO);
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(DeptDO::getSort));
|
||||
return success(DeptConvert.INSTANCE.convertList02(list));
|
||||
|
||||
@@ -70,9 +70,9 @@ public class PostController {
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获取岗位精简信息列表", description = "只包含被开启的岗位,主要用于前端的下拉选项")
|
||||
public CommonResult<List<PostSimpleRespVO>> getSimplePosts() {
|
||||
public CommonResult<List<PostSimpleRespVO>> getSimplePostList() {
|
||||
// 获得岗位列表,只要开启状态的
|
||||
List<PostDO> list = postService.getPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(PostDO::getSort));
|
||||
return success(PostConvert.INSTANCE.convertList02(list));
|
||||
@@ -90,7 +90,7 @@ public class PostController {
|
||||
@PreAuthorize("@ss.hasPermission('system:post:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void export(HttpServletResponse response, @Validated PostExportReqVO reqVO) throws IOException {
|
||||
List<PostDO> posts = postService.getPosts(reqVO);
|
||||
List<PostDO> posts = postService.getPostList(reqVO);
|
||||
List<PostExcelVO> data = PostConvert.INSTANCE.convertList03(posts);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostExcelVO.class, data);
|
||||
|
||||
@@ -61,8 +61,8 @@ public class DictDataController {
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地")
|
||||
// 无需添加权限认证,因为前端全局都需要
|
||||
public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDatas() {
|
||||
List<DictDataDO> list = dictDataService.getDictDatas();
|
||||
public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() {
|
||||
List<DictDataDO> list = dictDataService.getDictDataList();
|
||||
return success(DictDataConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class DictDataController {
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void export(HttpServletResponse response, @Valid DictDataExportReqVO reqVO) throws IOException {
|
||||
List<DictDataDO> list = dictDataService.getDictDatas(reqVO);
|
||||
List<DictDataDO> list = dictDataService.getDictDataList(reqVO);
|
||||
List<DictDataExcelVO> data = DictDataConvert.INSTANCE.convertList02(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "字典数据.xls", "数据列表", DictDataExcelVO.class, data);
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DictTypeController {
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获得全部字典类型列表", description = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项")
|
||||
// 无需添加权限认证,因为前端全局都需要
|
||||
public CommonResult<List<DictTypeSimpleRespVO>> listSimpleDictTypes() {
|
||||
public CommonResult<List<DictTypeSimpleRespVO>> getSimpleDictTypeList() {
|
||||
List<DictTypeDO> list = dictTypeService.getDictTypeList();
|
||||
return success(DictTypeConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class OperateLogController {
|
||||
@PreAuthorize("@ss.hasPermission('system:operate-log:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportOperateLog(HttpServletResponse response, @Valid OperateLogExportReqVO reqVO) throws IOException {
|
||||
List<OperateLogDO> list = operateLogService.getOperateLogs(reqVO);
|
||||
List<OperateLogDO> list = operateLogService.getOperateLogList(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> userIds = CollectionUtils.convertList(list, OperateLogDO::getUserId);
|
||||
|
||||
@@ -57,8 +57,8 @@ public class NoticeController {
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获取通知公告列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:query')")
|
||||
public CommonResult<PageResult<NoticeRespVO>> pageNotices(@Validated NoticePageReqVO reqVO) {
|
||||
return success(NoticeConvert.INSTANCE.convertPage(noticeService.pageNotices(reqVO)));
|
||||
public CommonResult<PageResult<NoticeRespVO>> getNoticePage(@Validated NoticePageReqVO reqVO) {
|
||||
return success(NoticeConvert.INSTANCE.convertPage(noticeService.getNoticePage(reqVO)));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
|
||||
@@ -61,7 +61,7 @@ public class OAuth2UserController {
|
||||
}
|
||||
// 获得岗位信息
|
||||
if (CollUtil.isNotEmpty(user.getPostIds())) {
|
||||
List<PostDO> posts = postService.getPosts(user.getPostIds());
|
||||
List<PostDO> posts = postService.getPostList(user.getPostIds());
|
||||
resp.setPosts(OAuth2UserConvert.INSTANCE.convertList(posts));
|
||||
}
|
||||
return success(resp);
|
||||
|
||||
@@ -57,8 +57,8 @@ public class MenuController {
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取菜单列表", description = "用于【菜单管理】界面")
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:query')")
|
||||
public CommonResult<List<MenuRespVO>> getMenus(MenuListReqVO reqVO) {
|
||||
List<MenuDO> list = menuService.getMenus(reqVO);
|
||||
public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) {
|
||||
List<MenuDO> list = menuService.getMenuList(reqVO);
|
||||
list.sort(Comparator.comparing(MenuDO::getSort));
|
||||
return success(MenuConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
@@ -66,11 +66,11 @@ public class MenuController {
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获取菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" +
|
||||
"在多租户的场景下,会只返回租户所在套餐有的菜单")
|
||||
public CommonResult<List<MenuSimpleRespVO>> getSimpleMenus() {
|
||||
public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() {
|
||||
// 获得菜单列表,只要开启状态的
|
||||
MenuListReqVO reqVO = new MenuListReqVO();
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<MenuDO> list = menuService.getTenantMenus(reqVO);
|
||||
List<MenuDO> list = menuService.getMenuListByTenant(reqVO);
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(MenuDO::getSort));
|
||||
return success(MenuConvert.INSTANCE.convertList02(list));
|
||||
|
||||
@@ -20,12 +20,12 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static java.util.Collections.singleton;
|
||||
|
||||
@Tag(name = "管理后台 - 角色")
|
||||
@RestController
|
||||
@@ -85,9 +85,9 @@ public class RoleController {
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获取角色精简信息列表", description = "只包含被开启的角色,主要用于前端的下拉选项")
|
||||
public CommonResult<List<RoleSimpleRespVO>> getSimpleRoles() {
|
||||
public CommonResult<List<RoleSimpleRespVO>> getSimpleRoleList() {
|
||||
// 获得角色列表,只要开启状态的
|
||||
List<RoleDO> list = roleService.getRoles(Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
List<RoleDO> list = roleService.getRoleListByStatus(singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(RoleDO::getSort));
|
||||
return success(RoleConvert.INSTANCE.convertList02(list));
|
||||
|
||||
@@ -90,8 +90,8 @@ public class SensitiveWordController {
|
||||
@GetMapping("/get-tags")
|
||||
@Operation(summary = "获取所有敏感词的标签数组")
|
||||
@PreAuthorize("@ss.hasPermission('system:sensitive-word:query')")
|
||||
public CommonResult<Set<String>> getSensitiveWordTags() throws IOException {
|
||||
return success(sensitiveWordService.getSensitiveWordTags());
|
||||
public CommonResult<Set<String>> getSensitiveWordTagSet() {
|
||||
return success(sensitiveWordService.getSensitiveWordTagSet());
|
||||
}
|
||||
|
||||
@GetMapping("/validate-text")
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SmsChannelController {
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获得短信渠道精简列表", description = "包含被禁用的短信渠道")
|
||||
public CommonResult<List<SmsChannelSimpleRespVO>> getSimpleSmsChannels() {
|
||||
public CommonResult<List<SmsChannelSimpleRespVO>> getSimpleSmsChannelList() {
|
||||
List<SmsChannelDO> list = smsChannelService.getSmsChannelList();
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(SmsChannelDO::getId));
|
||||
|
||||
@@ -111,9 +111,9 @@ public class UserController {
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项")
|
||||
public CommonResult<List<UserSimpleRespVO>> getSimpleUsers() {
|
||||
public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() {
|
||||
// 获用户列表,只要开启状态的
|
||||
List<AdminUserDO> list = userService.getUsersByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
// 排序后,返回给前端
|
||||
return success(UserConvert.INSTANCE.convertList04(list));
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class UserController {
|
||||
@Operation(summary = "获得用户详情")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:query')")
|
||||
public CommonResult<UserRespVO> getInfo(@RequestParam("id") Long id) {
|
||||
public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) {
|
||||
return success(UserConvert.INSTANCE.convert(userService.getUser(id)));
|
||||
}
|
||||
|
||||
@@ -130,10 +130,10 @@ public class UserController {
|
||||
@Operation(summary = "导出用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportUsers(@Validated UserExportReqVO reqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
public void exportUserList(@Validated UserExportReqVO reqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
// 获得用户列表
|
||||
List<AdminUserDO> users = userService.getUsers(reqVO);
|
||||
List<AdminUserDO> users = userService.getUserList(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId);
|
||||
@@ -183,7 +183,7 @@ public class UserController {
|
||||
public CommonResult<UserImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
|
||||
List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class);
|
||||
return success(userService.importUsers(list, updateSupport));
|
||||
return success(userService.importUserList(list, updateSupport));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.controller.admin.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO;
|
||||
@@ -31,6 +30,7 @@ import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
||||
@@ -63,7 +63,7 @@ public class UserProfileController {
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
UserProfileRespVO resp = UserConvert.INSTANCE.convert03(user);
|
||||
// 获得用户角色
|
||||
List<RoleDO> userRoles = roleService.getRolesFromCache(permissionService.getUserRoleIdListByUserId(user.getId()));
|
||||
List<RoleDO> userRoles = roleService.getRoleListFromCache(permissionService.getUserRoleIdListByUserId(user.getId()));
|
||||
resp.setRoles(UserConvert.INSTANCE.convertList(userRoles));
|
||||
// 获得部门信息
|
||||
if (user.getDeptId() != null) {
|
||||
@@ -72,7 +72,7 @@ public class UserProfileController {
|
||||
}
|
||||
// 获得岗位信息
|
||||
if (CollUtil.isNotEmpty(user.getPostIds())) {
|
||||
List<PostDO> posts = postService.getPosts(user.getPostIds());
|
||||
List<PostDO> posts = postService.getPostList(user.getPostIds());
|
||||
resp.setPosts(UserConvert.INSTANCE.convertList02(posts));
|
||||
}
|
||||
// 获得社交用户信息
|
||||
@@ -99,7 +99,7 @@ public class UserProfileController {
|
||||
@Operation(summary = "上传用户个人头像")
|
||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
||||
throw exception(FILE_IS_EMPTY);
|
||||
}
|
||||
String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
|
||||
return success(avatar);
|
||||
|
||||
@@ -9,13 +9,15 @@ import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuIdEnum;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||
import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT;
|
||||
|
||||
@Mapper
|
||||
public interface AuthConvert {
|
||||
|
||||
@@ -47,7 +49,7 @@ public interface AuthConvert {
|
||||
Map<Long, AuthMenuRespVO> treeNodeMap = new LinkedHashMap<>();
|
||||
menuList.forEach(menu -> treeNodeMap.put(menu.getId(), AuthConvert.INSTANCE.convertTreeNode(menu)));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(MenuIdEnum.ROOT.getId())).forEach(childNode -> {
|
||||
treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(ID_ROOT)).forEach(childNode -> {
|
||||
// 获得父节点
|
||||
AuthMenuRespVO parentNode = treeNodeMap.get(childNode.getParentId());
|
||||
if (parentNode == null) {
|
||||
@@ -62,7 +64,7 @@ public interface AuthConvert {
|
||||
parentNode.getChildren().add(childNode);
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
return CollectionUtils.filterList(treeNodeMap.values(), node -> MenuIdEnum.ROOT.getId().equals(node.getParentId()));
|
||||
return filterList(treeNodeMap.values(), node -> ID_ROOT.equals(node.getParentId()));
|
||||
}
|
||||
|
||||
SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO);
|
||||
|
||||
@@ -21,7 +21,12 @@ import lombok.EqualsAndHashCode;
|
||||
public class MenuDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
* 菜单编号 - 根节点
|
||||
*/
|
||||
public static final Long ID_ROOT = 0L;
|
||||
|
||||
/**
|
||||
* 菜单编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
@@ -19,9 +18,7 @@ public interface DeptMapper extends BaseMapperX<DeptDO> {
|
||||
}
|
||||
|
||||
default DeptDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(new LambdaQueryWrapper<DeptDO>()
|
||||
.eq(DeptDO::getParentId, parentId)
|
||||
.eq(DeptDO::getName, name));
|
||||
return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name);
|
||||
}
|
||||
|
||||
default Long selectCountByParentId(Long parentId) {
|
||||
|
||||
@@ -2,11 +2,10 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -16,31 +15,32 @@ import java.util.List;
|
||||
public interface PostMapper extends BaseMapperX<PostDO> {
|
||||
|
||||
default List<PostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
return selectList(new QueryWrapperX<PostDO>().inIfPresent("id", ids)
|
||||
.inIfPresent("status", statuses));
|
||||
return selectList(new LambdaQueryWrapperX<PostDO>()
|
||||
.inIfPresent(PostDO::getId, ids)
|
||||
.inIfPresent(PostDO::getStatus, statuses));
|
||||
}
|
||||
|
||||
default PageResult<PostDO> selectPage(PostPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<PostDO>()
|
||||
.likeIfPresent("code", reqVO.getCode())
|
||||
.likeIfPresent("name", reqVO.getName())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.orderByDesc("id"));
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<PostDO>()
|
||||
.likeIfPresent(PostDO::getCode, reqVO.getCode())
|
||||
.likeIfPresent(PostDO::getName, reqVO.getName())
|
||||
.eqIfPresent(PostDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(PostDO::getId));
|
||||
}
|
||||
|
||||
default List<PostDO> selectList(PostExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<PostDO>()
|
||||
.likeIfPresent("code", reqVO.getCode())
|
||||
.likeIfPresent("name", reqVO.getName())
|
||||
.eqIfPresent("status", reqVO.getStatus()));
|
||||
return selectList(new LambdaQueryWrapperX<PostDO>()
|
||||
.likeIfPresent(PostDO::getCode, reqVO.getCode())
|
||||
.likeIfPresent(PostDO::getName, reqVO.getName())
|
||||
.eqIfPresent(PostDO::getStatus, reqVO.getStatus()));
|
||||
}
|
||||
|
||||
default PostDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapper<PostDO>().eq("name", name));
|
||||
return selectOne(PostDO::getName, name);
|
||||
}
|
||||
|
||||
default PostDO selectByCode(String code) {
|
||||
return selectOne(new QueryWrapper<PostDO>().eq("code", code));
|
||||
return selectOne(PostDO::getCode, code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ import java.util.List;
|
||||
public interface UserPostMapper extends BaseMapperX<UserPostDO> {
|
||||
|
||||
default List<UserPostDO> selectListByUserId(Long userId) {
|
||||
return selectList(new LambdaQueryWrapperX<UserPostDO>()
|
||||
.eq(UserPostDO::getUserId, userId));
|
||||
return selectList(UserPostDO::getUserId, userId);
|
||||
}
|
||||
|
||||
default void deleteByUserIdAndPostId(Long userId, Collection<Long> postIds) {
|
||||
@@ -24,11 +23,10 @@ public interface UserPostMapper extends BaseMapperX<UserPostDO> {
|
||||
}
|
||||
|
||||
default List<UserPostDO> selectListByPostIds(Collection<Long> postIds) {
|
||||
return selectList(new LambdaQueryWrapperX<UserPostDO>()
|
||||
.in(UserPostDO::getPostId, postIds));
|
||||
return selectList(UserPostDO::getPostId, postIds);
|
||||
}
|
||||
|
||||
default void deleteByUserId(Long userId){
|
||||
default void deleteByUserId(Long userId) {
|
||||
delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,11 @@ import java.util.List;
|
||||
public interface DictDataMapper extends BaseMapperX<DictDataDO> {
|
||||
|
||||
default DictDataDO selectByDictTypeAndValue(String dictType, String value) {
|
||||
return selectOne(new LambdaQueryWrapper<DictDataDO>().eq(DictDataDO::getDictType, dictType)
|
||||
.eq(DictDataDO::getValue, value));
|
||||
return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getValue, value);
|
||||
}
|
||||
|
||||
default DictDataDO selectByDictTypeAndLabel(String dictType, String label) {
|
||||
return selectOne(new LambdaQueryWrapper<DictDataDO>().eq(DictDataDO::getDictType, dictType)
|
||||
.eq(DictDataDO::getLabel, label));
|
||||
return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getLabel, label);
|
||||
}
|
||||
|
||||
default List<DictDataDO> selectByDictTypeAndValues(String dictType, Collection<String> values) {
|
||||
|
||||
@@ -36,11 +36,11 @@ public interface ErrorCodeMapper extends BaseMapperX<ErrorCodeDO> {
|
||||
}
|
||||
|
||||
default List<ErrorCodeDO> selectListByCodes(Collection<Integer> codes) {
|
||||
return selectList(new LambdaQueryWrapperX<ErrorCodeDO>().in(ErrorCodeDO::getCode, codes));
|
||||
return selectList(ErrorCodeDO::getCode, codes);
|
||||
}
|
||||
|
||||
default ErrorCodeDO selectByCode(Integer code) {
|
||||
return selectOne(new LambdaQueryWrapperX<ErrorCodeDO>().eq(ErrorCodeDO::getCode, code));
|
||||
return selectOne(ErrorCodeDO::getCode, code);
|
||||
}
|
||||
|
||||
default List<ErrorCodeDO> selectListByApplicationNameAndUpdateTimeGt(String applicationName, LocalDateTime minUpdateTime) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
@@ -13,8 +12,7 @@ import java.util.List;
|
||||
public interface MenuMapper extends BaseMapperX<MenuDO> {
|
||||
|
||||
default MenuDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(new LambdaQueryWrapper<MenuDO>().eq(MenuDO::getParentId, parentId)
|
||||
.eq(MenuDO::getName, name));
|
||||
return selectOne(MenuDO::getParentId, parentId, MenuDO::getName, name);
|
||||
}
|
||||
|
||||
default Long selectCountByParentId(Long parentId) {
|
||||
@@ -22,7 +20,8 @@ public interface MenuMapper extends BaseMapperX<MenuDO> {
|
||||
}
|
||||
|
||||
default List<MenuDO> selectList(MenuListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<MenuDO>().likeIfPresent(MenuDO::getName, reqVO.getName())
|
||||
return selectList(new LambdaQueryWrapperX<MenuDO>()
|
||||
.likeIfPresent(MenuDO::getName, reqVO.getName())
|
||||
.eqIfPresent(MenuDO::getStatus, reqVO.getStatus()));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,8 @@ public interface SocialUserBindMapper extends BaseMapperX<SocialUserBindDO> {
|
||||
}
|
||||
|
||||
default SocialUserBindDO selectByUserTypeAndSocialUserId(Integer userType, Long socialUserId) {
|
||||
return selectOne(new LambdaQueryWrapperX<SocialUserBindDO>()
|
||||
.eq(SocialUserBindDO::getUserType, userType)
|
||||
.eq(SocialUserBindDO::getSocialUserId, socialUserId));
|
||||
return selectOne(SocialUserBindDO::getUserType, userType,
|
||||
SocialUserBindDO::getSocialUserId, socialUserId);
|
||||
}
|
||||
|
||||
default List<SocialUserBindDO> selectListByUserIdAndUserType(Long userId, Integer userType) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -16,15 +15,15 @@ import java.util.List;
|
||||
public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
|
||||
default AdminUserDO selectByUsername(String username) {
|
||||
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getUsername, username));
|
||||
return selectOne(AdminUserDO::getUsername, username);
|
||||
}
|
||||
|
||||
default AdminUserDO selectByEmail(String email) {
|
||||
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getEmail, email));
|
||||
return selectOne(AdminUserDO::getEmail, email);
|
||||
}
|
||||
|
||||
default AdminUserDO selectByMobile(String mobile) {
|
||||
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getMobile, mobile));
|
||||
return selectOne(AdminUserDO::getMobile, mobile);
|
||||
}
|
||||
|
||||
default PageResult<AdminUserDO> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) {
|
||||
@@ -50,10 +49,6 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByUsername(String username) {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getUsername, username));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByStatus(Integer status) {
|
||||
return selectList(AdminUserDO::getStatus, status);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
@Override
|
||||
public AuthLoginRespVO login(AuthLoginReqVO reqVO) {
|
||||
// 校验验证码
|
||||
verifyCaptcha(reqVO);
|
||||
validateCaptcha(reqVO);
|
||||
|
||||
// 使用账号密码,进行登录
|
||||
AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword());
|
||||
@@ -171,14 +171,8 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthLoginRespVO refreshToken(String refreshToken) {
|
||||
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, OAuth2ClientConstants.CLIENT_ID_DEFAULT);
|
||||
return AuthConvert.INSTANCE.convert(accessTokenDO);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void verifyCaptcha(AuthLoginReqVO reqVO) {
|
||||
void validateCaptcha(AuthLoginReqVO reqVO) {
|
||||
// 如果验证码关闭,则不进行校验
|
||||
if (!captchaEnable) {
|
||||
return;
|
||||
@@ -206,6 +200,12 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
return AuthConvert.INSTANCE.convert(accessTokenDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthLoginRespVO refreshToken(String refreshToken) {
|
||||
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, OAuth2ClientConstants.CLIENT_ID_DEFAULT);
|
||||
return AuthConvert.INSTANCE.convert(accessTokenDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout(String token, Integer logType) {
|
||||
// 删除访问令牌
|
||||
|
||||
@@ -52,7 +52,7 @@ public interface DeptService {
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<DeptDO> getSimpleDepts(DeptListReqVO reqVO);
|
||||
List<DeptDO> getDeptList(DeptListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得所有子部门,从缓存中
|
||||
@@ -61,7 +61,7 @@ public interface DeptService {
|
||||
* @param recursive 是否递归获取所有
|
||||
* @return 子部门列表
|
||||
*/
|
||||
List<DeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive);
|
||||
List<DeptDO> getDeptListByParentIdFromCache(Long parentId, boolean recursive);
|
||||
|
||||
/**
|
||||
* 获得部门信息数组
|
||||
@@ -69,7 +69,21 @@ public interface DeptService {
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门信息数组
|
||||
*/
|
||||
List<DeptDO> getDepts(Collection<Long> ids);
|
||||
List<DeptDO> getDeptList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门 Map
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门 Map
|
||||
*/
|
||||
default Map<Long, DeptDO> getDeptMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<DeptDO> list = getDeptList(ids);
|
||||
return CollectionUtils.convertMap(list, DeptDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门信息
|
||||
@@ -86,27 +100,6 @@ public interface DeptService {
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
*/
|
||||
void validDepts(Collection<Long> ids);
|
||||
void validateDeptList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门列表
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<DeptDO> getSimpleDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门 Map
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门 Map
|
||||
*/
|
||||
default Map<Long, DeptDO> getDeptMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<DeptDO> list = getSimpleDepts(ids);
|
||||
return CollectionUtils.convertMap(list, DeptDO::getId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.system.service.dept;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO;
|
||||
@@ -19,13 +17,11 @@ import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@@ -95,7 +91,7 @@ public class DeptServiceImpl implements DeptService {
|
||||
if (reqVO.getParentId() == null) {
|
||||
reqVO.setParentId(DeptIdEnum.ROOT.getId());
|
||||
}
|
||||
checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName());
|
||||
validateForCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName());
|
||||
// 插入部门
|
||||
DeptDO dept = DeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.insert(dept);
|
||||
@@ -110,7 +106,7 @@ public class DeptServiceImpl implements DeptService {
|
||||
if (reqVO.getParentId() == null) {
|
||||
reqVO.setParentId(DeptIdEnum.ROOT.getId());
|
||||
}
|
||||
checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
|
||||
validateForCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
|
||||
// 更新部门
|
||||
DeptDO updateObj = DeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.updateById(updateObj);
|
||||
@@ -121,10 +117,10 @@ public class DeptServiceImpl implements DeptService {
|
||||
@Override
|
||||
public void deleteDept(Long id) {
|
||||
// 校验是否存在
|
||||
checkDeptExists(id);
|
||||
validateDeptExists(id);
|
||||
// 校验是否有子部门
|
||||
if (deptMapper.selectCountByParentId(id) > 0) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN);
|
||||
throw exception(DEPT_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除部门
|
||||
deptMapper.deleteById(id);
|
||||
@@ -133,20 +129,20 @@ public class DeptServiceImpl implements DeptService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptDO> getSimpleDepts(DeptListReqVO reqVO) {
|
||||
public List<DeptDO> getDeptList(DeptListReqVO reqVO) {
|
||||
return deptMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive) {
|
||||
public List<DeptDO> getDeptListByParentIdFromCache(Long parentId, boolean recursive) {
|
||||
if (parentId == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<DeptDO> result = new ArrayList<>(); // TODO 芋艿:待优化,新增缓存,避免每次遍历的计算
|
||||
List<DeptDO> result = new ArrayList<>();
|
||||
// 递归,简单粗暴
|
||||
this.getDeptsByParentIdFromCache(result, parentId,
|
||||
recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次
|
||||
parentDeptCache);
|
||||
getDeptsByParentIdFromCache(result, parentId,
|
||||
recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次
|
||||
parentDeptCache);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -182,65 +178,65 @@ public class DeptServiceImpl implements DeptService {
|
||||
recursiveCount - 1, parentDeptMap));
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, Long parentId, String name) {
|
||||
private void validateForCreateOrUpdate(Long id, Long parentId, String name) {
|
||||
// 校验自己存在
|
||||
checkDeptExists(id);
|
||||
validateDeptExists(id);
|
||||
// 校验父部门的有效性
|
||||
checkParentDeptEnable(id, parentId);
|
||||
validateParentDeptEnable(id, parentId);
|
||||
// 校验部门名的唯一性
|
||||
checkDeptNameUnique(id, parentId, name);
|
||||
validateDeptNameUnique(id, parentId, name);
|
||||
}
|
||||
|
||||
private void checkParentDeptEnable(Long id, Long parentId) {
|
||||
private void validateParentDeptEnable(Long id, Long parentId) {
|
||||
if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) {
|
||||
return;
|
||||
}
|
||||
// 不能设置自己为父部门
|
||||
if (parentId.equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_ERROR);
|
||||
throw exception(DEPT_PARENT_ERROR);
|
||||
}
|
||||
// 父岗位不存在
|
||||
DeptDO dept = deptMapper.selectById(parentId);
|
||||
if (dept == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_NOT_EXITS);
|
||||
throw exception(DEPT_PARENT_NOT_EXITS);
|
||||
}
|
||||
// 父部门被禁用
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE);
|
||||
throw exception(DEPT_NOT_ENABLE);
|
||||
}
|
||||
// 父部门不能是原来的子部门
|
||||
List<DeptDO> children = this.getDeptsByParentIdFromCache(id, true);
|
||||
List<DeptDO> children = getDeptListByParentIdFromCache(id, true);
|
||||
if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_IS_CHILD);
|
||||
throw exception(DEPT_PARENT_IS_CHILD);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeptExists(Long id) {
|
||||
private void validateDeptExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
DeptDO dept = deptMapper.selectById(id);
|
||||
if (dept == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NOT_FOUND);
|
||||
throw exception(DEPT_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeptNameUnique(Long id, Long parentId, String name) {
|
||||
private void validateDeptNameUnique(Long id, Long parentId, String name) {
|
||||
DeptDO menu = deptMapper.selectByParentIdAndName(parentId, name);
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
|
||||
throw exception(DEPT_NAME_DUPLICATE);
|
||||
}
|
||||
if (!menu.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NAME_DUPLICATE);
|
||||
throw exception(DEPT_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptDO> getDepts(Collection<Long> ids) {
|
||||
public List<DeptDO> getDeptList(Collection<Long> ids) {
|
||||
return deptMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@@ -250,13 +246,12 @@ public class DeptServiceImpl implements DeptService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validDepts(Collection<Long> ids) {
|
||||
public void validateDeptList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得科室信息
|
||||
List<DeptDO> depts = deptMapper.selectBatchIds(ids);
|
||||
Map<Long, DeptDO> deptMap = CollectionUtils.convertMap(depts, DeptDO::getId);
|
||||
Map<Long, DeptDO> deptMap = getDeptMap(ids);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
DeptDO dept = deptMap.get(id);
|
||||
@@ -269,9 +264,4 @@ public class DeptServiceImpl implements DeptService {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptDO> getSimpleDepts(Collection<Long> ids) {
|
||||
return deptMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ public interface PostService {
|
||||
* @param ids 岗位编号数组。如果为空,不进行筛选
|
||||
* @return 部门列表
|
||||
*/
|
||||
default List<PostDO> getPosts(@Nullable Collection<Long> ids) {
|
||||
return getPosts(ids, asSet(CommonStatusEnum.ENABLE.getStatus(), CommonStatusEnum.DISABLE.getStatus()));
|
||||
default List<PostDO> getPostList(@Nullable Collection<Long> ids) {
|
||||
return getPostList(ids, asSet(CommonStatusEnum.ENABLE.getStatus(), CommonStatusEnum.DISABLE.getStatus()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ public interface PostService {
|
||||
* @param statuses 状态数组。如果为空,不进行筛选
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<PostDO> getPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
|
||||
List<PostDO> getPostList(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得岗位分页列表
|
||||
@@ -76,7 +76,7 @@ public interface PostService {
|
||||
* @param reqVO 查询条件
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<PostDO> getPosts(PostExportReqVO reqVO);
|
||||
List<PostDO> getPostList(PostExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位信息
|
||||
@@ -93,6 +93,6 @@ public interface PostService {
|
||||
*
|
||||
* @param ids 岗位编号数组
|
||||
*/
|
||||
void validPosts(Collection<Long> ids);
|
||||
void validatePostList(Collection<Long> ids);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.service.dept;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO;
|
||||
@@ -38,7 +37,8 @@ public class PostServiceImpl implements PostService {
|
||||
@Override
|
||||
public Long createPost(PostCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(null, reqVO.getName(), reqVO.getCode());
|
||||
validatePostForCreateOrUpdate(null, reqVO.getName(), reqVO.getCode());
|
||||
|
||||
// 插入岗位
|
||||
PostDO post = PostConvert.INSTANCE.convert(reqVO);
|
||||
postMapper.insert(post);
|
||||
@@ -48,7 +48,8 @@ public class PostServiceImpl implements PostService {
|
||||
@Override
|
||||
public void updatePost(PostUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode());
|
||||
validatePostForCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode());
|
||||
|
||||
// 更新岗位
|
||||
PostDO updateObj = PostConvert.INSTANCE.convert(reqVO);
|
||||
postMapper.updateById(updateObj);
|
||||
@@ -57,13 +58,59 @@ public class PostServiceImpl implements PostService {
|
||||
@Override
|
||||
public void deletePost(Long id) {
|
||||
// 校验是否存在
|
||||
this.checkPostExists(id);
|
||||
validatePostExists(id);
|
||||
// 删除部门
|
||||
postMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validatePostForCreateOrUpdate(Long id, String name, String code) {
|
||||
// 校验自己存在
|
||||
validatePostExists(id);
|
||||
// 校验岗位名的唯一性
|
||||
validatePostNameUnique(id, name);
|
||||
// 校验岗位编码的唯一性
|
||||
validatePostCodeUnique(id, code);
|
||||
}
|
||||
|
||||
private void validatePostNameUnique(Long id, String name) {
|
||||
PostDO post = postMapper.selectByName(name);
|
||||
if (post == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw exception(POST_NAME_DUPLICATE);
|
||||
}
|
||||
if (!post.getId().equals(id)) {
|
||||
throw exception(POST_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePostCodeUnique(Long id, String code) {
|
||||
PostDO post = postMapper.selectByCode(code);
|
||||
if (post == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw exception(POST_CODE_DUPLICATE);
|
||||
}
|
||||
if (!post.getId().equals(id)) {
|
||||
throw exception(POST_CODE_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePostExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
if (postMapper.selectById(id) == null) {
|
||||
throw exception(POST_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostDO> getPosts(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
public List<PostDO> getPostList(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
return postMapper.selectList(ids, statuses);
|
||||
}
|
||||
|
||||
@@ -73,7 +120,7 @@ public class PostServiceImpl implements PostService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostDO> getPosts(PostExportReqVO reqVO) {
|
||||
public List<PostDO> getPostList(PostExportReqVO reqVO) {
|
||||
return postMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@@ -82,55 +129,8 @@ public class PostServiceImpl implements PostService {
|
||||
return postMapper.selectById(id);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String name, String code) {
|
||||
// 校验自己存在
|
||||
checkPostExists(id);
|
||||
// 校验岗位名的唯一性
|
||||
checkPostNameUnique(id, name);
|
||||
// 校验岗位编码的唯一性
|
||||
checkPostCodeUnique(id, code);
|
||||
}
|
||||
|
||||
private void checkPostNameUnique(Long id, String name) {
|
||||
PostDO post = postMapper.selectByName(name);
|
||||
if (post == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE);
|
||||
}
|
||||
if (!post.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(POST_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPostCodeUnique(Long id, String code) {
|
||||
PostDO post = postMapper.selectByCode(code);
|
||||
if (post == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE);
|
||||
}
|
||||
if (!post.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(POST_CODE_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPostExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
PostDO post = postMapper.selectById(id);
|
||||
if (post == null) {
|
||||
throw ServiceExceptionUtil.exception(POST_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validPosts(Collection<Long> ids) {
|
||||
public void validatePostList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public interface DictDataService {
|
||||
*
|
||||
* @return 字典数据全列表
|
||||
*/
|
||||
List<DictDataDO> getDictDatas();
|
||||
List<DictDataDO> getDictDataList();
|
||||
|
||||
/**
|
||||
* 获得字典数据分页列表
|
||||
@@ -60,7 +60,7 @@ public interface DictDataService {
|
||||
* @param reqVO 列表请求
|
||||
* @return 字典数据列表
|
||||
*/
|
||||
List<DictDataDO> getDictDatas(DictDataExportReqVO reqVO);
|
||||
List<DictDataDO> getDictDataList(DictDataExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得字典数据详情
|
||||
@@ -86,7 +86,7 @@ public interface DictDataService {
|
||||
* @param dictType 字典类型
|
||||
* @param values 字典数据值的数组
|
||||
*/
|
||||
void validDictDatas(String dictType, Collection<String> values);
|
||||
void validateDictDataList(String dictType, Collection<String> values);
|
||||
|
||||
/**
|
||||
* 获得指定的字典数据
|
||||
|
||||
@@ -48,7 +48,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
private DictDataMapper dictDataMapper;
|
||||
|
||||
@Override
|
||||
public List<DictDataDO> getDictDatas() {
|
||||
public List<DictDataDO> getDictDataList() {
|
||||
List<DictDataDO> list = dictDataMapper.selectList();
|
||||
list.sort(COMPARATOR_TYPE_AND_SORT);
|
||||
return list;
|
||||
@@ -60,7 +60,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictDataDO> getDictDatas(DictDataExportReqVO reqVO) {
|
||||
public List<DictDataDO> getDictDataList(DictDataExportReqVO reqVO) {
|
||||
List<DictDataDO> list = dictDataMapper.selectList(reqVO);
|
||||
list.sort(COMPARATOR_TYPE_AND_SORT);
|
||||
return list;
|
||||
@@ -74,7 +74,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
@Override
|
||||
public Long createDictData(DictDataCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getValue(), reqVO.getDictType());
|
||||
validateDictDataForCreateOrUpdate(null, reqVO.getValue(), reqVO.getDictType());
|
||||
|
||||
// 插入字典类型
|
||||
DictDataDO dictData = DictDataConvert.INSTANCE.convert(reqVO);
|
||||
@@ -85,7 +85,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
@Override
|
||||
public void updateDictData(DictDataUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), reqVO.getValue(), reqVO.getDictType());
|
||||
validateDictDataForCreateOrUpdate(reqVO.getId(), reqVO.getValue(), reqVO.getDictType());
|
||||
|
||||
// 更新字典类型
|
||||
DictDataDO updateObj = DictDataConvert.INSTANCE.convert(reqVO);
|
||||
@@ -95,7 +95,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
@Override
|
||||
public void deleteDictData(Long id) {
|
||||
// 校验是否存在
|
||||
checkDictDataExists(id);
|
||||
validateDictDataExists(id);
|
||||
|
||||
// 删除字典数据
|
||||
dictDataMapper.deleteById(id);
|
||||
@@ -106,18 +106,17 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
return dictDataMapper.selectCountByDictType(dictType);
|
||||
}
|
||||
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String value, String dictType) {
|
||||
private void validateDictDataForCreateOrUpdate(Long id, String value, String dictType) {
|
||||
// 校验自己存在
|
||||
checkDictDataExists(id);
|
||||
validateDictDataExists(id);
|
||||
// 校验字典类型有效
|
||||
checkDictTypeValid(dictType);
|
||||
validateDictTypeExists(dictType);
|
||||
// 校验字典数据的值的唯一性
|
||||
checkDictDataValueUnique(id, dictType, value);
|
||||
validateDictDataValueUnique(id, dictType, value);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkDictDataValueUnique(Long id, String dictType, String value) {
|
||||
public void validateDictDataValueUnique(Long id, String dictType, String value) {
|
||||
DictDataDO dictData = dictDataMapper.selectByDictTypeAndValue(dictType, value);
|
||||
if (dictData == null) {
|
||||
return;
|
||||
@@ -132,7 +131,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkDictDataExists(Long id) {
|
||||
public void validateDictDataExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
@@ -143,7 +142,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkDictTypeValid(String type) {
|
||||
public void validateDictTypeExists(String type) {
|
||||
DictTypeDO dictType = dictTypeService.getDictType(type);
|
||||
if (dictType == null) {
|
||||
throw exception(DICT_TYPE_NOT_EXISTS);
|
||||
@@ -154,7 +153,7 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validDictDatas(String dictType, Collection<String> values) {
|
||||
public void validateDictDataList(String dictType, Collection<String> values) {
|
||||
if (CollUtil.isEmpty(values)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
@Override
|
||||
public Long createDictType(DictTypeCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getName(), reqVO.getType());
|
||||
validateDictTypeForCreateOrUpdate(null, reqVO.getName(), reqVO.getType());
|
||||
|
||||
// 插入字典类型
|
||||
DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO)
|
||||
.setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值
|
||||
@@ -68,7 +69,8 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
@Override
|
||||
public void updateDictType(DictTypeUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), reqVO.getName(), null);
|
||||
validateDictTypeForCreateOrUpdate(reqVO.getId(), reqVO.getName(), null);
|
||||
|
||||
// 更新字典类型
|
||||
DictTypeDO updateObj = DictTypeConvert.INSTANCE.convert(reqVO);
|
||||
dictTypeMapper.updateById(updateObj);
|
||||
@@ -77,7 +79,7 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
@Override
|
||||
public void deleteDictType(Long id) {
|
||||
// 校验是否存在
|
||||
DictTypeDO dictType = checkDictTypeExists(id);
|
||||
DictTypeDO dictType = validateDictTypeExists(id);
|
||||
// 校验是否有字典数据
|
||||
if (dictDataService.countByDictType(dictType.getType()) > 0) {
|
||||
throw exception(DICT_TYPE_HAS_CHILDREN);
|
||||
@@ -91,17 +93,17 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
return dictTypeMapper.selectList();
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String name, String type) {
|
||||
private void validateDictTypeForCreateOrUpdate(Long id, String name, String type) {
|
||||
// 校验自己存在
|
||||
checkDictTypeExists(id);
|
||||
validateDictTypeExists(id);
|
||||
// 校验字典类型的名字的唯一性
|
||||
checkDictTypeNameUnique(id, name);
|
||||
validateDictTypeNameUnique(id, name);
|
||||
// 校验字典类型的类型的唯一性
|
||||
checkDictTypeUnique(id, type);
|
||||
validateDictTypeUnique(id, type);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkDictTypeNameUnique(Long id, String name) {
|
||||
void validateDictTypeNameUnique(Long id, String name) {
|
||||
DictTypeDO dictType = dictTypeMapper.selectByName(name);
|
||||
if (dictType == null) {
|
||||
return;
|
||||
@@ -116,7 +118,7 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkDictTypeUnique(Long id, String type) {
|
||||
void validateDictTypeUnique(Long id, String type) {
|
||||
if (StrUtil.isEmpty(type)) {
|
||||
return;
|
||||
}
|
||||
@@ -134,7 +136,7 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public DictTypeDO checkDictTypeExists(Long id) {
|
||||
DictTypeDO validateDictTypeExists(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
|
||||
@Override
|
||||
public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
this.validateErrorCodeExists(updateReqVO.getId());
|
||||
validateErrorCodeExists(updateReqVO.getId());
|
||||
// 校验 code 重复
|
||||
validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId());
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
|
||||
@Override
|
||||
public void deleteErrorCode(Long id) {
|
||||
// 校验存在
|
||||
this.validateErrorCodeExists(id);
|
||||
validateErrorCodeExists(id);
|
||||
// 删除
|
||||
errorCodeMapper.deleteById(id);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void validateErrorCodeExists(Long id) {
|
||||
void validateErrorCodeExists(Long id) {
|
||||
if (errorCodeMapper.selectById(id) == null) {
|
||||
throw exception(ERROR_CODE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.service.OperateLog;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.service.OperateLogFrameworkService;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
|
||||
@@ -38,6 +36,6 @@ public interface OperateLogService {
|
||||
* @param reqVO 列表条件
|
||||
* @return 日志列表
|
||||
*/
|
||||
List<OperateLogDO> getOperateLogs(OperateLogExportReqVO reqVO);
|
||||
List<OperateLogDO> getOperateLogList(OperateLogExportReqVO reqVO);
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
|
||||
userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return PageResult.empty();
|
||||
}
|
||||
@@ -59,11 +59,11 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OperateLogDO> getOperateLogs(OperateLogExportReqVO reqVO) {
|
||||
public List<OperateLogDO> getOperateLogList(OperateLogExportReqVO reqVO) {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
|
||||
userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.service.mail;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.mail.MailAccount;
|
||||
import cn.hutool.extra.mail.MailUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
|
||||
@@ -20,15 +19,13 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 邮箱模版 服务实现类
|
||||
* 邮箱发送 Service 实现类
|
||||
*
|
||||
* @author wangjingyi
|
||||
* @since 2022-03-21
|
||||
@@ -82,13 +79,13 @@ public class MailSendServiceImpl implements MailSendService {
|
||||
public Long sendSingleMail(String mail, Long userId, Integer userType,
|
||||
String templateCode, Map<String, Object> templateParams) {
|
||||
// 校验邮箱模版是否合法
|
||||
MailTemplateDO template = checkMailTemplateValid(templateCode);
|
||||
MailTemplateDO template = validateMailTemplate(templateCode);
|
||||
// 校验邮箱账号是否合法
|
||||
MailAccountDO account = checkMailAccountValid(template.getAccountId());
|
||||
MailAccountDO account = validateMailAccount(template.getAccountId());
|
||||
|
||||
// 校验邮箱是否存在
|
||||
mail = checkMail(mail);
|
||||
checkTemplateParams(template, templateParams);
|
||||
mail = validateMail(mail);
|
||||
validateTemplateParams(template, templateParams);
|
||||
|
||||
// 创建发送日志。如果模板被禁用,则不发送短信,只记录日志
|
||||
Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus());
|
||||
@@ -106,7 +103,7 @@ public class MailSendServiceImpl implements MailSendService {
|
||||
@Override
|
||||
public void doSendMail(MailSendMessage message) {
|
||||
// 1. 创建发送账号
|
||||
MailAccountDO account = checkMailAccountValid(message.getAccountId());
|
||||
MailAccountDO account = validateMailAccount(message.getAccountId());
|
||||
MailAccount mailAccount = MailAccountConvert.INSTANCE.convert(account, message.getNickname());
|
||||
// 2. 发送邮件
|
||||
try {
|
||||
@@ -121,7 +118,7 @@ public class MailSendServiceImpl implements MailSendService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public MailTemplateDO checkMailTemplateValid(String templateCode) {
|
||||
MailTemplateDO validateMailTemplate(String templateCode) {
|
||||
// 获得邮件模板。考虑到效率,从缓存中获取
|
||||
MailTemplateDO template = mailTemplateService.getMailTemplateByCodeFromCache(templateCode);
|
||||
// 邮件模板不存在
|
||||
@@ -132,7 +129,7 @@ public class MailSendServiceImpl implements MailSendService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public MailAccountDO checkMailAccountValid(Long accountId) {
|
||||
MailAccountDO validateMailAccount(Long accountId) {
|
||||
// 获得邮箱账号。考虑到效率,从缓存中获取
|
||||
MailAccountDO account = mailAccountService.getMailAccountFromCache(accountId);
|
||||
// 邮箱账号不存在
|
||||
@@ -143,7 +140,7 @@ public class MailSendServiceImpl implements MailSendService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public String checkMail(String mail) {
|
||||
String validateMail(String mail) {
|
||||
if (StrUtil.isEmpty(mail)) {
|
||||
throw exception(MAIL_SEND_MAIL_NOT_EXISTS);
|
||||
}
|
||||
@@ -157,7 +154,7 @@ public class MailSendServiceImpl implements MailSendService {
|
||||
* @param templateParams 参数列表
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkTemplateParams(MailTemplateDO template, Map<String, Object> templateParams) {
|
||||
void validateTemplateParams(MailTemplateDO template, Map<String, Object> templateParams) {
|
||||
template.getParams().forEach(key -> {
|
||||
Object value = templateParams.get(key);
|
||||
if (value == null) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface NoticeService {
|
||||
* @param reqVO 分页条件
|
||||
* @return 部门分页列表
|
||||
*/
|
||||
PageResult<NoticeDO> pageNotices(NoticePageReqVO reqVO);
|
||||
PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位公告公告信息
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package cn.iocoder.yudao.module.system.service.notice;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
@Override
|
||||
public void updateNotice(NoticeUpdateReqVO reqVO) {
|
||||
// 校验是否存在
|
||||
this.checkNoticeExists(reqVO.getId());
|
||||
validateNoticeExists(reqVO.getId());
|
||||
// 更新通知公告
|
||||
NoticeDO updateObj = NoticeConvert.INSTANCE.convert(reqVO);
|
||||
noticeMapper.updateById(updateObj);
|
||||
@@ -45,13 +45,13 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
@Override
|
||||
public void deleteNotice(Long id) {
|
||||
// 校验是否存在
|
||||
this.checkNoticeExists(id);
|
||||
validateNoticeExists(id);
|
||||
// 删除通知公告
|
||||
noticeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<NoticeDO> pageNotices(NoticePageReqVO reqVO) {
|
||||
public PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO) {
|
||||
return noticeMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ public class NoticeServiceImpl implements NoticeService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkNoticeExists(Long id) {
|
||||
public void validateNoticeExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
NoticeDO notice = noticeMapper.selectById(id);
|
||||
if (notice == null) {
|
||||
throw ServiceExceptionUtil.exception(NOTICE_NOT_FOUND);
|
||||
throw exception(NOTICE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +44,13 @@ public class NotifySendServiceImpl implements NotifySendService {
|
||||
@Override
|
||||
public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams) {
|
||||
// 校验模版
|
||||
NotifyTemplateDO template = checkNotifyTemplateValid(templateCode);
|
||||
NotifyTemplateDO template = validateNotifyTemplate(templateCode);
|
||||
if (Objects.equals(template.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
|
||||
log.info("[sendSingleNotify][模版({})已经关闭,无法给用户({}/{})发送]", templateCode, userId, userType);
|
||||
return null;
|
||||
}
|
||||
// 校验参数
|
||||
checkTemplateParams(template, templateParams);
|
||||
validateTemplateParams(template, templateParams);
|
||||
|
||||
// 发送站内信
|
||||
String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams);
|
||||
@@ -58,7 +58,7 @@ public class NotifySendServiceImpl implements NotifySendService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public NotifyTemplateDO checkNotifyTemplateValid(String templateCode) {
|
||||
public NotifyTemplateDO validateNotifyTemplate(String templateCode) {
|
||||
// 获得站内信模板。考虑到效率,从缓存中获取
|
||||
NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode);
|
||||
// 站内信模板不存在
|
||||
@@ -75,7 +75,7 @@ public class NotifySendServiceImpl implements NotifySendService {
|
||||
* @param templateParams 参数列表
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkTemplateParams(NotifyTemplateDO template, Map<String, Object> templateParams) {
|
||||
public void validateTemplateParams(NotifyTemplateDO template, Map<String, Object> templateParams) {
|
||||
template.getParams().forEach(key -> {
|
||||
Object value = templateParams.get(key);
|
||||
if (value == null) {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
|
||||
@Override
|
||||
public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) {
|
||||
// 校验站内信编码是否重复
|
||||
checkNotifyTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
validateNotifyTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
|
||||
// 插入
|
||||
NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO);
|
||||
@@ -93,7 +93,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
|
||||
// 校验存在
|
||||
validateNotifyTemplateExists(updateReqVO.getId());
|
||||
// 校验站内信编码是否重复
|
||||
checkNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
validateNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
|
||||
// 更新
|
||||
NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO);
|
||||
@@ -136,7 +136,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkNotifyTemplateCodeDuplicate(Long id, String code) {
|
||||
public void validateNotifyTemplateCodeDuplicate(Long id, String code) {
|
||||
NotifyTemplateDO template = notifyTemplateMapper.selectByCode(code);
|
||||
if (template == null) {
|
||||
return;
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface MenuService {
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuDO> getMenus();
|
||||
List<MenuDO> getMenuList();
|
||||
|
||||
/**
|
||||
* 基于租户,筛选菜单列表
|
||||
@@ -56,7 +56,7 @@ public interface MenuService {
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuDO> getTenantMenus(MenuListReqVO reqVO);
|
||||
List<MenuDO> getMenuListByTenant(MenuListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 筛选菜单列表
|
||||
@@ -64,7 +64,7 @@ public interface MenuService {
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuDO> getMenus(MenuListReqVO reqVO);
|
||||
List<MenuDO> getMenuList(MenuListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得所有菜单,从缓存中
|
||||
|
||||
@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.service.permission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
||||
@@ -10,7 +9,6 @@ import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUp
|
||||
import cn.iocoder.yudao.module.system.convert.permission.MenuConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuIdEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
|
||||
import cn.iocoder.yudao.module.system.mq.producer.permission.MenuProducer;
|
||||
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
||||
@@ -19,6 +17,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -31,6 +30,8 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
@@ -49,6 +50,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
* 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private volatile Map<Long, MenuDO> menuCache;
|
||||
/**
|
||||
* 权限与菜单缓存
|
||||
@@ -58,6 +60,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
* 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private volatile Multimap<String, MenuDO> permissionMenuCache;
|
||||
|
||||
@Resource
|
||||
@@ -97,9 +100,10 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Override
|
||||
public Long createMenu(MenuCreateReqVO reqVO) {
|
||||
// 校验父菜单存在
|
||||
checkParentResource(reqVO.getParentId(), null);
|
||||
validateParentMenu(reqVO.getParentId(), null);
|
||||
// 校验菜单(自己)
|
||||
checkResource(reqVO.getParentId(), reqVO.getName(), null);
|
||||
validateMenu(reqVO.getParentId(), reqVO.getName(), null);
|
||||
|
||||
// 插入数据库
|
||||
MenuDO menu = MenuConvert.INSTANCE.convert(reqVO);
|
||||
initMenuProperty(menu);
|
||||
@@ -114,12 +118,13 @@ public class MenuServiceImpl implements MenuService {
|
||||
public void updateMenu(MenuUpdateReqVO reqVO) {
|
||||
// 校验更新的菜单是否存在
|
||||
if (menuMapper.selectById(reqVO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS);
|
||||
throw exception(MENU_NOT_EXISTS);
|
||||
}
|
||||
// 校验父菜单存在
|
||||
checkParentResource(reqVO.getParentId(), reqVO.getId());
|
||||
validateParentMenu(reqVO.getParentId(), reqVO.getId());
|
||||
// 校验菜单(自己)
|
||||
checkResource(reqVO.getParentId(), reqVO.getName(), reqVO.getId());
|
||||
validateMenu(reqVO.getParentId(), reqVO.getName(), reqVO.getId());
|
||||
|
||||
// 更新到数据库
|
||||
MenuDO updateObject = MenuConvert.INSTANCE.convert(reqVO);
|
||||
initMenuProperty(updateObject);
|
||||
@@ -128,21 +133,16 @@ public class MenuServiceImpl implements MenuService {
|
||||
menuProducer.sendMenuRefreshMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param menuId 菜单编号
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMenu(Long menuId) {
|
||||
// 校验是否还有子菜单
|
||||
if (menuMapper.selectCountByParentId(menuId) > 0) {
|
||||
throw ServiceExceptionUtil.exception(MENU_EXISTS_CHILDREN);
|
||||
throw exception(MENU_EXISTS_CHILDREN);
|
||||
}
|
||||
// 校验删除的菜单是否存在
|
||||
if (menuMapper.selectById(menuId) == null) {
|
||||
throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS);
|
||||
throw exception(MENU_NOT_EXISTS);
|
||||
}
|
||||
// 标记删除
|
||||
menuMapper.deleteById(menuId);
|
||||
@@ -160,20 +160,20 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDO> getMenus() {
|
||||
public List<MenuDO> getMenuList() {
|
||||
return menuMapper.selectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDO> getTenantMenus(MenuListReqVO reqVO) {
|
||||
List<MenuDO> menus = getMenus(reqVO);
|
||||
public List<MenuDO> getMenuListByTenant(MenuListReqVO reqVO) {
|
||||
List<MenuDO> menus = getMenuList(reqVO);
|
||||
// 开启多租户的情况下,需要过滤掉未开通的菜单
|
||||
tenantService.handleTenantMenu(menuIds -> menus.removeIf(menu -> !CollUtil.contains(menuIds, menu.getId())));
|
||||
return menus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDO> getMenus(MenuListReqVO reqVO) {
|
||||
public List<MenuDO> getMenuList(MenuListReqVO reqVO) {
|
||||
return menuMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@@ -223,23 +223,23 @@ public class MenuServiceImpl implements MenuService {
|
||||
* @param childId 当前菜单编号
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkParentResource(Long parentId, Long childId) {
|
||||
if (parentId == null || MenuIdEnum.ROOT.getId().equals(parentId)) {
|
||||
void validateParentMenu(Long parentId, Long childId) {
|
||||
if (parentId == null || ID_ROOT.equals(parentId)) {
|
||||
return;
|
||||
}
|
||||
// 不能设置自己为父菜单
|
||||
if (parentId.equals(childId)) {
|
||||
throw ServiceExceptionUtil.exception(MENU_PARENT_ERROR);
|
||||
throw exception(MENU_PARENT_ERROR);
|
||||
}
|
||||
MenuDO menu = menuMapper.selectById(parentId);
|
||||
// 父菜单不存在
|
||||
if (menu == null) {
|
||||
throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_EXISTS);
|
||||
throw exception(MENU_PARENT_NOT_EXISTS);
|
||||
}
|
||||
// 父菜单必须是目录或者菜单类型
|
||||
if (!MenuTypeEnum.DIR.getType().equals(menu.getType())
|
||||
&& !MenuTypeEnum.MENU.getType().equals(menu.getType())) {
|
||||
throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_DIR_OR_MENU);
|
||||
throw exception(MENU_PARENT_NOT_DIR_OR_MENU);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,17 +253,17 @@ public class MenuServiceImpl implements MenuService {
|
||||
* @param id 菜单编号
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkResource(Long parentId, String name, Long id) {
|
||||
void validateMenu(Long parentId, String name, Long id) {
|
||||
MenuDO menu = menuMapper.selectByParentIdAndName(parentId, name);
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的菜单
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE);
|
||||
throw exception(MENU_NAME_DUPLICATE);
|
||||
}
|
||||
if (!menu.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE);
|
||||
throw exception(MENU_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
}
|
||||
|
||||
// 判断角色是否包含超级管理员。如果是超级管理员,获取到全部
|
||||
List<RoleDO> roleList = roleService.getRolesFromCache(roleIds);
|
||||
List<RoleDO> roleList = roleService.getRoleListFromCache(roleIds);
|
||||
if (roleService.hasAnySuperAdmin(roleList)) {
|
||||
return menuService.getMenuListFromCache(menuTypes, menusStatuses);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
public Set<Long> getRoleMenuIds(Long roleId) {
|
||||
// 如果是管理员的情况下,获取全部菜单编号
|
||||
if (roleService.hasAnySuperAdmin(Collections.singleton(roleId))) {
|
||||
return convertSet(menuService.getMenus(), MenuDO::getId);
|
||||
return convertSet(menuService.getMenuList(), MenuDO::getId);
|
||||
}
|
||||
// 如果是非管理员的情况下,获得拥有的菜单编号
|
||||
return convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId);
|
||||
@@ -371,7 +371,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
if (roleService.hasAnySuperAdmin(roleIds)) {
|
||||
return true;
|
||||
}
|
||||
Set<String> userRoles = convertSet(roleService.getRolesFromCache(roleIds),
|
||||
Set<String> userRoles = convertSet(roleService.getRoleListFromCache(roleIds),
|
||||
RoleDO::getCode);
|
||||
return CollUtil.containsAny(userRoles, Sets.newHashSet(roles));
|
||||
}
|
||||
@@ -388,7 +388,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
result.setSelf(true);
|
||||
return result;
|
||||
}
|
||||
List<RoleDO> roles = roleService.getRolesFromCache(roleIds);
|
||||
List<RoleDO> roles = roleService.getRoleListFromCache(roleIds);
|
||||
|
||||
// 获得用户的部门编号的缓存,通过 Guava 的 Suppliers 惰性求值,即有且仅有第一次发起 DB 的查询
|
||||
Supplier<Long> userDeptIdCache = Suppliers.memoize(() -> userService.getUser(userId).getDeptId());
|
||||
@@ -418,7 +418,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
}
|
||||
// 情况四,DEPT_DEPT_AND_CHILD
|
||||
if (Objects.equals(role.getDataScope(), DataScopeEnum.DEPT_AND_CHILD.getScope())) {
|
||||
List<DeptDO> depts = deptService.getDeptsByParentIdFromCache(userDeptIdCache.get(), true);
|
||||
List<DeptDO> depts = deptService.getDeptListByParentIdFromCache(userDeptIdCache.get(), true);
|
||||
CollUtil.addAll(result.getDeptIds(), CollectionUtils.convertList(depts, DeptDO::getId));
|
||||
// 添加本身部门编号
|
||||
CollUtil.addAll(result.getDeptIds(), userDeptIdCache.get());
|
||||
|
||||
@@ -79,7 +79,7 @@ public interface RoleService {
|
||||
* @param statuses 筛选的状态。允许空,空时不筛选
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<RoleDO> getRoles(@Nullable Collection<Integer> statuses);
|
||||
List<RoleDO> getRoleListByStatus(@Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得角色数组,从缓存中
|
||||
@@ -87,7 +87,7 @@ public interface RoleService {
|
||||
* @param ids 角色编号数组
|
||||
* @return 角色数组
|
||||
*/
|
||||
List<RoleDO> getRolesFromCache(Collection<Long> ids);
|
||||
List<RoleDO> getRoleListFromCache(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 判断角色数组中,是否有超级管理员
|
||||
@@ -104,7 +104,7 @@ public interface RoleService {
|
||||
* @return 是否有管理员
|
||||
*/
|
||||
default boolean hasAnySuperAdmin(Set<Long> ids) {
|
||||
return hasAnySuperAdmin(getRolesFromCache(ids));
|
||||
return hasAnySuperAdmin(getRoleListFromCache(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,6 +138,6 @@ public interface RoleService {
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
*/
|
||||
void validRoles(Collection<Long> ids);
|
||||
void validateRoleList(Collection<Long> ids);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO;
|
||||
@@ -34,6 +33,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
log.info("[initLocalCache][缓存角色,数量为:{}]", roleList.size());
|
||||
|
||||
// 第二步:构建缓存
|
||||
roleCache = CollectionUtils.convertMap(roleList, RoleDO::getId);
|
||||
roleCache = convertMap(roleList, RoleDO::getId);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Transactional
|
||||
public Long createRole(RoleCreateReqVO reqVO, Integer type) {
|
||||
// 校验角色
|
||||
checkDuplicateRole(reqVO.getName(), reqVO.getCode(), null);
|
||||
validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), null);
|
||||
// 插入到数据库
|
||||
RoleDO role = RoleConvert.INSTANCE.convert(reqVO);
|
||||
role.setType(ObjectUtil.defaultIfNull(type, RoleTypeEnum.CUSTOM.getType()));
|
||||
@@ -105,13 +105,13 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Override
|
||||
public void updateRole(RoleUpdateReqVO reqVO) {
|
||||
// 校验是否可以更新
|
||||
checkUpdateRole(reqVO.getId());
|
||||
validateRoleForUpdate(reqVO.getId());
|
||||
// 校验角色的唯一字段是否重复
|
||||
checkDuplicateRole(reqVO.getName(), reqVO.getCode(), reqVO.getId());
|
||||
validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), reqVO.getId());
|
||||
|
||||
// 更新到数据库
|
||||
RoleDO updateObject = RoleConvert.INSTANCE.convert(reqVO);
|
||||
roleMapper.updateById(updateObject);
|
||||
RoleDO updateObj = RoleConvert.INSTANCE.convert(reqVO);
|
||||
roleMapper.updateById(updateObj);
|
||||
// 发送刷新消息
|
||||
roleProducer.sendRoleRefreshMessage();
|
||||
}
|
||||
@@ -119,12 +119,11 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Override
|
||||
public void updateRoleStatus(Long id, Integer status) {
|
||||
// 校验是否可以更新
|
||||
checkUpdateRole(id);
|
||||
validateRoleForUpdate(id);
|
||||
|
||||
// 更新状态
|
||||
RoleDO updateObject = new RoleDO();
|
||||
updateObject.setId(id);
|
||||
updateObject.setStatus(status);
|
||||
roleMapper.updateById(updateObject);
|
||||
RoleDO updateObj = new RoleDO().setId(id).setStatus(status);
|
||||
roleMapper.updateById(updateObj);
|
||||
// 发送刷新消息
|
||||
roleProducer.sendRoleRefreshMessage();
|
||||
}
|
||||
@@ -132,7 +131,8 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Override
|
||||
public void updateRoleDataScope(Long id, Integer dataScope, Set<Long> dataScopeDeptIds) {
|
||||
// 校验是否可以更新
|
||||
checkUpdateRole(id);
|
||||
validateRoleForUpdate(id);
|
||||
|
||||
// 更新数据范围
|
||||
RoleDO updateObject = new RoleDO();
|
||||
updateObject.setId(id);
|
||||
@@ -147,7 +147,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteRole(Long id) {
|
||||
// 校验是否可以更新
|
||||
this.checkUpdateRole(id);
|
||||
validateRoleForUpdate(id);
|
||||
// 标记删除
|
||||
roleMapper.deleteById(id);
|
||||
// 删除相关数据
|
||||
@@ -169,7 +169,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleDO> getRoles(@Nullable Collection<Integer> statuses) {
|
||||
public List<RoleDO> getRoleListByStatus(@Nullable Collection<Integer> statuses) {
|
||||
if (CollUtil.isEmpty(statuses)) {
|
||||
return roleMapper.selectList();
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleDO> getRolesFromCache(Collection<Long> ids) {
|
||||
public List<RoleDO> getRoleListFromCache(Collection<Long> ids) {
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -219,7 +219,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
* @param id 角色编号
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkDuplicateRole(String name, String code, Long id) {
|
||||
void validateRoleDuplicate(String name, String code, Long id) {
|
||||
// 0. 超级管理员,不允许创建
|
||||
if (RoleCodeEnum.isSuperAdmin(code)) {
|
||||
throw exception(ROLE_ADMIN_CODE_ERROR, code);
|
||||
@@ -246,7 +246,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
* @param id 角色编号
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkUpdateRole(Long id) {
|
||||
void validateRoleForUpdate(Long id) {
|
||||
RoleDO roleDO = roleMapper.selectById(id);
|
||||
if (roleDO == null) {
|
||||
throw exception(ROLE_NOT_EXISTS);
|
||||
@@ -258,13 +258,13 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validRoles(Collection<Long> ids) {
|
||||
public void validateRoleList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 获得角色信息
|
||||
List<RoleDO> roles = roleMapper.selectBatchIds(ids);
|
||||
Map<Long, RoleDO> roleMap = CollectionUtils.convertMap(roles, RoleDO::getId);
|
||||
Map<Long, RoleDO> roleMap = convertMap(roles, RoleDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
RoleDO role = roleMap.get(id);
|
||||
|
||||
@@ -81,7 +81,7 @@ public interface SensitiveWordService {
|
||||
*
|
||||
* @return 标签数组
|
||||
*/
|
||||
Set<String> getSensitiveWordTags();
|
||||
Set<String> getSensitiveWordTagSet();
|
||||
|
||||
/**
|
||||
* 获得文本所包含的不合法的敏感词数组
|
||||
|
||||
@@ -25,6 +25,7 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_EXISTS;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SENSITIVE_WORD_NOT_EXISTS;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
|
||||
private void initSensitiveWordTrie(List<SensitiveWordDO> wordDOs) {
|
||||
// 过滤禁用的敏感词
|
||||
wordDOs = CollectionUtils.filterList(wordDOs, word -> word.getStatus().equals(CommonStatusEnum.ENABLE.getStatus()));
|
||||
wordDOs = filterList(wordDOs, word -> word.getStatus().equals(CommonStatusEnum.ENABLE.getStatus()));
|
||||
|
||||
// 初始化默认的 defaultSensitiveWordTrie
|
||||
this.defaultSensitiveWordTrie = new SimpleTrie(CollectionUtils.convertList(wordDOs, SensitiveWordDO::getName));
|
||||
@@ -107,7 +108,8 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
@Override
|
||||
public Long createSensitiveWord(SensitiveWordCreateReqVO createReqVO) {
|
||||
// 校验唯一性
|
||||
checkSensitiveWordNameUnique(null, createReqVO.getName());
|
||||
validateSensitiveWordNameUnique(null, createReqVO.getName());
|
||||
|
||||
// 插入
|
||||
SensitiveWordDO sensitiveWord = SensitiveWordConvert.INSTANCE.convert(createReqVO);
|
||||
sensitiveWordMapper.insert(sensitiveWord);
|
||||
@@ -119,8 +121,9 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
@Override
|
||||
public void updateSensitiveWord(SensitiveWordUpdateReqVO updateReqVO) {
|
||||
// 校验唯一性
|
||||
checkSensitiveWordExists(updateReqVO.getId());
|
||||
checkSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName());
|
||||
validateSensitiveWordExists(updateReqVO.getId());
|
||||
validateSensitiveWordNameUnique(updateReqVO.getId(), updateReqVO.getName());
|
||||
|
||||
// 更新
|
||||
SensitiveWordDO updateObj = SensitiveWordConvert.INSTANCE.convert(updateReqVO);
|
||||
sensitiveWordMapper.updateById(updateObj);
|
||||
@@ -131,14 +134,14 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
@Override
|
||||
public void deleteSensitiveWord(Long id) {
|
||||
// 校验存在
|
||||
checkSensitiveWordExists(id);
|
||||
validateSensitiveWordExists(id);
|
||||
// 删除
|
||||
sensitiveWordMapper.deleteById(id);
|
||||
// 发送消息,刷新缓存
|
||||
sensitiveWordProducer.sendSensitiveWordRefreshMessage();
|
||||
}
|
||||
|
||||
private void checkSensitiveWordNameUnique(Long id, String name) {
|
||||
private void validateSensitiveWordNameUnique(Long id, String name) {
|
||||
SensitiveWordDO word = sensitiveWordMapper.selectByName(name);
|
||||
if (word == null) {
|
||||
return;
|
||||
@@ -152,7 +155,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSensitiveWordExists(Long id) {
|
||||
private void validateSensitiveWordExists(Long id) {
|
||||
if (sensitiveWordMapper.selectById(id) == null) {
|
||||
throw exception(SENSITIVE_WORD_NOT_EXISTS);
|
||||
}
|
||||
@@ -179,7 +182,7 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSensitiveWordTags() {
|
||||
public Set<String> getSensitiveWordTagSet() {
|
||||
return sensitiveWordTagsCache;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package cn.iocoder.yudao.module.system.service.sms;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -53,14 +52,6 @@ public interface SmsChannelService {
|
||||
*/
|
||||
SmsChannelDO getSmsChannel(Long id);
|
||||
|
||||
/**
|
||||
* 获得短信渠道列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 短信渠道列表
|
||||
*/
|
||||
List<SmsChannelDO> getSmsChannelList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得所有短信渠道列表
|
||||
*
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@@ -69,7 +68,7 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
||||
@Override
|
||||
public void updateSmsChannel(SmsChannelUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
this.validateSmsChannelExists(updateReqVO.getId());
|
||||
validateSmsChannelExists(updateReqVO.getId());
|
||||
// 更新
|
||||
SmsChannelDO updateObj = SmsChannelConvert.INSTANCE.convert(updateReqVO);
|
||||
smsChannelMapper.updateById(updateObj);
|
||||
@@ -80,7 +79,7 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
||||
@Override
|
||||
public void deleteSmsChannel(Long id) {
|
||||
// 校验存在
|
||||
this.validateSmsChannelExists(id);
|
||||
validateSmsChannelExists(id);
|
||||
// 校验是否有在使用该账号的模版
|
||||
if (smsTemplateService.countByChannelId(id) > 0) {
|
||||
throw exception(SMS_CHANNEL_HAS_CHILDREN);
|
||||
@@ -102,11 +101,6 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
||||
return smsChannelMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SmsChannelDO> getSmsChannelList(Collection<Long> ids) {
|
||||
return smsChannelMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SmsChannelDO> getSmsChannelList() {
|
||||
return smsChannelMapper.selectList();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.service.sms;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeValidateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
|
||||
|
||||
@@ -35,6 +35,6 @@ public interface SmsCodeService {
|
||||
*
|
||||
* @param reqDTO 校验请求
|
||||
*/
|
||||
void checkSmsCode(@Valid SmsCodeCheckReqDTO reqDTO);
|
||||
void validateSmsCode(@Valid SmsCodeValidateReqDTO reqDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.system.service.sms;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeValidateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsCodeDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsCodeMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
||||
@@ -16,11 +14,11 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomInt;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.isToday;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
@@ -58,11 +56,11 @@ public class SmsCodeServiceImpl implements SmsCodeService {
|
||||
if (lastSmsCode != null) {
|
||||
if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis()
|
||||
< smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁
|
||||
throw ServiceExceptionUtil.exception(SMS_CODE_SEND_TOO_FAST);
|
||||
throw exception(SMS_CODE_SEND_TOO_FAST);
|
||||
}
|
||||
if (DateUtils.isToday(lastSmsCode.getCreateTime()) && // 必须是今天,才能计算超过当天的上限
|
||||
if (isToday(lastSmsCode.getCreateTime()) && // 必须是今天,才能计算超过当天的上限
|
||||
lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。
|
||||
throw ServiceExceptionUtil.exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY);
|
||||
throw exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY);
|
||||
}
|
||||
// TODO 芋艿:提升,每个 IP 每天可发送数量
|
||||
// TODO 芋艿:提升,每个 IP 每小时可发送数量
|
||||
@@ -71,7 +69,7 @@ public class SmsCodeServiceImpl implements SmsCodeService {
|
||||
// 创建验证码记录
|
||||
String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1));
|
||||
SmsCodeDO newSmsCode = SmsCodeDO.builder().mobile(mobile).code(code).scene(scene)
|
||||
.todayIndex(lastSmsCode != null && DateUtils.isToday(lastSmsCode.getCreateTime()) ? lastSmsCode.getTodayIndex() + 1 : 1)
|
||||
.todayIndex(lastSmsCode != null && isToday(lastSmsCode.getCreateTime()) ? lastSmsCode.getTodayIndex() + 1 : 1)
|
||||
.createIp(ip).used(false).build();
|
||||
smsCodeMapper.insert(newSmsCode);
|
||||
return code;
|
||||
@@ -80,32 +78,32 @@ public class SmsCodeServiceImpl implements SmsCodeService {
|
||||
@Override
|
||||
public void useSmsCode(SmsCodeUseReqDTO reqDTO) {
|
||||
// 检测验证码是否有效
|
||||
SmsCodeDO lastSmsCode = this.checkSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene());
|
||||
SmsCodeDO lastSmsCode = validateSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene());
|
||||
// 使用验证码
|
||||
smsCodeMapper.updateById(SmsCodeDO.builder().id(lastSmsCode.getId())
|
||||
.used(true).usedTime(LocalDateTime.now()).usedIp(reqDTO.getUsedIp()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSmsCode(SmsCodeCheckReqDTO reqDTO) {
|
||||
checkSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene());
|
||||
public void validateSmsCode(SmsCodeValidateReqDTO reqDTO) {
|
||||
validateSmsCode0(reqDTO.getMobile(), reqDTO.getCode(), reqDTO.getScene());
|
||||
}
|
||||
|
||||
public SmsCodeDO checkSmsCode0(String mobile, String code, Integer scene) {
|
||||
private SmsCodeDO validateSmsCode0(String mobile, String code, Integer scene) {
|
||||
// 校验验证码
|
||||
SmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, code, scene);
|
||||
// 若验证码不存在,抛出异常
|
||||
if (lastSmsCode == null) {
|
||||
throw ServiceExceptionUtil.exception(SMS_CODE_NOT_FOUND);
|
||||
throw exception(SMS_CODE_NOT_FOUND);
|
||||
}
|
||||
// 超过时间
|
||||
if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis()
|
||||
>= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期
|
||||
throw ServiceExceptionUtil.exception(SMS_CODE_EXPIRED);
|
||||
throw exception(SMS_CODE_EXPIRED);
|
||||
}
|
||||
// 判断验证码是否已被使用
|
||||
if (Boolean.TRUE.equals(lastSmsCode.getUsed())) {
|
||||
throw ServiceExceptionUtil.exception(SMS_CODE_USED);
|
||||
throw exception(SMS_CODE_USED);
|
||||
}
|
||||
return lastSmsCode;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SmsSendServiceImpl implements SmsSendService {
|
||||
}
|
||||
}
|
||||
// 执行发送
|
||||
return this.sendSingleSms(mobile, userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
|
||||
return sendSingleSms(mobile, userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,21 +76,21 @@ public class SmsSendServiceImpl implements SmsSendService {
|
||||
mobile = memberService.getMemberUserMobile(userId);
|
||||
}
|
||||
// 执行发送
|
||||
return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
|
||||
return sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sendSingleSms(String mobile, Long userId, Integer userType,
|
||||
String templateCode, Map<String, Object> templateParams) {
|
||||
// 校验短信模板是否合法
|
||||
SmsTemplateDO template = this.checkSmsTemplateValid(templateCode);
|
||||
SmsTemplateDO template = validateSmsTemplate(templateCode);
|
||||
// 校验短信渠道是否合法
|
||||
SmsChannelDO smsChannel = this.checkSmsChannelValid(template.getChannelId());
|
||||
SmsChannelDO smsChannel = validateSmsChannel(template.getChannelId());
|
||||
|
||||
// 校验手机号码是否存在
|
||||
mobile = this.checkMobile(mobile);
|
||||
mobile = validateMobile(mobile);
|
||||
// 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志
|
||||
List<KeyValue<String, Object>> newTemplateParams = this.buildTemplateParams(template, templateParams);
|
||||
List<KeyValue<String, Object>> newTemplateParams = buildTemplateParams(template, templateParams);
|
||||
|
||||
// 创建发送日志。如果模板被禁用,则不发送短信,只记录日志
|
||||
Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus())
|
||||
@@ -108,7 +108,7 @@ public class SmsSendServiceImpl implements SmsSendService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public SmsChannelDO checkSmsChannelValid(Long channelId) {
|
||||
SmsChannelDO validateSmsChannel(Long channelId) {
|
||||
// 获得短信模板。考虑到效率,从缓存中获取
|
||||
SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId);
|
||||
// 短信模板不存在
|
||||
@@ -119,7 +119,7 @@ public class SmsSendServiceImpl implements SmsSendService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public SmsTemplateDO checkSmsTemplateValid(String templateCode) {
|
||||
SmsTemplateDO validateSmsTemplate(String templateCode) {
|
||||
// 获得短信模板。考虑到效率,从缓存中获取
|
||||
SmsTemplateDO template = smsTemplateService.getSmsTemplateByCodeFromCache(templateCode);
|
||||
// 短信模板不存在
|
||||
@@ -139,7 +139,7 @@ public class SmsSendServiceImpl implements SmsSendService {
|
||||
* @return 处理后的参数
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public List<KeyValue<String, Object>> buildTemplateParams(SmsTemplateDO template, Map<String, Object> templateParams) {
|
||||
List<KeyValue<String, Object>> buildTemplateParams(SmsTemplateDO template, Map<String, Object> templateParams) {
|
||||
return template.getParams().stream().map(key -> {
|
||||
Object value = templateParams.get(key);
|
||||
if (value == null) {
|
||||
@@ -150,7 +150,7 @@ public class SmsSendServiceImpl implements SmsSendService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public String checkMobile(String mobile) {
|
||||
public String validateMobile(String mobile) {
|
||||
if (StrUtil.isEmpty(mobile)) {
|
||||
throw exception(SMS_SEND_MOBILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@@ -105,11 +105,11 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
@Override
|
||||
public Long createSmsTemplate(SmsTemplateCreateReqVO createReqVO) {
|
||||
// 校验短信渠道
|
||||
SmsChannelDO channelDO = checkSmsChannel(createReqVO.getChannelId());
|
||||
SmsChannelDO channelDO = validateSmsChannel(createReqVO.getChannelId());
|
||||
// 校验短信编码是否重复
|
||||
checkSmsTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
validateSmsTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
// 校验短信模板
|
||||
checkApiTemplate(createReqVO.getChannelId(), createReqVO.getApiTemplateId());
|
||||
validateApiTemplate(createReqVO.getChannelId(), createReqVO.getApiTemplateId());
|
||||
|
||||
// 插入
|
||||
SmsTemplateDO template = SmsTemplateConvert.INSTANCE.convert(createReqVO);
|
||||
@@ -125,13 +125,13 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
@Override
|
||||
public void updateSmsTemplate(SmsTemplateUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
this.validateSmsTemplateExists(updateReqVO.getId());
|
||||
validateSmsTemplateExists(updateReqVO.getId());
|
||||
// 校验短信渠道
|
||||
SmsChannelDO channelDO = checkSmsChannel(updateReqVO.getChannelId());
|
||||
SmsChannelDO channelDO = validateSmsChannel(updateReqVO.getChannelId());
|
||||
// 校验短信编码是否重复
|
||||
checkSmsTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
validateSmsTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
// 校验短信模板
|
||||
checkApiTemplate(updateReqVO.getChannelId(), updateReqVO.getApiTemplateId());
|
||||
validateApiTemplate(updateReqVO.getChannelId(), updateReqVO.getApiTemplateId());
|
||||
|
||||
// 更新
|
||||
SmsTemplateDO updateObj = SmsTemplateConvert.INSTANCE.convert(updateReqVO);
|
||||
@@ -145,7 +145,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
@Override
|
||||
public void deleteSmsTemplate(Long id) {
|
||||
// 校验存在
|
||||
this.validateSmsTemplateExists(id);
|
||||
validateSmsTemplateExists(id);
|
||||
// 更新
|
||||
smsTemplateMapper.deleteById(id);
|
||||
// 发送刷新消息
|
||||
@@ -184,7 +184,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public SmsChannelDO checkSmsChannel(Long channelId) {
|
||||
public SmsChannelDO validateSmsChannel(Long channelId) {
|
||||
SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId);
|
||||
if (channelDO == null) {
|
||||
throw exception(SMS_CHANNEL_NOT_EXISTS);
|
||||
@@ -196,7 +196,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkSmsTemplateCodeDuplicate(Long id, String code) {
|
||||
public void validateSmsTemplateCodeDuplicate(Long id, String code) {
|
||||
SmsTemplateDO template = smsTemplateMapper.selectByCode(code);
|
||||
if (template == null) {
|
||||
return;
|
||||
@@ -217,7 +217,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
* @param apiTemplateId API 模板编号
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkApiTemplate(Long channelId, String apiTemplateId) {
|
||||
public void validateApiTemplate(Long channelId, String apiTemplateId) {
|
||||
// 获得短信模板
|
||||
SmsClient smsClient = smsClientFactory.getSmsClient(channelId);
|
||||
Assert.notNull(smsClient, String.format("短信客户端(%d) 不存在", channelId));
|
||||
|
||||
@@ -64,9 +64,9 @@ public class TenantPackageServiceImpl implements TenantPackageService {
|
||||
@Override
|
||||
public void deleteTenantPackage(Long id) {
|
||||
// 校验存在
|
||||
this.validateTenantPackageExists(id);
|
||||
validateTenantPackageExists(id);
|
||||
// 校验正在使用
|
||||
this.validateTenantUsed(id);
|
||||
validateTenantUsed(id);
|
||||
// 删除
|
||||
tenantPackageMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public interface TenantService {
|
||||
*
|
||||
* @return 租户编号数组
|
||||
*/
|
||||
List<Long> getTenantIds();
|
||||
List<Long> getTenantIdList();
|
||||
|
||||
/**
|
||||
* 校验租户是否合法
|
||||
|
||||
@@ -75,7 +75,7 @@ public class TenantServiceImpl implements TenantService {
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Override
|
||||
public List<Long> getTenantIds() {
|
||||
public List<Long> getTenantIdList() {
|
||||
List<TenantDO> tenants = tenantMapper.selectList();
|
||||
return CollectionUtils.convertList(tenants, TenantDO::getId);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class TenantServiceImpl implements TenantService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateTenant(TenantUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
TenantDO tenant = checkUpdateTenant(updateReqVO.getId());
|
||||
TenantDO tenant = validateUpdateTenant(updateReqVO.getId());
|
||||
// 校验套餐被禁用
|
||||
TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId());
|
||||
|
||||
@@ -156,7 +156,7 @@ public class TenantServiceImpl implements TenantService {
|
||||
public void updateTenantRoleMenu(Long tenantId, Set<Long> menuIds) {
|
||||
TenantUtils.execute(tenantId, () -> {
|
||||
// 获得所有角色
|
||||
List<RoleDO> roles = roleService.getRoles(null);
|
||||
List<RoleDO> roles = roleService.getRoleListByStatus(null);
|
||||
roles.forEach(role -> Assert.isTrue(tenantId.equals(role.getTenantId()), "角色({}/{}) 租户不匹配",
|
||||
role.getId(), role.getTenantId(), tenantId)); // 兜底校验
|
||||
// 重新分配每个角色的权限
|
||||
@@ -179,12 +179,12 @@ public class TenantServiceImpl implements TenantService {
|
||||
@Override
|
||||
public void deleteTenant(Long id) {
|
||||
// 校验存在
|
||||
checkUpdateTenant(id);
|
||||
validateUpdateTenant(id);
|
||||
// 删除
|
||||
tenantMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private TenantDO checkUpdateTenant(Long id) {
|
||||
private TenantDO validateUpdateTenant(Long id) {
|
||||
TenantDO tenant = tenantMapper.selectById(id);
|
||||
if (tenant == null) {
|
||||
throw exception(TENANT_NOT_EXISTS);
|
||||
@@ -248,7 +248,7 @@ public class TenantServiceImpl implements TenantService {
|
||||
TenantDO tenant = getTenant(TenantContextHolder.getRequiredTenantId());
|
||||
Set<Long> menuIds;
|
||||
if (isSystemTenant(tenant)) { // 系统租户,菜单是全量的
|
||||
menuIds = CollectionUtils.convertSet(menuService.getMenus(), MenuDO::getId);
|
||||
menuIds = CollectionUtils.convertSet(menuService.getMenuList(), MenuDO::getId);
|
||||
} else {
|
||||
menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds();
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public interface AdminUserService {
|
||||
* @param deptIds 部门数组
|
||||
* @return 用户数组
|
||||
*/
|
||||
List<AdminUserDO> getUsersByDeptIds(Collection<Long> deptIds);
|
||||
List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds);
|
||||
|
||||
/**
|
||||
* 获得指定岗位的用户数组
|
||||
@@ -135,7 +135,7 @@ public interface AdminUserService {
|
||||
* @param postIds 岗位数组
|
||||
* @return 用户数组
|
||||
*/
|
||||
List<AdminUserDO> getUsersByPostIds(Collection<Long> postIds);
|
||||
List<AdminUserDO> getUserListByPostIds(Collection<Long> postIds);
|
||||
|
||||
/**
|
||||
* 获得用户列表
|
||||
@@ -143,7 +143,7 @@ public interface AdminUserService {
|
||||
* @param ids 用户编号数组
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<AdminUserDO> getUsers(Collection<Long> ids);
|
||||
List<AdminUserDO> getUserList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 校验用户们是否有效。如下情况,视为无效:
|
||||
@@ -152,7 +152,7 @@ public interface AdminUserService {
|
||||
*
|
||||
* @param ids 用户编号数组
|
||||
*/
|
||||
void validUsers(Set<Long> ids);
|
||||
void validateUserList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得用户 Map
|
||||
@@ -164,7 +164,7 @@ public interface AdminUserService {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return CollectionUtils.convertMap(getUsers(ids), AdminUserDO::getId);
|
||||
return CollectionUtils.convertMap(getUserList(ids), AdminUserDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +173,7 @@ public interface AdminUserService {
|
||||
* @param reqVO 列表请求
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<AdminUserDO> getUsers(UserExportReqVO reqVO);
|
||||
List<AdminUserDO> getUserList(UserExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得用户列表,基于昵称模糊匹配
|
||||
@@ -181,15 +181,7 @@ public interface AdminUserService {
|
||||
* @param nickname 昵称
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<AdminUserDO> getUsersByNickname(String nickname);
|
||||
|
||||
/**
|
||||
* 获得用户列表,基于用户账号模糊匹配
|
||||
*
|
||||
* @param username 用户账号
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<AdminUserDO> getUsersByUsername(String username);
|
||||
List<AdminUserDO> getUserListByNickname(String nickname);
|
||||
|
||||
/**
|
||||
* 批量导入用户
|
||||
@@ -198,7 +190,7 @@ public interface AdminUserService {
|
||||
* @param isUpdateSupport 是否支持更新
|
||||
* @return 导入结果
|
||||
*/
|
||||
UserImportRespVO importUsers(List<UserImportExcelVO> importUsers, boolean isUpdateSupport);
|
||||
UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport);
|
||||
|
||||
/**
|
||||
* 获得指定状态的用户们
|
||||
@@ -206,7 +198,7 @@ public interface AdminUserService {
|
||||
* @param status 状态
|
||||
* @return 用户们
|
||||
*/
|
||||
List<AdminUserDO> getUsersByStatus(Integer status);
|
||||
List<AdminUserDO> getUserListByStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 判断密码是否匹配
|
||||
|
||||
@@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
||||
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* 后台用户 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service("adminUserService")
|
||||
@@ -73,10 +74,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Resource
|
||||
private FileApi fileApi;
|
||||
|
||||
@Resource
|
||||
@Lazy // 循环依赖(自己依赖自己),避免报错
|
||||
private AdminUserServiceImpl self;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createUser(UserCreateReqVO reqVO) {
|
||||
@@ -88,7 +85,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
});
|
||||
// 校验正确性
|
||||
self.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
validateUserForCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
// 插入用户
|
||||
AdminUserDO user = UserConvert.INSTANCE.convert(reqVO);
|
||||
@@ -107,7 +104,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateUser(UserUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
self.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
validateUserForCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
// 更新用户
|
||||
AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO);
|
||||
@@ -141,9 +138,9 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Override
|
||||
public void updateUserProfile(Long id, UserProfileUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkUserExists(id);
|
||||
checkEmailUnique(id, reqVO.getEmail());
|
||||
checkMobileUnique(id, reqVO.getMobile());
|
||||
validateUserExists(id);
|
||||
validateEmailUnique(id, reqVO.getEmail());
|
||||
validateMobileUnique(id, reqVO.getMobile());
|
||||
// 执行更新
|
||||
userMapper.updateById(UserConvert.INSTANCE.convert(reqVO).setId(id));
|
||||
}
|
||||
@@ -151,7 +148,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Override
|
||||
public void updateUserPassword(Long id, UserProfileUpdatePasswordReqVO reqVO) {
|
||||
// 校验旧密码密码
|
||||
checkOldPassword(id, reqVO.getOldPassword());
|
||||
validateOldPassword(id, reqVO.getOldPassword());
|
||||
// 执行更新
|
||||
AdminUserDO updateObj = new AdminUserDO().setId(id);
|
||||
updateObj.setPassword(encodePassword(reqVO.getNewPassword())); // 加密密码
|
||||
@@ -160,7 +157,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
@Override
|
||||
public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception {
|
||||
checkUserExists(id);
|
||||
validateUserExists(id);
|
||||
// 存储文件
|
||||
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
||||
// 更新路径
|
||||
@@ -174,7 +171,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Override
|
||||
public void updateUserPassword(Long id, String password) {
|
||||
// 校验用户存在
|
||||
checkUserExists(id);
|
||||
validateUserExists(id);
|
||||
// 更新密码
|
||||
AdminUserDO updateObj = new AdminUserDO();
|
||||
updateObj.setId(id);
|
||||
@@ -185,7 +182,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Override
|
||||
public void updateUserStatus(Long id, Integer status) {
|
||||
// 校验用户存在
|
||||
checkUserExists(id);
|
||||
validateUserExists(id);
|
||||
// 更新状态
|
||||
AdminUserDO updateObj = new AdminUserDO();
|
||||
updateObj.setId(id);
|
||||
@@ -197,7 +194,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteUser(Long id) {
|
||||
// 校验用户存在
|
||||
checkUserExists(id);
|
||||
validateUserExists(id);
|
||||
// 删除用户
|
||||
userMapper.deleteById(id);
|
||||
// 删除用户关联数据
|
||||
@@ -227,7 +224,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUsersByDeptIds(Collection<Long> deptIds) {
|
||||
public List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds) {
|
||||
if (CollUtil.isEmpty(deptIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -235,7 +232,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUsersByPostIds(Collection<Long> postIds) {
|
||||
public List<AdminUserDO> getUserListByPostIds(Collection<Long> postIds) {
|
||||
if (CollUtil.isEmpty(postIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -247,7 +244,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUsers(Collection<Long> ids) {
|
||||
public List<AdminUserDO> getUserList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -255,7 +252,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validUsers(Set<Long> ids) {
|
||||
public void validateUserList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
@@ -275,20 +272,15 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUsers(UserExportReqVO reqVO) {
|
||||
public List<AdminUserDO> getUserList(UserExportReqVO reqVO) {
|
||||
return userMapper.selectList(reqVO, getDeptCondition(reqVO.getDeptId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUsersByNickname(String nickname) {
|
||||
public List<AdminUserDO> getUserListByNickname(String nickname) {
|
||||
return userMapper.selectListByNickname(nickname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUsersByUsername(String username) {
|
||||
return userMapper.selectListByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门条件:查询指定部门的子部门编号们,包括自身
|
||||
* @param deptId 部门编号
|
||||
@@ -298,31 +290,33 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
if (deptId == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<Long> deptIds = convertSet(deptService.getDeptsByParentIdFromCache(
|
||||
Set<Long> deptIds = convertSet(deptService.getDeptListByParentIdFromCache(
|
||||
deptId, true), DeptDO::getId);
|
||||
deptIds.add(deptId); // 包括自身
|
||||
return deptIds;
|
||||
}
|
||||
|
||||
@DataPermission(enable = false) // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
||||
public void checkCreateOrUpdate(Long id, String username, String mobile, String email,
|
||||
Long deptId, Set<Long> postIds) {
|
||||
// 校验用户存在
|
||||
checkUserExists(id);
|
||||
// 校验用户名唯一
|
||||
checkUsernameUnique(id, username);
|
||||
// 校验手机号唯一
|
||||
checkMobileUnique(id, mobile);
|
||||
// 校验邮箱唯一
|
||||
checkEmailUnique(id, email);
|
||||
// 校验部门处于开启状态
|
||||
deptService.validDepts(CollectionUtils.singleton(deptId));
|
||||
// 校验岗位处于开启状态
|
||||
postService.validPosts(postIds);
|
||||
private void validateUserForCreateOrUpdate(Long id, String username, String mobile, String email,
|
||||
Long deptId, Set<Long> postIds) {
|
||||
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
||||
DataPermissionUtils.executeIgnore(() -> {
|
||||
// 校验用户存在
|
||||
validateUserExists(id);
|
||||
// 校验用户名唯一
|
||||
validateUsernameUnique(id, username);
|
||||
// 校验手机号唯一
|
||||
validateMobileUnique(id, mobile);
|
||||
// 校验邮箱唯一
|
||||
validateEmailUnique(id, email);
|
||||
// 校验部门处于开启状态
|
||||
deptService.validateDeptList(CollectionUtils.singleton(deptId));
|
||||
// 校验岗位处于开启状态
|
||||
postService.validatePostList(postIds);
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkUserExists(Long id) {
|
||||
void validateUserExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
@@ -333,7 +327,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkUsernameUnique(Long id, String username) {
|
||||
void validateUsernameUnique(Long id, String username) {
|
||||
if (StrUtil.isBlank(username)) {
|
||||
return;
|
||||
}
|
||||
@@ -351,7 +345,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkEmailUnique(Long id, String email) {
|
||||
void validateEmailUnique(Long id, String email) {
|
||||
if (StrUtil.isBlank(email)) {
|
||||
return;
|
||||
}
|
||||
@@ -369,7 +363,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkMobileUnique(Long id, String mobile) {
|
||||
void validateMobileUnique(Long id, String mobile) {
|
||||
if (StrUtil.isBlank(mobile)) {
|
||||
return;
|
||||
}
|
||||
@@ -392,7 +386,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
* @param oldPassword 旧密码
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkOldPassword(Long id, String oldPassword) {
|
||||
void validateOldPassword(Long id, String oldPassword) {
|
||||
AdminUserDO user = userMapper.selectById(id);
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
@@ -404,7 +398,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
||||
public UserImportRespVO importUsers(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) {
|
||||
public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) {
|
||||
if (CollUtil.isEmpty(importUsers)) {
|
||||
throw exception(USER_IMPORT_LIST_IS_EMPTY);
|
||||
}
|
||||
@@ -413,7 +407,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
importUsers.forEach(importUser -> {
|
||||
// 校验,判断是否有不符合的原因
|
||||
try {
|
||||
checkCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
|
||||
validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
|
||||
importUser.getDeptId(), null);
|
||||
} catch (ServiceException ex) {
|
||||
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
|
||||
@@ -441,7 +435,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUsersByStatus(Integer status) {
|
||||
public List<AdminUserDO> getUserListByStatus(Integer status) {
|
||||
return userMapper.selectListByStatus(status);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user