瀏覽代碼

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

TonyKang 5 年之前
父節點
當前提交
4262a4d23a

+ 135 - 169
app/base/base_tree_service.js

@@ -1,10 +1,7 @@
 'use strict';
 
 /**
- * 提供基础操作:
- * 1. 增删改查
- * 2. 粘贴整块
- * 3. 简易导入
+ * 提供基础操作:增删改查
  *
  * @author Mai
  * @date
@@ -14,6 +11,7 @@
 const Service = require('./base_service');
 // sql拼装器
 const SqlBuilder = require('../lib/sql_builder');
+const rootId = -1;
 
 class TreeService extends Service {
     /**
@@ -53,7 +51,7 @@ class TreeService extends Service {
         if (condition.mid) result[this.setting.mid] = condition.mid;
         if (condition.kid) result[this.setting.kid] = condition.kid;
         if (condition.pid) result[this.setting.pid] = condition.pid;
-        if (condition[this.setting.order]) result[this.setting.order] = condition[this.setting.order];
+        if (condition.order) result[this.setting.order] = condition.order;
         if (condition.level) result[this.setting.level] = condition.level;
         if (condition.fullPath) result[this.setting.fullPath] = condition.fullPath;
         if (condition.isLeaf) result[this.setting.isLeaf] = condition.isLeaf;
@@ -65,10 +63,24 @@ class TreeService extends Service {
      * @param {Number} mid - masterId
      * @returns {Promise<void>}
      */
