浏览代码

新增标段清单、批量插入子项,父节点刷新问题相关

MaiXinRong 6 年之前
父节点
当前提交
dd3a77331d
共有 2 个文件被更改,包括 38 次插入7 次删除
  1. 38 5
      app/service/ledger.js
  2. 0 2
      app/service/pos.js

+ 38 - 5
app/service/ledger.js

@@ -781,6 +781,13 @@ module.exports = app => {
             return result;
         }
 
+        /**
+         * 新增子节点,并排在所有子节点的末尾
+         * @param {Number} tenderId - 标段Id
+         * @param {Number} selectId - 父节点Id
+         * @param {Object} data - 新增节点数据(编号名称等)
+         * @returns {Promise<*>}
+         */
         async addChild(tenderId, selectId, data) {
             if ((tenderId <= 0) || (selectId <= 0)) {
                 return [];
@@ -805,16 +812,39 @@ module.exports = app => {
             data.order = children.length + 1;
             data.full_path = selectData.full_path + '.' + data.ledger_id;
             data.is_leaf = true;
-            const result = await this.db.insert(this.tableName, data);
+
+            this.transaction = await this.db.beginTransaction();
+            try {
+                const result = await this.transaction.insert(this.tableName, data);
+                if (children.length === 0) {
+                    await this.transaction.update(this.tableName, {is_leaf: false},
+                        { where: {tender_id: tenderId, ledger_id: selectData.ledger_id} });
+                }
+                await this.transaction.commit();
+            } catch(err) {
+                console.log(err);
+                this.transaction.rollback();
+                throw err;
+            }
 
             this.cache.set(cacheKey, maxId + 1, 'EX', this.ctx.app.config.cacheTime);
 
             // 查询应返回的结果
-            const createData = await this.getDataByNodeId(tenderId, data.ledger_id);
-            return { create: createData };
-
+            const resultData = {};
+            resultData.create = await this.getDataByNodeId(tenderId, data.ledger_id);
+            if (children.length === 0) {
+                resultData.update = await this.getDataByNodeId(tenderId, selectId);
+            }
+            return resultData;
         }
 
+        /**
+         * 添加标准节点,将选择的标准节点,添加为子节点(排序为末尾)
+         * @param {Number} tenderId - 标段Id
+         * @param {Number} selectId - 添加目标节点Id
+         * @param {Object} stdData - 标准节点数据
+         * @returns {Promise<*>}
+         */
         async addStdNodeAsChild(tenderId, selectId, stdData) {
             const newData = this._filterStdData(stdData);
             const result = await this.addChild(tenderId, selectId, newData);
@@ -1738,8 +1768,8 @@ module.exports = app => {
 
             this.transaction = await this.db.beginTransaction();
             const newIds = [];
+            const lastChild = await this.getLastChildData(tenderId, selectId);
             try {
-                const lastChild = await this.getLastChildData(tenderId, selectId);
                 // 更新父项isLeaf
                 if (!lastChild) {
                     await this.transaction.update(this.tableName, {
@@ -1789,6 +1819,9 @@ module.exports = app => {
 
             // 查询应返回的结果
             result.ledger.create = await this.getDataByIds(newIds);
+            if (!lastChild) {
+                result.ledger.update = await this.getDataByIds([selectData.id]);
+            }
             result.pos = await this.ctx.service.pos.getPosData({ lid: newIds });
             return result;
         }

+ 0 - 2
app/service/pos.js

@@ -125,11 +125,9 @@ module.exports = app => {
                         const bills = await this.ctx.service.ledger.getDataById(d.lid);
                         const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
                         d.quantity = this._.round(d.quantity, precision.value);
-                        console.log(updateLid);
                         if (updateLid.indexOf(d.lid) === -1) {
                             updateLid.push(d.lid);
                         }
-                        console.log(updateLid);
                     }
                     if (d.id) {
                         await transaction.update(this.tableName, d);