From 9096160925f7bd124c014f607d93e9db6aeee194 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 10 Dec 2024 11:41:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=20=E4=BF=AE=E5=A4=8D=E4=BF=A1?= =?UTF-8?q?=E5=88=9B=E6=8A=A5=E5=91=8A=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=9B=202.=20=E6=89=8B=E5=8A=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=B3=BB=E7=BB=9F=E7=94=B3=E8=AF=B7=E4=BF=A1=E5=88=9B?= =?UTF-8?q?=E6=B5=8B=E8=AF=84=E7=8A=B6=E6=80=81=E6=A0=A1=E9=AA=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PurchaseController.java | 3 +- .../projectdeclared/helper/MhXcfhxFileHelper.java | 95 ---------------------- .../helper/MhXcfhxReportHelper.java | 90 ++++++++++++++++++++ .../projectdeclared/manage/ConstructionManage.java | 19 ++--- .../api/projectdeclared/manage/PurchaseManage.java | 37 +++++++-- 5 files changed, 129 insertions(+), 115 deletions(-) delete mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxFileHelper.java create mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxReportHelper.java diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java index a7a3067..7ea807f 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java @@ -12,6 +12,7 @@ import com.hz.pm.api.projectlib.model.req.ProjectListReq; import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO; import com.ningdatech.basic.model.IdVo; import com.ningdatech.basic.model.PageVo; +import com.ningdatech.file.entity.vo.result.FileResultVO; import com.ningdatech.log.annotation.WebLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -163,7 +164,7 @@ public class PurchaseController { @GetMapping("/xcfhxReportFiles/{code}") @ApiOperation("获取信创文件预览") - public String xcfhxReportFiles(@PathVariable String code) { + public FileResultVO xcfhxReportFiles(@PathVariable String code) { return purchaseManage.xcfhxReportFiles(code); } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxFileHelper.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxFileHelper.java deleted file mode 100644 index 668faa7..0000000 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxFileHelper.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.hz.pm.api.projectdeclared.helper; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.json.JSONUtil; -import com.hz.pm.api.common.util.StrUtils; -import com.hz.pm.api.external.MhFileClient; -import com.ningdatech.basic.exception.BizException; -import com.ningdatech.basic.model.ApiResponse; -import com.ningdatech.file.controller.FileController; -import com.ningdatech.file.entity.vo.result.FileResultVO; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.stereotype.Component; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.net.URLEncoder; -import java.nio.file.Files; -import java.util.Collections; - -/** - * @Classname MhXchxFileHelper - * @Description - * @Date 2024/7/3 10:41 - * @Author PoffyZhang - */ -@Component -@RequiredArgsConstructor -@Slf4j -public class MhXcfhxFileHelper { - - private final MhFileClient mhFileClient; - - private final FileController fileController; - - public String getXcfhxFile(String reportFile, String fileName) { - if (StrUtils.isBlank(reportFile)) { - throw BizException.wrap("信创报告文件不能为空"); - } - ApiResponse retFileInfo; - File tmpFile = null; - FileInputStream fis = null; - try { - tmpFile = mhFileClient.downloadToTmpFile(reportFile); - if (StringUtils.isNotBlank(fileName)) { - fileName = fileName + FileUtil.getSuffix(tmpFile); - } else { - fileName = tmpFile.getName(); - } - fis = new FileInputStream(tmpFile); - String mimeType = FileUtil.getMimeType(tmpFile.getPath()); - MockMultipartFile multipartFile = new MockMultipartFile(fileName, fileName, mimeType, fis); - retFileInfo = fileController.upload(multipartFile, "default"); - } catch (IOException e) { - log.error("信创报告上传失败", e); - throw BizException.wrap("信创符合性测评报告上传失败"); - } finally { - if (tmpFile != null) { - tmpFile.deleteOnExit(); - } - if (fis != null) { - IOUtils.closeQuietly(fis); - } - } - return JSONUtil.toJsonStr(Collections.singletonList(retFileInfo.getData())); - } - - public void exportReport(String reportFile, HttpServletResponse response) throws UnsupportedEncodingException { - if (StrUtils.isBlank(reportFile)) { - throw BizException.wrap("信创报告文件不能为空"); - } - - File file = mhFileClient.downloadToTmpFile(reportFile); - // 设置响应的内容类型和头信息 - response.setContentType("application/pdf"); - response.setHeader("Content-Disposition", "attachment;filename=\"" + URLEncoder.encode(file.getName(), "utf-8") + "\""); - - // 使用ServletOutputStream写文件内容 - try (InputStream in = Files.newInputStream(file.toPath()); - ServletOutputStream out = response.getOutputStream()) { - byte[] buffer = new byte[1024]; - int bytesRead; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - - } -} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxReportHelper.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxReportHelper.java new file mode 100644 index 0000000..061cd3e --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXcfhxReportHelper.java @@ -0,0 +1,90 @@ +package com.hz.pm.api.projectdeclared.helper; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.lang.UUID; +import cn.hutool.core.util.StrUtil; +import com.hz.pm.api.common.util.StrUtils; +import com.hz.pm.api.external.MhFileClient; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.basic.model.ApiResponse; +import com.ningdatech.file.controller.FileController; +import com.ningdatech.file.entity.vo.result.FileResultVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.nio.file.Files; + +/** + * @Classname MhXcFhxFileHelper + * @Description + * @Date 2024/7/3 10:41 + * @Author PoffyZhang + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class MhXcfhxReportHelper { + + private final MhFileClient mhFileClient; + private final FileController fileController; + + public FileResultVO getXcfhxFile(String reportFile, String fileName) { + if (StrUtils.isBlank(reportFile)) { + throw BizException.wrap("信创报告文件不能为空"); + } + File tmpFile = mhFileClient.downloadToTmpFile(reportFile); + try (FileInputStream fis = new FileInputStream(tmpFile)) { + String newFileName; + if (StrUtil.isNotBlank(fileName)) { + newFileName = fileName + FileUtil.getSuffix(tmpFile); + } else { + newFileName = tmpFile.getName(); + } + String mimeType = FileUtil.getMimeType(tmpFile.getPath()); + MockMultipartFile multipartFile = new MockMultipartFile(newFileName, newFileName, mimeType, fis); + ApiResponse retFileInfo = fileController.upload(multipartFile, "default"); + return retFileInfo.getData(); + } catch (IOException e) { + log.error("信创报告上传失败", e); + throw BizException.wrap("信创符合性测评报告上传失败"); + } finally { + FileUtil.del(tmpFile); + } + } + + public void download(String reportFile, HttpServletResponse response) { + if (StrUtils.isBlank(reportFile)) { + throw BizException.wrap("信创报告文件不能为空"); + } + + File file = mhFileClient.downloadToTmpFile(reportFile); + // 设置响应的内容类型和头信息 + response.setContentType("application/pdf"); + String fileName; + try { + fileName = URLEncoder.encode(file.getName(), "utf-8"); + } catch (UnsupportedEncodingException e) { + log.warn("文件名编码失败:{}", file.getName(), e); + fileName = UUID.randomUUID().toString(true) + ".pdf"; + } + response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); + // 使用ServletOutputStream写文件内容 + try (InputStream in = Files.newInputStream(file.toPath()); + ServletOutputStream out = response.getOutputStream()) { + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + } + } catch (IOException e) { + log.error("导出信创报告失败", e); + throw BizException.wrap("导出信创测评报告失败"); + } + } +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/ConstructionManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/ConstructionManage.java index fd59600..b7c0f79 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/ConstructionManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/ConstructionManage.java @@ -3,13 +3,14 @@ package com.hz.pm.api.projectdeclared.manage; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.extra.spring.SpringUtil; +import cn.hutool.json.JSONUtil; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.collect.Lists; import com.hz.pm.api.common.enumeration.ProjectProcessType; +import com.hz.pm.api.common.exception.ReturnException; import com.hz.pm.api.common.helper.UserInfoHelper; import com.hz.pm.api.common.model.constant.BizConst; import com.hz.pm.api.common.model.constant.ExistsSqlConst; @@ -21,7 +22,7 @@ import com.hz.pm.api.common.util.ExcelDownUtil; import com.hz.pm.api.common.util.ExcelExportStyle; import com.hz.pm.api.common.util.StrUtils; import com.hz.pm.api.external.todo.enumerization.MHTodoTypeEnum; -import com.hz.pm.api.projectdeclared.helper.MhXcfhxFileHelper; +import com.hz.pm.api.projectdeclared.helper.MhXcfhxReportHelper; import com.hz.pm.api.projectdeclared.model.dto.DeclaredProjectExportDTO; import com.hz.pm.api.projectdeclared.model.dto.PaymentPlanSupplementDTO; import com.hz.pm.api.projectdeclared.model.dto.PreInsSaveDTO; @@ -58,6 +59,7 @@ import com.ningdatech.basic.function.VUtils; import com.ningdatech.basic.model.PageVo; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.basic.util.NdDateUtils; +import com.ningdatech.file.entity.vo.result.FileResultVO; import com.wflow.bean.entity.WflowModels; import com.wflow.workflow.bean.dto.OrgInfoDTO; import com.wflow.workflow.bean.vo.ProcessStartParamsVo; @@ -65,7 +67,6 @@ import com.wflow.workflow.service.ProcessInstanceService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.flowable.engine.TaskService; -import org.flowable.task.api.Task; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -105,7 +106,7 @@ public class ConstructionManage { private final IProjectAnnualPaymentPlanService projectPaymentPlanService; private final TenderStateMachineUtil tenderStateMachineUtil; private final XcfhxStateMachineUtil xcfhxStateMachineUtil; - private final MhXcfhxFileHelper mhXcfhxFileHelper; + private final MhXcfhxReportHelper mhXcfhxReportHelper; private final IXinchuangService xinchuangService; private final TaskService taskService; @@ -642,7 +643,8 @@ public class ConstructionManage { if (StrUtils.isBlank(purchase.getMhXcfhxReportFile()) || req.getMhXcfhxReportFile().equals(purchase.getMhXcfhxReportFile())) { String fileName = purchase.getBidName() + "-信创符合性测评报告."; - purchase.setXcfhxReportFiles(mhXcfhxFileHelper.getXcfhxFile(req.getMhXcfhxReportFile(), fileName)); + FileResultVO xcfhxFile = mhXcfhxReportHelper.getXcfhxFile(req.getMhXcfhxReportFile(), fileName); + purchase.setXcfhxReportFiles(JSONUtil.toJsonStr(Collections.singletonList(xcfhxFile))); } purchase.setMhXcfhxReportRecordId(req.getMhXcfhxReportRecordId()); purchase.setMhXcfhxReportFile(req.getMhXcfhxReportFile()); @@ -663,11 +665,8 @@ public class ConstructionManage { public synchronized String submitXcfhxApplyManual(Long id) { Xinchuang xinhcuang = xinchuangService.getById(id); VUtils.isTrue(Objects.isNull(xinhcuang)).throwMessage("信创符合性申请不存在"); - if (StringUtils.isNotBlank(xinhcuang.getInstCode())) { - List tasks = taskService.createTaskQuery().active() - .processInstanceId(xinhcuang.getInstCode()) - .list(); - VUtils.isTrue(CollUtil.isNotEmpty(tasks)).throwMessage("此信创符合性已经发起过审核 并且还没审核完!"); + if (xinhcuang.getStatus() != null && !TenderXcfhxApplyStatus.XCFHX_APPLY_FAILED.eq(xinhcuang.getStatus())) { + throw ReturnException.wrap("不支持提交信创符合性申请"); } UserInfoDetails user = LoginUserUtil.userDetailNotNull(); diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java index 4d553f8..59d6569 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java @@ -32,7 +32,7 @@ import com.hz.pm.api.external.model.dto.MhPurchaseNoticeDTO; import com.hz.pm.api.external.model.enumeration.MhUnitStripEnum; import com.hz.pm.api.external.todo.enumerization.MHTodoTypeEnum; import com.hz.pm.api.projectdeclared.chain.ProjectStatusRewriteHandlerContext; -import com.hz.pm.api.projectdeclared.helper.MhXcfhxFileHelper; +import com.hz.pm.api.projectdeclared.helper.MhXcfhxReportHelper; import com.hz.pm.api.projectdeclared.model.dto.DeclaredProjectExportDTO; import com.hz.pm.api.projectdeclared.model.dto.PurchaseSaveDTO; import com.hz.pm.api.projectdeclared.model.dto.XcfhxApplyEditDTO; @@ -90,7 +90,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; @@ -137,7 +136,7 @@ public class PurchaseManage { private final IProjectInstService projectInstService; private final EnvironmentUtil environmentUtil; private final IXinchuangService xinchuangService; - private final MhXcfhxFileHelper mhXcfhxFileHelper; + private final MhXcfhxReportHelper mhXcfhxReportHelper; private final IPurchaseStatusChangeService purchaseStatusChangeService; private final MhUnitQueryAuthHelper mhUnitQueryAuthHelper; private final IProjectGovSystemReplaceInfosService projectGovSystemReplaceInfosService; @@ -574,6 +573,24 @@ public class PurchaseManage { } }); } + List xinchuangList = xinchuangService.list(Wrappers.lambdaQuery(Xinchuang.class) + .select(Xinchuang::getId, Xinchuang::getXcfhxReportFiles) + .isNotNull(Xinchuang::getXcfhxReportFiles)); + for (Xinchuang xinchuang : xinchuangList) { + BizUtils.notBlank(xinchuang.getXcfhxReportFiles(), w -> { + try { + ApiResponse response = JSONUtil.toBean(w, new TypeReference>() { + }, false); + if (response.getCode() == ApiResponse.SUCCESS_CODE) { + xinchuang.setXcfhxReportFiles(JSONUtil.toJsonStr(Collections.singletonList(response.getData()))); + xinchuangService.updateById(xinchuang); + } + log.warn("修复采购信息xcfhxReportFiles成功:{}", w); + } catch (Exception ex) { + log.warn("修复采购信息xcfhxReportFiles失败:{}", w); + } + }); + } } public synchronized void pushToMhNotice(Long purchaseId) { @@ -1104,7 +1121,8 @@ public class PurchaseManage { if (Boolean.TRUE.equals(dto.getMatchXcfhx()) && StrUtils.isNotBlank(dto.getMhXcfhxReportFile())) { String fileName = xinchuang.getBidName() + "-信创符合性测评报告."; - xinchuang.setXcfhxReportFiles(mhXcfhxFileHelper.getXcfhxFile(dto.getMhXcfhxReportFile(), fileName)); + FileResultVO xcfhxFile = mhXcfhxReportHelper.getXcfhxFile(dto.getMhXcfhxReportFile(), fileName); + xinchuang.setXcfhxReportFiles(JSONUtil.toJsonStr(Collections.singletonList(xcfhxFile))); } if (xinchuangService.save(xinchuang)) { @@ -1121,7 +1139,8 @@ public class PurchaseManage { && StrUtils.isNotBlank(dto.getMhXcfhxReportFile()) && !dto.getMhXcfhxReportFile().equals(old.getMhXcfhxReportFile())) { String fileName = xinchuang.getBidName() + "-信创符合性测评报告."; - xinchuang.setXcfhxReportFiles(mhXcfhxFileHelper.getXcfhxFile(dto.getMhXcfhxReportFile(), fileName)); + FileResultVO xcfhxFile = mhXcfhxReportHelper.getXcfhxFile(dto.getMhXcfhxReportFile(), fileName); + xinchuang.setXcfhxReportFiles(JSONUtil.toJsonStr(Collections.singletonList(xcfhxFile))); } if (xinchuangService.updateById(xinchuang)) { return xinchuang.getId(); @@ -1129,12 +1148,12 @@ public class PurchaseManage { throw BizException.wrap("编辑失败"); } - public String xcfhxReportFiles(String code) { - return mhXcfhxFileHelper.getXcfhxFile(code, null); + public FileResultVO xcfhxReportFiles(String code) { + return mhXcfhxReportHelper.getXcfhxFile(code, null); } - public void exportXcfhFile(String code, HttpServletResponse response) throws UnsupportedEncodingException { - mhXcfhxFileHelper.exportReport(code, response); + public void exportXcfhFile(String code, HttpServletResponse response) { + mhXcfhxReportHelper.download(code, response); } @Transactional(rollbackFor = Exception.class)