明树Git Lab

Commit 34260035 authored by zfp1's avatar zfp1

update

parent 6588ab91
Pipeline #104237 passed with stage
in 3 seconds
...@@ -8,6 +8,7 @@ const ExcelJS = require('exceljs'); ...@@ -8,6 +8,7 @@ const ExcelJS = require('exceljs');
const path = require('path'); const path = require('path');
const { HyperFormula } = require('hyperformula'); const { HyperFormula } = require('hyperformula');
const errorMessage = require("../utils/errorMessage"); const errorMessage = require("../utils/errorMessage");
const _ = require('lodash');
const keyName = { const keyName = {
tjjh: "投决计划", tjjh: "投决计划",
...@@ -33,16 +34,31 @@ async function getXmtzzjllTem({ startYear, endYear, tampName, projectId }) { ...@@ -33,16 +34,31 @@ async function getXmtzzjllTem({ startYear, endYear, tampName, projectId }) {
} }
// 2.2 处理数据 // 2.2 处理数据
let rows = Array(worksheet.actualRowCount - 3).fill(Array(columns.length).fill("")); // 5 是模板有5行 let rows = []; // 5 是模板有5行
if (projectId) { if (projectId) {
let tzzjlls = await DB.ProjectTzzjll.findAll({ let excelData = await DB.ProjectExcelData.findOne({
where: { projectId: projectId, del: 0 }, order: [['createdAt', 'DESC']],
where: { projectId: projectId, del: 0, tampName },
attributes: ['data', 'createdAt', 'id'],
raw: true, raw: true,
}); });
tzzjlls = _.sortBy(tzzjlls, 'year'); console.log(excelData.id);
rows = thvc(tzzjlls); if (excelData && excelData.id && _.isArray(excelData.data) && excelData.data.length > 0) {
for (let index = 3; index < excelData.data.length; index++) { // 0、1行是表头
let element = excelData.data[index];
if (index) {
element = element.slice(3);
}
console.log(element)
rows.push(element);
}
} else {
rows = Array(worksheet.actualRowCount - 3).fill(Array(columns.length).fill(""))
}
} else {
rows = Array(worksheet.actualRowCount - 3).fill(Array(columns.length).fill(""))
} }
console.log(rows, "=============") // console.log(rows, "=============")
// 使用addTable创建表格 // 使用addTable创建表格
worksheet.addTable({ worksheet.addTable({
...@@ -170,7 +186,7 @@ async function importExcelTempData(req, res, next) { ...@@ -170,7 +186,7 @@ async function importExcelTempData(req, res, next) {
} else if (cell.type === ExcelJS.ValueType.String) { } else if (cell.type === ExcelJS.ValueType.String) {
rowData.push(cell.text + "_suffix"); rowData.push(cell.text + "_suffix");
} else if (cell.value === null || cell.value === undefined) { } else if (cell.value === null || cell.value === undefined) {
rowData.push(null); rowData.push("");
} else { } else {
rowData.push(cell.value); rowData.push(cell.value);
} }
...@@ -183,18 +199,19 @@ async function importExcelTempData(req, res, next) { ...@@ -183,18 +199,19 @@ async function importExcelTempData(req, res, next) {
const out = []; const out = [];
for (let r = 0; r < height; r++) { for (let r = 0; r < height; r++) {
let cc = []; let cc = [];
for (let c = 0; c < sheetData[0].length; c++) { for (let c = 0; c < sheetData[0].length; c++) {
// const formulaString = hf.getCellFormula({ sheet: 0, row: r, col: c }); // const formulaString = hf.getCellFormula({ sheet: 0, row: r, col: c });
let calculated = hf.getCellValue({ sheet: 0, row: r, col: c }); let calculated = hf.getCellValue({ sheet: 0, row: r, col: c });
// console.log(formulaString, calculated) // console.log(formulaString, calculated)
if(typeof calculated == 'string') { if (typeof calculated == 'string') {
calculated = removeSuffix(String(calculated),'_suffix') calculated = removeSuffix(String(calculated), '_suffix')
} }
cc.push(calculated); cc.push(calculated);
} }
out.push(cc); out.push(cc);
} }
await DB.ProjectExcelData.create({projectId, tampName, data: out}); await DB.ProjectExcelData.create({ projectId, tampName, data: out });
req.file = null;
return res.sendData(out); return res.sendData(out);
} catch (error) { } catch (error) {
next(error) next(error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment