|
@@ -498,12 +498,14 @@ module.exports = app => {
|
|
|
const postData2 = {
|
|
|
requestJson: JSON.stringify(data.requestJson),
|
|
|
};
|
|
|
- const result2 = await ctx.helper.sendMoreRequest(netcaSignApi + '/assemblyPdf', postData2, 'POST');
|
|
|
- console.log(result2);
|
|
|
+
|
|
|
+ const result3 = await this.roundNetcaSign(ctx, postData2);
|
|
|
+ // const result2 = await ctx.helper.sendMoreRequest(netcaSignApi + '/assemblyPdf', postData2, 'POST');
|
|
|
// 上传到oss
|
|
|
- if (result2.code === 0) {
|
|
|
- const result3 = await ctx.helper.sendMoreRequest(netcaSignApi + result2.data);
|
|
|
- const oss_reuslt = await ctx.oss.put('archive/sign/' + data.requestJson.fileName + '.PDF', result3);
|
|
|
+ // console.log(result3);
|
|
|
+ if (result3.code === 0) {
|
|
|
+ // const result3 = await ctx.helper.sendMoreRequest(netcaSignApi + result2.data);
|
|
|
+ const oss_reuslt = await ctx.oss.put('archive/sign/' + data.requestJson.fileName + '.PDF', result3.data);
|
|
|
if (oss_reuslt && oss_reuslt.res && oss_reuslt.res.status === 200) {
|
|
|
if (data.end) {
|
|
|
const versionId = oss_reuslt.res.headers['x-oss-version-id'];
|
|
@@ -517,6 +519,8 @@ module.exports = app => {
|
|
|
} else {
|
|
|
throw '上传文件失败';
|
|
|
}
|
|
|
+ } else {
|
|
|
+ throw result3.msg;
|
|
|
}
|
|
|
break;
|
|
|
// 移除签名和已签移除pdf
|
|
@@ -544,6 +548,37 @@ module.exports = app => {
|
|
|
|
|
|
ctx.body = response;
|
|
|
}
|
|
|
+
|
|
|
+ async roundNetcaSign(ctx, postData2, round = 3) {
|
|
|
+ let response = {
|
|
|
+ code: 0,
|
|
|
+ data: '',
|
|
|
+ };
|
|
|
+ // 无法获取到result3,因为result2生成的pdf已损坏,请重复获取result2,直到获取成功或尝试3次失败后报错为止
|
|
|
+ try {
|
|
|
+ const netcaSignApi = signConst.path.api;
|
|
|
+ const result2 = await ctx.helper.sendMoreRequest(netcaSignApi + '/assemblyPdf', postData2, 'POST');
|
|
|
+ if (result2.code === 0) {
|
|
|
+ const result3 = await ctx.curl(netcaSignApi + result2.data, {
|
|
|
+ timeout: 30000,
|
|
|
+ });
|
|
|
+ if (result3) {
|
|
|
+ response.data = result3.data;
|
|
|
+ } else {
|
|
|
+ if (round > 0) {
|
|
|
+ round = round - 1;
|
|
|
+ response = await this.roundNetcaSign(ctx, postData2, round);
|
|
|
+ } else {
|
|
|
+ throw 'pdf获取失败,网证通接口无法生成pdf';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ response.code = 1;
|
|
|
+ response.msg = error;
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
}
|
|
|
return ReportArchiveController;
|
|
|
};
|