tender_node_template.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 = 'tender_node_template';
  20. }
  21. /**
  22. * 获取模板数据
  23. *
  24. * @param {Boolean} isCache - 是否使用缓存
  25. * @return {Array} - 返回模板数据
  26. */
  27. async getData(isCache = true) {
  28. const cacheKey = 'tenderTPL';
  29. const data = await this.cache.get(cacheKey);
  30. if (data !== null && !isCache) {
  31. return JSON.parse(data);
  32. }
  33. // 获取所有数据
  34. const templateData = await this.db.select(this.tableName, {
  35. columns: ['code', 'name', 'unit', 'source', 'remark', 'pid', 'level', 'order', 'full_path', 'is_leaf', 'template_id'],
  36. });
  37. if (templateData.length <= 0) {
  38. return [];
  39. }
  40. this.cache.set(cacheKey, JSON.stringify(templateData), 'EX', app.config.cacheTime);
  41. return templateData;
  42. }
  43. }
  44. return TenderNodeTemplate;
  45. };