角色区域
This commit is contained in:
parent
2e73fcedd8
commit
bf8ac4e1bb
|
|
@ -76,9 +76,10 @@ public class SysRole extends BaseEntity
|
|||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||
private Long companyId;
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||
private Long areaId;
|
||||
|
||||
private Long[] areaIds;
|
||||
|
||||
/** 角色菜单权限 */
|
||||
private Set<String> permissions;
|
||||
|
||||
|
|
@ -254,6 +255,14 @@ public class SysRole extends BaseEntity
|
|||
this.areaId = areaId;
|
||||
}
|
||||
|
||||
public Long[] getAreaIds() {
|
||||
return areaIds;
|
||||
}
|
||||
|
||||
public void setAreaIds(Long[] areaIds) {
|
||||
this.areaIds = areaIds;
|
||||
}
|
||||
|
||||
public Set<String> getPermissions()
|
||||
{
|
||||
return permissions;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package com.bonus.system.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* 角色和区域关联 sys_role_area
|
||||
*
|
||||
* @author bonus
|
||||
*/
|
||||
public class SysRoleArea
|
||||
{
|
||||
/** 角色ID */
|
||||
private Long roleId;
|
||||
|
||||
/** 部门ID */
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||
private Long areaId;
|
||||
|
||||
public Long getRoleId()
|
||||
{
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Long roleId)
|
||||
{
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public Long getAreaId() {
|
||||
return areaId;
|
||||
}
|
||||
|
||||
public void setAreaId(Long areaId) {
|
||||
this.areaId = areaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("roleId", getRoleId())
|
||||
.append("areaId", getAreaId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.bonus.system.mapper;
|
||||
|
||||
import com.bonus.system.domain.SysRoleArea;
|
||||
import com.bonus.system.domain.SysRoleDept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色与区域关联表 数据层
|
||||
*
|
||||
* @author bonus
|
||||
*/
|
||||
public interface SysRoleAreaMapper
|
||||
{
|
||||
/**
|
||||
* 通过角色ID删除角色和区域关联
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleAreaByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量删除角色区域关联信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleArea(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询区域使用数量
|
||||
*
|
||||
* @param areaId 区域ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int selectCountRoleAreaByAreaId(Long areaId);
|
||||
|
||||
/**
|
||||
* 批量新增区域区域信息
|
||||
*
|
||||
* @param roleAreaList 角色区域列表
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchRoleArea(List<SysRoleArea> roleAreaList);
|
||||
}
|
||||
|
|
@ -9,6 +9,8 @@ import java.util.Set;
|
|||
import com.bonus.common.core.web.domain.BaseEntity;
|
||||
import com.bonus.common.datascope.utils.CommonDataPermissionInfo;
|
||||
import com.bonus.system.api.domain.SysUserRole;
|
||||
import com.bonus.system.domain.SysRoleArea;
|
||||
import com.bonus.system.mapper.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -23,10 +25,6 @@ import com.bonus.system.api.domain.SysRole;
|
|||
import com.bonus.system.api.domain.SysUser;
|
||||
import com.bonus.system.domain.SysRoleDept;
|
||||
import com.bonus.system.domain.SysRoleMenu;
|
||||
import com.bonus.system.mapper.SysRoleDeptMapper;
|
||||
import com.bonus.system.mapper.SysRoleMapper;
|
||||
import com.bonus.system.mapper.SysRoleMenuMapper;
|
||||
import com.bonus.system.mapper.SysUserRoleMapper;
|
||||
import com.bonus.system.service.ISysRoleService;
|
||||
|
||||
/**
|
||||
|
|
@ -49,6 +47,9 @@ public class SysRoleServiceImpl implements ISysRoleService
|
|||
@Autowired
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRoleAreaMapper roleAreaMapper;
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
|
|
@ -311,7 +312,12 @@ public class SysRoleServiceImpl implements ISysRoleService
|
|||
// 删除角色与部门关联
|
||||
roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());
|
||||
// 新增角色和部门信息(数据权限)
|
||||
return insertRoleDept(role);
|
||||
int roleDeptCount = insertRoleDept(role);
|
||||
// 删除角色与区域关联
|
||||
roleAreaMapper.deleteRoleAreaByRoleId(role.getRoleId());
|
||||
// 新增角色和区域信息(数据权限)
|
||||
int roleAreaCount = insertRoleArea(role);
|
||||
return roleDeptCount + roleAreaCount;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -362,6 +368,30 @@ public class SysRoleServiceImpl implements ISysRoleService
|
|||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色区域信息(数据权限)
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
public int insertRoleArea(SysRole role)
|
||||
{
|
||||
int rows = 1;
|
||||
// 新增角色与区域(数据权限)管理
|
||||
List<SysRoleArea> list = new ArrayList<SysRoleArea>();
|
||||
for (Long areaId : role.getAreaIds())
|
||||
{
|
||||
SysRoleArea rd = new SysRoleArea();
|
||||
rd.setRoleId(role.getRoleId());
|
||||
rd.setAreaId(areaId);
|
||||
list.add(rd);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
rows = roleAreaMapper.batchRoleArea(list);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.system.mapper.SysRoleAreaMapper">
|
||||
|
||||
<resultMap type="com.bonus.system.domain.SysRoleArea" id="SysRoleAreaResult">
|
||||
<result property="roleId" column="role_id" />
|
||||
<result property="areaId" column="dept_id" />
|
||||
</resultMap>
|
||||
|
||||
<delete id="deleteRoleAreaByRoleId" parameterType="Long">
|
||||
delete from sys_role_area where role_id=#{roleId}
|
||||
</delete>
|
||||
|
||||
<select id="selectCountRoleAreaByAreaId" resultType="Integer">
|
||||
select count(1) from sys_role_area where area_id=#{areaId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteRoleArea" parameterType="Long">
|
||||
delete from sys_role_area where role_id in
|
||||
<foreach collection="array" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchRoleArea">
|
||||
insert into sys_role_area(role_id, area_id) values
|
||||
<foreach item="item" index="index" collection="list" separator=",">
|
||||
(#{item.roleId},#{item.areaId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue