tender_node_template.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. if (templateData.length <= 0) {
  36. return [];
  37. }
  38. this.cache.set(cacheKey, JSON.stringify(templateData), 'EX', app.config.cacheTime);
  39. return templateData;
  40. }
  41. }
  42. return TenderNodeTemplate;
  43. };