数据权限

main
tamguo 7 years ago
parent 53a2f2f57c
commit f327e75e15

@ -36,6 +36,8 @@ public class SysRoleEntity implements Serializable {
@TableField(exist=false) @TableField(exist=false)
private String roleMenuListJson; private String roleMenuListJson;
@TableField(exist=false)
private String roleDataScopeListJson;
public SysRoleEntity() { public SysRoleEntity() {
} }
@ -172,4 +174,12 @@ public class SysRoleEntity implements Serializable {
this.roleMenuListJson = roleMenuListJson; this.roleMenuListJson = roleMenuListJson;
} }
public String getRoleDataScopeListJson() {
return roleDataScopeListJson;
}
public void setRoleDataScopeListJson(String roleDataScopeListJson) {
this.roleDataScopeListJson = roleDataScopeListJson;
}
} }

@ -18,4 +18,7 @@ public interface ISysRoleService extends IService<SysRoleEntity>{
/** 分配功能权限*/ /** 分配功能权限*/
void allowMenuPermission(SysRoleEntity role); void allowMenuPermission(SysRoleEntity role);
/** 授权数据权限*/
void allowDataScope(SysRoleEntity role);
} }

@ -14,9 +14,11 @@ import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tamguo.modules.sys.dao.SysMenuMapper; import com.tamguo.modules.sys.dao.SysMenuMapper;
import com.tamguo.modules.sys.dao.SysRoleDataScopeMapper;
import com.tamguo.modules.sys.dao.SysRoleMapper; import com.tamguo.modules.sys.dao.SysRoleMapper;
import com.tamguo.modules.sys.dao.SysRoleMenuMapper; import com.tamguo.modules.sys.dao.SysRoleMenuMapper;
import com.tamguo.modules.sys.model.SysMenuEntity; import com.tamguo.modules.sys.model.SysMenuEntity;
import com.tamguo.modules.sys.model.SysRoleDataScopeEntity;
import com.tamguo.modules.sys.model.SysRoleEntity; import com.tamguo.modules.sys.model.SysRoleEntity;
import com.tamguo.modules.sys.model.SysRoleMenuEntity; import com.tamguo.modules.sys.model.SysRoleMenuEntity;
import com.tamguo.modules.sys.model.condition.SysRoleCondition; import com.tamguo.modules.sys.model.condition.SysRoleCondition;
@ -31,6 +33,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity
private SysMenuMapper sysMenuMapper; private SysMenuMapper sysMenuMapper;
@Autowired @Autowired
private SysRoleMenuMapper sysRoleMenuMapper; private SysRoleMenuMapper sysRoleMenuMapper;
@Autowired
private SysRoleDataScopeMapper sysRoleDataScopeMapper;
@Transactional(readOnly=true) @Transactional(readOnly=true)
@Override @Override
@ -82,7 +86,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void allowMenuPermission(SysRoleEntity role) { public void allowMenuPermission(SysRoleEntity role) {
// 先删除关联表数据 // 删除关联菜单
sysRoleMenuMapper.delete(Condition.create().eq("role_code", role.getRoleCode())); sysRoleMenuMapper.delete(Condition.create().eq("role_code", role.getRoleCode()));
if(!StringUtils.isEmpty(role.getRoleMenuListJson())) { if(!StringUtils.isEmpty(role.getRoleMenuListJson())) {
@ -96,4 +100,25 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity
} }
} }
} }
@SuppressWarnings("unchecked")
@Override
public void allowDataScope(SysRoleEntity role) {
// 删除权限
sysRoleDataScopeMapper.delete(Condition.create().eq("role_code", role.getRoleCode()));
// 插入权限
if(!StringUtils.isEmpty(role.getRoleDataScopeListJson())) {
JSONArray roleDataScopes = JSONArray.parseArray(role.getRoleDataScopeListJson());
for(int i=0 ; i<roleDataScopes.size() ; i++) {
JSONObject dataScope = roleDataScopes.getJSONObject(i);
SysRoleDataScopeEntity roleDataScope = new SysRoleDataScopeEntity();
roleDataScope.setRoleCode(role.getRoleCode());
roleDataScope.setCtrlPermi("1");
roleDataScope.setCtrlType(dataScope.getString("ctrlType"));
roleDataScope.setCtrlData(dataScope.getString("ctrlData"));
sysRoleDataScopeMapper.insert(roleDataScope);
}
}
}
} }

@ -78,4 +78,12 @@ public class SysRoleController {
return Result.result(0, null, "保存角色【"+role.getRoleName()+"】成功!"); return Result.result(0, null, "保存角色【"+role.getRoleName()+"】成功!");
} }
/** 数据权限 */
@RequestMapping(path="allowDataScope",method=RequestMethod.POST)
@ResponseBody
public Result allowDataScope(SysRoleEntity role) {
iSysRoleService.allowDataScope(role);
return Result.result(0, null, "保存角色【"+role.getRoleName()+"】成功!");
}
} }

@ -27,7 +27,7 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button> <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div> </div>
</div> </div>
<form id="inputForm" action="sys/role/saveDataScope" method="post" class="form-horizontal"> <form id="inputForm" th:action="${setting.domain + 'sys/role/allowDataScope'}" method="post" class="form-horizontal">
<div class="box-body"><br/> <div class="box-body"><br/>
<div class="row"> <div class="row">
<div class="col-xs-6"> <div class="col-xs-6">
@ -118,7 +118,7 @@ content="width=device-width, initial-scale=1, user-scalable=1" name="viewport"/>
<script th:src="${setting.domain + 'common/jeesite.js'}"></script> <script th:src="${setting.domain + 'common/jeesite.js'}"></script>
<script th:src="${setting.domain + 'common/i18n/jeesite_zh_CN.js'}"></script> <script th:src="${setting.domain + 'common/i18n/jeesite_zh_CN.js'}"></script>
<script th:src="${setting.domain + 'common/common.js'}"></script> <script th:src="${setting.domain + 'common/common.js'}"></script>
<script> <script type="text/javascript" th:inline="javascript">
$("#inputForm").validate({ $("#inputForm").validate({
submitHandler: function(form){ submitHandler: function(form){
// 获取数据权限数据 // 获取数据权限数据
@ -135,7 +135,7 @@ $("#inputForm").validate({
// 提交表单数据 // 提交表单数据
js.ajaxSubmitForm($(form), function(data){ js.ajaxSubmitForm($(form), function(data){
js.showMessage(data.message); js.showMessage(data.message);
if(data.result == Global.TRUE){ if(data.code == 0){
js.closeCurrentTabPage(function(contentWindow){ js.closeCurrentTabPage(function(contentWindow){
contentWindow.page(); contentWindow.page();
}); });
@ -258,10 +258,10 @@ for (var i=0; i<dataScopes.length; i++){
}); });
} }
// 默认选择节点 // 默认选择节点
try{ var roleDataScopeList = [[${roleDataScopeList}]];
dataScopeTrees['Company'].checkNode(dataScopeTrees['Company'].getNodeByParam("id","SD1"), true, false); for(var i=0 ; i<roleDataScopeList.length ; i++){
}catch(e){} try{
try{ dataScopeTrees[roleDataScopeList[i].ctrlType].checkNode(dataScopeTrees[roleDataScopeList[i].ctrlType].getNodeByParam("id",roleDataScopeList[i].ctrlData), true, false);
dataScopeTrees['Company'].checkNode(dataScopeTrees['Company'].getNodeByParam("id","SD2"), true, false); }catch(e){}
}catch(e){} }
</script> </script>
Loading…
Cancel
Save