@zh350229319
2017-11-15T06:49:32.000000Z
字数 3192
阅读 432
公司框架
数据权限要求拥有搜索(个人)权限时,只能查看创建人为当前用户的数据;拥有搜索(组织)权限时,只能查看当前组织的数据,不包括子组织;拥有搜索(企业)权限时,可以查看当前企业下所有组织的数据。
同时拥有多个查询权限只显示一个,优先级企业>组织>个人
以PSS的盘订单为例子,修改流程如下
在OA菜单中新增三个查询权限,例如:pssOrderDisk:findEnt为搜索(企业),pssOrderDisk:findOrg为搜索(组织),原有的pssOrderDisk:find改为搜索(个人),对应的sql如下
INSERT INTO `580oa`.`ucs_system_permission` (`id`, `name`, `pid`, `app_id`, `type`, `url`, `description`, `status`, `sort`, `is_top`) VALUES ('67d4c0cfe9b54cd1b9c77c366ec52177', '搜索(企业)', 'a25cee43b32e11e78a03005056a84541', '3dfc595ab00211e78a03005056a84541', '02', 'pssOrderDisk:findEnt', '', '01', '0', '0');INSERT INTO `580oa`.`ucs_system_permission` (`id`, `name`, `pid`, `app_id`, `type`, `url`, `description`, `status`, `sort`, `is_top`) VALUES ('88f14bdced4e4268b4dab5b1162f4a50', '搜索(组织)', 'a25cee43b32e11e78a03005056a84541', '3dfc595ab00211e78a03005056a84541', '02', 'pssOrderDisk:findOrg', '', '01', '0', '0');UPDATE `580oa`.`ucs_system_permission` SET `name`='搜索(个人)', `description`='' WHERE `id`='96a640fcb3d911e78a03005056a84541';
在需要实现数据权限的表中新增ent_id(企业id)、org_id(组织id)和creator_id(创建人),字段名建议按照此命名规范来实行。如果已有可不修改。
新增数据时将当前用户的id、组织id和企业id写入对应字段,当前用户信息使用UserUtil.getCurrentShiroUser()可获取到
(可选)0为了不造成数据异常,在修改数据库字段后,可以执行批量更新将新增的字段赋值。用户id、组织id和企业id都可以赋值'00000000000000000000000000000000',sql例子如下。
SET SQL_SAFE_UPDATES=0;-- 更新原有订单数据update pss_order_disk set ent_id='00000000000000000000000000000000';
最终效果为当用户拥有搜索(企业)权限时,办事处初始化为当前企业的组织数据,办事处人员为空。后台查询时自动加上企业id查询条件;
当用户为组织权限时,可以查看用户当前组织的数据,办事处只读不可选择,销售人员下拉菜单初始化为当前组织人员。后台查询时自动加上组织id查询条件
当用户为个人权限时,可以查看个人的数据,办事处和销售人员查询框为只读,后台在查询中自动加上创建人ID和企业id查询条件;
/*** 主列表中查询* @dzmgenerated 2017-10-18 13:06:15* @return*/@RequiresPermissions({"pssOrderDisk:find","pssOrderDisk:findOrg","pssOrderDisk:findEnt"})@RequestMapping(value = "find", method = RequestMethod.POST)@ResponseBodypublic Map<String,Object> find(HttpServletRequest request){List<Condition> conditions = Condition.buildFromHttpRequest(request);Subject subject = SecurityUtils.getSubject();if(subject.isPermitted("pssOrderDisk:findEnt")) {conditions.add(new Condition("eqs_entId__PssOrderDiskExample", UserUtil.getCurrentShiroUser().getEnt().getId()));} else if(subject.isPermitted("pssOrderDisk:findOrg")) {conditions.add(new Condition("eqs_orgId__PssOrderDiskExample", UserUtil.getCurrentShiroUser().getOrg().getId()));} else if(subject.isPermitted("pssOrderDisk:find")) {conditions.add(new Condition("eqs_orgId__PssOrderDiskExample", UserUtil.getCurrentShiroUser().getOrg().getId()));conditions.add(new Condition("eqs_creatorId__PssOrderDiskExample", UserUtil.getCurrentShiroUser().getId()));}Page Page = new Page(request);MybatisExample mybatisExample = MybatisExample.getInstance();PssOrderDiskCustomerComplexExample example = (PssOrderDiskCustomerComplexExample)mybatisExample.buildExampleByCondition(conditions,Page.getRows()==0?null:Page,PssOrderDiskCustomerComplexExample.class.getName());PageList<PssOrderDiskDto> list = pssOrderDiskService.selectOrderListComplex(example,Page.getRows()==0?new PageBounds():new PageBounds(Page.getPage(),Page.getRows()));return getEasyUIGrid(list);}
前台shiro标签控制,支持or and not 关键词 不支持and or混用,参考http://jinnianshilongnian.iteye.com/blog/1864800
<shiro:hasPermission name="pssOrderDisk:find and not pssOrderDisk:findOrg and not pssOrderDisk:findEnt">readonly</shiro:hasPermission>