发起资质审核时的关系证明文件上传MDM

This commit is contained in:
pserimal
2023-06-27 18:58:01 +08:00
parent 945616ae0c
commit 15f3b74416
9 changed files with 153 additions and 8 deletions

View File

@@ -0,0 +1,24 @@
package com.cool.store.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ApprovalRegionDO {
@ApiModelProperty("id")
private Integer id;
@ApiModelProperty("业务对象ID")
private String instanceId;
@ApiModelProperty("地区编码")
private String code;
@ApiModelProperty("地区名")
private String regionName;
@ApiModelProperty("地区父级编号")
private String parentCode;
}

View File

@@ -0,0 +1,12 @@
package com.cool.store.request;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel
public class MDMUploadFileReq {
}

View File

@@ -4,12 +4,13 @@ import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS; import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException; import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.InputStream; import java.io.*;
@Component @Component
@Slf4j @Slf4j
@@ -65,4 +66,51 @@ public class OSSServer {
} }
return null; 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;
}
} }

View File

@@ -4,13 +4,15 @@ import com.cool.store.exception.ApiException;
import com.cool.store.request.CreateQualifyVerifyReq; import com.cool.store.request.CreateQualifyVerifyReq;
import com.cool.store.request.QualificationCallbackReq; import com.cool.store.request.QualificationCallbackReq;
import java.io.IOException;
/** /**
* @Author: young.yu * @Author: young.yu
* @Date: 2023-06-14 13:51 * @Date: 2023-06-14 13:51
* @Description: * @Description:
*/ */
public interface FlowService { public interface FlowService {
void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException; void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException, IOException;
void qualificationCallback(QualificationCallbackReq request); void qualificationCallback(QualificationCallbackReq request);
} }

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.cool.store.dao.EnterpriseUserDAO; import com.cool.store.dao.EnterpriseUserDAO;
import com.cool.store.dao.HyInterviewDAO; import com.cool.store.dao.HyInterviewDAO;
import com.cool.store.dto.mdm.AccessTokenDTO; 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.RpcCreateQualifyVerifyReq;
import com.cool.store.request.RpcGetMdmTokenReq; import com.cool.store.request.RpcGetMdmTokenReq;
import com.cool.store.request.data.flow.KeyText; 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.service.FlowService;
import com.cool.store.utils.PDFUtils; import com.cool.store.utils.PDFUtils;
import com.cool.store.utils.PassLetterUtils; import com.cool.store.utils.PassLetterUtils;
@@ -33,12 +35,17 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; 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.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*; import java.util.*;
/** /**
@@ -85,10 +92,10 @@ public class FlowServiceImpl implements FlowService {
@Override @Override
@Transactional @Transactional
public void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException { public void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException, IOException {
//1.发起加盟商资质审核 //1.发起加盟商资质审核
RpcCreateQualifyVerifyReq rpcRequest = new RpcCreateQualifyVerifyReq(); RpcCreateQualifyVerifyReq rpcRequest = new RpcCreateQualifyVerifyReq();
RpcCreateQualifyVerifyReq.Data dataBody = rpcRequest.getData(); RpcCreateQualifyVerifyReq.Data dataBody = new RpcCreateQualifyVerifyReq().new Data();
KeyText fraSource = new KeyText(); KeyText fraSource = new KeyText();
fraSource.setKey("HSAYPartner"); fraSource.setKey("HSAYPartner");
fraSource.setText("沪上阿姨合伙人"); fraSource.setText("沪上阿姨合伙人");
@@ -135,6 +142,12 @@ public class FlowServiceImpl implements FlowService {
} }
//通过 rpc 请求审核系统获取返回数据 //通过 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>>() {}); Map<String, String> qualifyVerifyRespData = JSON.parseObject(createQualifyVerify(rpcRequest), new TypeReference<HashMap<String,String>>() {});
//2.更新审核信息 //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{ public String createQualifyVerify(RpcCreateQualifyVerifyReq rpcRequest) throws ApiException{
String url = mdmBaseUrl + "/api/openapi/runtime/form/startFraQualExamWithData"; String url = mdmBaseUrl + "/api/openapi/runtime/form/startFraQualExamWithData";

View File

@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
/** /**
* @Author: young.yu * @Author: young.yu
* @Date: 2023-06-14 13:47 * @Date: 2023-06-14 13:47
@@ -28,7 +30,7 @@ public class FlowController {
private FlowService flowService; private FlowService flowService;
@PostMapping("/qualifyVerify/create") @PostMapping("/qualifyVerify/create")
@ApiOperation("发起加盟商资质审核") @ApiOperation("发起加盟商资质审核")
public ResponseResult createQualifyVerify(@RequestBody CreateQualifyVerifyReq request) throws ApiException { public ResponseResult createQualifyVerify(@RequestBody CreateQualifyVerifyReq request) throws ApiException, IOException {
flowService.createQualifyVerify(request); flowService.createQualifyVerify(request);
return ResponseResult.success(); return ResponseResult.success();
} }

View File

@@ -71,7 +71,7 @@ xxl.job.executor.logpath = logs/xxl-job/jobhandler
xxl.job.executor.logretentiondays = 3 xxl.job.executor.logretentiondays = 3
xxl.job.accessToken = xxl.job.accessToken =
hs.mdm.baseUrl=http://36.7.115.86:10112/ hs.mdm.baseUrl=http://36.7.115.86:10112
hs.mdm.appkey = HSAYPartner hs.mdm.appkey = HSAYPartner
hs.mdm.appsec = ab39fedb886fa3587c7f517551976de8b2606f5511fd8f8675266825d74c5cd3 hs.mdm.appsec = ab39fedb886fa3587c7f517551976de8b2606f5511fd8f8675266825d74c5cd3

View File

@@ -60,7 +60,7 @@ weixin.appSecret=245a483747e6e9f8762d3e8539cf0318
signKey=77fea013c3a6459685b83c21a2fc3411 signKey=77fea013c3a6459685b83c21a2fc3411
#MDM #MDM
hs.mdm.baseUrl=http://10.56.21.30/ hs.mdm.baseUrl=http://10.56.21.30
hs.mdm.appkey = HSAYPartner hs.mdm.appkey = HSAYPartner
hs.mdm.appsec = ab39fedb886fa3587c7f517551976de8b2606f5511fd8f8675266825d74c5cd3 hs.mdm.appsec = ab39fedb886fa3587c7f517551976de8b2606f5511fd8f8675266825d74c5cd3

View File

@@ -66,7 +66,7 @@ weixin.appSecret=245a483747e6e9f8762d3e8539cf0318
signKey=77fea013c3a6459685b83c21a2fc3411 signKey=77fea013c3a6459685b83c21a2fc3411
#MDM #MDM
hs.mdm.baseUrl=http://10.56.21.30/ hs.mdm.baseUrl=http://10.56.21.30
hs.mdm.appkey = HSAYPartner hs.mdm.appkey = HSAYPartner
hs.mdm.appsec = ab39fedb886fa3587c7f517551976de8b2606f5511fd8f8675266825d74c5cd3 hs.mdm.appsec = ab39fedb886fa3587c7f517551976de8b2606f5511fd8f8675266825d74c5cd3