Procházet zdrojové kódy

作者:张哲
时间:2023/08/16
类型:修改
描述:8.附件下载权限处理

zizg před 1 rokem
rodič
revize
bdc0e5c7bc

+ 4 - 0
src/main/java/com/redxun/knowledge/entity/dao/Knowledge.java

@@ -91,6 +91,10 @@ public class Knowledge extends BaseExtEntity<java.lang.String> {
     @TableField(exist = false)
     private OrganizationDto organizationIds;
 
+    //指定可下载附件的人员和组织
+    @TableField(value = "ALLOW_DOWNLOAD")
+    private String allowDownload;
+
 
     @Override
     public String getPkId() {

+ 3 - 0
src/main/java/com/redxun/knowledge/entity/dto/KnowledgeDto.java

@@ -51,4 +51,7 @@ public class KnowledgeDto {
     private Integer isDraft;
 
     private OrganizationDto organizationIds;
+
+    //指定可下载附件的人员和组织
+    private String allowDownload;
 }

+ 6 - 0
src/main/java/com/redxun/knowledge/entity/vo/KnowledgeVo.java

@@ -172,4 +172,10 @@ public class KnowledgeVo {
     private Date endTime;
 
     private Integer isWithdraw;
+
+    //可下载附件的人员或部门名称
+    private String allowDownload;
+
+    //是否可下载 可下载 返回0 不可下载 返回1
+    private Integer isAllowDownload;
 }

+ 65 - 0
src/main/java/com/redxun/knowledge/service/KnowledgeServiceImpl.java

@@ -18,6 +18,7 @@ import com.redxun.common.service.impl.SuperServiceImpl;
 import com.redxun.common.tool.IdGenerator;
 import com.redxun.common.tool.StringUtils;
 import com.redxun.common.utils.ContextUtil;
+import com.redxun.dto.user.OsGroupDto;
 import com.redxun.dto.user.OsUserDto;
 import com.redxun.knowledge.album.entity.dao.AlbumCatalogueKnowledge;
 import com.redxun.knowledge.album.mapper.AlbumCatalogueKnowledgeMapper;
@@ -160,6 +161,7 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
             knowledge.setCreateTime(new Date());
             knowledge.setUpdateBy(users.getUserId());
             knowledge.setUpdateTime(new Date());
+            knowledge.setAllowDownload(knowledgeDto.getAllowDownload());
             if (!ObjectUtil.valueAllNull(knowledgeDto.getOrganizationIds())){
                 String organizationId = JSON.toJSON(knowledgeDto.getOrganizationIds()).toString();
                 knowledge.setOrganizationId(organizationId);
@@ -253,6 +255,25 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
             if (!StringUtils.isEmpty(knowledge.getCategoryId())){
                 knowledgeVo.setKnowledgeCategoryAdminVo(knowledgeCategoryService.findAllParentByCategoryId(knowledge.getCategoryId()));
             }
+            //指定了附件下载权限会判断
+            if (StringUtils.isNotEmpty(knowledge.getAllowDownload())){
+                //附件下载权限
+                knowledgeVo.setIsAllowDownload(isAllowDownload(knowledge.getAllowDownload()));
+                //附件可下载人员或部门字符串复制
+                List<String> allowDownloadList = Arrays.asList(knowledge.getAllowDownload().split(","));
+                String allowDownloadNameResult = allowDownloadList.parallelStream().map(h -> {
+                    String allowDownloadName = null;
+                    OsUserDto osUserDto = userService.queryOsUserDto(h);
+                    if (osUserDto != null) {
+                        allowDownloadName = osUserDto.getFullName();
+                    } else {
+                        OsGroupDto osGroupDto = userService.findDeptByDeptId(h);
+                        allowDownloadName = osGroupDto.getName();
+                    }
+                    return allowDownloadName;
+                }).collect(Collectors.joining(","));
+                knowledgeVo.setAllowDownload(allowDownloadNameResult);
+            }
             if (knowledge.getIsDraft() == 0){
                 return knowledgeVo;
             }
@@ -374,6 +395,26 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
             } else {
                 e.setIsWithdraw(1);
             }
+            //指定了附件下载权限会判断
+            if (StringUtils.isNotEmpty(e.getAllowDownload())){
+                //附件下载权限
+                e.setIsAllowDownload(isAllowDownload(e.getAllowDownload()));
+                //附件可下载人员或部门字符串赋值
+                List<String> allowDownloadList = Arrays.asList(e.getAllowDownload().split(","));
+                String allowDownloadNameResult = allowDownloadList.parallelStream().map(h -> {
+                    String allowDownloadName = null;
+                    OsUserDto osUserDto = userService.queryOsUserDto(h);
+                    if (osUserDto != null) {
+                        allowDownloadName = osUserDto.getFullName();
+                    } else {
+                        OsGroupDto osGroupDto = userService.findDeptByDeptId(h);
+                        allowDownloadName = osGroupDto.getName();
+                    }
+                    return allowDownloadName;
+                }).collect(Collectors.joining(","));
+                e.setAllowDownload(allowDownloadNameResult);
+            }
+
         });
         return page;
     }
@@ -975,4 +1016,28 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
         knowledgeMapper.updateById(knowledge);
         knowledgeApproveMapper.deleteByKnowledgeId(knowledgeId);
     }
+
+    /**
+     * 判断是否有下载附件权限(有权限 返回0; 没权限 返回1)
+     * @return
+     */
+    private Integer isAllowDownload(String allowDownload){
+        String userId = userService.queryLoginUser();
+        List<String> deptAuthority = knowledgeApproveMapper.deptAuthority(userId);  //部门权限字符串
+        boolean flag = false;
+        for (int i = 0; i < deptAuthority.size(); i++) {
+            if (deptAuthority.get(i).contains(allowDownload)) {
+                flag = true;
+                break;
+            }
+        }
+        List<String> approverIdList = Arrays.asList(allowDownload.split(","));
+        // 如果有权限
+        if (!approverIdList.contains(userId) && !flag) {
+            // 不是该部门的人,不能查看
+            return 1;
+        } else {
+            return 0;
+        }
+    }
 }