修改附件上传类名称
parent
98923a4b27
commit
ff371a3cc9
|
@ -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;
|
|
||||||
}
|
|
|
@ -439,7 +439,7 @@ public class HttpUtils {
|
||||||
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
||||||
Map<String, Object> paramsMap = paramsHandle(params);
|
Map<String, Object> paramsMap = paramsHandle(params);
|
||||||
Map<String, String> headerMap = headersHandle(headers);
|
Map<String, String> headerMap = headersHandle(headers);
|
||||||
MultipartFile multipartFile = new MultipartFile();
|
HttpMultipartFile multipartFile = new HttpMultipartFile();
|
||||||
multipartFile.setFileName(fileName);
|
multipartFile.setFileName(fileName);
|
||||||
multipartFile.setFileKey(fileKey);
|
multipartFile.setFileKey(fileKey);
|
||||||
multipartFile.setStream(inputStream);
|
multipartFile.setStream(inputStream);
|
||||||
|
@ -459,7 +459,7 @@ public class HttpUtils {
|
||||||
* @return 响应数
|
* @return 响应数
|
||||||
* @throws IOException Io异常
|
* @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 {
|
Map<String, String> headers) throws IOException {
|
||||||
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
||||||
Map<String, Object> paramsMap = paramsHandle(params);
|
Map<String, Object> paramsMap = paramsHandle(params);
|
||||||
|
@ -479,7 +479,7 @@ public class HttpUtils {
|
||||||
* @return 响应数
|
* @return 响应数
|
||||||
* @throws IOException Io异常
|
* @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 {
|
Map<String, String> headers) throws IOException {
|
||||||
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
||||||
Map<String, Object> paramsMap = paramsHandle(params);
|
Map<String, Object> paramsMap = paramsHandle(params);
|
||||||
|
@ -505,7 +505,7 @@ public class HttpUtils {
|
||||||
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
CloseableHttpClient httpConnection = HttpManager.getHttpConnection(url, this.credentialsProvider);
|
||||||
Map<String, Object> paramsMap = paramsHandle(params);
|
Map<String, Object> paramsMap = paramsHandle(params);
|
||||||
Map<String, String> headerMap = headersHandle(headers);
|
Map<String, String> headerMap = headersHandle(headers);
|
||||||
MultipartFile multipartFile = new MultipartFile();
|
HttpMultipartFile multipartFile = new HttpMultipartFile();
|
||||||
multipartFile.setFileName(fileName);
|
multipartFile.setFileName(fileName);
|
||||||
multipartFile.setFileKey(fileKey);
|
multipartFile.setFileKey(fileKey);
|
||||||
multipartFile.setStream(inputStream);
|
multipartFile.setStream(inputStream);
|
||||||
|
@ -554,7 +554,7 @@ public class HttpUtils {
|
||||||
Map<String, Object> paramsMap = paramsHandle(params);
|
Map<String, Object> paramsMap = paramsHandle(params);
|
||||||
Map<String, String> headerMap = headersHandle(headers);
|
Map<String, String> headerMap = headersHandle(headers);
|
||||||
InputStream inputStream = ImageFileManager.getInputStreamById(id);
|
InputStream inputStream = ImageFileManager.getInputStreamById(id);
|
||||||
MultipartFile multipartFile = new MultipartFile();
|
HttpMultipartFile multipartFile = new HttpMultipartFile();
|
||||||
multipartFile.setFileName(fileName);
|
multipartFile.setFileName(fileName);
|
||||||
multipartFile.setFileKey(fileKey);
|
multipartFile.setFileKey(fileKey);
|
||||||
multipartFile.setStream(inputStream);
|
multipartFile.setStream(inputStream);
|
||||||
|
@ -1019,7 +1019,7 @@ public class HttpUtils {
|
||||||
* @param headers 请求头信息
|
* @param headers 请求头信息
|
||||||
* @return 返回httpPost
|
* @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) {
|
Map<String, Object> params, Map<String, String> headers) {
|
||||||
log.info(Util.logStr("start request : url is [{}]" +
|
log.info(Util.logStr("start request : url is [{}]" +
|
||||||
"", url));
|
"", url));
|
||||||
|
@ -1033,7 +1033,7 @@ public class HttpUtils {
|
||||||
builder.setCharset(StandardCharsets.UTF_8);
|
builder.setCharset(StandardCharsets.UTF_8);
|
||||||
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
|
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
|
||||||
Long totalSize = 0L;
|
Long totalSize = 0L;
|
||||||
for (MultipartFile multipartFile : multipartFileList) {
|
for (HttpMultipartFile multipartFile : multipartFileList) {
|
||||||
log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
|
log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
|
||||||
multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize()));
|
multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize()));
|
||||||
totalSize += multipartFile.getFileSize();
|
totalSize += multipartFile.getFileSize();
|
||||||
|
@ -1068,7 +1068,7 @@ public class HttpUtils {
|
||||||
* @param headers 请求头信息
|
* @param headers 请求头信息
|
||||||
* @return 返回httpPost
|
* @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) {
|
Map<String, Object> params, Map<String, String> headers) {
|
||||||
log.info(Util.logStr("start request : url is [{}]" +
|
log.info(Util.logStr("start request : url is [{}]" +
|
||||||
"", url));
|
"", url));
|
||||||
|
@ -1082,7 +1082,7 @@ public class HttpUtils {
|
||||||
builder.setCharset(StandardCharsets.UTF_8);
|
builder.setCharset(StandardCharsets.UTF_8);
|
||||||
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
|
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
|
||||||
Long totalSize = 0L;
|
Long totalSize = 0L;
|
||||||
for (MultipartFile multipartFile : multipartFileList) {
|
for (HttpMultipartFile multipartFile : multipartFileList) {
|
||||||
log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
|
log.info(Util.logStr("add file: fileName => [{}], fileKey => [{}], fileSize => [{}]kb",
|
||||||
multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize()));
|
multipartFile.getFileName(), multipartFile.getFileKey(), multipartFile.getFileSize()));
|
||||||
totalSize += multipartFile.getFileSize();
|
totalSize += multipartFile.getFileSize();
|
||||||
|
|
|
@ -33,7 +33,7 @@ public interface UtilMapper {
|
||||||
* @param onlyMark 唯一标识
|
* @param onlyMark 唯一标识
|
||||||
* @return 参数值
|
* @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,
|
public String selectCusConfigParam(@ParamMapper("onlyMark") String onlyMark,
|
||||||
@ParamMapper("configTableName") String cusConfigTableName);
|
@ParamMapper("configTableName") String cusConfigTableName);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
package youhong.ai.pcn;
|
package youhong.ai.pcn;
|
||||||
|
|
||||||
|
import aiyh.utils.httpUtil.HttpMultipartFile;
|
||||||
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
|
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||||
import basetest.BaseTest;
|
import basetest.BaseTest;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import ebu7common.youhong.ai.bean.Builder;
|
import ebu7common.youhong.ai.bean.Builder;
|
||||||
import ebu7common.youhong.ai.sftp.SftpConnectUtil;
|
import ebu7common.youhong.ai.sftp.SftpConnectUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import weaver.conn.RecordSet;
|
||||||
import weaver.general.GCONST;
|
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.Department;
|
||||||
import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Employee;
|
import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Employee;
|
||||||
import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position;
|
import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position;
|
||||||
|
@ -15,10 +23,7 @@ import java.io.BufferedReader;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -75,6 +80,50 @@ public class TestOrganization extends BaseTest {
|
||||||
System.out.println(build);
|
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
|
@Test
|
||||||
public void testReadCsv() {
|
public void testReadCsv() {
|
||||||
|
|
Loading…
Reference in New Issue