From 261392a35198dc0be336adde146c1b8adf997093 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 8 Aug 2023 11:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A1=A3=E6=A1=88=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/filemanage/manage/ProjectFileManage.java | 108 ++++++++++----------- 1 file changed, 52 insertions(+), 56 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/ProjectFileManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/ProjectFileManage.java index 1afda67..ad100c6 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/ProjectFileManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/ProjectFileManage.java @@ -123,13 +123,13 @@ public class ProjectFileManage { String empPosUnitCode = userFullInfo.getEmpPosUnitCode(); Page page = param.page(); - projectService.page(page,Wrappers.lambdaQuery(Project.class) - .like(StringUtils.isNotBlank(param.getProjectName()),Project::getProjectName,param.getProjectName()) - .like(StringUtils.isNotBlank(param.getBuildOrgName()),Project::getBuildOrgName,param.getBuildOrgName()) + projectService.page(page, Wrappers.lambdaQuery(Project.class) + .like(StringUtils.isNotBlank(param.getProjectName()), Project::getProjectName, param.getProjectName()) + .like(StringUtils.isNotBlank(param.getBuildOrgName()), Project::getBuildOrgName, param.getBuildOrgName()) .eq(Project::getStatus, ProjectStatusEnum.ACCEPTED.getCode()) .orderByDesc(Project::getUpdateOn)); - if(0L == page.getTotal()){ + if (0L == page.getTotal()) { return PageVo.empty(); } @@ -140,7 +140,7 @@ public class ProjectFileManage { ProjectFileListVO vo = new ProjectFileListVO(); vo.setId(p.getId()); // 用户只可查阅自己及下属单位的项目档案和已经申请借阅通过的项目档案 - if (subOrgSet.contains(p.getBuildOrgCode()) || checkCanRead(subOrgSet,p)) { + if (subOrgSet.contains(p.getBuildOrgCode()) || checkCanRead(subOrgSet, p)) { vo.setCanRead(Boolean.TRUE); } vo.setBuildOrgName(p.getBuildOrgName()); @@ -148,7 +148,7 @@ public class ProjectFileManage { vo.setProjectName(p.getProjectName()); // 判断当前项目,当前登录用户是否已经开启了申请借阅并且没有审批完成 ProjectApplyBorrow projectApplyBorrow = projectApplyBorrowService.getOne(Wrappers.lambdaQuery(ProjectApplyBorrow.class) - .eq(ProjectApplyBorrow::getApplyBorrowEmployeeCode,employeeCode) + .eq(ProjectApplyBorrow::getApplyBorrowEmployeeCode, employeeCode) .eq(ProjectApplyBorrow::getProjectId, p.getId()) .orderByDesc(ProjectApplyBorrow::getCreateOn) .last("limit 1")); @@ -200,8 +200,8 @@ public class ProjectFileManage { // 先将自己加入子集 orgSet.add(empPosUnitCode); Set subOrgList = dingOrganizationService - .list(Wrappers.lambdaQuery(DingOrganization.class).eq(DingOrganization::getParentCode, empPosUnitCode)) - .stream().map(DingOrganization::getOrganizationCode).collect(Collectors.toSet()); + .list(Wrappers.lambdaQuery(DingOrganization.class).eq(DingOrganization::getParentCode, empPosUnitCode)) + .stream().map(DingOrganization::getOrganizationCode).collect(Collectors.toSet()); // 遍历子集 for (String orgCode : subOrgList) { orgSet.addAll(getSubOrgList(orgCode)); @@ -218,7 +218,7 @@ public class ProjectFileManage { Project project = projectService.getById(projectId); Set subOrgList = getSubOrgList(empPosUnitCode); - if (!checkCanRead(subOrgList,project)){ + if (!checkCanRead(subOrgList, project)) { throw new BizException("您没有权限查看此项目档案!"); } ProjectFileVO projectFileVo = new ProjectFileVO(); @@ -260,8 +260,8 @@ public class ProjectFileManage { String regionCode = user.getRegionCode(); WflowModels model = processModelService.getOne(Wrappers.lambdaQuery(WflowModels.class) - .eq(WflowModels::getRegionCode, regionCode) - .eq(WflowModels::getProcessType, ProjectProcessStageEnum.APPLY_BORROW.getCode()).last(BizConst.LIMIT_1)); + .eq(WflowModels::getRegionCode, regionCode) + .eq(WflowModels::getProcessType, ProjectProcessStageEnum.APPLY_BORROW.getCode()).last(BizConst.LIMIT_1)); if (Objects.isNull(model)) { log.error("此 【{}】区域找不到申请借阅流程配置", regionCode); @@ -277,7 +277,7 @@ public class ProjectFileManage { // 获取发起单位、发起单位主管单位、发起单位上级条线主管单位信息 Map orgModelMap = defaultDeclaredProjectManage.buildOrgModelMapUserOrgCode(project); String instanceId = - processInstanceService.newStartProcess(model.getProcessDefId(), model.getFormId(), params, orgModelMap); + processInstanceService.newStartProcess(model.getProcessDefId(), model.getFormId(), params, orgModelMap); log.info("申请借阅申报成功 【{}】", instanceId); // 保存项目借阅实例相关 @@ -285,7 +285,7 @@ public class ProjectFileManage { // 发送给第一个审批人消息 noticeManage.sendFirtUser(project, model.getFormName(), instanceId, WorkNoticeConstant.PASS_MSG_TEMPLATE, - MsgTypeEnum.PROJECT_REVIEW); + MsgTypeEnum.PROJECT_REVIEW); return instanceId; } @@ -295,48 +295,43 @@ public class ProjectFileManage { // 获取项目各阶段上传文件ID List fileIdList = Lists.newArrayList(); getProjectAppendix(project, fileIdList); - + if (fileIdList.isEmpty()) { + throw BizException.wrap("暂无档案可供下载"); + } + List files = fileService.listByIds(fileIdList); + if (files.isEmpty()) { + throw BizException.wrap("暂无档案可供下载"); + } String zipFileName = "项目档案"; - // 设置response的header response.setContentType("application/zip"); - response.setHeader("Content-disposition", - "attachment;filename*=utf-8''" + ExcelDownUtil.encodeName(zipFileName) + ".zip"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + ExcelDownUtil.encodeName(zipFileName) + ".zip"); try { // 创建ZipOutputStream ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); - if (CollUtil.isNotEmpty(fileIdList)) { - // 对文件ID进行去重 - HashSet hashSet = new HashSet<>(); - List fidList = fileIdList.stream().filter(hashSet::add).collect(Collectors.toList()); - // 获取文件输入流 - for (Long fileId : fidList) { - File file = fileService.getById(fileId); - // 文件不存在,跳过 - if (Objects.isNull(file)) { - continue; - } - String originalFileName = file.getOriginalFileName(); - String name = originalFileName.substring(0, originalFileName.indexOf(StrPool.DOT)); - String fileName = name + StrPool.UNDERSCORE + fileId + // 获取文件输入流 + for (File file : files) { + String originalFileName = file.getOriginalFileName(); + String name = originalFileName.substring(0, originalFileName.indexOf(StrPool.DOT)); + String fileName = name + StrPool.UNDERSCORE + file.getId() + originalFileName.substring(originalFileName.indexOf(StrPool.DOT)); - InputStream fileInputStream = fileService.getFileInputStream(file); - // 文件 - ZipEntry zipEntry = new ZipEntry(fileName); - zos.putNextEntry(zipEntry); - byte[] bytes = new byte[1024]; - int length; - while ((length = fileInputStream.read(bytes)) >= 0) { - zos.write(bytes, 0, length); - } - fileInputStream.close(); - zos.closeEntry(); + InputStream fileInputStream = fileService.getFileInputStream(file); + // 文件 + ZipEntry zipEntry = new ZipEntry(fileName); + zos.putNextEntry(zipEntry); + byte[] bytes = new byte[1024]; + int length; + while ((length = fileInputStream.read(bytes)) >= 0) { + zos.write(bytes, 0, length); } - zos.close(); + fileInputStream.close(); + zos.closeEntry(); } + zos.close(); } catch (IOException e) { - throw new BizException(e.getMessage()); + log.error("项目档案下载失败:", e); + throw BizException.wrap("项目档案下载失败"); } } @@ -373,7 +368,7 @@ public class ProjectFileManage { fileIdList.addAll(projectAppFormFileIdList); // 获取项目应用信息中的文件 List applicationList = projectApplicationService - .list(Wrappers.lambdaQuery(ProjectApplication.class).eq(ProjectApplication::getProjectId, projectId)); + .list(Wrappers.lambdaQuery(ProjectApplication.class).eq(ProjectApplication::getProjectId, projectId)); for (ProjectApplication projectApplication : applicationList) { // 获取试点文件 String experimentsFile = projectApplication.getExperimentsFile(); @@ -387,7 +382,7 @@ public class ProjectFileManage { // 流程审核意见文件 // 获取项目关联的流程实例 List projectInstList = - projectInstService.list(Wrappers.lambdaQuery(ProjectInst.class).eq(ProjectInst::getProjectId, projectId)); + projectInstService.list(Wrappers.lambdaQuery(ProjectInst.class).eq(ProjectInst::getProjectId, projectId)); // 从历史评论表中获取对应流程实例的评论附件信息 for (ProjectInst projectInst : projectInstList) { String instanceId = projectInst.getInstCode(); @@ -434,7 +429,7 @@ public class ProjectFileManage { // 采购结果备案阶段 Purchase purchase = purchaseService - .getOne(Wrappers.lambdaQuery(Purchase.class).eq(Purchase::getProjectId, projectId).last(BizConst.LIMIT_1)); + .getOne(Wrappers.lambdaQuery(Purchase.class).eq(Purchase::getProjectId, projectId).last(BizConst.LIMIT_1)); // 获取投标文件 if (Objects.nonNull(purchase)) { String biddingDoc = purchase.getBiddingDoc(); @@ -452,7 +447,7 @@ public class ProjectFileManage { // 合同备案阶段 Contract contract = contractService - .getOne(Wrappers.lambdaQuery(Contract.class).eq(Contract::getProjectId, projectId).last(BizConst.LIMIT_1)); + .getOne(Wrappers.lambdaQuery(Contract.class).eq(Contract::getProjectId, projectId).last(BizConst.LIMIT_1)); // 获取合同附件 if (Objects.nonNull(contract)) { String attachment = contract.getAttachment(); @@ -528,6 +523,7 @@ public class ProjectFileManage { /** * 查看 借阅的详情 + * * @param instanceId * @return */ @@ -536,28 +532,28 @@ public class ProjectFileManage { .eq(ProjectApplyBorrow::getInstanceId, instanceId) .last(BizConst.LIMIT_1)); - if(Objects.isNull(apply)){ + if (Objects.isNull(apply)) { return null; } - ProjectApplyBorrowVO vo = BeanUtil.copyProperties(apply,ProjectApplyBorrowVO.class); - if(StringUtils.isNotBlank(vo.getApplyBorrowEmployeeCode())){ + ProjectApplyBorrowVO vo = BeanUtil.copyProperties(apply, ProjectApplyBorrowVO.class); + if (StringUtils.isNotBlank(vo.getApplyBorrowEmployeeCode())) { UserFullInfoDTO user = userInfoHelper.getUserFullInfoByEmployeeCode(vo.getApplyBorrowEmployeeCode()); - if(Objects.nonNull(user)){ + if (Objects.nonNull(user)) { vo.setApplyBorrowEmployeeName(user.getUsername()); } } - if(StringUtils.isNotBlank(vo.getApplyBorrowEmpPosUnitCode())){ + if (StringUtils.isNotBlank(vo.getApplyBorrowEmpPosUnitCode())) { DingOrganization organization = dingOrganizationService.getOne(Wrappers.lambdaQuery(DingOrganization.class) .eq(DingOrganization::getOrganizationCode, vo.getApplyBorrowEmpPosUnitCode()) .last(BizConst.LIMIT_1)); - if(Objects.nonNull(organization)){ + if (Objects.nonNull(organization)) { vo.setApplyBorrowEmpPosUnitName(organization.getOrganizationName()); } } - if(Objects.nonNull(vo.getProjectId())){ + if (Objects.nonNull(vo.getProjectId())) { Project project = projectService.getById(vo.getProjectId()); - if(Objects.nonNull(project)){ + if (Objects.nonNull(project)) { vo.setProjectName(project.getProjectName()); } }