|
@@ -9,6 +9,17 @@ if(!fs.existsSync(TemplateDocxDir)){
|
|
|
}
|
|
|
const tempDir = path.join(__dirname , "temp");
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 常用Word字符
|
|
|
+ */
|
|
|
+
|
|
|
+// 圆圈选中未选 ○ 未选 ● 选中
|
|
|
+const circleCheck = ["○","●"];
|
|
|
+// 方块选中未选 ○ 未选 ● 选中
|
|
|
+const squareCheck = [`□`,String.fromCharCode(0xFE)];
|
|
|
+
|
|
|
/**
|
|
|
* 定义导出申报合集文档云函数
|
|
|
* @example
|
|
@@ -148,6 +159,145 @@ export async function exportProcessReportDocs(processId,bookList) {
|
|
|
|
|
|
module.exports.exportProcessReportDocs = exportProcessReportDocs
|
|
|
|
|
|
+function fixVolumeData(json,volumeData,index){
|
|
|
+ json.index = index + 1;
|
|
|
+ // 教材基本信息
|
|
|
+
|
|
|
+ // 专业代码:前四位 majorPoniter
|
|
|
+ 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 majorName6 = volumeData?.major?.name || json?.major?.name || ""
|
|
|
+
|
|
|
+ // 是否重点立项
|
|
|
+ let importantProject = volumeData?.importantProject?.join();
|
|
|
+
|
|
|
+ let isJC = circleCheck[(volumeData?.approval?.indexOf("基础")>-1)?1:0];
|
|
|
+ let isZL = circleCheck[(volumeData?.approval?.indexOf("战略")>-1)?1:0];
|
|
|
+
|
|
|
+ let is101 = circleCheck[(volumeData?.approval?.indexOf("101计划")>-1)?1:0]; // 2024新重点
|
|
|
+ let isZY = circleCheck[(volumeData?.approval?.indexOf("中央")>-1)?1:0];
|
|
|
+ let isSX = circleCheck[(volumeData?.approval?.indexOf("四新")>-1)?1:0];
|
|
|
+ let isJS = circleCheck[(volumeData?.approval?.indexOf("建设")>-1)?1:0];
|
|
|
+
|
|
|
+
|
|
|
+ let isNotImpt = (volumeData?.approval?.indexOf("101计划")==-1) && (volumeData?.approval?.indexOf("中央")==-1) && (volumeData?.approval?.indexOf("四新")==-1) && (volumeData?.approval?.indexOf("建设")==-1)
|
|
|
+ isNotImpt = circleCheck[isNotImpt?1:0];
|
|
|
+ // 初版时间
|
|
|
+ let firstDate = new Date(volumeData?.editionFirst.iso);
|
|
|
+ let firstYear = firstDate?.getFullYear();
|
|
|
+ let firstMonth = firstDate?.getMonth()+1;
|
|
|
+ // 本版时间印次
|
|
|
+ let currentDate = new Date(volumeData?.editionDate.iso);
|
|
|
+ let currentYear = currentDate?.getFullYear();
|
|
|
+ let currentMonth = currentDate?.getMonth()+1;
|
|
|
+ // 最新时间印次
|
|
|
+ let latestDate = new Date(volumeData?.printDate.iso);
|
|
|
+ let latestYear = latestDate?.getFullYear();
|
|
|
+ let latestMonth = latestDate?.getMonth()+1;
|
|
|
+ let latestNum = volumeData?.printNumber || "";
|
|
|
+ let currentNum = volumeData?.editionNumber || "";
|
|
|
+ let printSum = volumeData?.printSum?volumeData?.printSum+"万":"" || "";
|
|
|
+ // 初版至今重点项目
|
|
|
+ let isBSQT = !((importantProject?.indexOf("建设")>-1) || (importantProject?.indexOf("本科国家")>-1) || (importantProject?.indexOf("省级优秀")>-1) || (importantProject?.indexOf("省级规划")>-1))// 是否其他省级奖项
|
|
|
+ let bsqtName = (volumeData?.importantProject || [])?.filter(item=>(item?.indexOf("建设")==-1&&item?.indexOf("本科国家")==-1&&item?.indexOf("省级优秀")==-1&&item?.indexOf("省级规划")==-1));
|
|
|
+
|
|
|
+
|
|
|
+ json.importantProject = importantProject
|
|
|
+ json.isJC = isJC
|
|
|
+ json.isZL = isZL
|
|
|
+ json.is101 = is101
|
|
|
+ json.isZY = isZY
|
|
|
+ json.isSX = isSX
|
|
|
+ json.isJS = isJS
|
|
|
+ json.isNotImpt = isNotImpt
|
|
|
+ json.firstDate = firstDate
|
|
|
+ json.firstYear = firstYear
|
|
|
+ json.firstMonth = firstMonth
|
|
|
+ json.currentDate = currentDate
|
|
|
+ json.currentYear = currentYear
|
|
|
+ json.currentMonth = currentMonth
|
|
|
+ json.latestDate = latestDate
|
|
|
+ json.latestYear = latestYear
|
|
|
+ json.latestMonth = latestMonth
|
|
|
+ json.currentNum = currentNum
|
|
|
+ json.latestMonth = latestMonth
|
|
|
+ json.latestNum = latestNum
|
|
|
+ json.printSum = printSum
|
|
|
+ json.isBSQT = isBSQT
|
|
|
+ json.bsqtName = bsqtName
|
|
|
+
|
|
|
+ json.uBS = circleCheck[(volumeData?.unitType?.indexOf("部属")>-1)?1:0];
|
|
|
+ json.uHJ = circleCheck[(volumeData?.unitType?.indexOf("合建")>-1)?1:0];
|
|
|
+ json.uGJ = circleCheck[(volumeData?.unitType?.indexOf("共建")>-1)?1:0];
|
|
|
+ json.uQT = circleCheck[(volumeData?.unitType?.indexOf("其他")>-1)?1:0];
|
|
|
+ json.mc4 = majorCode4;
|
|
|
+ json.mn4 = majorName4;
|
|
|
+ json.mc6 = majorCode6;
|
|
|
+ json.mn6 = majorName6;
|
|
|
+ json.lCN = circleCheck[(volumeData?.lang=="中文")?1:0];
|
|
|
+ json.lEN = circleCheck[(volumeData?.lang=="英文")?1:0];
|
|
|
+ json.lMW = circleCheck[(volumeData?.lang=="盲文")?1:0];
|
|
|
+ json.lOT = circleCheck[(volumeData?.lang?.indexOf("其他")>-1)?1:0];
|
|
|
+ json.lSS = circleCheck[(volumeData?.lang?.indexOf("少数")>-1)?1:0];
|
|
|
+ json.publisher = volumeData?.editionUnit;
|
|
|
+ json.isZZ = circleCheck[(volumeData?.carrierShape?.indexOf("纸质")>-1)?1:0];
|
|
|
+ json.isDZ = circleCheck[(volumeData?.carrierShape?.indexOf("电子")>-1)?1:0];
|
|
|
+ json.isSZ = circleCheck[(volumeData?.carrierShape?.indexOf("数字")>-1 || volumeData?.carrierShape?.indexOf("电子")>-1)?1:0];
|
|
|
+ json.isQT = circleCheck[(volumeData?.carrierShape?.indexOf("附带")>-1)?1:0];
|
|
|
+ json.isFD = circleCheck[(volumeData?.carrierShape?.indexOf("其他")>-1)?1:0];
|
|
|
+ json.latestY = latestYear;
|
|
|
+ json.latestM = latestMonth;
|
|
|
+ json.currentY = currentYear;
|
|
|
+ json.currentM = currentMonth;
|
|
|
+ json.isBGJ = circleCheck[(importantProject?.indexOf("本科国家")>-1)?1:0];
|
|
|
+ json.isBSYX = circleCheck[(importantProject?.indexOf("省级优秀")>-1)?1:0];
|
|
|
+ json.isBSGH = circleCheck[(importantProject?.indexOf("省级规划")>-1)?1:0];
|
|
|
+ json.isBSQT = circleCheck[isBSQT?1:0];
|
|
|
+ json.isFirstNot = circleCheck[volumeData?.importantProject?0:1];
|
|
|
+ // 作者列表
|
|
|
+ for (let index = 0; index < 6; index++) { // 补充空值
|
|
|
+ if(!volumeData?.authorList?.[index]){
|
|
|
+ volumeData.authorList.push({name:"",unit:"",birth:"",nationality:"",job:"",title:"",mobile:"",email:"",work:""})
|
|
|
+ }
|
|
|
+ }
|
|
|
+ volumeData.authorList = volumeData?.authorList?.map((item,index)=>{ // 转换格式
|
|
|
+ item.index = index + 1
|
|
|
+ item.birth = toYearMonth(item?.birth)
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ json.authorList = volumeData?.authorList;
|
|
|
+ // 成果列表
|
|
|
+ // aclist[index] = [json?.achievementOptions?.[index]?.name||" ",json?.achievementOptions?.[index]?.unit||" ",toYearMonth(json?.achievementOptions?.[index]?.date)||" "]
|
|
|
+ for (let index = 0; index < 5; index++) { // 补充空值
|
|
|
+ if(!volumeData?.achievementOptions?.[index]){
|
|
|
+ volumeData.achievementOptions.push({name:"",unit:"",date:""})
|
|
|
+ }
|
|
|
+ volumeData.achievementOptions = volumeData?.achievementOptions?.map((item,index)=>{ // 转换格式
|
|
|
+ item.index = index + 1
|
|
|
+ item.date = toYearMonth(item?.date)
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ }
|
|
|
+ json.achievementOptions = volumeData?.achievementOptions;
|
|
|
+
|
|
|
+ // 历程列表
|
|
|
+ // clist[index] = [num,toYearMonth(json?.courses?.[index]?.date)||" ",json?.courses?.[index]?.wordage||" ",json?.courses?.[index]?.num||" ",json?.courses?.[index]?.sumNum||" ",json?.courses?.[index]?.accolade||" "]
|
|
|
+ for (let index = 0; index < 4; index++) { // 补充空值
|
|
|
+ if(!volumeData?.courses?.[index]){
|
|
|
+ volumeData.courses.push({date:"",wordage:"",num:"",sumNum:"",accolade:""})
|
|
|
+ }
|
|
|
+ volumeData.courses = volumeData?.courses?.map((item,index)=>{ // 转换格式
|
|
|
+ item.index = index + 1
|
|
|
+ item.date = toYearMonth(item?.date)
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ }
|
|
|
+ json.courses = volumeData?.courses;
|
|
|
+ return json
|
|
|
+}
|
|
|
+
|
|
|
function renderReportDocsByTextbook(textbook){
|
|
|
console.log("renderReportDocsByTextbook")
|
|
|
return new Promise(async (resolve)=>{
|
|
@@ -163,11 +313,6 @@ function renderReportDocsByTextbook(textbook){
|
|
|
}
|
|
|
|
|
|
|
|
|
- // console.log(json)
|
|
|
- // 圆圈选中未选 ○ 未选 ● 选中
|
|
|
- let circleCheck = ["○","●"];
|
|
|
- // 方块选中未选 ○ 未选 ● 选中
|
|
|
- let squareCheck = [`□`,String.fromCharCode(0xFE)];
|
|
|
|
|
|
// 联系电话:默认为作者首个存在的电话;
|
|
|
let mobile = json?.authorList?.find(item => item.mobile)?.mobile || ""
|
|
@@ -175,45 +320,20 @@ function renderReportDocsByTextbook(textbook){
|
|
|
let createdAt = new Date(textbook?.createdAt);
|
|
|
let createdDate = `${createdAt?.getFullYear()}年${createdAt?.getMonth()+1}月${createdAt?.getDate()}日`;
|
|
|
|
|
|
- // 专业代码:前四位 majorPoniter
|
|
|
- let majorCode4 = json?.majorPoniter?.code?.slice(0,4) || ""
|
|
|
- let majorName4 = json?.majorPoniter?.name || ""
|
|
|
- // 专业代码:前六位 major
|
|
|
- let majorCode6 = json?.major?.code?.slice(0,6) || ""
|
|
|
- let majorName6 = json?.major?.name || ""
|
|
|
-
|
|
|
- // 是否重点立项
|
|
|
- let importantProject = json?.importantProject?.join();
|
|
|
-
|
|
|
- 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 isJS = circleCheck[(json?.approval?.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(book1Data?.editionFirst.iso);
|
|
|
- let firstYear = firstDate?.getFullYear();
|
|
|
- let firstMonth = firstDate?.getMonth()+1;
|
|
|
- // 本版时间印次
|
|
|
- let currentDate = new Date(book1Data?.editionDate.iso);
|
|
|
- let currentYear = currentDate?.getFullYear();
|
|
|
- let currentMonth = currentDate?.getMonth()+1;
|
|
|
- // 最新时间印次
|
|
|
- let latestDate = new Date(book1Data?.printDate.iso);
|
|
|
- let latestYear = latestDate?.getFullYear();
|
|
|
- let latestMonth = latestDate?.getMonth()+1;
|
|
|
- // 初版至今重点项目
|
|
|
- let isBSQT = !((importantProject?.indexOf("建设")>-1) || (importantProject?.indexOf("本科国家")>-1) || (importantProject?.indexOf("省级优秀")>-1) || (importantProject?.indexOf("省级规划")>-1))// 是否其他省级奖项
|
|
|
- let bsqtName = (json?.importantProject || [])?.filter(item=>(item?.indexOf("建设")==-1&&item?.indexOf("本科国家")==-1&&item?.indexOf("省级优秀")==-1&&item?.indexOf("省级规划")==-1));
|
|
|
// 教材适用
|
|
|
let characteristic = (json?.characteristic?.filter(item=>item?.checked).map(item=>item.label) || [])?.join(",")
|
|
|
|
|
|
+ json = fixVolumeData(json,book1Data,0)
|
|
|
+ let volumeList = []
|
|
|
+ for (let index = 0; index < 12; index++) {
|
|
|
+ if(json?.childrens?.[index]){
|
|
|
+ let volumeData = json?.childrens?.[index]
|
|
|
+ volumeData = fixVolumeData(volumeData,volumeData,index)
|
|
|
+ volumeList.push(volumeData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ json.volumeList = volumeList
|
|
|
+
|
|
|
// 作者列表 限6人
|
|
|
let alist = []
|
|
|
for (let index = 0; index < 9; index++) {
|
|
@@ -267,6 +387,7 @@ function renderReportDocsByTextbook(textbook){
|
|
|
console.log(codePngPath)
|
|
|
|
|
|
let fixData = {
|
|
|
+ volumeList:volumeList,
|
|
|
// 图片信息
|
|
|
codeBarImg:codePngPath,
|
|
|
// 封面信息
|
|
@@ -286,51 +407,7 @@ function renderReportDocsByTextbook(textbook){
|
|
|
createdDate:padString(createdDate,21),
|
|
|
// 基本信息
|
|
|
title:json?.title,
|
|
|
- author:json?.author,
|
|
|
- unit:json?.unit,
|
|
|
- uBS:circleCheck[(json?.unitType?.indexOf("部属")>-1)?1:0],
|
|
|
- uHJ:circleCheck[(json?.unitType?.indexOf("合建")>-1)?1:0],
|
|
|
- uGJ:circleCheck[(json?.unitType?.indexOf("共建")>-1)?1:0],
|
|
|
- uQT:circleCheck[(json?.unitType?.indexOf("其他")>-1)?1:0],
|
|
|
- mc4:majorCode4,
|
|
|
- mn4:majorName4,
|
|
|
- mc6:majorCode6,
|
|
|
- mn6:majorName6,
|
|
|
- lCN:circleCheck[(json?.lang=="中文")?1:0],
|
|
|
- lEN:circleCheck[(json?.lang=="英文")?1:0],
|
|
|
- lMW:circleCheck[(json?.lang=="盲文")?1:0],
|
|
|
- lOT:circleCheck[(json?.lang?.indexOf("其他")>-1)?1:0],
|
|
|
- lSS:circleCheck[(json?.lang?.indexOf("少数")>-1)?1:0],
|
|
|
- authors:json?.authors, // 其他主编
|
|
|
- editor:json?.editor, // 其他编者
|
|
|
- isJC:isJC,
|
|
|
- isZL:isZL,
|
|
|
- isSX:isSX,
|
|
|
- is101:is101,
|
|
|
- isZY:isZY,
|
|
|
- isJS:isJS,
|
|
|
- isNotImpt:isNotImpt,
|
|
|
- publisher:json?.editionUnit,
|
|
|
- firstYear:firstYear,
|
|
|
- firstMonth:firstMonth,
|
|
|
- isZZ:circleCheck[(json?.carrierShape?.indexOf("纸质")>-1)?1:0],
|
|
|
- isDZ:circleCheck[(json?.carrierShape?.indexOf("电子")>-1)?1:0],
|
|
|
- isSZ:circleCheck[(json?.carrierShape?.indexOf("数字")>-1 || json?.carrierShape?.indexOf("电子")>-1)?1:0],
|
|
|
- isQT:circleCheck[(json?.carrierShape?.indexOf("附带")>-1)?1:0],
|
|
|
- isFD:circleCheck[(json?.carrierShape?.indexOf("其他")>-1)?1:0],
|
|
|
- latestY:latestYear,
|
|
|
- latestM:latestMonth,
|
|
|
- latestNum:json?.printNumber || "",
|
|
|
- currentY:currentYear,
|
|
|
- currentM:currentMonth,
|
|
|
- currentNum:json?.editionNumber || "",
|
|
|
- printSum:json?.printSum?json?.printSum+"万":"" || "",
|
|
|
- isBGJ:circleCheck[(importantProject?.indexOf("本科国家")>-1)?1:0],
|
|
|
- isBSYX:circleCheck[(importantProject?.indexOf("省级优秀")>-1)?1:0],
|
|
|
- isBSGH:circleCheck[(importantProject?.indexOf("省级规划")>-1)?1:0],
|
|
|
- isBSQT:circleCheck[isBSQT?1:0],
|
|
|
- bsqtName:bsqtName||"",
|
|
|
- isFirstNot:circleCheck[json?.importantProject?0:1],
|
|
|
+
|
|
|
// 教材适用情况
|
|
|
lessons:json?.lessons||[],
|
|
|
period:json?.period||"", // 学时
|
|
@@ -376,8 +453,8 @@ function renderReportDocsByTextbook(textbook){
|
|
|
if(json?.childrens?.length>1){
|
|
|
TemplateDocxPath = path.join(TemplateDocxDir,"模板-本科教材申报书-全册.docx")
|
|
|
}else{
|
|
|
- TemplateDocxPath = path.join(TemplateDocxDir,"模板-本科教材申报书-单册.docx")
|
|
|
}
|
|
|
+ TemplateDocxPath = path.join(TemplateDocxDir,"模板-本科教材申报书-单册.docx")
|
|
|
try{
|
|
|
// DOCX模板合成 速度2-3秒
|
|
|
filePath = renderDocx(TemplateDocxPath,tempFileName,bookData)
|
|
@@ -422,8 +499,12 @@ function renderReportDocsByTextbook(textbook){
|
|
|
}
|
|
|
|
|
|
function toYearMonth(date){
|
|
|
+ // console.log("toYearMonth",date)
|
|
|
+ if(typeof date == "string" && date?.indexOf("年")>-1) return date
|
|
|
if(!date) return ""
|
|
|
- date = new Date(date?.iso||date);
|
|
|
+ let datestr = date?.iso||date
|
|
|
+ if(!datestr) return ""
|
|
|
+ date = new Date(datestr);
|
|
|
return `${date.getFullYear()}年${date.getMonth()+1}月`
|
|
|
}
|
|
|
|