|
@@ -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,21 @@ 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();
|
|
|
+ }
|
|
|
+
|
|
|
let docsList = []
|
|
|
for (let index = 0; index < textbookList.length; index++) {
|
|
|
let textbook = textbookList[index];
|
|
@@ -57,16 +78,15 @@ 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
|
|
|
}
|
|
|
docsList = docsList.map(item=>{return {code:item.code,title:item.title,url:item?.url}})
|
|
|
}
|
|
|
|
|
|
- console.log(textbookList);
|
|
|
- console.log(docsList)
|
|
|
- console.log(processId)
|
|
|
let result = {
|
|
|
docsList,
|
|
|
zipUrl
|
|
@@ -78,7 +98,7 @@ module.exports.exportProcessReportDocs = exportProcessReportDocs
|
|
|
|
|
|
function renderReportDocsByTextbook(textbook){
|
|
|
let json = textbook.toJSON();
|
|
|
-
|
|
|
+ console.log(json)
|
|
|
// 圆圈选中未选 ○ 未选 ● 选中
|
|
|
let circleCheck = ["○","●"];
|
|
|
// 方块选中未选 ○ 未选 ● 选中
|
|
@@ -98,8 +118,13 @@ function renderReportDocsByTextbook(textbook){
|
|
|
// 是否重点立项
|
|
|
let isJC = circleCheck[(json?.approval?.indexOf("基础")>-1)?1:0];
|
|
|
let isZL = circleCheck[(json?.approval?.indexOf("战略")>-1)?1:0];
|
|
|
+
|
|
|
+ let is101 = circleCheck[(json?.approval?.indexOf("101计划")>-1)?1:0]; // 2024新重点
|
|
|
+ let isZY = circleCheck[(json?.approval?.indexOf("中央")>-1)?1:0];
|
|
|
let isSX = circleCheck[(json?.approval?.indexOf("四新")>-1)?1:0];
|
|
|
- let isNotImpt = (json?.approval?.indexOf("基础")==-1) && (json?.approval?.indexOf("战略")==-1) && (json?.approval?.indexOf("四新")==-1)
|
|
|
+ let isJS = circleCheck[(json?.importantProject?.indexOf("建设")>-1)?1:0];
|
|
|
+
|
|
|
+ let isNotImpt = (json?.approval?.indexOf("101计划")==-1) && (json?.approval?.indexOf("中央")==-1) && (json?.approval?.indexOf("四新")==-1) && (json?.approval?.indexOf("建设")==-1)
|
|
|
isNotImpt = circleCheck[isNotImpt?1:0];
|
|
|
// 初版时间
|
|
|
let firstDate = new Date(textbook?.get("editionFirst"));
|
|
@@ -129,7 +154,7 @@ function renderReportDocsByTextbook(textbook){
|
|
|
mobile:padString(mobile,21),
|
|
|
authorUnit:padString(json?.unit,21),
|
|
|
publisherPad:padString(json?.editionUnit,21),
|
|
|
- recommandUnit:padString("",21), // 未找到
|
|
|
+ recommandUnit:padString("",14), // 未找到
|
|
|
majorCodePad:padString((majorCode),14),
|
|
|
createdDate:padString(createdDate,21),
|
|
|
// 基本信息
|
|
@@ -147,6 +172,9 @@ function renderReportDocsByTextbook(textbook){
|
|
|
isJC:isJC,
|
|
|
isZL:isZL,
|
|
|
isSX:isSX,
|
|
|
+ is101:is101,
|
|
|
+ isZY:isZY,
|
|
|
+ isJS:isJS,
|
|
|
isNotImpt:isNotImpt,
|
|
|
publisher:json?.editionUnit,
|
|
|
firstYear:firstYear,
|
|
@@ -163,12 +191,11 @@ function renderReportDocsByTextbook(textbook){
|
|
|
currentM:currentMonth,
|
|
|
currentNum:json?.editionNumber || "",
|
|
|
printSum:json?.printSum || "",
|
|
|
- isJS:circleCheck[(json?.importantProject?.indexOf("建设")>-1)?1:0],
|
|
|
isBGJ:circleCheck[(json?.importantProject?.indexOf("本科国家")>-1)?1:0],
|
|
|
isBSYX:circleCheck[(json?.importantProject?.indexOf("省级优秀")>-1)?1:0],
|
|
|
isBSGH:circleCheck[(json?.importantProject?.indexOf("省级规划")>-1)?1:0],
|
|
|
isBSQT:circleCheck[isBSQT?1:0],
|
|
|
- bsqtName:isBSQT?json?.importantProject:"",
|
|
|
+ bsqtName:isBSQT?(json?.importantProject || ""):"",
|
|
|
isFirstNot:circleCheck[json?.importantProject?0:1],
|
|
|
}
|
|
|
console.log(bookData)
|
|
@@ -194,7 +221,7 @@ function padString(str,width) {
|
|
|
str = str || ""
|
|
|
str = String(str)
|
|
|
width = width || 21 // 目标宽度为21个单位
|
|
|
- spaceChar = " " // 占位符
|
|
|
+ let spaceChar = " " // 占位符
|
|
|
// 计算字符串的宽度
|
|
|
const charWidth = {
|
|
|
'space': 1, // 空格占用1个单位
|