修改附件上传类名称

main
youHong.ai 2022-12-01 10:28:48 +08:00
parent 98923a4b27
commit ff371a3cc9
4 changed files with 63 additions and 49 deletions

View File

@ -1,35 +0,0 @@
package aiyh.utils.httpUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.InputStream;
/**
* <h1></h1>
*
* <p>create: 2022-11-21 11:54</p>
*
* @author youHong.ai
*/
@Setter
@Getter
@ToString
public class MultipartFile {
/**
*
*/
String fileName;
/**
* key
*/
String fileKey;
/**
*
*/
InputStream stream;
Long fileSize;
}

View File

@ -439,7 +439,7 @@ public class HttpUtils {
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
Map<String, Object> paramsMap = paramsHandle(params);
Map<String, String> 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<MultipartFile> multipartFileList, Map<String, Object> params,
public ResponeVo apiUploadFiles(String url, List<HttpMultipartFile> multipartFileList, Map<String, Object> params,
Map<String, String> headers) throws IOException {
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
Map<String, Object> paramsMap = paramsHandle(params);
@ -479,7 +479,7 @@ public class HttpUtils {
* @return
* @throws IOException Io
*/
public ResponeVo apiPutUploadFiles(String url, List<MultipartFile> multipartFileList, Map<String, Object> params,
public ResponeVo apiPutUploadFiles(String url, List<HttpMultipartFile> multipartFileList, Map<String, Object> params,
Map<String, String> headers) throws IOException {
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
Map<String, Object> paramsMap = paramsHandle(params);
@ -505,7 +505,7 @@ public class HttpUtils {
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
Map<String, Object> paramsMap = paramsHandle(params);
Map<String, String> 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<String, Object> paramsMap = paramsHandle(params);
Map<String, String> 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<MultipartFile> multipartFileList,
private HttpPost uploadFileByInputStream(String url, List<HttpMultipartFile> multipartFileList,
Map<String, Object> params, Map<String, String> 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<MultipartFile> multipartFileList,
private HttpPut uploadFileByInputStreamPut(String url, List<HttpMultipartFile> multipartFileList,
Map<String, Object> params, Map<String, String> 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();

View File

@ -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);

View File

@ -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<String, Object> requestParam = dealWithMapping.getRequestParam(new RecordSet(), unique);
//获取到对应的附件
List<MultipartFile> 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<String, Object> entityMap = responeVo.getEntityMap();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
// 响应的数据
}
}
@Test
public void testReadCsv() {