|
@@ -14,10 +14,46 @@ if(!fs.existsSync(TemplateDocxPath)){
|
|
|
导出流程
|
|
|
curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http://127.0.0.1:61337/parse/functions/tbookExportReport
|
|
|
curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http://8.140.98.43/parse/functions/tbookExportReport
|
|
|
+ curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http://8.140.98.43/parse/api/tbook/export
|
|
|
导出教材列表
|
|
|
curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "bookList": ["9V575dapEM","2YBKitpCJL","xLdiEaHGrX"] }' http://8.140.98.43/parse/functions/tbookExportReport
|
|
|
*/
|
|
|
- export function defineTbookExportReport(){
|
|
|
+ export function defineTbookExportReport(app){
|
|
|
+ app.post("/parse/api/tbook/export",async (request,res)=>{
|
|
|
+ let processId = request.body.processId;
|
|
|
+ let bookList = request.body.bookList;
|
|
|
+ console.log(request.body)
|
|
|
+ try{
|
|
|
+ let result
|
|
|
+ if(processId){
|
|
|
+ result = await exportProcessReportDocs(processId)
|
|
|
+ }
|
|
|
+ if(bookList?.length){
|
|
|
+ result = await exportProcessReportDocs(null,bookList)
|
|
|
+ }
|
|
|
+ if(result?.docsList?.length==0){
|
|
|
+ // throw new Parse.Error(404,"合集内无申报教材")
|
|
|
+ res.json({
|
|
|
+ code:400,
|
|
|
+ err:"合集内无申报教材"
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // return result
|
|
|
+ res.json({
|
|
|
+ code:200,
|
|
|
+ result:result
|
|
|
+ })
|
|
|
+ }catch(err){
|
|
|
+ console.error(err)
|
|
|
+ res.json({
|
|
|
+ code:400,
|
|
|
+ err:err
|
|
|
+ })
|
|
|
+ // throw new Parse.Error(404,"导出申报合集失败")
|
|
|
+ }
|
|
|
+ // throw new Parse.Error(404,"未找到该流程合集")
|
|
|
+
|
|
|
+ })
|
|
|
Parse.Cloud.define("tbookExportReport", async (request) => {
|
|
|
let processId = request.params.processId;
|
|
|
let bookList = request.params.bookList;
|
|
@@ -71,11 +107,20 @@ export async function exportProcessReportDocs(processId,bookList) {
|
|
|
}
|
|
|
|
|
|
let docsList = []
|
|
|
+ let plist = []
|
|
|
for (let index = 0; index < textbookList.length; index++) {
|
|
|
let textbook = textbookList[index];
|
|
|
- let result = await renderReportDocsByTextbook(textbook);
|
|
|
- docsList.push(result)
|
|
|
+ console.log("textbook",index)
|
|
|
+ // 直接将异步调用的 Promise 添加到 plist
|
|
|
+ plist.push(renderReportDocsByTextbook(textbook)); // 立即执行并返回 Promise
|
|
|
}
|
|
|
+ let presults = await Promise.all(plist);
|
|
|
+ presults.forEach(result=>{
|
|
|
+ if(result?.filePath){
|
|
|
+ docsList.push(result)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
let zipPath,zipUrl
|
|
|
if(docsList?.length){
|
|
|
let now = new Date();
|
|
@@ -98,6 +143,7 @@ export async function exportProcessReportDocs(processId,bookList) {
|
|
|
module.exports.exportProcessReportDocs = exportProcessReportDocs
|
|
|
|
|
|
function renderReportDocsByTextbook(textbook){
|
|
|
+ console.log("renderReportDocsByTextbook")
|
|
|
let json = textbook.toJSON();
|
|
|
// console.log(json)
|
|
|
// 圆圈选中未选 ○ 未选 ● 选中
|
|
@@ -292,15 +338,26 @@ function renderReportDocsByTextbook(textbook){
|
|
|
let bookid = json.code || json?.objectId;
|
|
|
let tempFileName = path.join(`${bookid}${json.title}.docx`)
|
|
|
return new Promise(async (resolve)=>{
|
|
|
- let filePath = renderDocx(TemplateDocxPath,tempFileName,bookData)
|
|
|
- // 需要API支持
|
|
|
- let pdfPath = filePath.replaceAll(".docx",".pdf")
|
|
|
- let options = {
|
|
|
- mergeFiles:mergeFiles
|
|
|
+ let filePath,pdfPath,urlDocx,urlPdf
|
|
|
+ try{
|
|
|
+ // DOCX模板合成 速度2-3秒
|
|
|
+ filePath = renderDocx(TemplateDocxPath,tempFileName,bookData)
|
|
|
+ urlDocx = (await uploadFileToOSS(filePath))?.url || null
|
|
|
+ console.log("DOCX CREATED:",filePath)
|
|
|
+
|
|
|
+ // PDF文档拼接 速度10-30s 需要API支持
|
|
|
+ pdfPath = filePath.replaceAll(".docx",".pdf")
|
|
|
+ let options = {
|
|
|
+ mergeFiles:mergeFiles
|
|
|
+ }
|
|
|
+ pdfPath = await docxToPdf(filePath,pdfPath,options) || filePath // 成功用pdf,失败继续用docx
|
|
|
+ console.log("PDF CREATED:",filePath)
|
|
|
+ if(pdfPath){
|
|
|
+ urlPdf = (await uploadFileToOSS(pdfPath))?.url || null
|
|
|
+ }
|
|
|
+ }catch(err){
|
|
|
+ console.error(err)
|
|
|
}
|
|
|
- pdfPath = await docxToPdf(filePath,pdfPath,options) || filePath // 成功用pdf,失败继续用docx
|
|
|
- let urlDocx = (await uploadFileToOSS(filePath))?.url || null
|
|
|
- let urlPdf = (await uploadFileToOSS(pdfPath))?.url || null
|
|
|
resolve({
|
|
|
code:bookid,
|
|
|
title:json?.title,
|