diff --git a/src/main/java/aiyh/utils/httpUtil/MultipartFile.java b/src/main/java/aiyh/utils/httpUtil/MultipartFile.java deleted file mode 100644 index bb2ed73..0000000 --- a/src/main/java/aiyh/utils/httpUtil/MultipartFile.java +++ /dev/null @@ -1,35 +0,0 @@ -package aiyh.utils.httpUtil; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -import java.io.InputStream; - -/** - *

文件上传类

- * - *

create: 2022-11-21 11:54

- * - * @author youHong.ai - */ - -@Setter -@Getter -@ToString -public class MultipartFile { - /** - * 文件名 - */ - String fileName; - /** - * 上传文件的key - */ - String fileKey; - /** - * 文件流信息 - */ - InputStream stream; - - Long fileSize; -} diff --git a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java index 99bd9bb..e858fb6 100644 --- a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java +++ b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java @@ -439,7 +439,7 @@ public class HttpUtils { CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider); Map paramsMap = paramsHandle(params); Map headerMap = headersHandle(headers); - MultipartFile multipartFile = new MultipartFile(); + HttpMultipartFile multipartFile = new HttpMultipartFile(); multipartFile.setFileName(fileName); multipartFile.setFileKey(fileKey); multipartFile.setStream(inputStream); @@ -459,7 +459,7 @@ public class HttpUtils { * @return 响应数 * @throws IOException Io异常 */ - public ResponeVo apiUploadFiles(String url, List multipartFileList, Map params, + public ResponeVo apiUploadFiles(String url, List multipartFileList, Map params, Map headers) throws IOException { CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider); Map paramsMap = paramsHandle(params); @@ -479,7 +479,7 @@ public class HttpUtils { * @return 响应数 * @throws IOException Io异常 */ - public ResponeVo apiPutUploadFiles(String url, List multipartFileList, Map params, + public ResponeVo apiPutUploadFiles(String url, List multipartFileList, Map params, Map headers) throws IOException { CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider); Map paramsMap = paramsHandle(params); @@ -505,7 +505,7 @@ public class HttpUtils { CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider); Map paramsMap = paramsHandle(params); Map headerMap = headersHandle(headers); - MultipartFile multipartFile = new MultipartFile(); + HttpMultipartFile multipartFile = new HttpMultipartFile(); multipartFile.setFileName(fileName); multipartFile.setFileKey(fileKey); multipartFile.setStream(inputStream); @@ -554,7 +554,7 @@ public class HttpUtils { Map paramsMap = paramsHandle(params); Map headerMap = headersHandle(headers); InputStream inputStream = ImageFileManager.getInputStreamById(id); - MultipartFile multipartFile = new MultipartFile(); + HttpMultipartFile multipartFile = new HttpMultipartFile(); multipartFile.setFileName(fileName); multipartFile.setFileKey(fileKey); multipartFile.setStream(inputStream); @@ -1019,7 +1019,7 @@ public class HttpUtils { * @param headers 请求头信息 * @return 返回httpPost */ - private HttpPost uploadFileByInputStream(String url, List multipartFileList, + private HttpPost uploadFileByInputStream(String url, List multipartFileList, Map params, Map headers) { log.info(Util.logStr("start request : url is [{}]" + "", url)); @@ -1033,7 +1033,7 @@ public class HttpUtils { builder.setCharset(StandardCharsets.UTF_8); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); Long totalSize = 0L; - for (MultipartFile multipartFile : multipartFileList) { + for (HttpMultipartFile multipartFile : multipartFileList) { log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb", multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize())); totalSize += multipartFile.getFileSize(); @@ -1068,7 +1068,7 @@ public class HttpUtils { * @param headers 请求头信息 * @return 返回httpPost */ - private HttpPut uploadFileByInputStreamPut(String url, List multipartFileList, + private HttpPut uploadFileByInputStreamPut(String url, List multipartFileList, Map params, Map headers) { log.info(Util.logStr("start request : url is [{}]" + "", url)); @@ -1082,7 +1082,7 @@ public class HttpUtils { builder.setCharset(StandardCharsets.UTF_8); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); Long totalSize = 0L; - for (MultipartFile multipartFile : multipartFileList) { + for (HttpMultipartFile multipartFile : multipartFileList) { log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb", multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize())); totalSize += multipartFile.getFileSize(); diff --git a/src/main/java/aiyh/utils/mapper/UtilMapper.java b/src/main/java/aiyh/utils/mapper/UtilMapper.java index 6cfc53d..1c7887f 100644 --- a/src/main/java/aiyh/utils/mapper/UtilMapper.java +++ b/src/main/java/aiyh/utils/mapper/UtilMapper.java @@ -33,7 +33,7 @@ public interface UtilMapper { * @param onlyMark 唯一标识 * @return 参数值 */ - @Select("select param_value from $t{cusConfigTableName} where only_mark = #{onlyMark} and enable_param = 1") + @Select("select param_value from $t{configTableName} where only_mark = #{onlyMark} and enable_param = 1") public String selectCusConfigParam(@ParamMapper("onlyMark") String onlyMark, @ParamMapper("configTableName") String cusConfigTableName); diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 6e93f55..5caff6a 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -1,11 +1,19 @@ package youhong.ai.pcn; +import aiyh.utils.httpUtil.HttpMultipartFile; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; import basetest.BaseTest; import com.alibaba.fastjson.JSON; +import com.fasterxml.jackson.core.JsonProcessingException; import ebu7common.youhong.ai.bean.Builder; import ebu7common.youhong.ai.sftp.SftpConnectUtil; import org.junit.Test; +import weaver.conn.RecordSet; import weaver.general.GCONST; +import weaver.xiao.commons.config.entity.MultipartFile; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.service.DealWithMapping; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Department; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Employee; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position; @@ -15,10 +23,7 @@ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -75,6 +80,50 @@ public class TestOrganization extends BaseTest { System.out.println(build); } + @Test + public void testUpload() { + HttpUtils httpUtils = new HttpUtils(); + //TODO 设置签名 + DealWithMapping dealWithMapping = new DealWithMapping(); + dealWithMapping.setMainTable("mainTable"); + RequestMappingConfig unique = dealWithMapping.treeDealWithUniqueCode("unique"); + // 获取到请求参数,不包含文件流数据 + Map requestParam = dealWithMapping.getRequestParam(new RecordSet(), unique); + //获取到对应的附件 + List multipartFileList = dealWithMapping.getMultipartFileList(); + for (MultipartFile multipartFile : multipartFileList) { + // faqingqiu + HttpMultipartFile file = new HttpMultipartFile(); + file.setFileKey(multipartFile.getFileKey()); + file.setFileName(multipartFile.getFileName()); + file.setStream(multipartFile.getStream()); + file.setFileSize(multipartFile.getFileSize()); + HttpMultipartFile build = Builder.builder(HttpMultipartFile::new) + .with(HttpMultipartFile::setFileKey, multipartFile.getFileKey()) + .with(HttpMultipartFile::setFileName, multipartFile.getFileName()) + .with(HttpMultipartFile::setFileSize, multipartFile.getFileSize()) + .with(HttpMultipartFile::setStream, multipartFile.getStream()) + .build(); + //BeanUtils.copyProperties(file,);// + ResponeVo responeVo = null; + try { + responeVo = httpUtils.apiUploadFiles(unique.getRequestUrl(), + Collections.singletonList(file), requestParam, new HashMap<>()); + } catch (IOException e) { + throw new RuntimeException(e); + } + if (responeVo.getCode() == 200) { + // TODO success + } + try { + Map entityMap = responeVo.getEntityMap(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + // 响应的数据 + } + + } @Test public void testReadCsv() {