浏览代码

复制整块调整

MaiXinRong 5 年之前
父节点
当前提交
643745cd91
共有 3 个文件被更改,包括 39 次插入26 次删除
  1. 3 3
      app/lib/rpt_data_analysis.js
  2. 22 14
      app/service/ledger.js
  3. 14 9
      app/service/pos.js

+ 3 - 3
app/lib/rpt_data_analysis.js

@@ -163,7 +163,7 @@ const gatherGcl = {
     },
     _loadGatherInfo: function (gcl, data) {
         for (const prop in data) {
-            if (/^t_[0-9]*_(id|name)$/.test(prop)) {
+            if (/^t_[0-9]+_(id|name)$/.test(prop)) {
                 gcl[prop] = data[prop];
             }
         }
@@ -188,7 +188,7 @@ const gatherGcl = {
         }
         const gatherOther = fields.indexOf('chapter') >= 0;
         const gclBills = [], other = {name: '未计入清单章节项', chapter: '10000'};
-        this._loadGatherInfo(other, gatherData[0]);
+        if (tableName.indexOf('mem_gather_') >= 0) this._loadGatherInfo(other, gatherData[0]);
 
         for (const b of gatherData) {
             const child = ctx.helper._.find(gatherData, {ledger_pid: b.ledger_id});
@@ -1339,7 +1339,7 @@ const stageSelectConverse = {
     },
     _commonConverse: function (helper, data, stages) {
         const result = [];
-        const reg = new RegExp('^t_[0-9]+_');
+        const reg = new RegExp('^s_[0-9]+_');
         for (const s of stages) {
             const curReg = new RegExp('^s_' + s + '_');
             for (const [i, d] of data.entries()) {

+ 22 - 14
app/service/ledger.js

@@ -324,22 +324,20 @@ module.exports = app => {
             if (!bSameParent) {
                 throw '复制数据错误:仅可操作同层节点';
             }
-            const orgParentPath = copyNodes[0].full_path.replace(copyNodes[0].ledger_id, '');
 
-            const newIds = [];
+            const pasteBillsData = [], pastePosData = [];
             this.transaction = await this.db.beginTransaction();
             try {
                 // 选中节点的所有后兄弟节点,order+粘贴节点个数
                 await this._updateChildrenOrder(tenderId, selectData.ledger_pid, selectData.order + 1, copyNodes.length);
                 // 数据库创建新增节点数据
+                const leafBillsId = [];
+                let maxId = await this._getMaxLid(this.ctx.tender.id);
                 for (let iNode = 0; iNode < copyNodes.length; iNode++) {
                     const node = copyNodes[iNode];
                     let datas = await this.getDataByFullPath(paste.tid, node.full_path + '%');
                     datas = this._.sortBy(datas, 'level');
 
-                    const maxId = await this._getMaxLid(this.ctx.tender.id);
-
-                    const leafBillsId = [];
                     // 计算粘贴数据中需更新部分
                     datas.sort(function (x, y) {
                         return x.level - y.level;
@@ -372,7 +370,6 @@ module.exports = app => {
                         if (data.is_leaf) {
                             leafBillsId.push(idChange);
                         }
-                        newIds.push(data.id);
                     }
                     for (const data of datas) {
                         delete data.children;
@@ -384,13 +381,26 @@ module.exports = app => {
                         } else {
                             data.full_path = newParentPath + '' + data.ledger_id;
                         }
+                        pasteBillsData.push(data)
                     }
-                    const newData = await this.transaction.insert(this.tableName, datas);
-                    for (const id of leafBillsId) {
-                        await this.ctx.service.pos.copyBillsPosData(id.org, id.new, this.transaction);
+                    maxId = maxId + datas.length;
+                }
+                const newData = await this.transaction.insert(this.tableName, pasteBillsData);
+                this._cacheMaxLid(tenderId, maxId);
+
+                for (const id of leafBillsId) {
+                    const posData = await this.ctx.service.pos.getAllDataByCondition({ where: { tid: paste.tid, lid: id.org } });
+                    if (posData.length > 0) {
+                        for (const pd of posData) {
+                            pd.id = this.uuid.v4();
+                            pd.lid = id.new;
+                            pd.tid = this.ctx.tender.id;
+                            pd.in_time = new Date();
+                            pastePosData.push(pd);
+                        }
                     }
-                    this._cacheMaxLid(tenderId, maxId + datas.length);
                 }
+                await this.transaction.insert(this.ctx.service.pos.tableName, pastePosData);
                 await this.transaction.commit();
             } catch (err) {
                 await this.transaction.rollback();
@@ -402,12 +412,10 @@ module.exports = app => {
             for (let i = 1; i <= copyNodes.length; i++) {
                 order.push(selectData.order + i);
             }
-            const createData = await this.getDataByIds(newIds);
             const updateData = await this.getNextsData(selectData.tender_id, selectData.ledger_pid, selectData.order + copyNodes.length);
-            const posData = await this.ctx.service.pos.getPosData({ lid: newIds });
             return {
-                ledger: { create: createData, update: updateData },
-                pos: posData,
+                ledger: { create: pasteBillsData, update: updateData },
+                pos: pastePosData,
             };
         }
 

+ 14 - 9
app/service/pos.js

@@ -454,17 +454,22 @@ module.exports = app => {
          * @param transaction - 复制整块事务
          * @returns {Promise<void>}
          */
-        async copyBillsPosData(orgLid, newLid, transaction) {
-            const posData = await this.getAllDataByCondition({ where: { lid: orgLid } });
-            if (posData.length > 0) {
-                for (const pd of posData) {
-                    pd.id = this.uuid.v4();
-                    pd.lid = newLid;
-                    pd.tid = this.ctx.tender.id;
-                    pd.in_time = new Date();
+        async copyBillsPosData(lid, transaction) {
+            const lidArr = lid instanceof Array ? lid : [lid];
+            const pasteData = [];
+            for (const id of lidArr) {
+                const posData = await this.getAllDataByCondition({ where: { lid: id.org } });
+                if (posData.length > 0) {
+                    for (const pd of posData) {
+                        pd.id = this.uuid.v4();
+                        pd.lid = id.new;
+                        pd.tid = this.ctx.tender.id;
+                        pd.in_time = new Date();
+                        pasteData.push(pd);
+                    }
                 }
-                await transaction.insert(this.tableName, posData);
             }
+            await transaction.insert(this.tableName, pasteData);
         }
 
         /**