发起资质审核时的关系证明文件上传MDM
This commit is contained in:
@@ -4,12 +4,13 @@ import com.aliyun.oss.ClientException;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.OSSException;
|
||||
import com.aliyun.oss.model.OSSObject;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -65,4 +66,51 @@ public class OSSServer {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端下载文件到内存流
|
||||
* @param objectName 自定义路径 + 文件名
|
||||
*/
|
||||
public ByteArrayOutputStream downloadFileServer(String objectName) throws IOException {
|
||||
// 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
|
||||
OSSObject ossObject = ossClient.getObject(bucket, "partner/" + corpId + "/" + objectName);
|
||||
|
||||
// 读取文件内容转为 ByteArrayInputStream
|
||||
InputStream objectInputstream = ossObject.getObjectContent();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = objectInputstream.read(buffer)) != -1 ) {
|
||||
outputStream.write(buffer, 0, len);
|
||||
}
|
||||
outputStream.flush();
|
||||
byte[] byteArray = outputStream.toByteArray();
|
||||
|
||||
// ossObject对象使用完毕后必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
ossObject.close();
|
||||
|
||||
} catch (OSSException oe) {
|
||||
log.error("Caught an OSSException, which means your request made it to OSS, "
|
||||
+ "but was rejected with an error response for some reason.");
|
||||
log.error("Error Message:" + oe.getErrorMessage());
|
||||
log.error("Error Code:" + oe.getErrorCode());
|
||||
log.error("Request ID:" + oe.getRequestId());
|
||||
log.error("Host ID:" + oe.getHostId());
|
||||
} catch (Throwable ce) {
|
||||
log.error("Caught an ClientException, which means the client encountered "
|
||||
+ "a serious internal problem while trying to communicate with OSS, "
|
||||
+ "such as not being able to access the network.");
|
||||
log.error("Error Message:" + ce.getMessage());
|
||||
} finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
outputStream.close();
|
||||
}
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@ import com.cool.store.exception.ApiException;
|
||||
import com.cool.store.request.CreateQualifyVerifyReq;
|
||||
import com.cool.store.request.QualificationCallbackReq;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Author: young.yu
|
||||
* @Date: 2023-06-14 13:51
|
||||
* @Description:
|
||||
*/
|
||||
public interface FlowService {
|
||||
void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException;
|
||||
void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException, IOException;
|
||||
|
||||
void qualificationCallback(QualificationCallbackReq request);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.HyInterviewDAO;
|
||||
import com.cool.store.dto.mdm.AccessTokenDTO;
|
||||
@@ -24,6 +25,7 @@ import com.cool.store.request.QualificationCallbackReq;
|
||||
import com.cool.store.request.RpcCreateQualifyVerifyReq;
|
||||
import com.cool.store.request.RpcGetMdmTokenReq;
|
||||
import com.cool.store.request.data.flow.KeyText;
|
||||
import com.cool.store.request.data.flow.SkrRelshipProve;
|
||||
import com.cool.store.service.FlowService;
|
||||
import com.cool.store.utils.PDFUtils;
|
||||
import com.cool.store.utils.PassLetterUtils;
|
||||
@@ -33,12 +35,17 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -85,10 +92,10 @@ public class FlowServiceImpl implements FlowService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException {
|
||||
public void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException, IOException {
|
||||
//1.发起加盟商资质审核
|
||||
RpcCreateQualifyVerifyReq rpcRequest = new RpcCreateQualifyVerifyReq();
|
||||
RpcCreateQualifyVerifyReq.Data dataBody = rpcRequest.getData();
|
||||
RpcCreateQualifyVerifyReq.Data dataBody = new RpcCreateQualifyVerifyReq().new Data();
|
||||
KeyText fraSource = new KeyText();
|
||||
fraSource.setKey("HSAYPartner");
|
||||
fraSource.setText("沪上阿姨合伙人");
|
||||
@@ -135,6 +142,12 @@ public class FlowServiceImpl implements FlowService {
|
||||
|
||||
}
|
||||
//通过 rpc 请求审核系统获取返回数据
|
||||
//上传证明文件数据
|
||||
if (StringUtils.isNotEmpty(request.getSignerRealControlRelationCert())) {
|
||||
List<String> certFileList = Arrays.asList(request.getSignerRealControlRelationCert().split(","));
|
||||
List<SkrRelshipProve> relshipProves = OSSFileToMDMFile(certFileList);
|
||||
rpcRequest.getData().setSkrRelshipProve(relshipProves);
|
||||
}
|
||||
Map<String, String> qualifyVerifyRespData = JSON.parseObject(createQualifyVerify(rpcRequest), new TypeReference<HashMap<String,String>>() {});
|
||||
|
||||
//2.更新审核信息
|
||||
@@ -230,6 +243,50 @@ public class FlowServiceImpl implements FlowService {
|
||||
}
|
||||
}
|
||||
|
||||
public List<SkrRelshipProve> OSSFileToMDMFile(List<String> fileUrlList) throws ApiException, IOException {
|
||||
String url = mdmBaseUrl + "/api/openapi/ext/upload/file";
|
||||
ResponseEntity<MDMResultDTO> responseEntity = null;
|
||||
RpcGetMdmTokenReq rpcGetMDMTokenReq = new RpcGetMdmTokenReq();
|
||||
rpcGetMDMTokenReq.setAppKey(mdmAppKey);
|
||||
rpcGetMDMTokenReq.setAppSecret(mdmAppSec);
|
||||
ByteArrayOutputStream outputStream = null;
|
||||
List<SkrRelshipProve> relshipProves = new ArrayList<>();
|
||||
|
||||
//逐个处理文件
|
||||
for (String fileUrl : fileUrlList) {
|
||||
//1. 获取 OSS 下载的文件流
|
||||
String fileName = fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
|
||||
outputStream = ossServer.downloadFileServer(fileName);
|
||||
//2. 将下载到的文件上传到 MDM 系统中
|
||||
try {
|
||||
//获取 token 设置到 header
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", getMdmAccessToken(rpcGetMDMTokenReq));
|
||||
//将文件流编辑为 formdata 格式的数据
|
||||
MultiValueMap<String,Object> param = new LinkedMultiValueMap<>();
|
||||
ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray()) {
|
||||
@Override
|
||||
public String getFilename() throws IllegalStateException {
|
||||
return fileName;
|
||||
}
|
||||
};
|
||||
param.add("file", resource);
|
||||
//上传文件
|
||||
responseEntity = RestTemplateUtil.post(url, headers, param, MDMResultDTO.class);
|
||||
log.info("url:{}, header:{}, request:{} response statusCode:{}", url, JSONObject.toJSONString(headers), JSONObject.toJSONString(param, SerializerFeature.IgnoreErrorGetter), JSONObject.toJSONString(responseEntity.getStatusCode()));
|
||||
Map<String, String> data = (Map<String, String>) responseEntity.getBody().getData();
|
||||
SkrRelshipProve skrRelshipProve= BeanUtil.fillBeanWithMap(data, new SkrRelshipProve(), false);
|
||||
relshipProves.add(skrRelshipProve);
|
||||
} catch (Exception e) {
|
||||
log.info("调用MDM接口出错{}", e.getMessage());
|
||||
throw new ApiException(e.getMessage());
|
||||
} finally {
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
return relshipProves;
|
||||
}
|
||||
|
||||
public String createQualifyVerify(RpcCreateQualifyVerifyReq rpcRequest) throws ApiException{
|
||||
String url = mdmBaseUrl + "/api/openapi/runtime/form/startFraQualExamWithData";
|
||||
|
||||
Reference in New Issue
Block a user