|
@@ -282,43 +282,6 @@ module.exports = app => {
|
|
|
await this.ctx.service.pos.deletePosData(this.transaction, mid, this._.map(deleteData, 'id'));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 过滤data中update方式不可提交的字段
|
|
|
- * @param {Number} id - 主键key
|
|
|
- * @param {Object} data
|
|
|
- * @return {Object<{id: *}>}
|
|
|
- * @private
|
|
|
- */
|
|
|
- // _filterUpdateInvalidField(id, data) {
|
|
|
- // const result = {
|
|
|
- // id,
|
|
|
- // };
|
|
|
- // for (const prop in data) {
|
|
|
- // if (readOnlyFields.indexOf(prop) === -1) {
|
|
|
- // result[prop] = data[prop];
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return result;
|
|
|
- // }
|
|
|
-
|
|
|
- /**
|
|
|
- * newData中,以orgData为基准,过滤掉orgData中未定义或值相等的部分
|
|
|
- * @param {Object} orgData
|
|
|
- * @param {Object} newData
|
|
|
- * @private
|
|
|
- */
|
|
|
- _filterChangedField(orgData, newData) {
|
|
|
- const result = {};
|
|
|
- let bChanged = false;
|
|
|
- for (const prop in orgData) {
|
|
|
- if (this._.isEmpty(newData[prop]) && newData[prop] !== orgData[prop]) {
|
|
|
- result[prop] = newData[prop];
|
|
|
- bChanged = true;
|
|
|
- }
|
|
|
- }
|
|
|
- return bChanged ? result : undefined;
|
|
|
- }
|
|
|
-
|
|
|
_checkField(data, field) {
|
|
|
const fields = field instanceof Array ? field : [field];
|
|
|
for (const prop in data) {
|
|
@@ -330,21 +293,6 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 检查data中是否含有计算字段
|
|
|
- * @param {Object} data
|
|
|
- * @return {boolean}
|
|
|
- * @private
|
|
|
- */
|
|
|
- // _checkCalcField(data) {
|
|
|
- // for (const prop in data) {
|
|
|
- // if (calcFields.indexOf(prop) >= 0) {
|
|
|
- // return true;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return false;
|
|
|
- // }
|
|
|
-
|
|
|
- /**
|
|
|
* 复制粘贴整块
|
|
|
* @param {Number} tenderId - 标段Id
|
|
|
* @param {Number} selectId - 选中几点Id
|
|
@@ -451,103 +399,6 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 提交数据 - 响应计算(增量方式计算)
|
|
|
- * @param {Number} tenderId
|
|
|
- * @param {Object} data
|
|
|
- * @return {Promise<*>}
|
|
|
- */
|
|
|
- // async updateCalc(tenderId, data) {
|
|
|
- // // 简单验证数据
|
|
|
- // if (tenderId <= 0 || !this.ctx.tender) {
|
|
|
- // throw '标段不存在';
|
|
|
- // }
|
|
|
- // const info = this.ctx.tender.info;
|
|
|
- // if (!data) {
|
|
|
- // throw '提交数据错误';
|
|
|
- // }
|
|
|
- // const datas = data instanceof Array ? data : [data];
|
|
|
- // const ids = [];
|
|
|
- // for (const row of datas) {
|
|
|
- // if (tenderId !== row.tender_id) {
|
|
|
- // throw '提交数据错误';
|
|
|
- // }
|
|
|
- // ids.push(row.id);
|
|
|
- // }
|
|
|
- //
|
|
|
- // this.transaction = await this.db.beginTransaction();
|
|
|
- // try {
|
|
|
- // for (const row of datas) {
|
|
|
- // const updateNode = await this.getDataById(row.id);
|
|
|
- // if (!updateNode || tenderId !== updateNode.tender_id || row.ledger_id !== updateNode.ledger_id) {
|
|
|
- // throw '提交数据错误';
|
|
|
- // }
|
|
|
- // let updateData;
|
|
|
- // if (row.unit) {
|
|
|
- // if (row.sgfh_qty === undefined) { row.sgfh_qty = updateNode.sgfh_qty; }
|
|
|
- // if (row.sjcl_qty === undefined) { row.sjcl_qty = updateNode.sjcl_qty; }
|
|
|
- // if (row.qtcl_qty === undefined) { row.qtcl_qty = updateNode.qtcl_qty; }
|
|
|
- // if (row.deal_qty === undefined) { row.deal_qty = updateNode.deal_qty; }
|
|
|
- // }
|
|
|
- // if (row.b_code) {
|
|
|
- // row.dgn_qty1 = null;
|
|
|
- // row.dgn_qty2 = null;
|
|
|
- // }
|
|
|
- // if (this._checkCalcField(row)) {
|
|
|
- // let calcData = JSON.parse(JSON.stringify(row));
|
|
|
- // const precision = this.ctx.helper.findPrecision(info.precision, row.unit ? row.unit : updateNode.unit);
|
|
|
- // // 数量保留小数位数
|
|
|
- // this.ctx.helper.checkFieldPrecision(calcData, qtyFields, precision.value);
|
|
|
- // // 单位保留小数位数
|
|
|
- // this.ctx.helper.checkFieldPrecision(calcData, upFields, info.decimal.up);
|
|
|
- // // 未提交单价则读取数据库单价
|
|
|
- // if (row.unit_price === undefined) calcData.unit_price = updateNode.unit_price;
|
|
|
- // // 计算
|
|
|
- // if (row.sgfh_qty !== undefined || row.sjcl_qty !== undefined || row.qtcl_qty !== undefined ||
|
|
|
- // row.deal_qty !== undefined || row.unit_price) {
|
|
|
- // if (row.sgfh_qty === undefined) calcData.sgfh_qty = updateNode.sgfh_qty;
|
|
|
- // if (row.sjcl_qty === undefined) calcData.sjcl_qty = updateNode.sjcl_qty;
|
|
|
- // if (row.qtcl_qty === undefined) calcData.qtcl_qty = updateNode.qtcl_qty;
|
|
|
- // if (row.deal_qty === undefined) calcData.deal_qty = updateNode.deal_qty;
|
|
|
- // calcData.quantity = this.ctx.helper.sum([calcData.sgfh_qty, calcData.sjcl_qty, calcData.qtcl_qty]);
|
|
|
- // calcData.sgfh_tp = this.ctx.helper.mul(calcData.sgfh_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.sjcl_tp = this.ctx.helper.mul(calcData.sjcl_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.qtcl_tp = this.ctx.helper.mul(calcData.qtcl_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.total_price = this.ctx.helper.mul(calcData.quantity, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.deal_tp = this.ctx.helper.mul(calcData.deal_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // } else if (row.sgfh_tp !== undefined || row.sjcl_tp !== undefined || row.qtcl_tp !== undefined || row.deal_tp !== undefined) {
|
|
|
- // calcData.sgfh_qty = null;
|
|
|
- // calcData.sjcl_qty = null;
|
|
|
- // calcData.qtcl_qty = null;
|
|
|
- // calcData.quantity = null;
|
|
|
- // calcData.deal_qty = null;
|
|
|
- // calcData.sgfh_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.sgfh_tp, info.decimal.tp) : updateNode.sgfh_tp;
|
|
|
- // calcData.sjcl_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.sjcl_tp, info.decimal.tp) : updateNode.sjcl_tp;
|
|
|
- // calcData.qtcl_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.qtcl_tp, info.decimal.tp) : updateNode.qtcl_tp;
|
|
|
- // calcData.total_price = this.ctx.helper.sum([calcData.sgfh_tp, calcData.sjcl_tp, calcData.qtcl_tp]);
|
|
|
- // calcData.deal_tp = (row.deal_tp !== undefined) ? this.ctx.helper.round(calcData.row.deal_tp, info.decimal.tp) : updateNode.deal_tp;
|
|
|
- // } else if (row.unit_price !== undefined) {
|
|
|
- // calcData.sgfh_tp = this.ctx.helper.mul(calcData.sgfh_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.sjcl_tp = this.ctx.helper.mul(calcData.sjcl_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.qtcl_tp = this.ctx.helper.mul(calcData.qtcl_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.total_price = this.ctx.helper.mul(calcData.quantity, calcData.unit_price, info.decimal.tp);
|
|
|
- // calcData.deal_tp = this.ctx.helper.mul(calcData.deal_qty, calcData.unit_price, info.decimal.tp);
|
|
|
- // }
|
|
|
- // updateData = this._filterUpdateInvalidField(updateNode.id, calcData);
|
|
|
- // } else {
|
|
|
- // updateData = this._filterUpdateInvalidField(updateNode.id, row);
|
|
|
- // }
|
|
|
- // await this.transaction.update(this.tableName, updateData);
|
|
|
- // }
|
|
|
- // await this.transaction.commit();
|
|
|
- // } catch (err) {
|
|
|
- // await this.transaction.rollback();
|
|
|
- // throw err;
|
|
|
- // }
|
|
|
- //
|
|
|
- // return { update: await this.getDataByIds(ids) };
|
|
|
- // }
|
|
|
-
|
|
|
- /**
|
|
|
*
|
|
|
* @param tenderId
|
|
|
* @param xmj
|
|
@@ -821,24 +672,16 @@ module.exports = app => {
|
|
|
* @returns {Promise<void>}
|
|
|
*/
|
|
|
async importExcel(templateId, excelData) {
|
|
|
- console.time('analysis');
|
|
|
- const AnalysisExcel = require('../lib/analysis_excel');
|
|
|
+ const AnalysisExcel = require('../lib/analysis_excel').AnalysisExcelTree;
|
|
|
const analysisExcel = new AnalysisExcel(this.ctx);
|
|
|
const tempData = await this.ctx.service.tenderNodeTemplate.getData(templateId, true);
|
|
|
const cacheTree = analysisExcel.analysisData(excelData, tempData);
|
|
|
const cacheKey = keyPre + this.ctx.tender.id;
|
|
|
const orgMaxId = parseInt(await this.cache.get(cacheKey));
|
|
|
- console.timeEnd('analysis');
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- console.time('deleteBills');
|
|
|
await transaction.delete(this.tableName, {tender_id: this.ctx.tender.id});
|
|
|
- console.timeEnd('deleteBills');
|
|
|
- console.time('deletePos');
|
|
|
await transaction.delete(this.ctx.service.pos.tableName, {tid: this.ctx.tender.id});
|
|
|
- console.timeEnd('deletePos');
|
|
|
- console.time('insertBills');
|
|
|
- //const bills = await this._importCacheTreeNodes(transaction, cacheTree.items);
|
|
|
const datas = [];
|
|
|
for (const node of cacheTree.items) {
|
|
|
datas.push({
|
|
@@ -866,12 +709,9 @@ module.exports = app => {
|
|
|
});
|
|
|
}
|
|
|
await transaction.insert(this.tableName, datas);
|
|
|
- console.timeEnd('insertBills');
|
|
|
- console.time('insertPos');
|
|
|
if (cacheTree.pos && cacheTree.pos.length > 0) {
|
|
|
await transaction.insert(this.ctx.service.pos.tableName, cacheTree.pos);
|
|
|
}
|
|
|
- console.timeEnd('insertPos');
|
|
|
await transaction.commit();
|
|
|
this.cache.set(cacheKey, cacheTree.items.length + 1, 'EX', this.ctx.app.config.cacheTime);
|
|
|
return {bills: datas, pos: cacheTree.pos}
|