|
@@ -296,8 +296,12 @@ class ImportBaseTree {
|
|
* @param {object} pos - 部位明细
|
|
* @param {object} pos - 部位明细
|
|
* @returns {*}
|
|
* @returns {*}
|
|
*/
|
|
*/
|
|
- addPos (pos){
|
|
|
|
|
|
+ addPos (pos, strict = false){
|
|
if (this.finalNode && this.finalNode.pos) {
|
|
if (this.finalNode && this.finalNode.pos) {
|
|
|
|
+ if (strict) {
|
|
|
|
+ const exist = this.finalNode.pos.find(x => { return x.name === pos.name; });
|
|
|
|
+ if (exist) return;
|
|
|
|
+ }
|
|
pos.id = this.ctx.app.uuid.v4();
|
|
pos.id = this.ctx.app.uuid.v4();
|
|
pos.lid = this.finalNode.id;
|
|
pos.lid = this.finalNode.id;
|
|
pos.tid = this.ctx.tender.id;
|
|
pos.tid = this.ctx.tender.id;
|
|
@@ -876,17 +880,12 @@ class AnalysisGclExcelTree {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class ImportStageBaseTree {
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class AnalysisStageTree {
|
|
|
|
|
|
+class AnalysisStageExcelTree extends AnalysisExcelTree {
|
|
/**
|
|
/**
|
|
* 构造函数
|
|
* 构造函数
|
|
*/
|
|
*/
|
|
constructor(ctx, setting) {
|
|
constructor(ctx, setting) {
|
|
- this.ctx = ctx;
|
|
|
|
- this.setting = setting;
|
|
|
|
|
|
+ super(ctx, setting);
|
|
this.mid = ctx.tender.id;
|
|
this.mid = ctx.tender.id;
|
|
this.decimal = ctx.tender.info.decimal;
|
|
this.decimal = ctx.tender.info.decimal;
|
|
this.precision = ctx.tender.info.precision;
|
|
this.precision = ctx.tender.info.precision;
|
|
@@ -897,23 +896,11 @@ class AnalysisStageTree {
|
|
pos: {value: ['计量单元'], type: colDefineType.match},
|
|
pos: {value: ['计量单元'], type: colDefineType.match},
|
|
name: {value: ['名称'], type: colDefineType.match},
|
|
name: {value: ['名称'], type: colDefineType.match},
|
|
unit: {value: ['单位'], type: colDefineType.match},
|
|
unit: {value: ['单位'], type: colDefineType.match},
|
|
|
|
+ unit_price: {value: ['单价'], type: colDefineType.match},
|
|
contract_qty: {value: ['本期合同计量|数量'], type: colDefineType.match},
|
|
contract_qty: {value: ['本期合同计量|数量'], type: colDefineType.match},
|
|
contract_tp: {value: ['本期合同计量|金额'], type: colDefineType.match},
|
|
contract_tp: {value: ['本期合同计量|金额'], type: colDefineType.match},
|
|
};
|
|
};
|
|
- this.needCols = ['code', 'b_code', 'pos', 'name', 'unit', 'contract_qty', 'contract_tp'];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 读取表头并检查
|
|
|
|
- * @param {Number} row - Excel数据行
|
|
|
|
- */
|
|
|
|
- checkColHeader(row) {
|
|
|
|
- const colsDef = aeUtils.checkColHeader(row, this.colHeaderMatch);
|
|
|
|
- let check = true;
|
|
|
|
- for (const col of this.needCols) {
|
|
|
|
- if (!colsDef[col]) check = false;
|
|
|
|
- }
|
|
|
|
- if (check) this.colsDef = colsDef;
|
|
|
|
|
|
+ this.needCols = ['code', 'b_code', 'pos', 'name', 'unit', 'unit_price', 'contract_qty', 'contract_tp'];
|
|
}
|
|
}
|
|
|
|
|
|
mergeHeaderRow(iRow, row, subRow, merge) {
|
|
mergeHeaderRow(iRow, row, subRow, merge) {
|
|
@@ -934,8 +921,69 @@ class AnalysisStageTree {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- loadRowData(row, iRow) {
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 读取项目节节点
|
|
|
|
+ * @param {Array} row - excel行数据
|
|
|
|
+ * @returns {*}
|
|
|
|
+ * @private
|
|
|
|
+ */
|
|
|
|
+ _loadXmjNode(row) {
|
|
|
|
+ try {
|
|
|
|
+ const node = {};
|
|
|
|
+ node.code = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.code]));
|
|
|
|
+ node.name = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.name]));
|
|
|
|
+ node.unit = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.unit]));
|
|
|
|
+ return this.cacheTree.addXmjNode(node);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ if (error.stack) {
|
|
|
|
+ this.ctx.logger.error(error);
|
|
|
|
+ } else {
|
|
|
|
+ this.ctx.getLogger('fail').info(JSON.stringify({
|
|
|
|
+ error,
|
|
|
|
+ project: this.ctx.session.sessionProject,
|
|
|
|
+ user: this.ctx.session.sessionUser,
|
|
|
|
+ body: row,
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 读取工程量清单数据
|
|
|
|
+ * @param {Array} row - excel行数据
|
|
|
|
+ * @returns {*}
|
|
|
|
+ * @private
|
|
|
|
+ */
|
|
|
|
+ _loadGclNode(row) {
|
|
|
|
+ if (this.filter.filterGcl) return true;
|
|
|
|
+ const node = {};
|
|
|
|
+ node.b_code = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.b_code]));
|
|
|
|
+ node.name = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.name]));
|
|
|
|
+ node.unit = this.ctx.helper.replaceReturn(this.ctx.helper._.trimEnd(row[this.colsDef.unit]));
|
|
|
|
+ node.unit_price = this.ctx.helper.round(aeUtils.toNumber(row[this.colsDef.unit_price]), this.decimal.up);
|
|
|
|
+ const precision = this.ctx.helper.findPrecision(this.precision, node.unit);
|
|
|
|
+ node.contract_qty = this.ctx.helper.round(aeUtils.toNumber(row[this.colsDef.contract_qty]), precision.value);
|
|
|
|
+ if (node.quantity && node.unit_price) {
|
|
|
|
+ node.contract_tp = this.ctx.helper.mul(node.quantity, node.unit_price, this.decimal.tp);
|
|
|
|
+ } else {
|
|
|
|
+ node.contract_tp = null;
|
|
|
|
+ }
|
|
|
|
+ if (this.filter.filterZeroGcl && !node.quantity && !node.total_price) return true;
|
|
|
|
+ return this.cacheTree.addGclNode(node);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 读取部位明细数据
|
|
|
|
+ * @param {Array} row - excel行数据
|
|
|
|
+ * @returns {*}
|
|
|
|
+ * @private
|
|
|
|
+ */
|
|
|
|
+ _loadPos(row) {
|
|
|
|
+ if (this.filter.filterPos) return true;
|
|
|
|
+ const pos = {};
|
|
|
|
+ pos.name = this.ctx.helper.replaceReturn(row[this.colsDef.name]);
|
|
|
|
+ pos.quantity = aeUtils.toNumber(row[this.colsDef.quantity]);
|
|
|
|
+ pos.contrac_qty = pos.contract_qty;
|
|
|
|
+ return this.cacheTree.addPos(pos, true);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -944,20 +992,21 @@ class AnalysisStageTree {
|
|
* @param {Array} tempData - 新建项目使用的清单模板
|
|
* @param {Array} tempData - 新建项目使用的清单模板
|
|
* @returns {ImportBaseTree}
|
|
* @returns {ImportBaseTree}
|
|
*/
|
|
*/
|
|
- analysisData(ledger, pos, sheet) {
|
|
|
|
|
|
+ analysisData(sheet, tempData, filter) {
|
|
this.filter = filter ? filter : {};
|
|
this.filter = filter ? filter : {};
|
|
this.colsDef = null;
|
|
this.colsDef = null;
|
|
- this.cacheTree = this._getNewLedger();
|
|
|
|
|
|
+ this.cacheTree = this._getNewCacheTree(tempData);
|
|
this.errorData = [];
|
|
this.errorData = [];
|
|
this.loadEnd = false;
|
|
this.loadEnd = false;
|
|
this.loadBegin = sheet.rows.length;
|
|
this.loadBegin = sheet.rows.length;
|
|
|
|
|
|
- for (const iRow in sheet.rows) {
|
|
|
|
|
|
+ for (const [iRow, row] of sheet.rows.entries()) {
|
|
if (this.colsDef && !this.loadEnd) {
|
|
if (this.colsDef && !this.loadEnd) {
|
|
if (iRow < this.loadBegin) continue;
|
|
if (iRow < this.loadBegin) continue;
|
|
- this.loadRowData(sheet.rows[iRow], iRow);
|
|
|
|
|
|
+ this.loadRowData(row, iRow);
|
|
} else {
|
|
} else {
|
|
- const mergeRow = this.mergeHeaderRow(iRow, sheet.rows[iRow], sheet.rows[iRow + 1], sheet.merge);
|
|
|
|
|
|
+ if (iRow === sheet.rows.length - 1) continue;
|
|
|
|
+ const mergeRow = this.mergeHeaderRow(iRow, row, sheet.rows[iRow + 1], sheet.merge);
|
|
this.checkColHeader(mergeRow);
|
|
this.checkColHeader(mergeRow);
|
|
if (this.colsDef) this.loadBegin = iRow + 2;
|
|
if (this.colsDef) this.loadBegin = iRow + 2;
|
|
}
|
|
}
|
|
@@ -967,4 +1016,4 @@ class AnalysisStageTree {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-module.exports = { AnalysisExcelTree, AnalysisGclExcelTree, AnalysisStageTree };
|
|
|
|
|
|
+module.exports = { AnalysisExcelTree, AnalysisGclExcelTree, AnalysisStageExcelTree };
|