From f0daaeae8ae521906ca5e92bf9a247ee17b529c9 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Tue, 13 Oct 2020 15:38:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E6=9D=83=E9=99=90=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RolePermissionController.java | 25 +++++++++++-------- .../hrauth/dao/RolePermissionMapper.java | 7 +++++- .../hrauth/service/RolePermissionService.java | 8 +++++- .../impl/RolePermissionServiceImpl.java | 20 +++++++++++++-- .../mapper/hrmsauth/RolePermissionMapper.xml | 13 ++++++++++ .../domain/hrms/response/HrmsCode.java | 3 +++ 6 files changed, 62 insertions(+), 14 deletions(-) diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java index e1651350..592f987c 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java @@ -1,14 +1,13 @@ package com.daqing.financial.hrauth.controller; import com.daqing.financial.hrauth.service.RolePermissionService; -import com.daqing.framework.domain.hrms.DeptPositionEntity; import com.daqing.framework.domain.hrms.PermissionEntity; -import com.daqing.framework.domain.hrms.RoleEntity; import com.daqing.framework.domain.hrms.request.RolePermissionRequest; +import com.daqing.framework.domain.hrms.response.HrmsCode; import com.daqing.framework.domain.hrms.response.RolePermissionResponse; +import com.daqing.framework.exception.ExceptionCast; import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.utils.PageUtils; -import com.daqing.framework.utils.SnowflakeIdUtils; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -76,7 +75,10 @@ public class RolePermissionController { rolePermission.setCreateTime(date); rolePermission.setMotifyTime(date); //此处要判重,新增的角色名称要唯一 - + int count = permissionService.uniqueRoleName(rolePermission.getName()); + if(count >0){ + ExceptionCast.cast(HrmsCode.ROLE_NAME_EXIST); + } //新增角色到角色表 int request = permissionService.addHrmsRole(rolePermission); //根据选中的permissionId批量新增数据到hrms_role_permission @@ -123,14 +125,17 @@ public class RolePermissionController { @Transactional @PostMapping("/delRolePermission") public ResponseResult delRolePermission(@RequestBody RolePermissionRequest rolePermission) { - //查询该角色是否有用户关联 - - - //没有关联则删除hrms_role表对应记录 - + //根据角色Id查询该角色是否有用户关联 + int count = permissionService.queryCountByRoleId(rolePermission.getRoleId()); + if(count >0){ + ExceptionCast.cast(HrmsCode.ROLE_EMP_EXIST); + } + //没有关联则根据roleId删除hrms_role表对应记录 + permissionService.deleteHrmsRoleByRoleId(rolePermission.getRoleId()); //根据角色id删除对应所有权限 + boolean result = permissionService.deleteHrmsRolePermission(rolePermission.getRoleId()); - return null; + return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java index 1e200fef..e68888a3 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java @@ -30,6 +30,11 @@ public interface RolePermissionMapper extends BaseMapper { int updateHrmsRole(RolePermissionRequest rolePermission); - void deleteHrmsRolePermission(Long roleId); + boolean deleteHrmsRolePermission(Long roleId); + int queryCountByRoleId(Long roleId); + + boolean deleteHrmsRoleByRoleId(Long roleId); + + int uniqueRoleName(String name); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java index c8cf06c1..c847b586 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java @@ -29,6 +29,12 @@ public interface RolePermissionService extends IService { int updateHrmsRole(RolePermissionRequest rolePermission); - void deleteHrmsRolePermission(Long roleId); + boolean deleteHrmsRolePermission(Long roleId); + + int queryCountByRoleId(Long roleId); + + boolean deleteHrmsRoleByRoleId(Long roleId); + + int uniqueRoleName(String name); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java index fa7da69e..f56cfb0b 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java @@ -79,8 +79,24 @@ public class RolePermissionServiceImpl extends ServiceImpl + + + + delete from hrms_role where id=#{roleId} + + + + \ No newline at end of file diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java index 6287f554..d4a4d1ad 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java @@ -32,6 +32,9 @@ public enum HrmsCode implements ResultCode { NEW_PASSWORD_DIFFERENT(false,33008,"输入的新密码不能与账号相同!"), PASSWORD_ERROR(false,33009,"当前密码输入不正确!"), NEWPWD_PASSWORD_SAME(false,33010,"新密码不能与当前密码一致!"), + + ROLE_EMP_EXIST(false,44001,"该角色有用户关联,不能删除!"), + ROLE_NAME_EXIST(false,44002,"该角色名称已存在,请重新输入!"), EMP_POSITION_EXSIT(false, 22006, "该职位下已关联员工!");