'use strict'; /** * * * @author Mai * @date * @version */ const TreeService = require('./base_tree_service'); class BaseBudget extends TreeService { /** * 构造函数 * * @param {Object} ctx - egg全局变量 * @param {String} tableName - 表名 * @return {void} */ constructor(ctx, setting, tablename) { super(ctx, { mid: 'bid', kid: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', isLeaf: 'is_leaf', fullPath: 'full_path', keyPre: setting.keyPre, uuid: true, }); this.tableName = tablename; } async initByTemplate(conn, budgetId, templateId){ if (!conn) throw '内部错误'; if (budgetId <= 0) throw '概算项目id错误'; const data = await this.ctx.service.tenderNodeTemplate.getData(templateId); if (!data.length) throw '模板数据有误'; // 整理数据 const insertData = []; for (const tmp of data) { insertData.push({ id: this.uuid.v4(), bid: budgetId, tree_id: tmp.template_id, tree_pid: tmp.pid, level: tmp.level, order: tmp.order, full_path: tmp.full_path, is_leaf: tmp.is_leaf, code: tmp.code, name: tmp.name, node_type: tmp.node_type, }); } const operate = await conn.insert(this.tableName, insertData); return operate.affectedRows === data.length; } } module.exports = BaseBudget;