|
@@ -812,6 +812,7 @@ module.exports = app => {
|
|
|
});
|
|
|
}
|
|
|
await transaction.insert(this.tableName, datas);
|
|
|
+ return datas;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -820,32 +821,60 @@ module.exports = app => {
|
|
|
* @returns {Promise<void>}
|
|
|
*/
|
|
|
async importExcel(templateId, excelData) {
|
|
|
- //console.time('analysis');
|
|
|
+ console.time('analysis');
|
|
|
const AnalysisExcel = require('../lib/analysis_excel');
|
|
|
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');
|
|
|
+ console.timeEnd('analysis');
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- //console.time('deleteBills');
|
|
|
+ console.time('deleteBills');
|
|
|
await transaction.delete(this.tableName, {tender_id: this.ctx.tender.id});
|
|
|
- //console.timeEnd('deleteBills');
|
|
|
- //console.time('deletePos');
|
|
|
+ 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');
|
|
|
- await this._importCacheTreeNodes(transaction, cacheTree.items);
|
|
|
- //console.timeEnd('insertBills');
|
|
|
- //console.time('insertPos');
|
|
|
+ console.timeEnd('deletePos');
|
|
|
+ console.time('insertBills');
|
|
|
+ //const bills = await this._importCacheTreeNodes(transaction, cacheTree.items);
|
|
|
+ const datas = [];
|
|
|
+ for (const node of cacheTree.items) {
|
|
|
+ datas.push({
|
|
|
+ id: node.id,
|
|
|
+ tender_id: this.ctx.tender.id,
|
|
|
+ ledger_id: node.ledger_id,
|
|
|
+ ledger_pid: node.ledger_pid,
|
|
|
+ level: node.level,
|
|
|
+ order: node.order,
|
|
|
+ is_leaf: !node.children || node.children.length === 0,
|
|
|
+ full_path: node.full_path,
|
|
|
+ code: node.code,
|
|
|
+ b_code: node.b_code,
|
|
|
+ name: node.name,
|
|
|
+ unit: node.unit,
|
|
|
+ sgfh_qty: node.sgfh_qty,
|
|
|
+ sgfh_tp: node.sgfh_tp,
|
|
|
+ quantity: node.quantity,
|
|
|
+ unit_price: node.unit_price,
|
|
|
+ total_price: node.total_price,
|
|
|
+ dgn_qty1: node.dgn_qty1,
|
|
|
+ dgn_qty2: node.dgn_qty2,
|
|
|
+ memo: node.memo,
|
|
|
+ drawing_code: node.drawing_code,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ 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');
|
|
|
+ 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}
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
|
if (orgMaxId) {
|