列表列字段导出权限示例
最后更新于:2022-04-02 07:16:22
列表列字段导出权限控制
===
> 针对数据列表的列进行权限控制后,列表导出数据时与列权限相对应
> 需基于列表列字段权限控制已完成
**举例:** 打卡时间字段已做权限控制,在列表中隐藏,则在导出时,也不会导出
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/50/36/50364f62c7db5d16a31b49a34ec29be6_1138x172.png)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/f6/ed/f6ed283e425fcde02e07305739cd0e6e_621x165.png)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/e1/bb/e1bb2a0189a9d88cde63ebdee4880b5f_606x111.png)
### 权限控制步骤
#### 后台导出方法添加权限逻辑,获取需导出的字段,将所有需要导出字段逗号隔开,拼接字符串
~~~
@RequestMapping(value = "/exportXls")
@PermissionData(pageComponent = "jeecg/JeecgDemoList")
public ModelAndView exportXls(HttpServletRequest request, JeecgDemo jeecgDemo) {
//获取导出表格字段
String exportFields = jeecgDemoService.getExportFields();
return super.exportXls(request, jeecgDemo, JeecgDemo.class, "单表模型",exportFields);
}
~~~
~~~
public String getExportFields() {
//获取当前登录人
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//权限配置列导出示例
List noAuthList = new ArrayList<>();
List exportFieldsList = new ArrayList<>();
//1.此前缀必须与列表字段权限控制前缀一致
String permsPrefix = "testdemo:";
//查询配置菜单有效字段
List allAuth = this.baseMapper.queryAllAuth(permsPrefix);
//查询已授权字段
List userAuth = this.baseMapper.queryUserAuth(sysUser.getId(),permsPrefix);
//列出未授权字段
for(String perms : allAuth){
if(!userAuth.contains(perms)){
noAuthList.add(perms.substring(permsPrefix.length()));
}
}
//实体类中字段与未授权字段比较,列出需导出字段
Field[] fileds = JeecgDemo.class.getDeclaredFields();
List list = new ArrayList(Arrays.asList(fileds));
for(Field field : list){
if(!noAuthList.contains(field.getName())){
exportFieldsList.add(field.getName());
}
}
return exportFieldsList != null && exportFieldsList.size()>0 ? String.join(",", exportFieldsList) : "";
}
~~~
';