-    async getData(mid) {
-        return await this.db.select(this.tableName, {
-            where: this.getCondition({mid: mid})
-        });
+    async getData(mid, level) {
+        if (level) {
+            this.initSqlBuilder();
+            this.sqlBuilder.setAndWhere('list_id', {
+                operate: '=',
+                value: mid,
+            });
+            this.sqlBuilder.setAndWhere('level', {
+                operate: '<=',
+                value: level,
+            });
+            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
+            return await this.db.query(sql, sqlParam);
+        } else {
+            return await this.db.select(this.tableName, {
+                where: this.getCondition({mid: mid})
+            });
+        }
     }
 
     /**
@@ -77,7 +89,7 @@ class TreeService extends Service {
      * @param {Number} id
      * @returns {Promise<void>}
      */
-    async getDataByLid (mid, kid) {
+    async getDataByKid (mid, kid) {
         return await this.db.get(this.tableName, this.getCondition({
             mid: mid, kid: kid,
         }));
@@ -163,6 +175,52 @@ class TreeService extends Service {
     }
 
     /**
+     * 根据full_path获取数据 full_path Like ‘1.2.3%’(传参full_path = '1.2.3%')
+     * @param {Number} tenderId - 标段id
+     * @param {String} full_path - 路径
+     * @return {Promise<void>}
+     */
+    async getDataByFullPath(mid, full_path) {
+        this.initSqlBuilder();
+        this.sqlBuilder.setAndWhere(this.setting.mid, {
+            value: mid,
+            operate: '=',
+        });
+        this.sqlBuilder.setAndWhere(this.setting.fullPath, {
+            value: this.db.escape(full_path),
+            operate: 'Like',
+        });
+        const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
+        const resultData = await this.db.query(sql, sqlParam);
+        return resultData;
+    }
+    /**
+     * 根据full_path检索自己及所有父项
+     * @param {Number} tenderId - 标段id
+     * @param {Array|String} fullPath - 节点完整路径
+     * @return {Promise<*>}
+     * @private
+     */
+    async getFullLevelDataByFullPath(mid, fullPath) {
+        const explodePath = this.ctx.helper.explodePath(fullPath);
+
+        this.initSqlBuilder();
+        this.sqlBuilder.setAndWhere(this.setting.mid, {
+            value: mid,
+            operate: '=',
+        });
+        this.sqlBuilder.setAndWhere(this.setting.fullPath, {
+            value: explodePath,
+            operate: 'in',
+        });
+
+        const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
+        const data = await this.db.query(sql, sqlParam);
+
+        return data;
+    }
+
+    /**
      * 获取最大节点id
      *
      * @param {Number} mid - master id
@@ -174,7 +232,7 @@ class TreeService extends Service {
         let maxId = parseInt(await this.cache.get(cacheKey));
         if (!maxId) {
             const sql = 'SELECT Max(??) As max_id FROM ?? Where ' + this.setting.mid + ' = ?';
-            const sqlParam = ['ledger_id', this.tableName, mid];
+            const sqlParam = [this.setting.kid, this.tableName, mid];
             const queryResult = await this.db.queryOne(sql, sqlParam);
             maxId = queryResult.max_id || 0;
             this.cache.set(cacheKey, maxId, 'EX', this.ctx.app.config.cacheTime);
@@ -242,13 +300,13 @@ class TreeService extends Service {
         }
         const maxId = await this._getMaxLid(mid);
 
-        data.id = this.uuid.v4();
+        if (this.setting.uuid) data.id = this.uuid.v4();
         data[this.setting.kid] = maxId + 1;
-        data[this.setting.pid] = select[this.setting.pid];
+        data[this.setting.pid] = select ? select[this.setting.pid] : rootId;
         data[this.setting.mid] = mid;
-        data[this.setting.level] = select[this.setting.level];
-        data[this.setting.order] = select[this.setting.order] + 1;
-        data[this.setting.fullPath] = select[this.setting.fullPath].replace('.' + select[this.setting.kid], '.' + data[this.setting.kid]);
+        data[this.setting.level] = select ? select[this.setting.level] : 1;
+        data[this.setting.order] = select ? select[this.setting.order] + 1 : 1;
+        data[this.setting.fullPath] = data[this.setting.level] > 1 ? select[this.setting.fullPath].replace('.' + select[this.setting.kid], '.' + data[this.setting.kid]) : data[this.setting.kid] + '';
         data[this.setting.isLeaf] = true;
         const result = await this.transaction.insert(this.tableName, data);
 
@@ -264,19 +322,15 @@ class TreeService extends Service {
      * @returns {Promise<void>}
      */
     async addNode(mid, kid, data) {
-        if (!mid || !kid) return null;
-        const select = await this.getDataByLid(mid, kid);
-        if (!select) {
-            throw '新增节点数据错误';
-        }
+        if (!mid) return null;
+        const select = kid ? await this.getDataByKid(mid, kid) : null;
+        if (kid && !select) throw '新增节点数据错误';
 
         this.transaction = await this.db.beginTransaction();
         try {
-            await this._updateChildrenOrder(mid, select[this.setting.pid], select[this.setting.order]+1);
+            if (select) await this._updateChildrenOrder(mid, select[this.setting.pid], select[this.setting.order]+1);
             const newNode = await this._addNodeData(mid, select, data);
-            if (newNode.affectedRows !== 1) {
-                throw '新增节点数据额错误';
-            }
+            if (newNode.affectedRows !== 1) throw '新增节点数据额错误';
             await this.transaction.commit();
             this.transaction = null;
         } catch (err) {
@@ -285,9 +339,14 @@ class TreeService extends Service {
             throw err;
         }
 
-        const createData = await this.getDataByParentAndOrder(mid, select[this.setting.pid], [select[this.setting.order] + 1]);
-        const updateData = await this.getNextsData(mid, select[this.setting.pid], select[this.setting.order] + 1);
-        return {create: createData, update: updateData};
+        if (select) {
+            const createData = await this.getDataByParentAndOrder(mid, select[this.setting.pid], [select[this.setting.order] + 1]);
+            const updateData = await this.getNextsData(mid, select[this.setting.pid], select[this.setting.order] + 1);
+            return {create: createData, update: updateData};
+        } else {
+            const createData = await this.getDataByParentAndOrder(mid, -1, [1]);
+            return {create: createData};
+        }
     }
 
     /**
@@ -322,9 +381,9 @@ class TreeService extends Service {
      */
     async deleteNode(mid, kid) {
         if ((mid <= 0) || (kid <= 0)) return [];
-        const select = await this.getDataByNodeId(mid, kid);
+        const select = await this.getDataByKid(mid, kid);
         if (!select) throw '删除节点数据错误';
-        const parent = await this.getDataByNodeId(mid, select[this.setting.pid]);
+        const parent = await this.getDataByKid(mid, select[this.setting.pid]);
         // 获取将要被删除的数据
         const deleteData = await this.getDataByFullPath(mid, select[this.setting.fullPath] + '%');
         if (deleteData.length === 0) throw '删除节点数据错误';
@@ -343,18 +402,21 @@ class TreeService extends Service {
                 }
             }
             // 选中节点--全部后节点 order--
-            await this._updateSelectNextsOrder(select, -1);
+            await this._updateChildrenOrder(mid, select[this.setting.pid], select[this.setting.order] + 1, -1);
+            //await this._updateSelectNextsOrder(select, -1);
             // 删除部位明细
             //await this.ctx.service.pos.deletePosData(this.transaction, tenderId, this._.map(deleteData, 'id'));
             await this.transaction.commit();
+            this.transaction = null;
         } catch (err) {
             await this.transaction.rollback();
+            this.transaction = null;
             throw err;
         }
         // 查询结果
         const updateData = await this.getNextsData(mid, select[this.setting.pid], select[this.setting.order] - 1);
         if (parent) {
-            const updateData1 = await this.getDataByNodeId(mid, select[this.setting.pid]);
+            const updateData1 = await this.getDataByKid(mid, select[this.setting.pid]);
             if (updateData1[this.setting.isLeaf]) {
                 updateData.push(updateData1);
             }
@@ -371,7 +433,7 @@ class TreeService extends Service {
      */
     async upMoveNode(mid, kid) {
         if (!mid || !kid) return null;
-        const select = await this.getDataByLid(mid, kid);
+        const select = await this.getDataByKid(mid, kid);
         if (!select) {
             throw '上移节点数据错误';
         }
@@ -385,8 +447,10 @@ class TreeService extends Service {
             const sData = await this.transaction.update(this.tableName, { id: select.id, order: select[this.setting.order] - 1 });
             const pData = await this.transaction.update(this.tableName, { id: pre.id, order: pre[this.setting.order] + 1 });
             await this.transaction.commit();
+            this.transaction = null;
         } catch (err) {
             await this.transaction.rollback();
+            this.transaction = null;
             throw err;
         }
 
@@ -403,7 +467,7 @@ class TreeService extends Service {
      */
     async downMoveNode(mid, kid) {
         if (!mid || !kid) return null;
-        const select = await this.getDataByLid(mid, kid);
+        const select = await this.getDataByKid(mid, kid);
         if (!select) {
             throw '下移节点数据错误';
         }
@@ -417,8 +481,10 @@ class TreeService extends Service {
             const sData = await this.transaction.update(this.tableName, { id: select.id, order: select[this.setting.order] + 1 });
             const pData = await this.transaction.update(this.tableName, { id: next.id, order: next[this.setting.order] - 1 });
             await this.transaction.commit();
+            this.transaction = null;
         } catch (err) {
             await this.transaction.rollback();
+            this.transaction = null;
             throw err;
         }
 
@@ -435,11 +501,11 @@ class TreeService extends Service {
     async _syncUplevelChildren(select) {
         this.initSqlBuilder();
         this.sqlBuilder.setAndWhere(this.setting.mid, {
-            value: selectData.tender_id,
+            value: select[this.setting.mid],
             operate: '=',
         });
         this.sqlBuilder.setAndWhere(this.setting.fullPath, {
-            value: this.db.escape(select[this.setting.fullPath] + '.%'),
+            value: this.db.escape(select[this.setting.fullPath] + '-%'),
             operate: 'like',
         });
         this.sqlBuilder.setUpdateData(this.setting.level, {
@@ -528,9 +594,9 @@ class TreeService extends Service {
     async upLevelNode(mid, kid) {
         if ((mid <= 0) || (kid <= 0)) return [];
 
-        const select = await this.getDataByNodeId(mid, kid);
+        const select = await this.getDataByKid(mid, kid);
         if (!select) throw '升级节点数据错误';
-        const parent = await this.getDataByNodeId(mid, select[this.setting.pid]);
+        const parent = await this.getDataByKid(mid, select[this.setting.pid]);
         if (!parent) throw '升级节点数据错误';
 
         this.transaction = await this.db.beginTransaction();
@@ -544,12 +610,13 @@ class TreeService extends Service {
                 });
             }
             // 选中节点--父节点--全部后兄弟节点 order+1
-            await this._updateSelectNextsOrder(parent);
+            await this._updateChildrenOrder(mid, parent[this.setting.pid], parent[this.setting.order] + 1);
+            //await this._updateSelectNextsOrder(parent);
             // 选中节点 修改pid, order, full_path, level, is_leaf, 清空计算项
             const updateData = { id: select.id };
             updateData[this.setting.pid] = parent[this.setting.pid];
             updateData[this.setting.order] = parent[this.setting.order] + 1;
-            updateData[this.setting.level] = select[this.setting.level] + 1;
+            updateData[this.setting.level] = select[this.setting.level] - 1;
             updateData[this.setting.fullPath] = newFullPath;
 
             const nexts = await this.getNextsData(mid, parent[this.setting.kid], select[this.setting.order]);
@@ -567,14 +634,16 @@ class TreeService extends Service {
             // 选中节点--全部后兄弟节点 收编为子节点 修改pid, order, full_path
             await this._syncUpLevelNexts(select);
             await this.transaction.commit();
+            this.transaction = null;
         } catch (err) {
             await this.transaction.rollback();
+            this.transaction = null;
             throw err;
         }
 
         // 查询修改的数据
         const resultData1 = await this.getDataByFullPath(mid, newFullPath + '%');
-        const resultData2 = await this.getNextsData(mid, parent[this.setting.pid], parent[this.setting.order] + 1);
+        const resultData2 = await this.getNextsData(mid, parent[this.setting.pid], parent[this.setting.order] - 1);
         return { update: resultData1.concat(resultData2) };
     }
 
@@ -592,7 +661,7 @@ class TreeService extends Service {
             operate: '=',
         });
         this.sqlBuilder.setAndWhere(this.setting.fullPath, {
-            value: this.db.escape(select[this.setting.fullPath] + '.%'),
+            value: this.db.escape(select[this.setting.fullPath] + '-%'),
             operate: 'like',
         });
         this.sqlBuilder.setUpdateData(this.setting.level, {
@@ -600,7 +669,7 @@ class TreeService extends Service {
             selfOperate: '+',
         });
         this.sqlBuilder.setUpdateData(this.setting.fullPath, {
-            value: [this.setting.fullPath, this.db.escape('.' + select[this.setting.kid]), this.db.escape('.' + pre[this.setting.kid] + '.' + select[this.setting.kid])],
+            value: [this.setting.fullPath, this.db.escape(select[this.setting.kid] + '.'), this.db.escape(pre[this.setting.kid] + '.' + select[this.setting.kid] + '.')],
             literal: 'Replace',
         });
         const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
@@ -618,7 +687,7 @@ class TreeService extends Service {
      */
     async downLevelNode(mid, kid) {
         if ((mid <= 0) || (kid <= 0)) return [];
-        const select = await this.getDataByNodeId(mid, kid);
+        const select = await this.getDataByKid(mid, kid);
         if (!select) throw '降级节点数据错误';
         const pre = await this.getDataByParentAndOrder(mid, select[this.setting.pid], select[this.setting.order] - 1);
         if (!pre) throw '节点不可降级';
@@ -630,10 +699,10 @@ class TreeService extends Service {
         const newFullPath = select.full_path.replace(orgLastPath, newLastPath);
         try {
             // 选中节点--全部后节点 order--
-            await this._updateSelectNextsOrder(select, -1);
+            await this._updateChildrenOrder(mid, select[this.setting.pid], select[this.setting.order] + 1, -1);
             // 选中节点 修改pid, level, order, full_path
             const updateData = { id: select.id };
-            updateData[this.setting.kid] = pre[this.setting.kid];
+            updateData[this.setting.pid] = pre[this.setting.kid];
             updateData[this.setting.order] = preLastChild ? preLastChild[this.setting.order] + 1 : 1;
             updateData[this.setting.level] = select[this.setting.level] + 1;
             updateData[this.setting.fullPath] = newFullPath;
@@ -650,8 +719,10 @@ class TreeService extends Service {
             // updateData2.deal_tp = null;
             await this.transaction.update(this.tableName, updateData2);
             await this.transaction.commit();
+            this.transaction = null;
         } catch (err) {
             await this.transaction.rollback();
+            this.transaction = null;
             throw err;
         }
 
@@ -659,7 +730,7 @@ class TreeService extends Service {
         // 选中节点及子节点
         const resultData1 = await this.getDataByFullPath(mid, newFullPath + '%');
         // 选中节点--原前兄弟节点&全部后兄弟节点
-        const resultData2 = await this.getNextsData(mid, pre[this.setting.pid], pre[this.setting.order]);
+        const resultData2 = await this.getNextsData(mid, pre[this.setting.pid], pre[this.setting.order] - 1);
         return { update: resultData1.concat(resultData2) };
     }
 
@@ -688,133 +759,28 @@ class TreeService extends Service {
      */
     async updateInfos(mid, datas) {
         if (mid <= 0) throw '数据错误';
-        for (const data of datas) {
-            if (mid !== data[this.setting.mid]) throw '提交数据错误';
-        }
 
-        this.transaction = await this.db.beginTransaction();
-        try {
-            for (const data of datas) {
-                const updateNode = await this.getDataById(data.id);
-                if (!updateNode || mid !== updateNode[this.setting.mid] || data.kid !== updateNode[this.setting.kid]) {
-                    throw '提交数据错误';
-                }
-                const updateData = this._filterUpdateInvalidField(updateNode.id, data);
-                await this.transaction.update(this.tableName, updateData);
+        if (Array.isArray(datas)) {
+            const updateDatas = [];
+            for (const d of datas) {
+                if (mid !== d[this.setting.mid]) throw '提交数据错误';
+                const node = await this.getDataById(d.id);
+                if (!node || mid !== node[this.setting.mid] || d[this.setting.kid] !== node[this.setting.kid]) throw '提交数据错误';
+                updateDatas.push(this._filterUpdateInvalidField(node.id, d));
             }
-            await this.transaction.commit();
-        } catch (err) {
-            await this.transaction.rollback();
-            throw err;
-        }
-
-        const resultData = await this.getDataById(this._.map(datas, 'id'));
-        return resultData;
-    }
-
-    async pasteBlockRelaData(relaData) {
-        if (!this.transaction) throw '更新数据错误';
-        // for (const id of relaData) {
-        //     await this.ctx.service.pos.copyBillsPosData(id.org, id.new, this.transaction);
-        // }
-    }
-
-    async getPasteBlockResult(select, copyNodes) {
-        const createData = await this.getDataByIds(newIds);
-        const updateData = await this.getNextsData(selectData[this.setting.mid], selectData[this.setting.pid], selectData[this.setting.order] + copyNodes.length);
-        //const posData = await this.ctx.service.pos.getPosData({ lid: newIds });
-        return {
-            ledger: { create: createData, update: updateData },
-            //pos: posData,
-        };
-    }
-
-    /**
-     * 复制粘贴整块
-     * @param {Number} tenderId - 标段Id
-     * @param {Number} selectId - 选中几点Id
-     * @param {Array} block - 复制节点Id
-     * @return {Object} - 提价后的数据(其中新增粘贴数据,只返回第一层)
-     */
-    async pasteBlock(mid, kid, block) {
-        if ((mid <= 0) || (kid <= 0)) return [];
-
-        const selectData = await this.getDataByNodeId(mid, kid);
-        if (!selectData) throw '数据错误';
-
-        const copyNodes = await this.getDataByNodeIds(mid, block);
-        if (!copyNodes || copyNodes.length <= 0)  throw '复制数据错误';
-        for (const node of copyNodes) {
-            if (node[this.setting.pid] !== copyNodes[0][this.setting.pid]) throw '复制数据错误:仅可操作同层节点';
-        }
+            await this.db.updateRows(this.tableName, updateDatas);
 
-        const newParentPath = selectData[this.setting.fullPath].replace(selectData[this.setting.kid], '');
-        const orgParentPath = copyNodes[0][this.setting.fullPath].replace(copyNodes[0][this.setting.kid], '');
-        const newIds = [];
-        this.transaction = await this.db.beginTransaction();
-        try {
-            // 选中节点的所有后兄弟节点,order+粘贴节点个数
-            await this._updateSelectNextsOrder(selectData, copyNodes.length);
-            for (let iNode = 0; iNode < copyNodes.length; iNode++) {
-                const node = copyNodes[iNode];
-                let datas = await this.getDataByFullPath(mid, node[this.setting.fullPath] + '%');
-                datas = this._.sortBy(datas, 'level');
-
-                const maxId = await this._getMaxLid(mid);
-                this._cacheMaxLid(mid, maxId + datas.length);
-
-                const billsId = [];
-                // 计算粘贴数据中需更新部分
-                for (let index = 0; index < datas.length; index++) {
-                    const data = datas[index];
-                    const newId = maxId + index + 1;
-                    const idChange = {
-                        org: data.id,
-                    };
-                    data.id = this.uuid.v4();
-                    idChange.new = data.id;
-                    data[this.setting.mid] = mid;
-                    if (!data[this.setting.isLeaf]) {
-                        for (const children of datas) {
-                            children[this.setting.fullPath] = children[this.setting.fullPath].replace('.' + data[this.setting.kid], '.' + newId);
-                            if (children[this.setting.pid] === data[this.setting.kid]) {
-                                children[this.setting.pid] = newId;
-                            }
-                        }
-                    } else {
-                        data[this.setting.fullPath] = data[this.setting.fullPath].replace('.' + data[this.setting.kid], '.' + newId);
-                    }
-                    data[this.setting.kid] = newId;
-                    data[this.setting.fullPath] = data[this.setting.fullPath].replace(orgParentPath, newParentPath);
-                    if (data[this.setting.pid] === node[this.setting.pid]) {
-                        data[this.setting.pid] = selectData[this.setting.pid];
-                        data[this.setting.order] = selectData[this.setting.order] + iNode + 1;
-                    }
-                    data[this.setting.level] = data[this.setting.level] + selectData[this.setting.level] - copyNodes[0][this.setting.level];
-                    idChange.isLeaf = data[this.setting.isLeaf];
-                    billsId.push(idChange);
-                    newIds.push(data.id);
-                }
-                const newData = await this.transaction.insert(this.tableName, datas);
-                await this.pasteBlockRelaData(billsId);
-            }
-            // 数据库创建新增节点数据
-            await this.transaction.commit();
-        } catch (err) {
-            await this.transaction.rollback();
-            throw err;
+            const resultData = await this.getDataById(this._.map(datas, 'id'));
+            return resultData;
+        } else {
+            if (mid !== datas[this.setting.mid]) throw '提交数据错误';
+            const node = await this.getDataById(datas.id);
+            if (!node || mid !== node[this.setting.mid] || datas[this.setting.kid] !== node[this.setting.kid]) throw '提交数据错误';
+            const updateData = this._filterUpdateInvalidField(node.id, datas);
+            await this.db.update(this.tableName, updateData);
+            return await this.getDataById(datas.id);
         }
-
-        // 查询应返回的结果
-        const createData = await this.getDataByIds(newIds);
-        const updateData = await this.getNextsData(selectData[this.setting.mid], selectData[this.setting.pid], selectData[this.setting.order] + copyNodes.length);
-        //const posData = await this.ctx.service.pos.getPosData({ lid: newIds });
-        return {
-            ledger: { create: createData, update: updateData },
-            //pos: posData,
-        };
     }
-
 }
 
 module.exports = TreeService;

+ 4 - 4
app/controller/ledger_controller.js

@@ -345,12 +345,12 @@ module.exports = app => {
 
                 let stdLib, addType;
                 switch (data.stdType) {
-                    case 'chapter':
-                        stdLib = ctx.service.stdChapter;
+                    case 'xmj':
+                        stdLib = ctx.service.stdXmj;
                         addType = stdDataAddType.withParent;
                         break;
-                    case 'bills':
-                        stdLib = ctx.service.stdBills;
+                    case 'gcl':
+                        stdLib = ctx.service.stdGcl;
                         const selectNode = await ctx.service.ledger.getDataByNodeId(ctx.tender.id, data.id);
                         if (selectNode.b_code) {
                             addType = stdDataAddType.next;

+ 1 - 1
app/controller/measure_controller.js

@@ -216,7 +216,7 @@ module.exports = app => {
                         const data = { order: order, bills: [], pos: [] };
                         const stage = await this.ctx.service.stage.getDataByCondition({tid: ctx.tender.id, order: order});
                         data.bills = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stage.id);
-                        data.pos = await ctx.service.stagePos.getLastestStageData(ctx.tender.id, stage.id);
+                        data.pos = await ctx.service.stagePos.getLastestStageData2(ctx.tender.id, stage.id);
                         result.stages.push(data);
                     }
                 }

+ 8 - 8
app/controller/stage_controller.js

@@ -156,7 +156,7 @@ module.exports = app => {
                 }
                 // 查询截止上期数据
                 if (ctx.stage.order > 1) {
-                    preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, ctx.stage);
+                    preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, ctx.stage.order - 1);
                     //renderData.preStageData = await ctx.service.stageBills.getEndStageData(ctx.tender.id, ctx.stage.order - 1);
                 } else {
                     preStageData = [];
@@ -197,22 +197,24 @@ module.exports = app => {
                 //console.time('cur');
                 const curWhere = JSON.parse(ctx.request.body.data);
                 if (ctx.stage.readOnly) {
-                    curStageData = await ctx.service.stagePos.getAuditorStageData(ctx.tender.id,
+                    curStageData = await ctx.service.stagePos.getAuditorStageData2(ctx.tender.id,
                         ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder, curWhere);
                 } else {
-                    curStageData = await ctx.service.stagePos.getLastestStageData(ctx.tender.id, ctx.stage.id, curWhere);
+                    curStageData = await ctx.service.stagePos.getLastestStageData2(ctx.tender.id, ctx.stage.id, curWhere);
                 }
                 //console.timeEnd('cur');
                 // 查询截止上期数据
                 //console.time('pre');
                 if (ctx.stage.order > 1) {
-                    preStageData = await ctx.service.stagePosFinal.getFinalData(ctx.tender.data, ctx.stage);
+                    preStageData = await ctx.service.stagePosFinal.getFinalData(ctx.tender.data, ctx.stage.order - 1);
                     //responseData.data.preStageData = await ctx.service.stagePos.getEndStageData(ctx.tender.id, ctx.stage.order - 1);
                 } else {
                     preStageData = [];
                 }
                 //console.timeEnd('pre');
                 //console.time('assign');
+                console.log('cur: ' + curStageData.length);
+                console.log('pre: ' + preStageData.length);
                 this.ctx.helper.assignRelaData(responseData.data, [
                     {data: curStageData, fields: ['contract_qty', 'qc_qty', 'postil'], prefix: '', relaId: 'pid'},
                     {data: preStageData, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
@@ -389,7 +391,7 @@ module.exports = app => {
                         this.ctx.helper.assignRelaData(result.ledger, [
                             {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
                         ]);
-                        const curPosStage = await ctx.service.stagePos.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
+                        const curPosStage = await ctx.service.stagePos.getAuditorStageData2(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder);
                         this.ctx.helper.assignRelaData(result.pos, [
                             {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
                         ]);
@@ -399,13 +401,12 @@ module.exports = app => {
                         this.ctx.helper.assignRelaData(result.ledger, [
                             {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
                         ]);
-                        const curPosStage = await ctx.service.stagePos.getLastestStageData(ctx.tender.id, ctx.stage.id);
+                        const curPosStage = await ctx.service.stagePos.getLastestStageData2(ctx.tender.id, ctx.stage.id);
                         this.ctx.helper.assignRelaData(result.pos, [
                             {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
                         ]);
                         result.stageDetail = await ctx.service.stageDetail.getLastestStageData(ctx.tender.id, ctx.stage.id);
                     }
-                    console.log(result.length);
                     ctx.body = { err: 0, msg: '', data: result };
                 }
             } catch (err) {
@@ -908,7 +909,6 @@ module.exports = app => {
                 }
 
                 await ctx.service.stageAudit.check(ctx.stage.id, data, ctx.stage.times);
-                console.log('success');
 
                 ctx.redirect(ctx.request.header.referer);
             } catch (err) {

+ 63 - 36
app/controller/standard_lib_controller.js

@@ -9,46 +9,73 @@
  */
 
 
-const BaseController = require('../base/base_controller');
 
+module.exports = app => {
+    class StandardLibController extends app.BaseController {
+        async getData(ctx) {
+            const responseData = {
+                err: 0,
+                msg: '',
+                data: [],
+            };
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (isNaN(data.list_id) || data.list_id <= 0) {
+                    throw '参数错误';
+                }
+                switch (data.stdType) {
+                    case 'gcl':
+                        responseData.data = await this.ctx.service.stdGcl.getData(data.list_id);
+                        break;
+                    case 'xmj':
+                        responseData.data = await this.ctx.service.stdXmj.getData(data.list_id);
+                        break;
+                    default:
+                        throw '查询的标准清单不存在';
+                }
+            } catch (error) {
+                responseData.err = 1;
+                responseData.msg = error;
+            }
+            ctx.body = responseData;
+        }
 
-class StandardLibController extends BaseController {
-
-    /**
-     * 构造函数
-     *
-     * @param {Object} ctx - egg全局变量
-     * @param {Object} model - 标准库名称
-     * @return {void}
-     */
-    constructor(ctx, model) {
-        super(ctx);
-        this.model = model;
-        this.app = null;
-    }
-
-    async getData(ctx) {
-        const responseData = {
-            err: 0,
-            msg: '',
-            data: [],
-        };
-        try {
-            const data = JSON.parse(ctx.request.body.data);
-            if (isNaN(data.list_id) || data.list_id <= 0) {
-                throw '参数错误';
+        /**
+         * 根据id获取子项
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async getChildren(ctx) {
+            const responseData = {
+                err: 0,
+                msg: '',
+                data: [],
+            };
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                if (isNaN(data.pid) || data.pid <= 0 || isNaN(data.list_id) || data.list_id <= 0) {
+                    throw '参数错误';
+                }
+                const condition = { pid: data.pid, list_id: data.list_id };
+                switch (data.stdType) {
+                    case 'gcl':
+                        responseData.data = await this.ctx.service.stdGcl.getAllDataByCondition({ where: condition });
+                        break;
+                    case 'xmj':
+                        responseData.data = await this.ctx.service.stdXmj.getAllDataByCondition({ where: condition });
+                        break;
+                    default:
+                        throw '查询的标准清单不存在';
+                }
+            } catch (error) {
+                responseData.err = 1;
+                responseData.msg = error;
             }
-            const libData = await this.model.getData(data.list_id);
 
-            responseData.data = libData;
-        } catch (error) {
-            responseData.err = 1;
-            responseData.msg = error;
+            ctx.body = responseData;
         }
-
-        ctx.body = responseData;
     }
 
-}
-
-module.exports = StandardLibController;
+    return StandardLibController;
+};

+ 0 - 58
app/controller/std_bills_controller.js

@@ -1,58 +0,0 @@
-'use strict';
-
-/**
- * 标准清单控制器
- *
- * @author Mai
- * @date 2018/3/13
- * @version
- */
-const StandardLibController = require('./standard_lib_controller');
-
-module.exports = app => {
-    class StdBillsController extends StandardLibController {
-
-        /**
-         * 构造函数
-         *
-         * @param {Object} ctx - egg全局变量
-         * @return {void}
-         */
-        constructor(ctx) {
-            super(ctx, ctx.service.stdBills);
-            this.app = app;
-        }
-
-        /**
-         * 根据id获取子项
-         *
-         * @param {Object} ctx - egg全局变量
-         * @return {void}
-         */
-        async getChildren(ctx) {
-            const responseData = {
-                err: 0,
-                msg: '',
-                data: [],
-            };
-            try {
-                const data = JSON.parse(ctx.request.body.data);
-                if (isNaN(data.bill_id) || data.bill_id <= 0 || isNaN(data.list_id) || data.list_id <= 0) {
-                    throw '参数错误';
-                }
-                const condition = { pid: data.bill_id, list_id: data.list_id };
-                const libData = await this.model.getAllDataByCondition({ where: condition });
-
-                responseData.data = libData;
-            } catch (error) {
-                responseData.err = 1;
-                responseData.msg = error;
-            }
-
-            ctx.body = responseData;
-        }
-
-    }
-
-    return StdBillsController;
-};

+ 0 - 58
app/controller/std_chapter_controller.js

@@ -1,58 +0,0 @@
-'use strict';
-
-/**
- * 标准清单控制器
- *
- * @author Mai
- * @date 2018/3/13
- * @version
- */
-const StandardLibController = require('./standard_lib_controller');
-
-module.exports = app => {
-    class StdChapterController extends StandardLibController {
-
-        /**
-         * 构造函数
-         *
-         * @param {Object} ctx - egg全局变量
-         * @return {void}
-         */
-        constructor(ctx) {
-            super(ctx, ctx.service.stdChapter);
-            this.app = app;
-        }
-
-        /**
-         * 根据id获取子项
-         *
-         * @param {Object} ctx - egg全局变量
-         * @return {void}
-         */
-        async getChildren(ctx) {
-            const responseData = {
-                err: 0,
-                msg: '',
-                data: [],
-            };
-            try {
-                const data = JSON.parse(ctx.request.body.data);
-                if (isNaN(data.chapter_id) || data.chapter_id <= 0 || isNaN(data.list_id) || data.list_id <= 0) {
-                    throw '参数错误';
-                }
-                const condition = { pid: data.chapter_id, list_id: data.list_id };
-                const libData = await this.model.getAllDataByCondition({ where: condition });
-
-                responseData.data = libData;
-            } catch (error) {
-                responseData.err = 1;
-                responseData.msg = error;
-            }
-
-            ctx.body = responseData;
-        }
-
-    }
-
-    return StdChapterController;
-};

+ 4 - 2
app/lib/analysis_excel.js

@@ -42,9 +42,9 @@ class ImportBaseTree {
      */
     _loadTemplateTree(data) {
         for (const node of data) {
-            node.ledger_id = node.id;
+            node.ledger_id = node.template_id;
             node.ledger_pid = node.pid;
-            delete node.id;
+            node.id = this.ctx.app.uuid.v4();
             delete node.pid;
             if (node.code) {
                 this.codeNodes[node.code] = node;
@@ -97,6 +97,7 @@ class ImportBaseTree {
      * @returns {*}
      */
     addNodeWithParent(node, parent) {
+        node.id = this.ctx.app.uuid.v4();
         node.ledger_id = this.keyNodeId;
         this.keyNodeId += 1;
         node.ledger_pid = parent ? parent.ledger_id : -1;
@@ -176,6 +177,7 @@ class ImportBaseTree {
     addPos (pos){
         if (this.finalNode && this.finalNode.pos) {
             pos.id = this.ctx.app.uuid.v4();
+            pos.lid = this.finalNode.id;
             pos.tid = this.ctx.tender.id;
             pos.add_stage = 0;
             pos.add_times = 0;

+ 17 - 17
app/public/js/ledger.js

@@ -1016,7 +1016,7 @@ $(document).ready(function() {
         SpreadJsObj.forbiddenSpreadContextMenu('#pos-spread', posSpread);
     }
 
-    let stdChapter, stdBills, dealBills, searchLedger;
+    let stdXmj, stdGcl, dealBills, searchLedger;
 
     $.divResizer({
         select: '#right-spr',
@@ -1025,11 +1025,11 @@ $(document).ready(function() {
             if (posSpread) {
                 posSpread.refresh();
             }
-            if (stdChapter) {
-                stdChapter.spread.refresh();
+            if (stdXmj) {
+                stdXmj.spread.refresh();
             }
-            if (stdBills) {
-                stdBills.spread.refresh();
+            if (stdGcl) {
+                stdGcl.spread.refresh();
             }
             if (dealBills) {
                 dealBills.spread.refresh();
@@ -1074,9 +1074,9 @@ $(document).ready(function() {
             $('.tab-content .tab-pane').removeClass('active');
             tabPanel.addClass('active');
             showSideTools(tab.hasClass('active'));
-            if (tab.attr('content') === '#std-chapter') {
-                if (!stdChapter) {
-                    stdChapter = new stdLib('#std-chapter', 'chapter', {
+            if (tab.attr('content') === '#std-xmj') {
+                if (!stdXmj) {
+                    stdXmj = new stdLib('#std-xmj', 'xmj', {
                         id: 'chapter_id',
                         pid: 'pid',
                         order: 'order',
@@ -1095,12 +1095,12 @@ $(document).ready(function() {
                         headRowHeight: [40],
                         defaultRowHeight: 21,
                     });
-                    stdChapter.loadLib($('select', '#std-chapter').val());
+                    stdXmj.loadLib($('select', '#std-xmj').val());
                 }
-                stdChapter.spread.refresh();
-            } else if (tab.attr('content') === '#std-bills') {
-                if (!stdBills) {
-                    stdBills = new stdLib('#std-bills', 'bills', {
+                stdXmj.spread.refresh();
+            } else if (tab.attr('content') === '#std-gcl') {
+                if (!stdGcl) {
+                    stdGcl = new stdLib('#std-gcl', 'gcl', {
                         id: 'bill_id',
                         pid: 'pid',
                         order: 'order',
@@ -1119,9 +1119,9 @@ $(document).ready(function() {
                         headRowHeight: [40],
                         defaultRowHeight: 21,
                     });
-                    stdBills.loadLib($('select', '#std-bills').val());
+                    stdGcl.loadLib($('select', '#std-gcl').val());
                 }
-                stdBills.spread.refresh();
+                stdGcl.spread.refresh();
             } else if (tab.attr('content') === '#deal-bills') {
                 if (!dealBills) {
                     dealBills = new DealBills('#deal-bills-spread', {
@@ -1182,7 +1182,7 @@ $(document).ready(function() {
         constructor(selector, stdType, treeSetting, spreadSetting) {
             const self = this;
             this.obj = $(selector + '-spread')[0];
-            this.url = '/std/' + stdType;
+            this.stdType = stdType;
             this.treeSetting = treeSetting;
             treeSetting.preUrl = this.url;
             this.spreadSetting = spreadSetting;
@@ -1233,7 +1233,7 @@ $(document).ready(function() {
                 SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'tree', this.pathTree);
             } else {
                 const self = this;
-                postData(this.url+'/get-data', {list_id: listId}, function (data) {
+                postData('/std-lib/get-data', {stdType: this.stdType, list_id: listId}, function (data) {
                     self.cacheLib.push({id: listId, data: data});
                     self.pathTree.loadDatas(data);
                     SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);

+ 4 - 3
app/public/js/path_tree.js

@@ -348,7 +348,7 @@ const createNewPathTree = function (type, setting) {
         getAllParents (node) {
             const parents = [];
             if (node.full_path && node.full_path !== '') {
-                const parentIds = node.full_path.split('.');
+                const parentIds = node.full_path.split('-');
                 for (const id of parentIds) {
                     if (id !== node[this.setting.id]) {
                         parents.push(this.getItems(id));
@@ -397,7 +397,7 @@ const createNewPathTree = function (type, setting) {
          * @param {Number} path
          */
         getFullPathNodes (path) {
-            const self = this, ids = path.split('.');
+            const self = this, ids = path.split('-');
             if (ids.length > 0) {
                 return this.nodes.filter((x) => {
                     return ids.indexOf('' + x[self.setting.id]) >= 0;
@@ -443,7 +443,8 @@ const createNewPathTree = function (type, setting) {
          */
         getPosterity (node) {
             if (node.full_path !== '') {
-                const reg = new RegExp('^' + node.full_path + '.');
+                const reg = new RegExp('^' + node.full_path + '-');
+                console.log(reg);
                 return this.datas.filter(function (x) {
                     return reg.test(x.full_path);
                 });

+ 16 - 16
app/public/js/revise.js

@@ -321,7 +321,7 @@ $(document).ready(() => {
         constructor(selector, stdType, treeSetting, spreadSetting) {
             const self = this;
             this.obj = $(selector + '-spread')[0];
-            this.url = '/std/' + stdType;
+            this.stdType = stdType;
             this.treeSetting = treeSetting;
             treeSetting.preUrl = this.url;
             this.spreadSetting = spreadSetting;
@@ -364,7 +364,7 @@ $(document).ready(() => {
                 SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'tree', this.pathTree);
             } else {
                 const self = this;
-                postData(this.url+'/get-data', {list_id: listId}, function (data) {
+                postData('/std-lib/get-data', {stdType: this.stdType, list_id: listId}, function (data) {
                     self.cacheLib.push({id: listId, data: data});
                     self.pathTree.loadDatas(data);
                     SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
@@ -589,7 +589,7 @@ $(document).ready(() => {
             return result;
         }
     }
-    let stdChapter, stdBills, searchLedger;
+    let stdXmj, stdGcl, searchLedger;
     const dealBills = new DealBills('#deal-bills-spread', {
         cols: [
             {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
@@ -611,11 +611,11 @@ $(document).ready(() => {
             if (posSpread) {
                 posSpread.refresh();
             }
-            if (stdChapter) {
-                stdChapter.spread.refresh();
+            if (stdXmj) {
+                stdXmj.spread.refresh();
             }
-            if (stdBills) {
-                stdBills.spread.refresh();
+            if (stdGcl) {
+                stdGcl.spread.refresh();
             }
         }
     });
@@ -654,9 +654,9 @@ $(document).ready(() => {
             $('.tab-content .tab-pane').removeClass('active');
             tabPanel.addClass('active');
             showSideTools(tab.hasClass('active'));
-            if (tab.attr('content') === '#std-chapter') {
-                if (!stdChapter) {
-                    stdChapter = new stdLib('#std-chapter', 'chapter', {
+            if (tab.attr('content') === '#std-xmj') {
+                if (!stdXmj) {
+                    stdXmj = new stdLib('#std-xmj', 'xmj', {
                         id: 'chapter_id',
                         pid: 'pid',
                         order: 'order',
@@ -675,12 +675,12 @@ $(document).ready(() => {
                         headRowHeight: [40],
                         defaultRowHeight: 21,
                     });
-                    stdChapter.loadLib($('select', '#std-chapter').val());
+                    stdXmj.loadLib($('select', '#std-xmj').val());
                 }
-                stdChapter.spread.refresh();
+                stdXmj.spread.refresh();
             } else if (tab.attr('content') === '#std-bills') {
-                if (!stdBills) {
-                    stdBills = new stdLib('#std-bills', 'bills', {
+                if (!stdGcl) {
+                    stdGcl = new stdLib('#std-gcl', 'gcl', {
                         id: 'bill_id',
                         pid: 'pid',
                         order: 'order',
@@ -699,9 +699,9 @@ $(document).ready(() => {
                         headRowHeight: [40],
                         defaultRowHeight: 21,
                     });
-                    stdBills.loadLib($('select', '#std-bills').val());
+                    stdGcl.loadLib($('select', '#std-gcl').val());
                 }
-                stdBills.spread.refresh();
+                stdGcl.spread.refresh();
             } else if (tab.attr('content') === '#deal-bills') {
                 dealBills.loadData();
                 dealBills.spread.refresh();

+ 4 - 1
app/public/js/stage.js

@@ -693,6 +693,9 @@ $(document).ready(() => {
         },
         measureAllPosInNode(node, ratio = 1) {
             const posterity = stageTree.getPosterity(node);
+            console.log(node);
+            console.log(posterity.length);
+            console.log(posterity);
             const data = {updateType: 'update', updateData: []};
             for (const p of posterity) {
                 if (p.children && p.children.length > 0) continue;
@@ -711,7 +714,7 @@ $(document).ready(() => {
                         data.updateData.push(pData);
                     }
                 }
-                if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 200) {
+                if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
                     toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
                     break;
                 }

+ 1 - 4
app/router.js

@@ -245,10 +245,7 @@ module.exports = app => {
     // app.get('/tender/:id/stage/:order/report', sessionAuth, tenderSelect, 'stageController.stageReport');
 
     // 标准库相关
-    app.post('/std/bills/get-data', sessionAuth, 'stdBillsController.getData');
-    app.post('/std/bills/get-children', sessionAuth, 'stdBillsController.getChildren');
-    app.post('/std/chapter/get-data', sessionAuth, 'stdChapterController.getData');
-    app.post('/std/chapter/get-children', sessionAuth, 'stdChapterController.getChildren');
+    app.post('/std-lib/get-data', sessionAuth, 'standardLibController.getData');
 
     // 查询
     app.post('/search/user', sessionAuth, 'projectController.searchAccount');

+ 32 - 77
app/service/ledger.js

@@ -349,7 +349,7 @@ module.exports = app => {
                 operate: '=',
             });
             this.sqlBuilder.setAndWhere('full_path', {
-                value: this.db.escape(node.full_path + '.%'),
+                value: this.db.escape(node.full_path + '-%'),
                 operate: 'like',
             });
 
@@ -633,7 +633,7 @@ module.exports = app => {
             data.ledger_pid = selectData.ledger_pid;
             data.level = selectData.level;
             data.order = selectData.order + 1;
-            data.full_path = selectData.full_path.replace('.' + selectData.ledger_id, '.' + data.ledger_id);
+            data.full_path = selectData.full_path.replace('-' + selectData.ledger_id, '-' + data.ledger_id);
             data.is_leaf = true;
             const result = await this.transaction.insert(this.tableName, data);
 
@@ -673,7 +673,7 @@ module.exports = app => {
                 data.order = 1;
             }
             data.level = parentData ? parentData.level + 1 : 1;
-            data.full_path = parentData ? parentData.full_path + '.' + data.ledger_id : '' + data.ledger_id;
+            data.full_path = parentData ? parentData.full_path + '-' + data.ledger_id : '' + data.ledger_id;
             if (data.is_leaf === undefined) {
                 data.is_leaf = true;
             }
@@ -816,7 +816,7 @@ module.exports = app => {
             data.ledger_pid = selectData.ledger_id;
             data.level = selectData.level + 1;
             data.order = children.length + 1;
-            data.full_path = selectData.full_path + '.' + data.ledger_id;
+            data.full_path = selectData.full_path + '-' + data.ledger_id;
             data.is_leaf = true;
 
             this.transaction = await this.db.beginTransaction();
@@ -1097,7 +1097,7 @@ module.exports = app => {
                 operate: '=',
             });
             this.sqlBuilder.setAndWhere('full_path', {
-                value: this.db.escape(selectData.full_path + '.%'),
+                value: this.db.escape(selectData.full_path + '-%'),
                 operate: 'like',
             });
             this.sqlBuilder.setUpdateData('level', {
@@ -1105,7 +1105,7 @@ module.exports = app => {
                 selfOperate: '-',
             });
             this.sqlBuilder.setUpdateData('full_path', {
-                value: ['`full_path`', this.db.escape(selectData.ledger_pid + '.'), this.db.escape('')],
+                value: ['`full_path`', this.db.escape(selectData.ledger_pid + '-'), this.db.escape('')],
                 literal: 'Replace',
             });
             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
@@ -1159,8 +1159,8 @@ module.exports = app => {
                 }
 
                 // 修改nextsData及其子节点的full_path
-                const oldSubStr = this.db.escape(selectData.ledger_pid + '.');
-                const newSubStr = this.db.escape(selectData.ledger_id + '.');
+                const oldSubStr = this.db.escape(selectData.ledger_pid + '-');
+                const newSubStr = this.db.escape(selectData.ledger_id + '-');
                 const sqlArr = [];
                 sqlArr.push('Update ?? SET `full_path` = Replace(`full_path`,' + oldSubStr + ',' + newSubStr + ') Where');
                 sqlArr.push('(`tender_id` = ' + selectData.tender_id + ')');
@@ -1199,7 +1199,7 @@ module.exports = app => {
             }
 
             this.transaction = await this.db.beginTransaction();
-            const newFullPath = selectData.full_path.replace(selectData.ledger_pid + '.', '');
+            const newFullPath = selectData.full_path.replace(selectData.ledger_pid + '-', '');
             try {
                 // 选中节点--父节点 选中节点为firstChild时,修改is_leaf
                 if (selectData.order === 1) {
@@ -1261,7 +1261,7 @@ module.exports = app => {
                 operate: '=',
             });
             this.sqlBuilder.setAndWhere('full_path', {
-                value: this.db.escape(selectData.full_path + '.%'),
+                value: this.db.escape(selectData.full_path + '-%'),
                 operate: 'like',
             });
             this.sqlBuilder.setUpdateData('level', {
@@ -1269,7 +1269,7 @@ module.exports = app => {
                 selfOperate: '+',
             });
             this.sqlBuilder.setUpdateData('full_path', {
-                value: ['`full_path`', this.db.escape('.' + selectData.ledger_id), this.db.escape('.' + preData.ledger_id + '.' + selectData.ledger_id)],
+                value: ['`full_path`', this.db.escape('-' + selectData.ledger_id), this.db.escape('-' + preData.ledger_id + '-' + selectData.ledger_id)],
                 literal: 'Replace',
             });
             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
@@ -1300,8 +1300,8 @@ module.exports = app => {
             const preLastChildData = await this.getLastChildData(tenderId, preData.ledger_id);
 
             this.transaction = await this.db.beginTransaction();
-            const orgLastPath = selectData.level === 1 ? selectData.ledger_id : '.' + selectData.ledger_id;
-            const newLastPath = selectData.level === 1 ? preData.ledger_id + '.' + selectData.ledger_id : '.' + preData.ledger_id + '.' + selectData.ledger_id;
+            const orgLastPath = selectData.level === 1 ? selectData.ledger_id : '-' + selectData.ledger_id;
+            const newLastPath = selectData.level === 1 ? preData.ledger_id + '-' + selectData.ledger_id : '-' + preData.ledger_id + '-' + selectData.ledger_id;
             const newFullPath = selectData.full_path.replace(orgLastPath, newLastPath);
             try {
                 // 选中节点--全部后节点 order--
@@ -1548,13 +1548,13 @@ module.exports = app => {
                         data.tender_id = this.ctx.tender.id;
                         if (!data.is_leaf) {
                             for (const children of datas) {
-                                children.full_path = children.full_path.replace('.' + data.ledger_id, '.' + newId);
+                                children.full_path = children.full_path.replace('-' + data.ledger_id, '-' + newId);
                                 if (children.ledger_pid === data.ledger_id) {
                                     children.ledger_pid = newId;
                                 }
                             }
                         } else {
-                            data.full_path = data.full_path.replace('.' + data.ledger_id, '.' + newId);
+                            data.full_path = data.full_path.replace('-' + data.ledger_id, '-' + newId);
                         }
                         data.ledger_id = newId;
                         data.full_path = data.full_path.replace(orgParentPath, newParentPath);
@@ -1750,7 +1750,7 @@ module.exports = app => {
                 level: parentData.level + 1,
                 name: xmj.name,
             };
-            parent.full_path = parentData.full_path + '.' + parent.ledger_id;
+            parent.full_path = parentData.full_path + '-' + parent.ledger_id;
             // 添加gcl数据
             for (let i = 0, iLen = xmj.children.length; i < iLen; i++) {
                 const gcl = xmj.children[i];
@@ -1767,7 +1767,7 @@ module.exports = app => {
                     unit_price: gcl.unit_price,
                     quantity: gcl.quantity,
                 };
-                child.full_path = parent.full_path + '.' + child.ledger_id;
+                child.full_path = parent.full_path + '-' + child.ledger_id;
                 child.total_price = this.ctx.helper.mul(child.unit_price, child.quantity, this.ctx.tender.info.decimal.tp);
                 tp = this.ctx.helper.add(tp, child.total_price);
                 result.push(child);
@@ -1836,7 +1836,7 @@ module.exports = app => {
                         unit: data[i].unit,
                         unit_price: data[i].price,
                     };
-                    qd.full_path = selectData.full_path + '.' + qd.ledger_id;
+                    qd.full_path = selectData.full_path + '-' + qd.ledger_id;
                     const insertResult = await this.transaction.insert(this.tableName, qd);
                     newIds.push(qd.id);
                     if (data[i].pos.length > 0) {
@@ -1909,7 +1909,7 @@ module.exports = app => {
                         unit: data[i].unit,
                         unit_price: data[i].price,
                     };
-                    qd.full_path = parentData.full_path + '.' + qd.ledger_id;
+                    qd.full_path = parentData.full_path + '-' + qd.ledger_id;
                     const insertResult = await this.transaction.insert(this.tableName, qd);
                     newIds.push(qd.id);
                     if (data[i].pos.length > 0) {
@@ -1982,58 +1982,17 @@ module.exports = app => {
             if (!node) {
                 throw '查询数据有误';
             }
-            const expandIds = node.full_path.split('.');
+            const expandIds = node.full_path.split('-');
             expandIds.pop();
             const expandData = await this.getChildrenByParentId(tenderId, expandIds);
             return { expand: expandData };
         }
 
-        async _importCacheTreeNode(transaction, node) {
-            const data = {
-                id: this.uuid.v4(),
-                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,
-            };
-            const result = await transaction.insert(this.tableName, data);
-            //data.id = result.insertId;
-            if (node.children && node.children.length > 0) {
-                for (const child of node.children) {
-                    await this._importCacheTreeNode(transaction, child);
-                }
-            } else if (node.pos && node.pos.length > 0) {
-                await this.ctx.service.pos.insertLedgerPosData(transaction, this.ctx.tender.id, data, node.pos);
-            }
-            if (node.pos && node.pos.length > 0) {
-                for (const p of node.pos) {
-                    //p.lid = result.insertId;
-                    p.lid = node.id;
-                }
-            }
-        }
-
         async _importCacheTreeNodes(transaction, nodes) {
             const datas = [];
             for (const node of nodes) {
                 datas.push({
-                    id: this.uuid.v4(),
+                    id: node.id,
                     tender_id: this.ctx.tender.id,
                     ledger_id: node.ledger_id,
                     ledger_pid: node.ledger_pid,
@@ -2057,17 +2016,6 @@ module.exports = app => {
                 });
             }
             await transaction.insert(this.tableName, datas);
-            const sql = 'SELECT id, ledger_id FROM ' + this.tableName + ' WHERE tender_id = ?';
-            const sqlParam = [this.ctx.tender.id];
-            const insertDatas = await transaction.query(sql, sqlParam);
-            for (const iD of insertDatas) {
-                const node = this.ctx.helper._.find(nodes, {ledger_id: iD.ledger_id});
-                if (node.pos && node.pos.length > 0) {
-                    for (const p of node.pos) {
-                        p.lid = iD.id;
-                    }
-                }
-            }
         }
 
         /**
@@ -2076,27 +2024,34 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async importExcel(excelData) {
+            //console.time('analysis');
             const AnalysisExcel = require('../lib/analysis_excel');
             const analysisExcel = new AnalysisExcel(this.ctx);
             const tempData = await this.ctx.service.tenderNodeTemplate.getData(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});
-                // for (const node of cacheTree.roots) {
-                //     await this._importCacheTreeNode(transaction, node);
-                // }
+                //console.timeEnd('deletePos');
+                //console.time('insertBills');
                 await this._importCacheTreeNodes(transaction, cacheTree.items);
+                //console.timeEnd('insertBills');
+                //console.time('insertPos');
                 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);
             } catch (err) {
                 await transaction.rollback();
                 if (orgMaxId) {
-                    this.cache.set(cacheKey, orgMaxId, 'EX', this.ctx.app.config.cacheTime);
+                    this.cache.set(cacheKey, cacheTree.keyNodeId, 'EX', this.ctx.app.config.cacheTime);
                 }
                 throw err;
             }

+ 2 - 2
app/service/revise_bills.js

@@ -97,7 +97,7 @@ module.exports = app => {
                     qd.sgfh_qty = this.ctx.helper.add(qd.sgfh_qty, inP.sgfh_qty);
                     pos.push(inP);
                 }
-                qd.full_path = select.full_path + '.' + qd.ledger_id;
+                qd.full_path = select.full_path + '-' + qd.ledger_id;
                 qd.sgfh_tp = this.ctx.helper.mul(qd.sgfh_qty, qd.unit_price, this.ctx.tender.info.decimal.tp);
                 qd.quantity = qd.sgfh_qty;
                 qd.total_price = qd.sgfh_tp;
@@ -195,7 +195,7 @@ module.exports = app => {
                     qd.sgfh_qty = this.ctx.helper.add(qd.sgfh_qty, inP.sgfh_qty);
                     pos.push(inP);
                 }
-                qd.full_path = parentData.full_path + '.' + qd.ledger_id;
+                qd.full_path = parentData.full_path + '-' + qd.ledger_id;
                 qd.sgfh_tp = this.ctx.helper.mul(qd.sgfh_qty, qd.unit_price, this.ctx.tender.info.decimal.tp);
                 qd.quantity = qd.sgfh_qty;
                 qd.total_price = qd.sgfh_tp;

+ 2 - 0
app/service/stage_audit.js

@@ -261,8 +261,10 @@ module.exports = app => {
                 } else {
                     // 本期结束
                     // 生成截止本期数据 final数据
+                    console.time('generatePre');
                     await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
                     await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
+                    console.timeEnd('generatePre');
                     // 同步 期信息
                     await transaction.update(this.ctx.service.stage.tableName, {
                         id: stageId, status: checkData.checkType,

+ 26 - 0
app/service/stage_bills.js

@@ -88,6 +88,32 @@ module.exports = app => {
             }
         }
 
+        async getLastestStageData2(tid, sid, lid) {
+            let lidSql = '', result;
+            if (lid) {
+                if (lid instanceof Array) {
+                    lidSql = lid.length > 0 ? ' And lid in (' + this.ctx.helper.getInArrStrSqlFilter(lid) + ')' : '';
+                } else {
+                    lidSql = ' And lid in (' + this.db.escape(lid) + ')';
+                }
+            }
+            const sql = 'SELECT Bills.* FROM ' + this.tableName + ' As Bills ' +
+                '  INNER JOIN ( ' +
+                '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `progress`, `lid`, `sid` From ' + this.tableName +
+                '      WHERE tid = ? And sid = ?' + lidSql +
+                '      GROUP BY `lid`' +
+                '  ) As MaxFilter ' +
+                '  ON (Bills.times * ' + timesLen + ' + `order`) = MaxFilter.progress And Bills.lid = MaxFilter.lid And Bills.`sid` = MaxFilter.`sid`';
+            const sqlParam = [tid, sid];
+            if (!lid) {
+                return await this.db.query(sql, sqlParam);
+            } else if (lid instanceof Array) {
+                return await this.db.query(sql, sqlParam);
+            } else {
+                return await this.db.queryOne(sql, sqlParam);
+            }
+        }
+
         /**
          * 获取截止本期数据
          * @param {Number} tid - 标段id

+ 23 - 12
app/service/stage_bills_final.js

@@ -29,16 +29,20 @@ module.exports = app => {
          * @param {Object} stage - 本期
          * @returns {Promise<void>}
          */
-        async getFinalData(tender, stage) {
-            const sql = 'SELECT * FROM ' + this.tableName + ' As Bills' +
-                '  INNER JOIN ( ' +
-                '    SELECT MAX(`sorder`) As `sorder`, `lid` From ' + this.tableName +
-                '      WHERE tid = ? AND sorder < ?' +
-                '      GROUP BY `lid`' +
-                '  ) As MaxFilter ' +
-                '  ON Bills.sorder = MaxFilter.sorder And Bills.lid = MaxFilter.lid';
-            const sqlParam = [tender.id, stage.order, tender.id];
-            return await this.db.query(sql, sqlParam);
+        async getFinalData(tender, stageOrder) {
+            // const sql = 'SELECT * FROM ' + this.tableName + ' As Bills' +
+            //     '  INNER JOIN ( ' +
+            //     '    SELECT MAX(`sorder`) As `sorder`, `lid` From ' + this.tableName +
+            //     '      WHERE tid = ? AND sorder < ?' +
+            //     '      GROUP BY `lid`' +
+            //     '  ) As MaxFilter ' +
+            //     '  ON Bills.sorder = MaxFilter.sorder And Bills.lid = MaxFilter.lid';
+            // const sqlParam = [tender.id, stage.order, tender.id];
+            // return await this.db.query(sql, sqlParam);
+            return await this.getAllDataByCondition({
+                //columns: ['lid', 'contract_qty', 'qc_qty', 'contract_tp', 'qc_tp'],
+                where: {tid: tender.id, sorder: stageOrder},
+            });
         }
 
         /**
@@ -74,7 +78,7 @@ module.exports = app => {
             if (stage.order > 1) {
                 const cur = await this.ctx.service.stageBills.getLastestStageData(tender.id, stage.id);
                 if (!cur || cur.length === 0) return;
-                const pre = await this.getFinalData(tender, stage);
+                const pre = await this.getFinalData(tender, stage.order - 1);
                 for (const c of cur) {
                     delete c.id;
                     delete c.said;
@@ -90,8 +94,15 @@ module.exports = app => {
                     c.contract_tp = this.ctx.helper.add(c.contract_tp, p.contract_tp);
                     c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
                     c.qc_tp = this.ctx.helper.add(c.qc_tp, p.qc_tp);
+                    pre.splice(pre.indexOf(p), 1);
+                }
+
+                //await transaction.insert(this.tableName, cur);
+                for (const p of pre) {
+                    p.sid = stage.id;
+                    p.sorder = stage.order;
                 }
-                await transaction.insert(this.tableName, cur);
+                await transaction.insert(this.tableName, cur.concat(pre));
             } else {
                 const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp)' +
                     '  SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp' +

+ 1 - 1
app/service/stage_change.js

@@ -220,7 +220,7 @@ module.exports = app => {
             try {
                 const data = { bills: {}, pos: {} };
                 data.bills.curStageData = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, [pos.lid]);
-                data.pos.curStageData = await this.ctx.service.stagePos.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
+                data.pos.curStageData = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
                 return data;
             } catch(err) {
                 throw '获取数据错误,请刷新页面';

+ 40 - 4
app/service/stage_pos.js

@@ -80,7 +80,7 @@ module.exports = app => {
                 '  (SELECT * FROM '+ this.tableName + ' WHERE tid = ? And sid = ?) As Pos ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `flow`, `pid`, `sid` From ' + this.tableName +
-                '      WHERE `times` < ? OR (`times` = ? AND `order` <= ?) And tid = ? And sid = ?' + filterSql +
+                '      WHERE (`times` < ? OR (`times` = ? AND `order` <= ?)) And tid = ? And sid = ?' + filterSql +
                 '      GROUP BY `pid`' +
                 '  ) As MaxFilter ' +
                 '  ON (Pos.times * ' + timesLen + ' + Pos.order) = MaxFilter.flow And Pos.pid = MaxFilter.pid And Pos.sid = MaxFilter.sid';
@@ -88,6 +88,42 @@ module.exports = app => {
             return await this.db.query(sql, sqlParam);
         }
 
+        async _filterLastestData(stagePos) {
+            const stagePosIndex = {};
+            for (const sp of stagePos) {
+                const key = 'sp-' + sp.pid;
+                const spi = stagePosIndex[key];
+                if (spi) {
+                    if ((spi.times * timesLen + spi.order) < (sp.times * timesLen + spi.order)) stagePosIndex[key] = sp;
+                } else {
+                    stagePosIndex[key] = sp;
+                }
+            }
+            const result = [];
+            for (const prop in stagePosIndex) {
+                result.push(stagePosIndex[prop]);
+            }
+            return result;
+        }
+        async getLastestStageData2(tid, sid, where) {
+            const filterSql = this._getPosFilterSql(where);
+            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`' +
+                '  FROM ' + this.tableName +
+                '  WHERE tid = ? And sid = ? ' + filterSql;
+            const sqlParam = [tid, sid];
+            const stagePos = await this.db.query(sql, sqlParam);
+            return this._filterLastestData(stagePos);
+        }
+        async getAuditorStageData2(tid, sid, times, order, where) {
+            const filterSql = this._getPosFilterSql(where);
+            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`' +
+                '  FROM ' + this.tableName +
+                '  WHERE tid = ? And sid = ? And (`times` < ? OR (`times` = ? AND `order` <= ?)) ' + filterSql;
+            const sqlParam = [tid, sid, times, times, order];
+            const stagePos = await this.db.query(sql, sqlParam);
+            return this._filterLastestData(stagePos);
+        }
+
         /**
          * 新增部位明细数据(仅供updateStageData调用)
          *
@@ -176,7 +212,7 @@ module.exports = app => {
             const result = {ledger: [], pos: [], stageUpdate: true}, ledgerCalc = [];
             const datas = data instanceof Array ? data : [data];
             const orgPos = await this.ctx.service.pos.getPosDataByIds(this._.map(datas, 'pid'));
-            const orgStagePos = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, {pid: this._.map(datas, 'pid')});
+            const orgStagePos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: this._.map(datas, 'pid')});
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -325,7 +361,7 @@ module.exports = app => {
                     } else if (refreshData.pos.length > 0) {
                         result.pos.pos = await this.ctx.service.pos.getPosData({id: refreshData.pos});
                         if (refreshData.stageUpdate) {
-                            result.pos.curStageData = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, {pid: refreshData.pos});
+                            result.pos.curStageData = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: refreshData.pos});
                         }
                     }
                 }
@@ -336,7 +372,7 @@ module.exports = app => {
         }
 
         async updateChangeQuantity(transaction, pos, qty) {
-            let orgPos = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
+            let orgPos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
             if (orgPos.length > 1) {
                 throw '数据错误';
             } else {

+ 25 - 18
app/service/stage_pos_final.js

@@ -30,19 +30,22 @@ module.exports = app => {
          * @param {Object} stage - 本期
          * @returns {Promise<void>}
          */
-        async getFinalData(tender, stage) {
-            const sql = 'SELECT Pos.* FROM ' +
-                //'  (SELECT pid, contract_qty, qc_qty, sorder FROM ' + this.tableName + ' WHERE tid = ?) As Pos' +
-                this.tableName + ' As Pos' +
-                '  INNER JOIN ( ' +
-                '    SELECT MAX(`sorder`) As `sorder`, `pid` From ' + this.tableName +
-                '      WHERE tid = ? AND sorder < ?' +
-                '      GROUP BY `pid`' +
-                '  ) As MaxFilter ' +
-                '  ON Pos.sorder = MaxFilter.sorder And Pos.pid = MaxFilter.pid';
-            //const sqlParam = [tender.id, tender.id, stage.order];
-            const sqlParam = [tender.id, stage.order];
-            return await this.db.query(sql, sqlParam);
+        async getFinalData(tender, stageOrder) {
+            // const sql = 'SELECT Pos.* FROM ' +
+            //     //'  (SELECT pid, contract_qty, qc_qty, sorder FROM ' + this.tableName + ' WHERE tid = ?) As Pos' +
+            //     this.tableName + ' As Pos' +
+            //     '  INNER JOIN ( ' +
+            //     '    SELECT MAX(`sorder`) As `sorder`, `pid` From ' + this.tableName +
+            //     '      WHERE tid = ? AND sorder < ?' +
+            //     '      GROUP BY `pid`' +
+            //     '  ) As MaxFilter ' +
+            //     '  ON Pos.sorder = MaxFilter.sorder And Pos.pid = MaxFilter.pid';
+            // //const sqlParam = [tender.id, tender.id, stage.order];
+            // const sqlParam = [tender.id, stage.order];
+            return await this.getAllDataByCondition({
+                //columns: ['pid', 'contract_qty', 'qc_qty'],
+                where: {tid: tender.id, sorder: stageOrder},
+            });
         }
 
         /**
@@ -57,9 +60,9 @@ module.exports = app => {
                 throw '数据错误';
             }
             if (stage.order > 1) {
-                const cur = await this.ctx.service.stagePos.getLastestStageData(tender.id, stage.id);
+                const cur = await this.ctx.service.stagePos.getLastestStageData2(tender.id, stage.id);
                 if (!cur || cur.length === 0) return;
-                const pre = await this.getFinalData(tender, stage);
+                const pre = await this.getFinalData(tender, stage.order - 1);
                 for (const c of cur) {
                     delete c.id;
                     delete c.said;
@@ -73,10 +76,14 @@ module.exports = app => {
                     if (!p) continue;
                     c.contract_qty = this.ctx.helper.add(c.contract_qty, p.contract_qty);
                     c.qc_qty = this.ctx.helper.add(c.qc_qty, p.qc_qty);
-                    //pre.splice(pre.indexOf(p), 1);
+                    pre.splice(pre.indexOf(p), 1);
                 }
-                await transaction.insert(this.tableName, cur);
-                //await transaction.insert(this.tableName, cur.concat(pre));
+                //await transaction.insert(this.tableName, cur);
+                for (const p of pre) {
+                    p.sid = stage.id;
+                    p.sorder = stage.order;
+                }
+                await transaction.insert(this.tableName, cur.concat(pre));
             } else {
                 const sql = 'Insert Into ??(tid, sid, lid, pid, sorder, contract_qty, qc_qty)' +
                             '  SELECT p.tid, p.sid, p.lid, p.pid, ? As `sorder`, p.contract_qty, p.qc_qty' +

+ 2 - 2
app/service/std_bills.js

@@ -29,8 +29,8 @@ module.exports = app => {
                 isLeaf: 'is_leaf',
                 fullPath: 'full_path',
                 keyPre: 'revise_bills_maxLid:'
-            }, 'bill');
-            this.stdType = 'bill';
+            }, 'std_gcl');
+            this.stdType = 'gcl';
         }
     }
 

+ 2 - 2
app/service/std_chapter.js

@@ -29,8 +29,8 @@ module.exports = app => {
                 isLeaf: 'is_leaf',
                 fullPath: 'full_path',
                 keyPre: 'revise_bills_maxLid:'
-            }, 'project_chapter');
-            this.stdType = 'chapter';
+            }, 'std_xmj');
+            this.stdType = 'xmj';
         }
 
     }

+ 0 - 1
app/service/tender.js

@@ -130,7 +130,6 @@ module.exports = app => {
                     this.ctx.service.stageAudit.tableName, session.sessionUser.accountId,
                     this.ctx.service.changeAudit.tableName, session.sessionUser.accountId];
             }
-            // console.log(this.db.format(sql, sqlParam));
             const list = await this.db.query(sql, sqlParam);
             for (const l of list) {
                 l.category = l.category && l.category !== '' ? JSON.parse(l.category) : null;

+ 1 - 1
app/service/tender_node_template.js

@@ -20,7 +20,7 @@ module.exports = app => {
          */
         constructor(ctx) {
             super(ctx);
-            this.tableName = 'tender_node_template';
+            this.tableName = 'bills_template';
         }
 
         /**

+ 2 - 2
app/service/valuation.js

@@ -41,11 +41,11 @@ module.exports = app => {
             const valuation = await this.getDataById(id);
             const billsId = this._.map(valuation.bill_id.split(','), this._.toInteger);
             const chaptersId = this._.map(valuation.chapter_id.split(','), this._.toInteger);
-            const billsList = await this.db.select('zh_bill_list', {
+            const billsList = await this.db.select('zh_std_gcl_list', {
                 where: {id: billsId},
                 columns: ['id', 'name'],
             });
-            const chapterList = await this.db.select('zh_project_chapter_list', {
+            const chapterList = await this.db.select('zh_std_xmj_list', {
                 where: {id: chaptersId},
                 columns: ['id', 'name'],
             });

+ 6 - 6
app/view/ledger/explode.ejs

@@ -98,7 +98,7 @@
                         <!--<div id="search-result" class="sjs-sh-1">-->
                         <!--</div>-->
                     </div>
-                    <div id="std-chapter" class="tab-pane">
+                    <div id="std-xmj" class="tab-pane">
                         <div class="sjs-bar-2">
                             <div class="pb-1">
                                 <select class="form-control form-control-sm">
@@ -108,10 +108,10 @@
                                 </select>
                             </div>
                         </div>
-                        <div id="std-chapter-spread" class="sjs-sh-2">
+                        <div id="std-xmj-spread" class="sjs-sh-2">
                         </div>
                     </div>
-                    <div id="std-bills" class="tab-pane">
+                    <div id="std-gcl" class="tab-pane">
                         <div class="sjs-bar-3">
                             <div class="pb-1">
                                 <select class="form-control form-control-sm">
@@ -121,7 +121,7 @@
                                 </select>
                             </div>
                         </div>
-                        <div id="std-bills-spread" class="sjs-sh-3">
+                        <div id="std-gcl-spread" class="sjs-sh-3">
                         </div>
                     </div>
                     <div id="deal-bills" class="tab-pane">
@@ -143,10 +143,10 @@
                     <a class="nav-link" content="#search" href="javascript: void(0);">查找定位</a>
                 </li>
                 <li class="nav-item">
-                    <a class="nav-link" content="#std-chapter" href="javascript: void(0);">项目节</a>
+                    <a class="nav-link" content="#std-xmj" href="javascript: void(0);">项目节</a>
                 </li>
                 <li class="nav-item">
-                    <a class="nav-link" content="#std-bills" href="javascript: void(0);">工程量清单</a>
+                    <a class="nav-link" content="#std-gcl" href="javascript: void(0);">工程量清单</a>
                 </li>
                 <li class="nav-item">
                     <a class="nav-link" content="#deal-bills" href="javascript: void(0);">签约清单</a>

+ 4 - 4
app/view/revise/info.ejs

@@ -111,22 +111,22 @@
                     </div>
                     <div id="search" class="tab-pane">
                     </div>
-                    <div id="std-chapter" class="tab-pane">
+                    <div id="std-xmj" class="tab-pane">
                         <div class="sjs-bar-3">
                             <div class="pb-1">
                                 <select class="form-control form-control-sm"><option>0号计量台帐部位参考(项目节)</option></select>
                             </div>
                         </div>
-                        <div id="std-chapter-spread" class="sjs-sh-3">
+                        <div id="std-gcl-spread" class="sjs-sh-3">
                         </div>
                     </div>
-                    <div id="std-bills" class="tab-pane">
+                    <div id="std-gcl" class="tab-pane">
                         <div class="sjs-bar-4">
                             <div class="pb-1">
                                 <select class="form-control form-control-sm"><option>0号计量台帐部位参考(工程量清單)</option></select>
                             </div>
                         </div>
-                        <div id="std-bills-spread" class="sjs-sh-4">
+                        <div id="std-gcl-spread" class="sjs-sh-4">
                         </div>
                     </div>
                     <div id="deal-bills" class="tab-pane">

+ 2 - 2
test/app/service/ledger.test.js

@@ -465,13 +465,13 @@ describe('test/app/service/ledger.test.js', () => {
         const node1 = _.find(create, {code: '1-1-1'});
         assert(node1.order === 2);
         assert(node1.level === 3);
-        assert(node1.full_path === node.full_path.replace('.' + node.ledger_id, '.' + node1.ledger_id));
+        assert(node1.full_path === node.full_path.replace('-' + node.ledger_id, '-' + node1.ledger_id));
         const node2 = _.find(create, function (c) {
             return c.ledger_pid === node.ledger_pid && c.ledger_id !== node1.ledger_id;
         });
         assert(node2.order === 3);
         assert(node2.level === 3);
-        assert(node2.full_path === node.full_path.replace('.' + node.ledger_id, '.' + node2.ledger_id));
+        assert(node2.full_path === node.full_path.replace('-' + node.ledger_id, '-' + node2.ledger_id));
 
         assert(resultData.ledger.update.length === 1);
         assert(resultData.ledger.update[0].order === 4);

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

@@ -47,7 +47,7 @@ describe('test/app/service/std_bills.test.js', () => {
         assert(result.length === 6);
 
         // 查询1-10-1的子孙节点
-        const result1 = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '.%');
+        const result1 = yield ctx.service.stdBills.getDataByFullPath(1, node.full_path + '-%');
         assert(result1.length === 5);
     });
     it('test getFullLevelDataByFullPath', function* () {