|
@@ -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:
|
|
|
curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http:
|
|
|
+ curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "FR7KZtefyR" }' http:
|
|
|
导出教材列表
|
|
|
curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "bookList": ["9V575dapEM","2YBKitpCJL","xLdiEaHGrX"] }' http:
|
|
|
*/
|
|
|
- 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){
|
|
|
+
|
|
|
+ res.json({
|
|
|
+ code:400,
|
|
|
+ err:"合集内无申报教材"
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ res.json({
|
|
|
+ code:200,
|
|
|
+ result:result
|
|
|
+ })
|
|
|
+ }catch(err){
|
|
|
+ console.error(err)
|
|
|
+ res.json({
|
|
|
+ code:400,
|
|
|
+ err:err
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ })
|
|
|
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)
|
|
|
+
|
|
|
+ plist.push(renderReportDocsByTextbook(textbook));
|
|
|
}
|
|
|
+ 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();
|
|
|
|
|
|
|
|
@@ -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)
|
|
|
-
|
|
|
- let pdfPath = filePath.replaceAll(".docx",".pdf")
|
|
|
- let options = {
|
|
|
- mergeFiles:mergeFiles
|
|
|
+ let filePath,pdfPath,urlDocx,urlPdf
|
|
|
+ try{
|
|
|
+
|
|
|
+ filePath = renderDocx(TemplateDocxPath,tempFileName,bookData)
|
|
|
+ urlDocx = (await uploadFileToOSS(filePath))?.url || null
|
|
|
+ console.log("DOCX CREATED:",filePath)
|
|
|
+
|
|
|
+
|
|
|
+ pdfPath = filePath.replaceAll(".docx",".pdf")
|
|
|
+ let options = {
|
|
|
+ mergeFiles:mergeFiles
|
|
|
+ }
|
|
|
+ pdfPath = await docxToPdf(filePath,pdfPath,options) || filePath
|
|
|
+ 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
|
|
|
- let urlDocx = (await uploadFileToOSS(filePath))?.url || null
|
|
|
- let urlPdf = (await uploadFileToOSS(pdfPath))?.url || null
|
|
|
resolve({
|
|
|
code:bookid,
|
|
|
title:json?.title,
|