Explorar o código

1. 标段属性,单元测试错误
2. 签约清单,导入报错

MaiXinRong %!s(int64=6) %!d(string=hai) anos
pai
achega
fc94b47467

+ 1 - 1
app/controller/deal_bills_controller.js

@@ -65,7 +65,7 @@ module.exports = app => {
                         rows: xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
                         rows: xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
                         merge: wb.Sheets[name]["!merges"],
                         merge: wb.Sheets[name]["!merges"],
                     };
                     };
-                    const result = await ctx.service.dealBills.importDataJsXlsx(sheetData.rows, ctx.tender.id);
+                    const result = await ctx.service.dealBills.importDataJsXlsx(sheetData, ctx.tender.id);
                     if (!result) {
                     if (!result) {
                         throw '导入数据失败';
                         throw '导入数据失败';
                     }
                     }

+ 43 - 41
app/service/deal_bills.js

@@ -100,50 +100,52 @@ module.exports = app => {
          */
          */
         async importDataJsXlsx(sheet, tenderId) {
         async importDataJsXlsx(sheet, tenderId) {
             let result = false;
             let result = false;
-            const transaction = await this.db.beginTransaction();
-            try {
-                const bills = [];
-                let iCode = -1, iName = -1, iUnit = -1, iUp = -1, iQty = -1, iTp = -1, bCheckCol = false;
-                for (let iRow = 0; iRow < sheet.rows.length; iRow++) {
-                    const row = sheet.rows[iRow];
+            // 整理数据
+            const bills = [];
+            let iCode = -1, iName = -1, iUnit = -1, iUp = -1, iQty = -1, iTp = -1, bCheckCol = false;
+            for (let iRow = 0; iRow < sheet.rows.length; iRow++) {
+                const row = sheet.rows[iRow];
+                if (!bCheckCol) {
+                    for (let iCol = 0; iCol < row.length; iCol++) {
+                        const value = row[iCol];
+                        if (typeof value !== "string") { continue }
+                        if (value === '子目号' || value === '清单编号') iCode = iCol;
+                        if (value.indexOf('名称') >= 0) iName = iCol;
+                        if (value.indexOf('单位') >= 0) iUnit = iCol;
+                        if (value.indexOf('单价') >= 0) iUp = iCol;
+                        if (value.indexOf('数量') >= 0) iQty = iCol;
+                        if (value.indexOf('金额') >= 0 || value.indexOf('合价') >= 0) iTp = iCol;
+                    }
+                    bCheckCol = (iCode >= 0 && iName >= 0 && iUnit >= 0 && iUp >= 0 && iQty >= 0);
                     if (!bCheckCol) {
                     if (!bCheckCol) {
-                        for (let iCol = 0; iCol < row.length; iCol++) {
-                            const value = row[iCol];
-                            if (typeof value !== "string") { continue }
-                            if (value === '子目号' || value === '清单编号') iCode = iCol;
-                            if (value.indexOf('名称') >= 0) iName = iCol;
-                            if (value.indexOf('单位') >= 0) iUnit = iCol;
-                            if (value.indexOf('单价') >= 0) iUp = iCol;
-                            if (value.indexOf('数量') >= 0) iQty = iCol;
-                            if (value.indexOf('金额') >= 0 || value.indexOf('合价') >= 0) iTp = iCol;
-                        }
-                        bCheckCol = (iCode >= 0 && iName >= 0 && iUnit >= 0 && iUp >= 0 && iQty >= 0);
-                        if (!bCheckCol) {
-                            iCode = -1;
-                            iName = -1;
-                            iUnit = -1;
-                            iUp = -1;
-                            iQty = -1;
-                        }
-                    } else if (this.ctx.helper.validBillsCode(row[iCode])) {
-                        const data = {
-                            deal_id: bills.length + 1,
-                            tender_id: tenderId,
-                            code: row[iCode],
-                            name: row[iName],
-                            unit: row[iUnit],
-                            unit_price: this._.toNumber(row[iUp]),
-                            quantity: this._.toNumber(row[iQty]),
-                        };
-                        if (this._.isNaN(data.unit_price) || this._.isNaN(data.quantity)) {
-                            throw '导入的Excel的数据类型有误,请检查第' + (iRow + 1) + '行';
-                        }
-                        bills.push(data);
+                        iCode = -1;
+                        iName = -1;
+                        iUnit = -1;
+                        iUp = -1;
+                        iQty = -1;
                     }
                     }
+                } else if (this.ctx.helper.validBillsCode(row[iCode])) {
+                    const data = {
+                        deal_id: bills.length + 1,
+                        tender_id: tenderId,
+                        code: row[iCode],
+                        name: row[iName],
+                        unit: row[iUnit],
+                        unit_price: this._.toNumber(row[iUp]),
+                        quantity: this._.toNumber(row[iQty]),
+                    };
+                    if (this._.isNaN(data.unit_price) || this._.isNaN(data.quantity)) {
+                        throw '导入的Excel的数据类型有误,请检查第' + (iRow + 1) + '行';
+                    }
+                    bills.push(data);
                 }
                 }
-                if (!bCheckCol) {
-                    throw '导入的Excel表头定义有误,请下载示例检查';
-                }
+            }
+            if (!bCheckCol) {
+                throw '导入的Excel表头定义有误,请下载示例检查';
+            }
+            // 写入数据
+            const transaction = await this.db.beginTransaction();
+            try {
                 if (bills.length > 0) {
                 if (bills.length > 0) {
                     await transaction.delete(this.tableName, {tender_id: tenderId});
                     await transaction.delete(this.tableName, {tender_id: tenderId});
                     const billsResult = await transaction.insert(this.tableName, bills);
                     const billsResult = await transaction.insert(this.tableName, bills);

+ 2 - 3
app/service/ledger.js

@@ -822,7 +822,6 @@ module.exports = app => {
                 }
                 }
                 await this.transaction.commit();
                 await this.transaction.commit();
             } catch(err) {
             } catch(err) {
-                console.log(err);
                 this.transaction.rollback();
                 this.transaction.rollback();
                 throw err;
                 throw err;
             }
             }
@@ -1939,7 +1938,7 @@ module.exports = app => {
             data.id = node.id;
             data.id = node.id;
             data.quantity = this.round(data.quantity, precision.value);
             data.quantity = this.round(data.quantity, precision.value);
             data.total_price = this.round(this.ctx.helper.times(data.quantity, node.unit_price), info.decimal.tp);
             data.total_price = this.round(this.ctx.helper.times(data.quantity, node.unit_price), info.decimal.tp);
-            await transaction.update(this.tableName, data);
+            const result = await transaction.update(this.tableName, data);
         }
         }
 
 
         /**
         /**
@@ -1954,7 +1953,7 @@ module.exports = app => {
             if (!node) {
             if (!node) {
                 throw '数据错误';
                 throw '数据错误';
             }
             }
-            this._calcNode(node, transaction);
+            await this._calcNode(node, transaction);
         }
         }
 
 
         /**
         /**

+ 4 - 5
app/service/pos.js

@@ -51,9 +51,9 @@ module.exports = app => {
          * @returns {Promise<{ledger: {}, pos: null}>}
          * @returns {Promise<{ledger: {}, pos: null}>}
          */
          */
         async savePosData(data, tid) {
         async savePosData(data, tid) {
+            const result = { ledger: {}, pos: null };
             const transaction = await this.db.beginTransaction();
             const transaction = await this.db.beginTransaction();
             try {
             try {
-                const result = { ledger: {}, pos: null };
                 if (data.updateType === 'add') {
                 if (data.updateType === 'add') {
                     const tender = await this.ctx.service.tender.getTender(tid);
                     const tender = await this.ctx.service.tender.getTender(tid);
                     if (data.updateData instanceof Array) {
                     if (data.updateData instanceof Array) {
@@ -88,7 +88,6 @@ module.exports = app => {
                     }
                     }
                     const pos = await this.getPosData({tid: tid, id: data.updateData});
                     const pos = await this.getPosData({tid: tid, id: data.updateData});
                     const ledgerIds = this._.map(pos, 'lid');
                     const ledgerIds = this._.map(pos, 'lid');
-                    console.log(ledgerIds);
                     await transaction.delete(this.tableName, {tid: tid, id: data.updateData});
                     await transaction.delete(this.tableName, {tid: tid, id: data.updateData});
                     for (const lid of ledgerIds) {
                     for (const lid of ledgerIds) {
                         await this.ctx.service.ledger.calc(tid, lid, transaction);
                         await this.ctx.service.ledger.calc(tid, lid, transaction);
@@ -98,13 +97,13 @@ module.exports = app => {
                     throw '提交数据错误';
                     throw '提交数据错误';
                 }
                 }
                 await transaction.commit();
                 await transaction.commit();
-                result.pos = data.updateData;
-                result.ledger.update = await this.ctx.service.ledger.getDataByIds(result.ledger.update);
-                return result;
             } catch (err) {
             } catch (err) {
                 await transaction.rollback();
                 await transaction.rollback();
                 throw err;
                 throw err;
             }
             }
+            result.pos = data.updateData;
+            result.ledger.update = await this.ctx.service.ledger.getDataByIds(result.ledger.update);
+            return result;
         }
         }
 
 
         /**
         /**

+ 1 - 1
test/app/service/tender_info.test.js

@@ -55,7 +55,7 @@ describe('test/app/service/tender.test.js', () => {
             const iRst = yield ctx.service.tenderInfo.db.delete(ctx.service.tenderInfo.tableName, {
             const iRst = yield ctx.service.tenderInfo.db.delete(ctx.service.tenderInfo.tableName, {
                 tid: tender1.id
                 tid: tender1.id
             });
             });
-            assert(iRst.affectedRows === 5);
+            assert(iRst.affectedRows === 1);
         }
         }
         // 新增测试用标段
         // 新增测试用标段
         const result = yield ctx.service.tender.add(addData);
         const result = yield ctx.service.tender.add(addData);