diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/mapper/MeetingExpertMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/mapper/MeetingExpertMapper.xml index e030cd3..9e0ac18 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/mapper/MeetingExpertMapper.xml +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/mapper/MeetingExpertMapper.xml @@ -111,7 +111,7 @@ and np.project_name like concat('%', #{p.projectName}, '%') - and np.build_org_name like concat('%', #{buildOrgName}, '%') + and np.build_org_name like concat('%', #{p.buildOrgName}, '%') and m.start_time >= #{p.reviewTimeMin} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java index d141dc4..e6d5251 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java @@ -1,6 +1,7 @@ package com.ningdatech.pmapi.sys.controller; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.basic.util.CollUtils; @@ -24,6 +25,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.util.Collections; import java.util.List; /** @@ -69,7 +71,14 @@ public class MenuController { @ApiOperation(value = "查询当前登录用户的菜单", notes = "查询当前登录用户的菜单") @GetMapping("/myMenu") public List currentUserMenu() { - List list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); + List roleIdList = LoginUserUtil.getRoleIdList(); + if (CollUtil.isEmpty(roleIdList)) { + return Collections.emptyList(); + } + String tmpSql = "(" + CollUtils.joinByComma(roleIdList) + ")"; + List list = menuService.list(Wrappers.lambdaQuery(Menu.class) + .exists("select 1 from nd_role_menu nur where nur.menu_id = nd_menu.id and nur.role_id in " + tmpSql) + .orderByAsc(Menu::getSort)); return menuManage.buildUserMenu(list); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java index 6d59c64..a5f9a3d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java @@ -3,6 +3,8 @@ package com.ningdatech.pmapi.sys.service; import com.baomidou.mybatisplus.extension.service.IService; import com.ningdatech.pmapi.sys.model.entity.UserRole; +import java.util.List; + /** * * 业务接口 @@ -20,4 +22,15 @@ public interface IUserRoleService extends IService { * @return 是否正确 */ boolean initAdmin(Long userId); + + /** + * 查询角色关联的用户ID + * + * @param roleId 角色ID + * @return 用户ID集合 + * @author WendyYang + **/ + List listUserIdByRoleId(Long roleId); + + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java index 0c6e452..0d6c7b0 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java @@ -12,10 +12,10 @@ import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.exception.code.ExceptionCode; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.cache.repository.CachePlusOps; +import com.ningdatech.pmapi.sys.mapper.RoleMapper; import com.ningdatech.pmapi.sys.model.dto.MenuDataScopeDTO; import com.ningdatech.pmapi.sys.model.dto.RoleSaveDTO; import com.ningdatech.pmapi.sys.model.dto.RoleUpdateDTO; -import com.ningdatech.pmapi.sys.mapper.RoleMapper; import com.ningdatech.pmapi.sys.model.entity.*; import com.ningdatech.pmapi.sys.service.*; import com.ningdatech.pmapi.sys.utils.AuthCacheKeyUtils; @@ -40,18 +40,12 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class RoleServiceImpl extends ServiceImpl implements IRoleService { - private final IUserRoleService IUserRoleService; + private final IUserRoleService userRoleService; private final RoleMapper roleMapper; private final IRoleMenuDatascopeService roleMenuDatascopeService; - private final CachePlusOps cachePlusOps; - private final IRoleMenuService roleMenuService; - - private final IMenuService IMenuService; - - private static final String SUPER_ADMIN = "SUPER_ADMIN"; - + private final IMenuService menuService; /** * 删除角色时,需要级联删除跟角色相关的一切资源: @@ -68,7 +62,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR return true; } - if (IUserRoleService.count(Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId) + if (userRoleService.count(Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId) .in(UserRole::getRoleId, ids)) > 0) { throw new BizException(ExceptionCode.OPERATION_EX.getCode(), "该角色下还有用户 不能随意删除!"); } @@ -77,7 +71,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR boolean removeFlag = removeByIds(ids); //角色拥有的用户 - IUserRoleService.remove(Wrappers.lambdaQuery(UserRole.class).in(UserRole::getRoleId, ids)); + userRoleService.remove(Wrappers.lambdaQuery(UserRole.class).in(UserRole::getRoleId, ids)); if (removeFlag) { // 角色绑定了那些用户 if (roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).in(RoleMenu::getRoleId, ids))) { @@ -149,18 +143,19 @@ public class RoleServiceImpl extends ServiceImpl implements IR public void updateRole(RoleUpdateDTO data, Long userId) { Role roleOld = roleMapper.selectById(data.getId()); if (Objects.isNull(roleOld)) { - throw new BaseUncheckedException(HttpStatus.HTTP_OK, String.format("修改用户%d 为空", data.getId())); + throw BizException.wrap("修改用户 %d 为空", data.getId()); } if (StrUtil.isNotBlank(data.getName()) && check(data.getName(), roleOld.getId())) { - throw BizException.wrap("角色名{} 已经存在", data.getName()); + throw BizException.wrap("角色名 %s 已经存在", data.getName()); } Role role = BeanUtil.toBean(data, Role.class); role.setUpdateBy(userId); updateById(role); saveRoleMenu(data.getMenuIds(), role.getId()); saveRoleMenuDatascope(data.getMenuDataScopeList(), role.getId()); - cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(userId)); + List userIdList = userRoleService.listUserIdByRoleId(role.getId()); + userIdList.forEach(w -> cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(w))); } @Override @@ -180,11 +175,11 @@ public class RoleServiceImpl extends ServiceImpl implements IR } private void saveRoleMenu(List menuIds, Long roleId) { + roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); if (CollUtil.isNotEmpty(menuIds)) { - roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); Set toAddMenus = new HashSet<>(); for (Long menuId : menuIds) { - Menu menu = IMenuService.getById(menuId); + Menu menu = menuService.getById(menuId); if (Objects.isNull(menu)) { continue; } @@ -203,7 +198,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR if (Objects.isNull(menu.getPid()) || menu.getPid().equals(0L)) { return; } - Menu parent = IMenuService.getById(menu.getPid()); + Menu parent = menuService.getById(menu.getPid()); if (Objects.isNull(parent)) { return; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java index 184f164..d2697ae 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java @@ -4,16 +4,19 @@ import cn.hutool.http.HttpStatus; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ningdatech.basic.exception.BaseUncheckedException; -import com.ningdatech.pmapi.sys.model.entity.Role; -import com.ningdatech.pmapi.sys.model.entity.UserRole; +import com.ningdatech.basic.util.CollUtils; import com.ningdatech.pmapi.sys.mapper.RoleMapper; import com.ningdatech.pmapi.sys.mapper.UserRoleMapper; +import com.ningdatech.pmapi.sys.model.entity.Role; +import com.ningdatech.pmapi.sys.model.entity.UserRole; import com.ningdatech.pmapi.sys.service.IUserRoleService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + /** * * 业务实现类 @@ -46,4 +49,12 @@ public class UserRoleServiceImpl extends ServiceImpl i return super.save(userRole); } + + @Override + public List listUserIdByRoleId(Long roleId) { + List userRoles = this.list(Wrappers.lambdaQuery() + .eq(UserRole::getRoleId, roleId)); + return CollUtils.fieldList(userRoles, UserRole::getUserId); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java index a5e2608..63db7d2 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java @@ -500,8 +500,9 @@ public class TodoCenterManage { // 判断当前工作流任务前一个审核人的部门和当前登录用户的部门是否是同一个,如果是同一个才可以撤回,否则抛出异常 // 获取当前当前工作流任务当前审核人信息 UserFullInfoDTO currentUserInfo = userInfoHelper.getUserFullInfoByEmployeeCode(currentProgressNode.getUserId()); - VUtils.isTrue(!currentUserInfo.getOrganizationCode().equals(user.getOrganizationCode())) - .throwMessage("当前审核人和您不是同一个部门,无法撤回!"); + if(!currentUserInfo.getOrganizationCode().equals(user.getOrganizationCode())){ + return Boolean.FALSE; + } UserFullInfoDTO beforeUser = null; Boolean isAndOr = Boolean.FALSE;
* 业务接口 @@ -20,4 +22,15 @@ public interface IUserRoleService extends IService { * @return 是否正确 */ boolean initAdmin(Long userId); + + /** + * 查询角色关联的用户ID + * + * @param roleId 角色ID + * @return 用户ID集合 + * @author WendyYang + **/ + List listUserIdByRoleId(Long roleId); + + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java index 0c6e452..0d6c7b0 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java @@ -12,10 +12,10 @@ import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.exception.code.ExceptionCode; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.cache.repository.CachePlusOps; +import com.ningdatech.pmapi.sys.mapper.RoleMapper; import com.ningdatech.pmapi.sys.model.dto.MenuDataScopeDTO; import com.ningdatech.pmapi.sys.model.dto.RoleSaveDTO; import com.ningdatech.pmapi.sys.model.dto.RoleUpdateDTO; -import com.ningdatech.pmapi.sys.mapper.RoleMapper; import com.ningdatech.pmapi.sys.model.entity.*; import com.ningdatech.pmapi.sys.service.*; import com.ningdatech.pmapi.sys.utils.AuthCacheKeyUtils; @@ -40,18 +40,12 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class RoleServiceImpl extends ServiceImpl implements IRoleService { - private final IUserRoleService IUserRoleService; + private final IUserRoleService userRoleService; private final RoleMapper roleMapper; private final IRoleMenuDatascopeService roleMenuDatascopeService; - private final CachePlusOps cachePlusOps; - private final IRoleMenuService roleMenuService; - - private final IMenuService IMenuService; - - private static final String SUPER_ADMIN = "SUPER_ADMIN"; - + private final IMenuService menuService; /** * 删除角色时,需要级联删除跟角色相关的一切资源: @@ -68,7 +62,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR return true; } - if (IUserRoleService.count(Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId) + if (userRoleService.count(Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId) .in(UserRole::getRoleId, ids)) > 0) { throw new BizException(ExceptionCode.OPERATION_EX.getCode(), "该角色下还有用户 不能随意删除!"); } @@ -77,7 +71,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR boolean removeFlag = removeByIds(ids); //角色拥有的用户 - IUserRoleService.remove(Wrappers.lambdaQuery(UserRole.class).in(UserRole::getRoleId, ids)); + userRoleService.remove(Wrappers.lambdaQuery(UserRole.class).in(UserRole::getRoleId, ids)); if (removeFlag) { // 角色绑定了那些用户 if (roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).in(RoleMenu::getRoleId, ids))) { @@ -149,18 +143,19 @@ public class RoleServiceImpl extends ServiceImpl implements IR public void updateRole(RoleUpdateDTO data, Long userId) { Role roleOld = roleMapper.selectById(data.getId()); if (Objects.isNull(roleOld)) { - throw new BaseUncheckedException(HttpStatus.HTTP_OK, String.format("修改用户%d 为空", data.getId())); + throw BizException.wrap("修改用户 %d 为空", data.getId()); } if (StrUtil.isNotBlank(data.getName()) && check(data.getName(), roleOld.getId())) { - throw BizException.wrap("角色名{} 已经存在", data.getName()); + throw BizException.wrap("角色名 %s 已经存在", data.getName()); } Role role = BeanUtil.toBean(data, Role.class); role.setUpdateBy(userId); updateById(role); saveRoleMenu(data.getMenuIds(), role.getId()); saveRoleMenuDatascope(data.getMenuDataScopeList(), role.getId()); - cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(userId)); + List userIdList = userRoleService.listUserIdByRoleId(role.getId()); + userIdList.forEach(w -> cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(w))); } @Override @@ -180,11 +175,11 @@ public class RoleServiceImpl extends ServiceImpl implements IR } private void saveRoleMenu(List menuIds, Long roleId) { + roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); if (CollUtil.isNotEmpty(menuIds)) { - roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); Set toAddMenus = new HashSet<>(); for (Long menuId : menuIds) { - Menu menu = IMenuService.getById(menuId); + Menu menu = menuService.getById(menuId); if (Objects.isNull(menu)) { continue; } @@ -203,7 +198,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR if (Objects.isNull(menu.getPid()) || menu.getPid().equals(0L)) { return; } - Menu parent = IMenuService.getById(menu.getPid()); + Menu parent = menuService.getById(menu.getPid()); if (Objects.isNull(parent)) { return; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java index 184f164..d2697ae 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java @@ -4,16 +4,19 @@ import cn.hutool.http.HttpStatus; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ningdatech.basic.exception.BaseUncheckedException; -import com.ningdatech.pmapi.sys.model.entity.Role; -import com.ningdatech.pmapi.sys.model.entity.UserRole; +import com.ningdatech.basic.util.CollUtils; import com.ningdatech.pmapi.sys.mapper.RoleMapper; import com.ningdatech.pmapi.sys.mapper.UserRoleMapper; +import com.ningdatech.pmapi.sys.model.entity.Role; +import com.ningdatech.pmapi.sys.model.entity.UserRole; import com.ningdatech.pmapi.sys.service.IUserRoleService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + /** * * 业务实现类 @@ -46,4 +49,12 @@ public class UserRoleServiceImpl extends ServiceImpl i return super.save(userRole); } + + @Override + public List listUserIdByRoleId(Long roleId) { + List userRoles = this.list(Wrappers.lambdaQuery() + .eq(UserRole::getRoleId, roleId)); + return CollUtils.fieldList(userRoles, UserRole::getUserId); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java index a5e2608..63db7d2 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java @@ -500,8 +500,9 @@ public class TodoCenterManage { // 判断当前工作流任务前一个审核人的部门和当前登录用户的部门是否是同一个,如果是同一个才可以撤回,否则抛出异常 // 获取当前当前工作流任务当前审核人信息 UserFullInfoDTO currentUserInfo = userInfoHelper.getUserFullInfoByEmployeeCode(currentProgressNode.getUserId()); - VUtils.isTrue(!currentUserInfo.getOrganizationCode().equals(user.getOrganizationCode())) - .throwMessage("当前审核人和您不是同一个部门,无法撤回!"); + if(!currentUserInfo.getOrganizationCode().equals(user.getOrganizationCode())){ + return Boolean.FALSE; + } UserFullInfoDTO beforeUser = null; Boolean isAndOr = Boolean.FALSE;
* 业务实现类 @@ -46,4 +49,12 @@ public class UserRoleServiceImpl extends ServiceImpl i return super.save(userRole); } + + @Override + public List listUserIdByRoleId(Long roleId) { + List userRoles = this.list(Wrappers.lambdaQuery() + .eq(UserRole::getRoleId, roleId)); + return CollUtils.fieldList(userRoles, UserRole::getUserId); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java index a5e2608..63db7d2 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java @@ -500,8 +500,9 @@ public class TodoCenterManage { // 判断当前工作流任务前一个审核人的部门和当前登录用户的部门是否是同一个,如果是同一个才可以撤回,否则抛出异常 // 获取当前当前工作流任务当前审核人信息 UserFullInfoDTO currentUserInfo = userInfoHelper.getUserFullInfoByEmployeeCode(currentProgressNode.getUserId()); - VUtils.isTrue(!currentUserInfo.getOrganizationCode().equals(user.getOrganizationCode())) - .throwMessage("当前审核人和您不是同一个部门,无法撤回!"); + if(!currentUserInfo.getOrganizationCode().equals(user.getOrganizationCode())){ + return Boolean.FALSE; + } UserFullInfoDTO beforeUser = null; Boolean isAndOr = Boolean.FALSE;