From f6fd034a773a97292e554a25aab71330837dbbcc Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 26 Mar 2024 19:00:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E4=BF=A1=E4=BA=A7=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hz/pm/api/external/MhApiClient.java | 4 +-- .../java/com/hz/pm/api/external/MhFileClient.java | 21 +++++++++++++++ .../api/projectdeclared/manage/PurchaseManage.java | 30 ++++++++++++++++++++-- hz-pm-api/src/main/resources/application-dev.yml | 2 ++ hz-pm-api/src/main/resources/application-prod.yml | 1 + .../com/hz/pm/api/todocenter/MhApiClientTest.java | 19 +++++++++++--- hz-pm-api/src/test/resources/application-dev.yml | 1 + 7 files changed, 71 insertions(+), 7 deletions(-) diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/MhApiClient.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/MhApiClient.java index 920f0d3..8efb84e 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/external/MhApiClient.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/MhApiClient.java @@ -101,9 +101,9 @@ public class MhApiClient { } public void publishPurchaseNotice(List notices) { - if (environmentUtil.isDevEnv()) { + /*if (environmentUtil.isDevEnv()) { return; - } + }*/ String requestUrl = mhApiHost + PURCHASE_NOTICE; String retBody = HttpUtil.post(requestUrl, JSONUtil.toJsonStr(notices)); MhRetDTO retObj = JSONUtil.toBean(retBody, diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/MhFileClient.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/MhFileClient.java index d2036fb..ed5d3db 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/external/MhFileClient.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/MhFileClient.java @@ -1,6 +1,9 @@ package com.hz.pm.api.external; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.TypeReference; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONUtil; import com.hz.pm.api.external.model.dto.MhFileInfoDTO; @@ -11,9 +14,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -41,6 +46,9 @@ public class MhFileClient { @Value("${mh.file.detail-url:}") private String fileDetailUrl; + @Value("${mh.file.upload-url:}") + private String fileUploadUrl; + private boolean isProdEnv() { String[] profiles = environment.getActiveProfiles(); return Arrays.asList(profiles).contains("prod"); @@ -80,4 +88,17 @@ public class MhFileClient { } } + public String uploadFile(File file) { + HttpRequest request = HttpUtil.createPost(fileUploadUrl); + request.form("file", file); + try (HttpResponse response = request.execute()) { + MhRetDTO retObj = JSONUtil.toBean(response.body(), MhRetDTO.class); + if (retObj.isOk()) { + return retObj.getData().toString(); + } + log.error("文件上传失败:{}", retObj); + throw BizException.wrap("文件上传失败"); + } + } + } 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 0ebc26e..0dd38f1 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 @@ -2,8 +2,11 @@ package com.hz.pm.api.projectdeclared.manage; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.URLUtil; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONUtil; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -14,6 +17,7 @@ import com.hz.pm.api.common.statemachine.util.TenderStateMachineUtil; import com.hz.pm.api.common.util.ExcelDownUtil; import com.hz.pm.api.common.util.ExcelExportStyle; import com.hz.pm.api.external.MhApiClient; +import com.hz.pm.api.external.MhFileClient; import com.hz.pm.api.external.model.dto.MhPurchaseNoticeDTO; import com.hz.pm.api.projectdeclared.model.dto.DeclaredProjectExportDTO; import com.hz.pm.api.projectdeclared.model.dto.PurchaseSaveDTO; @@ -43,15 +47,24 @@ 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.File; +import com.ningdatech.file.entity.vo.result.FileResultVO; +import com.ningdatech.file.service.FileService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigDecimal; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -76,6 +89,8 @@ public class PurchaseManage { private final TenderStateMachineUtil tenderStateMachineUtil; private final StateMachineUtil stateMachineUtil; private final MhApiClient mhApiClient; + private final MhFileClient mhFileClient; + private final FileService fileService; /** * 待采购的-项目列表 @@ -297,13 +312,24 @@ public class PurchaseManage { private MhPurchaseNoticeDTO buildPurchaseNotice(PurchaseNoticeTenderDTO w, UserInfoDetails user) { Date now = new Date(); + List bidFiles = JSONUtil.toList(w.getBidDoc(), FileResultVO.class); + List files = fileService.listByIds(CollUtils.fieldSet(bidFiles, FileResultVO::getId)); + String fileIds = files.stream().map(file -> { + String fileUrl = fileService.findUrlByFile(file); + String filePath = FileUtil.getTmpDirPath() + file.getOriginalFileName(); + java.io.File tmpFile = new java.io.File(filePath); + HttpUtil.downloadFile(fileUrl, tmpFile); + String fileId = mhFileClient.uploadFile(tmpFile); + tmpFile.deleteOnExit(); + return fileId; + }).collect(Collectors.joining(",")); return MhPurchaseNoticeDTO.builder() .bidOpenTime(DateUtil.date(w.getBidStartTime()).toJdkDate()) .endTime(DateUtil.date(w.getBidEndTime()).toJdkDate()) .buyDesc(w.getPurchaseRemark()) .budgetMoney(w.getBidBudget().multiply(BigDecimal.valueOf(10000))) .buyItem(w.getBidName()) - .buyFile(w.getBidDoc()) + .buyFile(fileIds) .buyScope(PurchaseScopeEnum.PUBLIC.eq(w.getPurchaseScope()) ? "Y" : "N") .buyWay(w.getPurchaseMethod()) .buyUnitName(w.getPurchaseUnit()) diff --git a/hz-pm-api/src/main/resources/application-dev.yml b/hz-pm-api/src/main/resources/application-dev.yml index c8a5c2d..93803dc 100644 --- a/hz-pm-api/src/main/resources/application-dev.yml +++ b/hz-pm-api/src/main/resources/application-dev.yml @@ -257,6 +257,8 @@ mh: file: down-url: https://weixin.hzszxc.hzswb.cn:8443/test/mh-gateway/oss/oss/previewFileLogin detail-url: https://weixin.hzszxc.hzswb.cn:8443/test/mh-gateway/oss/ossfile/getFileInfoList + upload-url: https://weixin.hzszxc.hzswb.cn:8443/test/mh-gateway/oss/oss/uploadFileSkipLogin + auth-code: secret-key: nqkmzqojg5j4eiypr3rb8s7nb4noa8b2 agent-login: diff --git a/hz-pm-api/src/main/resources/application-prod.yml b/hz-pm-api/src/main/resources/application-prod.yml index 3bdc909..e38b8a7 100644 --- a/hz-pm-api/src/main/resources/application-prod.yml +++ b/hz-pm-api/src/main/resources/application-prod.yml @@ -255,6 +255,7 @@ mh: file: detail-url: http://10.54.38.13:8081/mh-gateway/oss/ossfile/getFileInfoList down-url: http://10.54.38.13:8081/mh-gateway/oss/oss/downloadFileNotLogin + upload-url: http://10.54.38.13:8081/mh-gateway/oss/oss/uploadFileSkipLogin sync-mh-company: open: false sync-mh-user: diff --git a/hz-pm-api/src/test/java/com/hz/pm/api/todocenter/MhApiClientTest.java b/hz-pm-api/src/test/java/com/hz/pm/api/todocenter/MhApiClientTest.java index 9e5e7c6..ac565fd 100644 --- a/hz-pm-api/src/test/java/com/hz/pm/api/todocenter/MhApiClientTest.java +++ b/hz-pm-api/src/test/java/com/hz/pm/api/todocenter/MhApiClientTest.java @@ -1,17 +1,26 @@ package com.hz.pm.api.todocenter; -import cn.hutool.json.JSONObject; +import cn.hutool.core.io.FileUtil; +import cn.hutool.http.HttpUtil; import com.hz.pm.api.AppTests; -import com.hz.pm.api.common.helper.UserInfoHelper; import com.hz.pm.api.external.MhApiClient; +import com.hz.pm.api.external.MhFileClient; import com.hz.pm.api.external.model.dto.MhZwddWorkNoticeDTO; import com.hz.pm.api.external.todo.MHTodoClient; import com.hz.pm.api.external.todo.dto.MhTodoExtraParamDTO; import com.hz.pm.api.external.todo.enumerization.MHTodoTypeEnum; import com.hz.pm.api.user.security.model.UserFullInfoDTO; +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.file.entity.File; +import com.ningdatech.file.entity.vo.result.FileResultVO; +import com.ningdatech.file.service.FileService; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + /** *

* MhApiClientTest @@ -26,6 +35,10 @@ public class MhApiClientTest extends AppTests { private MHTodoClient mhTodoClient; @Autowired private MhApiClient mhApiClient; + @Autowired + private MhFileClient mhFileClient; + @Autowired + private FileService fileService; @Test public void sendTodo() { @@ -45,7 +58,7 @@ public class MhApiClientTest extends AppTests { } @Test - public void test(){ + public void test() { MhZwddWorkNoticeDTO notice = MhZwddWorkNoticeDTO.builder() .title(MHTodoTypeEnum.DECLARED_RECORD_AUDIT.getVal()) .targetUser("ce44b47503147319fc3b5c826cb51fd2") diff --git a/hz-pm-api/src/test/resources/application-dev.yml b/hz-pm-api/src/test/resources/application-dev.yml index 8e1b79d..c46328c 100644 --- a/hz-pm-api/src/test/resources/application-dev.yml +++ b/hz-pm-api/src/test/resources/application-dev.yml @@ -257,6 +257,7 @@ mh: file: down-url: https://weixin.hzszxc.hzswb.cn:8443/test/mh-gateway/oss/oss/previewFileLogin detail-url: https://weixin.hzszxc.hzswb.cn:8443/test/mh-gateway/oss/ossfile/getFileInfoList + upload-url: https://weixin.hzszxc.hzswb.cn:8443/test/mh-gateway/oss/oss/uploadFileSkipLogin auth-code: secret-key: nqkmzqojg5j4eiypr3rb8s7nb4noa8b2 agent-login: