tender_node_template.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. /**
  3. * 标段项目模板数据模型
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/12/1
  7. * @version
  8. */
  9. module.exports = app => {
  10. class TenderNodeTemplate extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'bills_template';
  20. }
  21. /**
  22. * 获取模板数据
  23. *
  24. * @param {Integer} tid - 模板id
  25. * @param {Boolean} isCache - 是否使用缓存
  26. * @return {Array} - 返回模板数据
  27. */
  28. async getData(tid, isCache = true) {
  29. const cacheKey = 'tenderTPL';
  30. const data = await this.cache.get(cacheKey);
  31. if (data !== null && !isCache) {
  32. return JSON.parse(data);
  33. }
  34. // 获取所有数据
  35. const templateData = await this.db.select(this.tableName, {
  36. where: {list_id: tid},
  37. columns: ['code', 'name', 'unit', 'source', 'remark', 'pid', 'level', 'order', 'full_path', 'is_leaf', 'template_id', 'node_type'],
  38. });
  39. if (templateData.length <= 0) {
  40. return [];
  41. }
  42. this.cache.set(cacheKey, JSON.stringify(templateData), 'EX', app.config.cacheTime);
  43. return templateData;
  44. }
  45. }
  46. return TenderNodeTemplate;
  47. };