| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Copyright lx |
| | |
| | | |
| | | @Override |
| | | public FieldSetEntity getButtonPermissions(FieldSetEntity fieldSetEntity) throws BaseException { |
| | | String butt = ""; |
| | | String finalButtonPermissions = ""; |
| | | DataTableEntity dataTable = null; |
| | | FieldSetEntity fse = new FieldSetEntity(); |
| | | fse.setTableName(CmnConst.PRODUCT_OA_DOCUMENT); |
| | | if (StringUtils.equalsAny(fieldSetEntity.getString(CmnConst.DIRECTORY_UUID), "!borrow", "!favorite")) { |
| | | // 收藏夹和借阅文件夹特殊处理 |
| | | |
| | | dataTable = this.documentAll(fieldSetEntity); |
| | | butt = "1,2"; |
| | | finalButtonPermissions = "1,2"; |
| | | } else if ("1".equals(fieldSetEntity.getString(CmnConst.DIRECTORY_TYPE))) { |
| | | //获取的user_id |
| | | Integer user_id = SpringMVCContextHolder.getCurrentUser().getUser_id(); |
| | | String key = "%," + user_id + ",%"; |
| | | //获取当前点击文件夹UUID |
| | | String directory_uuid = fieldSetEntity.getString(CmnConst.DIRECTORY_UUID); |
| | | //String key = "%,140,%"; |
| | | DataTableEntity dataTableEntity = new DataTableEntity(); |
| | | |
| | | FieldSetEntity org = recursionRole(directory_uuid); |
| | | if (verifyOrgExist(org.getString("storage_uuid"))) { |
| | | StringBuffer sql = new StringBuffer(); |
| | | sql.append(" SELECT substring_index(substring_index(a.rigths,',',b.help_topic_id+1),',',-1) fun FROM PRODUCT_OA_directory_rights a ") |
| | | .append(" INNER join mysql.help_topic b on b.help_topic_id < (length(a.rigths) - length(replace(a.rigths,',',''))+1) ") |
| | | .append(" WHERE a.directory_uuid = ? "); |
| | | dataTableEntity = baseDao.listTable(sql.toString(), new String[]{org.getString("directory_uuid")}); |
| | | } |
| | | StringBuffer button = new StringBuffer(); |
| | | if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) { |
| | | for (int i = 0, length = dataTableEntity.getRows(); i < length; i++) { |
| | | FieldSetEntity field = dataTableEntity.getFieldSetEntity(i); |
| | | String fun = field.getString("fun"); |
| | | //权限1(查看),2(下载),3(新增上传),4(修改,重命名),5(删除),6(移动) |
| | | button.append(fun).append(","); |
| | | if ("1".equals(fun)) { |
| | | //有查看权限就加载列表 |
| | | dataTable = this.documentAll(fieldSetEntity); |
| | | // 获取点击文件夹的操作权限(如果当前文件夹没有配置权限,则递归上级目录权限) |
| | | DataTableEntity dtOperationPermissions = recursionRole(directory_uuid); |
| | | if (!BaseUtil.dataTableIsEmpty(dtOperationPermissions)) { |
| | | String buttonPermissions = ","; |
| | | for (int i = 0; i < dtOperationPermissions.getRows(); i++) { |
| | | // 获取单条操作权限数据 |
| | | FieldSetEntity fseOperationPermissions = dtOperationPermissions.getFieldSetEntity(i); |
| | | // 验证操作权限是否与当前操作人匹配成功 |
| | | if (verifyOrgExist(fseOperationPermissions.getString("storage_uuid"))) { |
| | | // 按钮权限拼接 |
| | | buttonPermissions += fseOperationPermissions.getString("rigths") + ","; |
| | | } |
| | | } |
| | | } |
| | | if (!BaseUtil.strIsNull(button.toString())) { |
| | | butt = button.substring(0, button.length() - 1); |
| | | if (!BaseUtil.strIsNull(buttonPermissions)) { |
| | | // 判断是否包含查看权限,包含查看权限则获取文件列表 |
| | | if (buttonPermissions.contains(",1,")) { |
| | | dataTable = this.documentAll(fieldSetEntity); |
| | | } |
| | | finalButtonPermissions = Arrays.stream(buttonPermissions.split(",")) |
| | | .filter(s -> !s.isEmpty()) |
| | | .distinct() |
| | | .collect(Collectors.joining(",")); |
| | | } |
| | | } |
| | | } else { |
| | | dataTable = this.documentAll(fieldSetEntity); |
| | | } |
| | | Map<String, DataTableEntity> dataMap = MapUtils.newHashMap(); |
| | | fse.setValue("button", butt); |
| | | fse.setValue("button", finalButtonPermissions); |
| | | //加载文件路径 |
| | | DataTableEntity file_list; |
| | | if (StringUtils.equalsAny(fieldSetEntity.getString(CmnConst.DIRECTORY_UUID), "!borrow", "!favorite")) { |
| | |
| | | |
| | | return fse; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 递归获取权限如果当前文档未配置权限就去递归查询父级权限 |
| | | * @param directory_uuid |
| | | * @return |
| | | */ |
| | | private FieldSetEntity recursionRole(String directory_uuid){ |
| | | FieldSetEntity org = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY_RIGHTS, "directory_uuid=?", new String[]{directory_uuid}, false); |
| | | if (FieldSetEntity.isEmpty(org)&&!StringUtils.isEmpty(directory_uuid)){ |
| | | FieldSetEntity directoryFs = baseDao.getFieldSet(CmnConst.PRODUCT_OA_DIRECTORY, directory_uuid,false); |
| | | FieldSetEntity parentFs = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY, "tricode=?",new String[]{directoryFs.getString("tricode_parent")},false); |
| | | org=recursionRole(parentFs.getUUID()); |
| | | private DataTableEntity recursionRole(String directory_uuid){ |
| | | DataTableEntity dtOperationPermissions = baseDao.listTable(CmnConst.PRODUCT_OA_DIRECTORY_RIGHTS, "directory_uuid = ?", new Object[] {directory_uuid}); |
| | | if (BaseUtil.dataTableIsEmpty(dtOperationPermissions)) { |
| | | FieldSetEntity fseDirectory = baseDao.getFieldSet(CmnConst.PRODUCT_OA_DIRECTORY, directory_uuid,false); |
| | | FieldSetEntity fseDirectoryParent = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_OA_DIRECTORY, "tricode=?",new String[]{fseDirectory.getString("tricode_parent")},false); |
| | | dtOperationPermissions = recursionRole(fseDirectoryParent.getUUID()); |
| | | } |
| | | return org; |
| | | return dtOperationPermissions; |
| | | } |
| | | |
| | | @Override |