test-export.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. const Parse = require("parse/node");
  2. Parse.initialize("edu-textbook");
  3. Parse.serverURL = "http://8.140.98.43/parse";
  4. global.Parse = Parse;
  5. import fs from "fs";
  6. import path from "path";
  7. import { downloadUrl, mergePdfListReduce, uploadFileToOSS } from "../../../lib/docs";
  8. /**
  9. *
  10. (npx vite build) -and (node temp/test-export.js)
  11. npx vite build && node temp/test-export.js
  12. npx vite build
  13. node temp/test-export.js
  14. @desc 本地合成测试指令
  15. sudo apt install poppler-utils
  16. libreoffice --headless --convert-to pdf *.jpg
  17. pdfunite 1*.pdf final.pdf
  18. libreoffice 更多用法可以在终端输入 libreoffice --help 或者 man libreoffice 。
  19. */
  20. import { exportProcessReportDocs } from "../func-tbook-export";
  21. async function main(){
  22. try{
  23. console.log("测试合集")
  24. // console.log(await exportProcessReportDocs("FR7KZtefyR"))
  25. // console.log("测试列表")
  26. // console.log(await exportProcessReportDocs(null,["9V575dapEM"]))
  27. // console.log(await exportProcessReportDocs(null,["c2WUE5PgCo"]))
  28. // console.log(await exportProcessReportDocs(null,["R9r0XtMsK3"])) // CIP顺序问题,后两个pdf到了最前面
  29. // console.log(await exportProcessReportDocs(null,["MU5YpUizfW"]))
  30. // console.log(await exportProcessReportDocs(null,["UUGgHPHsIC"]))
  31. // console.log(await exportProcessReportDocs(null,["KxhErArSbB"]))
  32. // console.log(await exportProcessReportDocs(null,["7cf69rSawD"]))
  33. // console.log(await exportProcessReportDocs(null,["kY6MbE1JXC"])) // 21个附件,超时
  34. // console.log(await exportProcessReportDocs(null,["O8kCxqdasp"])) // \u0002 乱码
  35. // console.log(await exportProcessReportDocs(null,["VK81UnQmkn"]))
  36. // console.log(await exportProcessReportDocs(null,["SD0NCAdscz"]))
  37. // console.log(await exportProcessReportDocs(null,["sbVgvo4qEk"]))
  38. // console.log(await exportProcessReportDocs(null,["4LnH46Mu03"]))
  39. // console.log(await exportProcessReportDocs(null,["xdIAG8BYnX"]))
  40. // console.log(await exportProcessReportDocs(null,["NJ2hWa17gi"]))
  41. // console.log(await exportProcessReportDocs(null,["tnEfUnTaQU"])) // C/C++ pathname error
  42. // console.log(await exportProcessReportDocs(null,["2s353GQBjk"]))
  43. // console.log(await exportProcessReportDocs(null,["KvvN9lWhri"]))
  44. // console.log(await exportProcessReportDocs(null,["orBBW42ZCn"])) // rar attach
  45. // console.log(await exportProcessReportDocs(null,["UwPtEptZTR"])) // pdf 七 八 加密
  46. // console.log(await exportProcessReportDocs(null,["TsjBrECA4m"])) // pdf 加密
  47. // console.log(await exportProcessReportDocs(null,["z7yhFusOns"]))
  48. // console.log(await exportProcessReportDocs(null,["ybzJWkXqQG"]))
  49. // console.log(await exportProcessReportDocs(null,["4UAwQ4nc5A"]))
  50. // console.log(await exportProcessReportDocs(null,["ybzJWkXqQG"]))
  51. // console.log(await exportProcessReportDocs(null,["yrmicQ8ZTR"]))
  52. // 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"]))
  53. // console.log(await exportProcessReportDocs(null,["nZy0XB9vHw"]))
  54. // console.log(await exportProcessReportDocs(null,["3wJSkW9HNV"]))
  55. // console.log(await exportProcessReportDocs(null,["tHhfIDBkhf"]))
  56. // console.log(await exportProcessReportDocs(null,["cgTEtIvkK4"]))
  57. // console.log(await exportProcessReportDocs(null,["KvvN9lWhri"]))
  58. // console.log(await exportProcessReportDocs(null,["zVVwoy6ETT"],true))
  59. // console.log(await exportProcessReportDocs(null,["7PAU2PNcoB"],true))
  60. // console.log(await exportProcessReportDocs(null,["v8DjfCGfrP"],true))
  61. // console.log(await exportProcessReportDocs(null,["7sDvlq2w6Z"],true))
  62. // console.log(await exportProcessReportDocs(null,["Oa1yB6n64u","j4pt2MMTXM","jAMGxwrl1F","BwZpEoOtS8","X10kCktA0r"]))
  63. // console.log(await exportProcessReportDocs(null,["BwZpEoOtS8","X10kCktA0r"]))
  64. // 单独上传
  65. // console.log(await uploadFileToOSS("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/export/all/"+"申报书-多位专业代码修复导出.zip"))
  66. // 单独上传 指定Key
  67. // console.log(await uploadFileToOSS("/home/ryan/Downloads/1727678422495-《物流英语》人员政治审查表.pdf",null,"/dHqLe4hyyU/2024-9-30/1727678422495-《物流英语》人员政治审查表.pdf"))
  68. // 根据export.txt 导出全部
  69. // await exportAllFromTxt()
  70. exportAll400();
  71. }catch(err){
  72. console.error(err)
  73. }
  74. }
  75. main()
  76. // mergePdfListReduce([
  77. // path.join("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/template/模板-推荐申报表.docx"),
  78. // path.join("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/template/模板-推荐申报表.docx")
  79. // ],{
  80. // files: [
  81. // '/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/temp/temp/112_1f15d43c0534288c61089099792e44e7.docx'
  82. // ],
  83. // properties: { pageSize: 'A4', margin: { top: 0, right: 0, bottom: 0, left: 0 } },
  84. // pdfa: false,
  85. // pdfUA: false,
  86. // merge: true
  87. // });
  88. async function exportAll400(){
  89. let query = new Parse.Query("EduTextbook");
  90. query.select("objectId");
  91. query.limit(20000);
  92. query.notEqualTo("isDeleted",true);
  93. query.notEqualTo("discard",true);
  94. query.equalTo("render",true);
  95. query.containedIn("status",['400']);
  96. let list = await query.find();
  97. list = list.map(item=>item?.id)
  98. console.log(list.length)
  99. exportAllFromTxt(list)
  100. }
  101. async function exportAllFromTxt(list){
  102. if(!list?.length){
  103. let txt = fs.readFileSync(path.join(__dirname,"../","export.txt")).toString();
  104. list = txt.split("\n");
  105. }
  106. list = list.filter(item=>{
  107. let tdir = path.join(__dirname,"../export",item);
  108. if(!fs.existsSync(tdir)){return true};
  109. let fileList = fs.readdirSync(tdir);
  110. if(!fileList?.length){
  111. return true;
  112. }
  113. if(fileList?.length&&fileList.join("")?.indexOf("pdf")==-1){
  114. return true
  115. }
  116. return false;
  117. });
  118. // list = list.slice(0,1);
  119. console.log(list?.length)
  120. for (let index = 0; index < list.length; index++) {
  121. let id = list[index];
  122. console.log(index+1,id)
  123. let docDir = path.join(__dirname,"../export",id)
  124. console.log(docDir)
  125. if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
  126. let data = await exportProcessReportDocs(null,[id],true)
  127. // console.log(data)
  128. let docList = data?.docsList || []
  129. // console.log(docList)
  130. for (let index = 0; index < docList.length; index++) {
  131. let doc = docList[index]
  132. let docDir = path.join(__dirname,"../export",doc.objectId);
  133. if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
  134. let urlPdf = doc.urlPdf;
  135. console.log(doc)
  136. // let targetPath = path.join(docDir,path.basename(pdfPath));
  137. // fs.copyFileSync(pdfPath,targetPath)
  138. // console.log(targetPath)
  139. let filepath = await downloadUrl(urlPdf,{tempDir:docDir,keepFileName:true});
  140. console.log(filepath)
  141. if(!filepath || !fs.existsSync(filepath)){
  142. fs.rmdirSync(docDir,{recursive:true,force:true});
  143. }
  144. }
  145. }
  146. }