@@ -101,9 +101,9 @@ public class MhApiClient { | |||
} | |||
public void publishPurchaseNotice(List<MhPurchaseNoticeDTO> notices) { | |||
if (environmentUtil.isDevEnv()) { | |||
/*if (environmentUtil.isDevEnv()) { | |||
return; | |||
} | |||
}*/ | |||
String requestUrl = mhApiHost + PURCHASE_NOTICE; | |||
String retBody = HttpUtil.post(requestUrl, JSONUtil.toJsonStr(notices)); | |||
MhRetDTO<Object> retObj = JSONUtil.toBean(retBody, | |||
@@ -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("文件上传失败"); | |||
} | |||
} | |||
} |
@@ -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<FileResultVO> bidFiles = JSONUtil.toList(w.getBidDoc(), FileResultVO.class); | |||
List<File> 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()) | |||
@@ -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: | |||
@@ -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: | |||
@@ -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; | |||
/** | |||
* <p> | |||
* 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") | |||
@@ -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: | |||