|
@@ -1,4 +1,4 @@
|
|
|
-import { replaceDocx, createZip, uploadFileToOSS, docxToPdf, renderDocx, toBarCode } from "../../lib/docs";
|
|
|
+import { replaceDocx, createZip, uploadFileToOSS, docxToPdf, renderDocx, toBarCode, downloadUrl } from "../../lib/docs";
|
|
|
// const Parse = global.Parse;
|
|
|
|
|
|
const path = require("path")
|
|
@@ -9,7 +9,7 @@ if(!fs.existsSync(TemplateDocxDir)){
|
|
|
}
|
|
|
const tempDir = path.join(__dirname , "temp");
|
|
|
|
|
|
-
|
|
|
+const crypto = require('crypto');
|
|
|
|
|
|
/**
|
|
|
* 常用Word字符
|
|
@@ -202,8 +202,9 @@ export async function exportProcessReportDocs(processId,bookList) {
|
|
|
plist.push(renderReportDocsByTextbook(textbook)); // 立即执行并返回 Promise
|
|
|
}
|
|
|
let presults = await Promise.all(plist);
|
|
|
+ console.log(presults)
|
|
|
presults.forEach(result=>{
|
|
|
- if(result?.filePath){
|
|
|
+ if(result?.filePath || result?.pdfPath){
|
|
|
docsList.push(result)
|
|
|
}
|
|
|
})
|
|
@@ -212,7 +213,10 @@ export async function exportProcessReportDocs(processId,bookList) {
|
|
|
if(docsList?.length){
|
|
|
let now = new Date();
|
|
|
let fileList = docsList?.map(item=>item?.pdfPath);
|
|
|
- let zipName = `申报书导出-${now.getFullYear()}${now.getMonth()+1}${now.getDate()}-${now.getHours()}${now.getMinutes()}${now.getSeconds()}.zip`
|
|
|
+ // zip包md5生成
|
|
|
+ let md5 = crypto.createHash('md5');
|
|
|
+ let fileListMd5 = md5.update(fileList?.join("")).digest('hex')
|
|
|
+ let zipName = `申报书导出-${now.getFullYear()}${now.getMonth()+1}${now.getDate()}${now.getHours()}${now.getMinutes()}${now.getSeconds()}${now.getMilliseconds()}-${fileListMd5}.zip`
|
|
|
zipPath = await createZip(fileList,zipName,{tempDir:null})
|
|
|
if(zipPath){
|
|
|
zipUrl = (await uploadFileToOSS(zipPath))?.url || null
|
|
@@ -222,7 +226,7 @@ export async function exportProcessReportDocs(processId,bookList) {
|
|
|
fs.rmSync(path.dirname(tempFile),{recursive:true,force:true});
|
|
|
})
|
|
|
}
|
|
|
- docsList = docsList.map(item=>{return {code:item.code,title:item.title,url:item?.url,urlPdf:item?.urlPdf}})
|
|
|
+ docsList = docsList.map(item=>{return {code:item.code,objectId:item?.objectId,title:item.title,url:item?.url,urlPdf:item?.urlPdf}})
|
|
|
}
|
|
|
|
|
|
let result = {
|
|
@@ -415,13 +419,30 @@ function pushDistinctItem(list,item){
|
|
|
return list
|
|
|
}
|
|
|
function renderReportDocsByTextbook(textbook){
|
|
|
+
|
|
|
console.log("renderReportDocsByTextbook")
|
|
|
return new Promise(async (resolve)=>{
|
|
|
+
|
|
|
let json = textbook.toJSON();
|
|
|
json.hasNoSign = false; // 未上传作者签名
|
|
|
json.hasNoUnit = false; // 未上传单位资料
|
|
|
json.hasNoNine = false; // 无需添加滞后九
|
|
|
- let bookid = json.code || json?.objectId;
|
|
|
+ let bookid = json.code || json?.objectId;
|
|
|
+
|
|
|
+ let exportPDF = textbook.get("exportPDF");
|
|
|
+ if(exportPDF){
|
|
|
+ // console.log(exportPDF)
|
|
|
+ let exportPath = await downloadUrl(exportPDF,{tempDir:path.join(tempDir,textbook.id),keepFileName:true});
|
|
|
+ // console.log(exportPath)
|
|
|
+ resolve({
|
|
|
+ code:bookid,
|
|
|
+ objectId:textbook.id,
|
|
|
+ title:json?.title,
|
|
|
+ pdfPath:exportPath,
|
|
|
+ urlPdf:exportPDF,
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
// 默认单册为第一分册
|
|
|
let book1Data = json?.childrens?.[0]
|
|
@@ -534,7 +555,7 @@ function renderReportDocsByTextbook(textbook){
|
|
|
}
|
|
|
|
|
|
|
|
|
- let bookTempDir = path.join(tempDir,bookid)
|
|
|
+ let bookTempDir = path.join(tempDir,json?.objectId)
|
|
|
if(!fs.existsSync(bookTempDir)) fs.mkdirSync(bookTempDir)
|
|
|
|
|
|
|
|
@@ -629,9 +650,9 @@ function renderReportDocsByTextbook(textbook){
|
|
|
|
|
|
// mergeFiles 处理七八九是否签名或后置问题
|
|
|
let lastPageList = []
|
|
|
- let docx7 = await getPageDocx(bookid,"七",bookData);
|
|
|
- let docx8 = await getPageDocx(bookid,"八",bookData);
|
|
|
- let docx9 = await getPageDocx(bookid,"九",bookData);
|
|
|
+ let docx7 = await getPageDocx(json?.objectId,bookid,"七",bookData);
|
|
|
+ let docx8 = await getPageDocx(json?.objectId,bookid,"八",bookData);
|
|
|
+ let docx9 = await getPageDocx(json?.objectId,bookid,"九",bookData);
|
|
|
lastPageList.push(json?.authorSignPDF?.url||docx7);
|
|
|
lastPageList.push(json?.unitMaterial?.url||docx8);
|
|
|
lastPageList.push(docx9);
|
|
@@ -668,13 +689,18 @@ function renderReportDocsByTextbook(textbook){
|
|
|
pdfPath = await docxToPdf(filePath,pdfPath,options) || filePath // 成功用pdf,失败继续用docx
|
|
|
console.log("PDF CREATED:",filePath)
|
|
|
if(pdfPath){
|
|
|
- urlPdf = (await uploadFileToOSS(pdfPath))?.url || null
|
|
|
+ urlPdf = (await uploadFileToOSS(pdfPath,json?.objectId))?.url || null
|
|
|
+ if(urlPdf){
|
|
|
+ textbook.set("exportPDF",urlPdf);
|
|
|
+ textbook.save();
|
|
|
+ }
|
|
|
}
|
|
|
}catch(err){
|
|
|
console.error(err)
|
|
|
}
|
|
|
resolve({
|
|
|
code:bookid,
|
|
|
+ objectId:json?.objectId,
|
|
|
title:json?.title,
|
|
|
filePath,
|
|
|
pdfPath,
|
|
@@ -685,10 +711,10 @@ function renderReportDocsByTextbook(textbook){
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-async function getPageDocx(bookid,pageName,bookData){
|
|
|
+async function getPageDocx(objectId,bookid,pageName,bookData){
|
|
|
let tplPath = path.join(TemplateDocxDir,`模板-本科教材申报书-${pageName}.docx`);
|
|
|
let title = bookData?.title?.replaceAll("/","")
|
|
|
- let tempFileName = path.join(`${bookid}_${title}_申报书及附件_${pageName}.docx`);
|
|
|
+ let tempFileName = path.join(objectId,`${bookid}_${title}_申报书及附件_${pageName}.docx`);
|
|
|
let filePath = renderDocx(tplPath,tempFileName,bookData);
|
|
|
return filePath;
|
|
|
// 转pdf
|