Ver Fonte

fix: test export.txt to export

ryanemax há 1 mês atrás
pai
commit
ef1c395911

+ 19 - 11
server/cloud/tbook/func-tbook-export.js

@@ -175,7 +175,8 @@ const squareCheck = [`□`,String.fromCharCode(0xFE)];
  * docsList
  * zipUrl
  */
-export async function exportProcessReportDocs(processId,bookList) {
+export async function exportProcessReportDocs(processId,bookList,isNew) {
+    isNew = isNew || false;
     if(!processId && !bookList?.length) return {}
 
     let textbookList
@@ -200,7 +201,7 @@ export async function exportProcessReportDocs(processId,bookList) {
         let textbook = textbookList[index];
         console.log("textbook",index)
         // 直接将异步调用的 Promise 添加到 plist
-        plist.push(renderReportDocsByTextbook(textbook)); // 立即执行并返回 Promise
+        plist.push(renderReportDocsByTextbook(textbook,isNew)); // 立即执行并返回 Promise
     }
     let presults = await Promise.all(plist);
     console.log(presults)
@@ -251,7 +252,7 @@ function fixVolumeData(json,volumeData,index,totalJson,isChildren){
     let majorCode4 = volumeData?.majorPoniter?.code?.slice(0,4) || json?.majorPoniter?.code?.slice(0,4) || ""
     let majorName4 = volumeData?.majorPoniter?.name || json?.majorPoniter?.name  || ""
     // 专业代码:前六位 major
-    let majorCode6 = volumeData?.major?.code?.slice(0,6) || json?.major?.code?.slice(0,6)  || ""
+    let majorCode6 = volumeData?.major?.code?.slice(0) || json?.major?.code?.slice(0)  || ""
     let majorName6 = volumeData?.major?.name || json?.major?.name || ""
     
     
@@ -347,6 +348,10 @@ function fixVolumeData(json,volumeData,index,totalJson,isChildren){
     // console.log(volumeData?.authorList)
     for (let index = 0; index < 6; index++) { // 补充空值
         if(!volumeData?.authorList?.[index]){
+            if(!volumeData?.authorList){
+                // console.log(volumeData)
+                // volumeData.authorList = []
+            }
          volumeData.authorList.push({name:"",unit:"",birth:"",nationality:"",job:"",title:"",mobile:"",email:"",work:""})
         }
      }
@@ -419,18 +424,20 @@ function pushDistinctItem(list,item){
     }
     return list
 }
-function renderReportDocsByTextbook(textbook){
-    
-    console.log("renderReportDocsByTextbook")
+function renderReportDocsByTextbook(textbook,isNew){
+    let TID = textbook?.id;
+    console.log("renderReportDocsByTextbook",textbook?.id)
     return new Promise(async (resolve)=>{
   
         let json = textbook.toJSON();
+        json.TID = TID;
         json.hasNoSign = false; // 未上传作者签名
         json.hasNoUnit = false; // 未上传单位资料
         json.hasNoNine = false; // 无需添加滞后九
         let bookid = json.code || json?.objectId;
     
         let exportPDF = textbook.get("exportPDF");
+        if(isNew) exportPDF = null;
         if(exportPDF){
             // console.log(exportPDF)
             let exportPath = await downloadUrl(exportPDF,{tempDir:path.join(tempDir,textbook.id),keepFileName:true});
@@ -447,6 +454,7 @@ function renderReportDocsByTextbook(textbook){
 
     // 默认单册为第一分册
     let book1Data = json?.childrens?.[0]
+    // console.log(json,book1Data)
     if(book1Data){
         Object.keys(book1Data).forEach(key=>{
             json[key] = book1Data[key] || json[key] || ""
@@ -556,7 +564,7 @@ function renderReportDocsByTextbook(textbook){
     }
 
  
-    let bookTempDir = path.join(tempDir,json?.objectId)
+    let bookTempDir = path.join(tempDir,json?.TID)
     if(!fs.existsSync(bookTempDir)) fs.mkdirSync(bookTempDir)
 
 
@@ -651,9 +659,9 @@ function renderReportDocsByTextbook(textbook){
 
     // mergeFiles 处理七八九是否签名或后置问题
     let lastPageList = []
-    let docx7 = await getPageDocx(json?.objectId,bookid,"七",bookData);
-    let docx8 = await getPageDocx(json?.objectId,bookid,"八",bookData);
-    let docx9 = await getPageDocx(json?.objectId,bookid,"九",bookData);
+    let docx7 = await getPageDocx(json?.TID,bookid,"七",bookData);
+    let docx8 = await getPageDocx(json?.TID,bookid,"八",bookData);
+    let docx9 = await getPageDocx(json?.TID,bookid,"九",bookData);
     lastPageList.push(json?.authorSignPDF?.url||docx7);
     lastPageList.push(json?.unitMaterial?.url||docx8);
     lastPageList.push(docx9);
@@ -701,7 +709,7 @@ function renderReportDocsByTextbook(textbook){
         }
         resolve({
             code:bookid,
-            objectId:json?.objectId,
+            objectId:json?.TID,
             title:json?.title,
             filePath,
             pdfPath,

+ 2 - 0
server/cloud/tbook/test/.gitignore

@@ -0,0 +1,2 @@
+*.txt
+export/

+ 62 - 3
server/cloud/tbook/test/test-export.js

@@ -3,8 +3,9 @@ Parse.initialize("edu-textbook");
 Parse.serverURL = "http://8.140.98.43/parse";
 global.Parse = Parse;
 
+import fs from "fs";
 import path from "path";
-import { mergePdfListReduce } from "../../../lib/docs";
+import { downloadUrl, mergePdfListReduce, uploadFileToOSS } from "../../../lib/docs";
 /**
  * 
  (npx vite build) -and (node temp/test-export.js)
@@ -52,8 +53,9 @@ async function main(){
         // console.log(await exportProcessReportDocs(null,["ybzJWkXqQG"])) 
         // console.log(await exportProcessReportDocs(null,["4UAwQ4nc5A"])) 
         // console.log(await exportProcessReportDocs(null,["ybzJWkXqQG"])) 
-        console.log(await exportProcessReportDocs(null,["yrmicQ8ZTR"])) 
+        // console.log(await exportProcessReportDocs(null,["yrmicQ8ZTR"])) 
         // console.log(await exportProcessReportDocs(null,["pdo6maunud","iWBI0FMTAS","Faw2Hl4qTf","lAG4JpaAIW","1aRyDbVyUu","GVNtZWdm50","5dq8TYCGfu","YkLYd4rv2v","889gBLs62l","fWTphlIAZu","DrHtcRrgXe","n6TxQZ0aOp","oV9W7FbyPj","sY1jZXS5rF","uvmtqWdMlM","rPaRkc0S3I","ikQXhMJPw7","ll0kl2RCBk","QCdJfwlBCh","F7aE1ACEgd","CcMa620Q5J","tk4zR6RbQN","6GLa6Po9p8","TbwoGVrSlR","xNDkRbGDP5","qg1ITwStRR","xHfG3po2yC","Tg7ndNBZvz","Hi1C6G43TM","mwCcj1VDrc"])) 
+        // console.log(await exportProcessReportDocs(null,["nZy0XB9vHw"])) 
         
         // console.log(await exportProcessReportDocs(null,["3wJSkW9HNV"]))
         // console.log(await exportProcessReportDocs(null,["tHhfIDBkhf"]))
@@ -63,6 +65,13 @@ async function main(){
         
         // console.log(await exportProcessReportDocs(null,["Oa1yB6n64u","j4pt2MMTXM","jAMGxwrl1F","BwZpEoOtS8","X10kCktA0r"]))
         // console.log(await exportProcessReportDocs(null,["BwZpEoOtS8","X10kCktA0r"]))
+
+        // 单独上传
+        console.log(await uploadFileToOSS("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/export/all/"+"申报书-多位专业代码修复导出.zip"))
+
+        // 根据export.txt 导出全部
+        // await exportAllFromTxt()
+
     }catch(err){
         console.error(err)
     }
@@ -80,4 +89,54 @@ main()
 //     pdfa: false,
 //     pdfUA: false,
 //     merge: true
-//   });
+//   });
+
+async function exportAllFromTxt(){
+    let txt = fs.readFileSync(path.join(__dirname,"../","export.txt")).toString();
+    let list = txt.split("\n");
+    list = list.filter(item=>{
+        let tdir = path.join(__dirname,"../export",item);
+        if(!fs.existsSync(tdir)){return true};
+        let fileList = fs.readdirSync(tdir);
+        if(!fileList?.length){
+            return true;
+        }
+        if(fileList?.length&&fileList.join("")?.indexOf("pdf")==-1){
+            return true
+        }
+        return false;
+    });
+    // list = list.slice(0,1);
+    console.log(list?.length)
+    for (let index = 0; index < list.length; index++) {
+        let id = list[index];
+        console.log(index+1,id)
+        console.log(index+1,id)
+        console.log(index+1,id)
+        console.log(index+1,id)
+        let docDir = path.join(__dirname,"../export",id)
+        console.log(docDir)
+        if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
+
+        let data = await exportProcessReportDocs(null,[id],true)
+        // console.log(data) 
+        let docList = data?.docsList || []
+        // console.log(docList)
+        for (let index = 0; index < docList.length; index++) {
+            let doc = docList[index]
+            let docDir = path.join(__dirname,"../export",doc.objectId);
+            if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
+            let urlPdf = doc.urlPdf;
+            let pdfPath = doc.pdfPath
+            console.log(doc)
+            // let targetPath = path.join(docDir,path.basename(pdfPath));
+            // fs.copyFileSync(pdfPath,targetPath)
+            // console.log(targetPath)
+            let filepath = await downloadUrl(urlPdf,{tempDir:docDir,keepFileName:true});
+            console.log(filepath)
+            if(!filepath || !fs.existsSync(filepath)){
+                fs.rmdirSync(docDir,{recursive:true,force:true});
+            }
+        }
+    }
+}