角色权限删除功能

master
shijie 4 years ago
parent 367c1388ff
commit f0daaeae8a
  1. 25
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java
  2. 7
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java
  3. 8
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java
  4. 20
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java
  5. 13
      dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/RolePermissionMapper.xml
  6. 3
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java

@ -1,14 +1,13 @@
package com.daqing.financial.hrauth.controller; package com.daqing.financial.hrauth.controller;
import com.daqing.financial.hrauth.service.RolePermissionService; 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.PermissionEntity;
import com.daqing.framework.domain.hrms.RoleEntity;
import com.daqing.framework.domain.hrms.request.RolePermissionRequest; 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.domain.hrms.response.RolePermissionResponse;
import com.daqing.framework.exception.ExceptionCast;
import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.utils.PageUtils; import com.daqing.framework.utils.PageUtils;
import com.daqing.framework.utils.SnowflakeIdUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -76,7 +75,10 @@ public class RolePermissionController {
rolePermission.setCreateTime(date); rolePermission.setCreateTime(date);
rolePermission.setMotifyTime(date); rolePermission.setMotifyTime(date);
//此处要判重,新增的角色名称要唯一 //此处要判重,新增的角色名称要唯一
int count = permissionService.uniqueRoleName(rolePermission.getName());
if(count >0){
ExceptionCast.cast(HrmsCode.ROLE_NAME_EXIST);
}
//新增角色到角色表 //新增角色到角色表
int request = permissionService.addHrmsRole(rolePermission); int request = permissionService.addHrmsRole(rolePermission);
//根据选中的permissionId批量新增数据到hrms_role_permission //根据选中的permissionId批量新增数据到hrms_role_permission
@ -123,14 +125,17 @@ public class RolePermissionController {
@Transactional @Transactional
@PostMapping("/delRolePermission") @PostMapping("/delRolePermission")
public ResponseResult delRolePermission(@RequestBody RolePermissionRequest rolePermission) { public ResponseResult delRolePermission(@RequestBody RolePermissionRequest rolePermission) {
//查询该角色是否有用户关联 //根据角色Id查询该角色是否有用户关联
int count = permissionService.queryCountByRoleId(rolePermission.getRoleId());
if(count >0){
//没有关联则删除hrms_role表对应记录 ExceptionCast.cast(HrmsCode.ROLE_EMP_EXIST);
}
//没有关联则根据roleId删除hrms_role表对应记录
permissionService.deleteHrmsRoleByRoleId(rolePermission.getRoleId());
//根据角色id删除对应所有权限 //根据角色id删除对应所有权限
boolean result = permissionService.deleteHrmsRolePermission(rolePermission.getRoleId());
return null; return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
} }

@ -30,6 +30,11 @@ public interface RolePermissionMapper extends BaseMapper<PermissionEntity> {
int updateHrmsRole(RolePermissionRequest rolePermission); int updateHrmsRole(RolePermissionRequest rolePermission);
void deleteHrmsRolePermission(Long roleId); boolean deleteHrmsRolePermission(Long roleId);
int queryCountByRoleId(Long roleId);
boolean deleteHrmsRoleByRoleId(Long roleId);
int uniqueRoleName(String name);
} }

@ -29,6 +29,12 @@ public interface RolePermissionService extends IService<PermissionEntity> {
int updateHrmsRole(RolePermissionRequest rolePermission); int updateHrmsRole(RolePermissionRequest rolePermission);
void deleteHrmsRolePermission(Long roleId); boolean deleteHrmsRolePermission(Long roleId);
int queryCountByRoleId(Long roleId);
boolean deleteHrmsRoleByRoleId(Long roleId);
int uniqueRoleName(String name);
} }

@ -79,8 +79,24 @@ public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper,
} }
@Override @Override
public void deleteHrmsRolePermission(Long roleId) { public boolean deleteHrmsRolePermission(Long roleId) {
this.getBaseMapper().deleteHrmsRolePermission(roleId); return this.getBaseMapper().deleteHrmsRolePermission(roleId);
}
@Override
public int queryCountByRoleId(Long roleId) {
int count = this.getBaseMapper().queryCountByRoleId(roleId);
return count;
}
@Override
public boolean deleteHrmsRoleByRoleId(Long roleId) {
return this.getBaseMapper().deleteHrmsRoleByRoleId(roleId);
}
@Override
public int uniqueRoleName(String name) {
return this.getBaseMapper().uniqueRoleName(name);
} }
} }

@ -66,4 +66,17 @@
WHERE id = #{roleId} WHERE id = #{roleId}
</update> </update>
<select id="queryCountByRoleId" parameterType="long"
resultType="java.lang.Integer">
select count(0) from hrms_employee_role where role_id = #{roleId}
</select>
<delete id="deleteHrmsRoleByRoleId">
delete from hrms_role where id=#{roleId}
</delete>
<select id="uniqueRoleName" parameterType="string" resultType="java.lang.Integer">
select count(0) from hrms_role where `name` = #{name}
</select>
</mapper> </mapper>

@ -32,6 +32,9 @@ public enum HrmsCode implements ResultCode {
NEW_PASSWORD_DIFFERENT(false,33008,"输入的新密码不能与账号相同!"), NEW_PASSWORD_DIFFERENT(false,33008,"输入的新密码不能与账号相同!"),
PASSWORD_ERROR(false,33009,"当前密码输入不正确!"), PASSWORD_ERROR(false,33009,"当前密码输入不正确!"),
NEWPWD_PASSWORD_SAME(false,33010,"新密码不能与当前密码一致!"), NEWPWD_PASSWORD_SAME(false,33010,"新密码不能与当前密码一致!"),
ROLE_EMP_EXIST(false,44001,"该角色有用户关联,不能删除!"),
ROLE_NAME_EXIST(false,44002,"该角色名称已存在,请重新输入!"),
EMP_POSITION_EXSIT(false, 22006, "该职位下已关联员工!"); EMP_POSITION_EXSIT(false, 22006, "该职位下已关联员工!");

Loading…
Cancel
Save