|
@@ -2,36 +2,47 @@ import { replaceDocx, docsToPdf, createZip, uploadFileToOSS } from "../../lib/do
|
|
|
// const Parse = global.Parse;
|
|
|
|
|
|
const path = require("path")
|
|
|
-const TemplateDocxPath = path.join(__dirname,"template/模板-推荐申报表.docx")
|
|
|
-
|
|
|
+const fs = require("fs")
|
|
|
+var TemplateDocxPath = path.join(__dirname,"template/模板-推荐申报表.docx")
|
|
|
+if(!fs.existsSync(TemplateDocxPath)){
|
|
|
+ TemplateDocxPath = path.join(__dirname,"../../template/模板-推荐申报表.docx")
|
|
|
+}
|
|
|
/**
|
|
|
* 定义导出申报合集文档云函数
|
|
|
* @example
|
|
|
* Cloud Code test
|
|
|
+ 导出流程
|
|
|
curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "processId": "Wz34loxdbO" }' 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": "Wz34loxdbO" }' http://8.140.98.43/parse/functions/tbookExportReport
|
|
|
+ 导出教材列表
|
|
|
+ curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "bookList": ["2YBKitpCJL","xLdiEaHGrX"] }' http://127.0.0.1:61337/parse/functions/tbookExportReport
|
|
|
*/
|
|
|
export function defineTbookExportReport(){
|
|
|
Parse.Cloud.define("tbookExportReport", async (request) => {
|
|
|
let processId = request.params.processId;
|
|
|
- if(processId) {
|
|
|
- try{
|
|
|
- let result = await exportProcessReportDocs(processId)
|
|
|
- if(result?.docsList?.length==0){
|
|
|
- throw new Parse.Error(404,"合集内无申报教材")
|
|
|
- }
|
|
|
- return result
|
|
|
- }catch(err){
|
|
|
- console.error(err)
|
|
|
- throw new Parse.Error(404,"导出申报合集失败")
|
|
|
+ let bookList = request.params.bookList;
|
|
|
+ try{
|
|
|
+ let result
|
|
|
+ if(processId){
|
|
|
+ await exportProcessReportDocs(processId)
|
|
|
+ }
|
|
|
+ if(bookList?.length){
|
|
|
+ await exportProcessReportDocs(null,bookList)
|
|
|
}
|
|
|
+ if(result?.docsList?.length==0){
|
|
|
+ throw new Parse.Error(404,"合集内无申报教材")
|
|
|
+ }
|
|
|
+ return result
|
|
|
+ }catch(err){
|
|
|
+ console.error(err)
|
|
|
+ throw new Parse.Error(404,"导出申报合集失败")
|
|
|
}
|
|
|
throw new Parse.Error(404,"未找到该流程合集")
|
|
|
},{
|
|
|
fields : {
|
|
|
processId:{
|
|
|
- required:true
|
|
|
- }
|
|
|
+ required:false
|
|
|
+ },
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -44,11 +55,22 @@ const TemplateDocxPath = path.join(__dirname,"template/模板-推荐申报表.do
|
|
|
* docsList
|
|
|
* zipUrl
|
|
|
*/
|
|
|
-async function exportProcessReportDocs(processId) {
|
|
|
- if(!processId) return {}
|
|
|
- let query = new Parse.Query("EduTextbook")
|
|
|
- query.equalTo("eduProcess",processId);
|
|
|
- let textbookList = await query.find();
|
|
|
+export async function exportProcessReportDocs(processId,bookList) {
|
|
|
+ if(!processId && !bookList?.length) return {}
|
|
|
+
|
|
|
+ let textbookList
|
|
|
+ if(processId){ // 流程读取教材列表
|
|
|
+ let query = new Parse.Query("EduTextbook")
|
|
|
+ query.equalTo("eduProcess",processId);
|
|
|
+ textbookList = await query.find();
|
|
|
+ }
|
|
|
+ if(bookList?.length){ // 直接导出教材列表
|
|
|
+ let query = new Parse.Query("EduTextbook")
|
|
|
+ query.containedIn("objectId",bookList);
|
|
|
+ textbookList = await query.find();
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(textbookList)
|
|
|
let docsList = []
|
|
|
for (let index = 0; index < textbookList.length; index++) {
|
|
|
let textbook = textbookList[index];
|
|
@@ -57,7 +79,9 @@ async function exportProcessReportDocs(processId) {
|
|
|
}
|
|
|
let zipPath,zipUrl
|
|
|
if(docsList?.length){
|
|
|
- zipPath = await createZip(docsList?.map(item=>item?.filePath),`流程合集-${processId}.zip`)
|
|
|
+ let now = new Date();
|
|
|
+ let zipName = `申报书导出-${now.getFullYear()}${now.getMonth()+1}${now.getDate()}-${now.getHours()}${now.getMinutes()}${now.getSeconds()}.zip`
|
|
|
+ zipPath = await createZip(docsList?.map(item=>item?.filePath),zipName)
|
|
|
if(zipPath){
|
|
|
zipUrl = (await uploadFileToOSS(zipPath))?.url || null
|
|
|
}
|
|
@@ -78,7 +102,7 @@ module.exports.exportProcessReportDocs = exportProcessReportDocs
|
|
|
|
|
|
function renderReportDocsByTextbook(textbook){
|
|
|
let json = textbook.toJSON();
|
|
|
-
|
|
|
+ console.log(json)
|
|
|
// 圆圈选中未选 ○ 未选 ● 选中
|
|
|
let circleCheck = ["○","●"];
|
|
|
// 方块选中未选 ○ 未选 ● 选中
|
|
@@ -194,7 +218,7 @@ function padString(str,width) {
|
|
|
str = str || ""
|
|
|
str = String(str)
|
|
|
width = width || 21 // 目标宽度为21个单位
|
|
|
- spaceChar = " " // 占位符
|
|
|
+ let spaceChar = " " // 占位符
|
|
|
// 计算字符串的宽度
|
|
|
const charWidth = {
|
|
|
'space': 1, // 空格占用1个单位
|