'use strict'; /** * 标段项目模板数据模型 * * @author CaiAoLin * @date 2017/12/1 * @version */ module.exports = app => { class TenderNodeTemplate extends app.BaseService { /** * 构造函数 * * @param {Object} ctx - egg全局变量 * @return {void} */ constructor(ctx) { super(ctx); this.tableName = 'bills_template'; } /** * 获取模板数据 * * @param {Integer} tid - 模板id * @param {Boolean} isCache - 是否使用缓存 * @return {Array} - 返回模板数据 */ async getData(tid, isCache = true) { const cacheKey = 'tenderTPL'; const data = await this.cache.get(cacheKey); if (data !== null && !isCache) { return JSON.parse(data); } // 获取所有数据 const templateData = await this.db.select(this.tableName, { where: {list_id: tid}, columns: ['code', 'name', 'unit', 'source', 'remark', 'pid', 'level', 'order', 'full_path', 'is_leaf', 'template_id', 'node_type'], }); if (templateData.length <= 0) { return []; } this.cache.set(cacheKey, JSON.stringify(templateData), 'EX', app.config.cacheTime); return templateData; } } return TenderNodeTemplate; };