| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | 
							- 'use strict';
 
- /**
 
-  * 报表模板组织架构模型
 
-  *
 
-  * @author TonyKang
 
-  * @date 2019/05/05
 
-  * @version
 
-  */
 
- const BaseService = require('../base/base_service');
 
- module.exports = app => {
 
-     class RptTreeNode extends BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             this.tableName = 'rpt_tree_node';
 
-             this.dataId = 'id';
 
-         }
 
-         async getNodesByType(typeArr) {
 
-             this.initSqlBuilder();
 
-             this.sqlBuilder.setAndWhere('rpt_type', {
 
-                 value: typeArr,
 
-                 operate: 'in',
 
-             });
 
-             this.sqlBuilder.columns = ['id', 'name', 'rpt_type', 'pid', 'items', 'last_update_time'];
 
-             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
 
-             const list = await this.db.query(sql, sqlParam);
 
-             return list;
 
-         }
 
-         async getNodesByProjectId(prjIdArr) {
 
-             this.initSqlBuilder();
 
-             this.sqlBuilder.setAndWhere('pid', {
 
-                 value: prjIdArr,
 
-                 operate: 'in',
 
-             });
 
-             this.sqlBuilder.columns = ['id', 'name', 'rpt_type', 'pid', 'items', 'last_update_time'];
 
-             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
 
-             const list = await this.db.query(sql, sqlParam);
 
-             return list;
 
-         }
 
-         async getNodeById(id) {
 
-             this.initSqlBuilder();
 
-             this.sqlBuilder.setAndWhere('id', {
 
-                 value: id,
 
-                 operate: '=',
 
-             });
 
-             this.sqlBuilder.columns = ['id', 'name', 'rpt_type', 'pid', 'items', 'last_update_time'];
 
-             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
 
-             const list = await this.db.query(sql, sqlParam);
 
-             return list;
 
-         }
 
-         async createNode(prjId, name) {
 
-             let rst = null;
 
-             this.transaction = await this.db.beginTransaction();
 
-             try {
 
-                 const data = {
 
-                     // id: 0,
 
-                     rpt_type: 0,
 
-                     name: name,
 
-                     pid: prjId,
 
-                     items: '[]',
 
-                     last_update_time: (new Date()).getTime().toString(),
 
-                 };
 
-                 console.log('createNode:');
 
-                 console.log(data);
 
-                 rst = await this.transaction.insert(this.tableName, data);
 
-                 await this.transaction.commit();
 
-             } catch (ex) {
 
-                 console.log(ex);
 
-                 // 回滚
 
-                 await this.transaction.rollback();
 
-             }
 
-             return rst;
 
-         }
 
-         async updateTopNode(topNode) {
 
-             try {
 
-                 this.transaction = await this.db.beginTransaction();
 
-                 await this.transaction.update(this.tableName, topNode);
 
-                 // const operate = await this.db.update(this.tableName, topNode);
 
-                 // console.log(operate.affectedRows);
 
-                 // return operate.affectedRows === 1;
 
-                 this.transaction.commit();
 
-                 return true;
 
-             } catch (ex) {
 
-                 console.log(ex);
 
-                 this.transaction.rollback();
 
-                 return false;
 
-             }
 
-         }
 
-     }
 
-     return RptTreeNode;
 
- };
 
 
  |