| 
					
				 | 
			
			
				@@ -481,6 +481,34 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const result = await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * 获取多期(合同和数量变更相加)计量-小计(材料调差调用) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @param {Number} tid - 标段id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @param {String} stage_id_list - 期id列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @param {String} lid - 台账id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @param {String} pid - 部位id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @returns {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async getGatherQtyByMaterial(tid, stage_id_list, lid, pid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            stage_id_list = stage_id_list !== null ? stage_id_list.split(',') : []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let gather_qty = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const sid of stage_id_list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const sql = 'SELECT Pos.contract_qty, Pos.qc_qty FROM ' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '  (SELECT * FROM ' + this.tableName + ' WHERE tid = ? AND sid = ?) As Pos ' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '  INNER JOIN ( ' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `flow`, `tid`, `sid`, `pid` From ' + this.tableName + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '      WHERE `tid` = ? AND sid = ?' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '      GROUP BY `pid`' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '  ) As MaxFilter ' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '  ON (Pos.times * ' + timesLen + ' + Pos.order) = MaxFilter.flow And Pos.pid = MaxFilter.pid And Pos.sid = MaxFilter.sid' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ' WHERE Pos.lid = ? AND Pos.pid = ?'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const sqlParam = [tid, sid, tid, sid, lid, pid]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const result = await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                gather_qty = this.ctx.helper.add(gather_qty, this.ctx.helper.add(result.contract_qty, result.qc_qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return gather_qty !== 0 ? gather_qty : null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return StagePos; 
			 |