| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | 
							- 'use strict';
 
- /**
 
-  * Created by Tony on 2020/6/6.
 
-  * 用户自定义显示报表模板组织
 
-  * @author TonyKang
 
-  * @date 2019/05/05
 
-  * @version
 
-  */
 
- const BaseService = require('../base/base_service');
 
- module.exports = app => {
 
-     class RptTreeNodeCust extends BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             this.tableName = 'rpt_tree_node_cust';
 
-             this.dataId = 'id';
 
-         }
 
-         async getCustFoldersByUserId(userId) {
 
-             this.initSqlBuilder();
 
-             this.sqlBuilder.setAndWhere('cust_acc_id', {
 
-                 value: userId,
 
-                 operate: '=',
 
-             });
 
-             this.sqlBuilder.columns = ['id', 'cust_acc_id', 'rpt_tpl_items'];
 
-             const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
 
-             const list = await this.db.query(sql, sqlParam);
 
-             return list;
 
-         }
 
-         async createCustNode(cust_acc_id, newRptItems) {
 
-             let rst = null;
 
-             this.transaction = await this.db.beginTransaction();
 
-             try {
 
-                 const data = {
 
-                     cust_acc_id: cust_acc_id,
 
-                     rpt_tpl_items: newRptItems,
 
-                 };
 
-                 // 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();
 
-             } finally {
 
-                 return rst;
 
-             }
 
-         }
 
-         async updateCustNode(cust_acc_id, newNodeItems) {
 
-             let rst = null;
 
-             try {
 
-                 const custNode = await this.getCustFoldersByUserId(cust_acc_id);
 
-                 // console.log('query Node:');
 
-                 // console.log(custNode);
 
-                 if (custNode.length > 0) {
 
-                     this.transaction = await this.db.beginTransaction();
 
-                     custNode[0].rpt_tpl_items = newNodeItems;
 
-                     rst = await this.transaction.update(this.tableName, custNode[0]);
 
-                     this.transaction.commit();
 
-                 } else {
 
-                     rst = await this.createCustNode(cust_acc_id, newNodeItems);
 
-                 }
 
-             } catch (ex) {
 
-                 console.log(ex);
 
-                 this.transaction.rollback();
 
-                 rst = null;
 
-             } finally {
 
-                 return rst;
 
-             }
 
-         }
 
-     }
 
-     return RptTreeNodeCust;
 
- };
 
 
  |