| 
					
				 | 
			
			
				@@ -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; 
			 |