project.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. /**
  3. * 项目数据模型
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/11/16
  7. * @version
  8. */
  9. module.exports = app => {
  10. class Project extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'project';
  20. // 状态相关
  21. this.status = {
  22. TRY: 1,
  23. NORMAL: 2,
  24. DISABLE: 3,
  25. };
  26. }
  27. /**
  28. * 根据项目code获取项目数据
  29. *
  30. * @param {String} code - 项目code
  31. * @return {Object} - 返回项目数据
  32. */
  33. async getProjectByCode(code) {
  34. // 获取项目状态为非禁止的项目
  35. this.initSqlBuilder();
  36. this.sqlBuilder.setAndWhere('code', {
  37. value: this.db.escape(code),
  38. operate: '=',
  39. });
  40. this.sqlBuilder.setAndWhere('status', {
  41. value: this.status.DISABLE,
  42. operate: '<',
  43. });
  44. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  45. const projectData = await this.db.queryOne(sql, sqlParam);
  46. return projectData;
  47. }
  48. }
  49. return Project;
  50. };