*/
protected static Junction dataScopeFilter(User user, String officeAlias, String userAlias) {
// 进行权限过滤,多个角色权限范围之间为或者关系。
List<String> dataScope = Lists.newArrayList();
Junction junction = Restrictions.disjunction();
// 超级管理员,跳过权限过滤
if (!user.isAdmin()){
for (Role r : user.getRoleList()){
if (!dataScope.contains(r.getDataScope()) && StringUtils.isNotBlank(officeAlias)){
boolean isDataScopeAll = false;
if (Role.DATA_SCOPE_ALL.equals(r.getDataScope())){
isDataScopeAll = true;
}
else if (Role.DATA_SCOPE_COMPANY_AND_CHILD.equals(r.getDataScope())){
junction.add(Restrictions.eq(officeAlias+".id", user.getCompany().getId()));
junction.add(Restrictions.like(officeAlias+".parentIds", user.getCompany().getParentIds()+user.getCompany().getId()+",%"));
}
else if (Role.DATA_SCOPE_COMPANY.equals(r.getDataScope())){
junction.add(Restrictions.eq(officeAlias+".id", user.getCompany().getId()));
junction.add(Restrictions.and(Restrictions.eq(officeAlias+".parent.id", user.getCompany().getId()),
Restrictions.eq(officeAlias+".type", "2"))); // 包括本公司下的部门
}
else if (Role.DATA_SCOPE_OFFICE_AND_CHILD.equals(r.getDataScope())){
junction.add(Restrictions.eq(officeAlias+".id", user.getOffice().getId()));
junction.add(Restrictions.like(officeAlias+".parentIds", user.getOffice().getParentIds()+user.getOffice().getId()+",%"));
}
else if (Role.DATA_SCOPE_OFFICE.equals(r.getDataScope())){
junction.add(Restrictions.eq(officeAlias+".id", user.getOffice().getId()));
}
else if (Role.DATA_SCOPE_CUSTOM.equals(r.getDataScope())){
junction.add(Restrictions.in(officeAlias+".id", r.getOfficeIdList()));
}
//else if (Role.DATA_SCOPE_SELF.equals(r.getDataScope())){
if (!isDataScopeAll){
if (StringUtils.isNotBlank(userAlias)){
junction.add(Restrictions.eq(userAlias+".id", user.getId()));
}else {
junction.add(Restrictions.isNull(officeAlias+".id"));
}
}else{
// 如果包含全部权限,则去掉之前添加的所有条件,并跳出循环。
junction = Restrictions.disjunction();
break;