quotaLib.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author EllisRan.
  6. * @date 2018/4/19
  7. * @version
  8. */
  9. const libConst = require('../const/lib');
  10. module.exports = app => {
  11. class QuotaLib extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'quota_lib';
  21. }
  22. /**
  23. * 获取指标源列表
  24. *
  25. * @param {Object} status - 指标源状态
  26. * @return {Array} - 返回列表数据
  27. */
  28. async getList(status = 0) {
  29. this.initSqlBuilder();
  30. if(status !== 0) {
  31. this.sqlBuilder.setAndWhere('status', {
  32. value: status,
  33. operate: '=',
  34. });
  35. }
  36. this.sqlBuilder.orderBy = [['id', 'desc']];
  37. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  38. return await this.db.query(sql, sqlParam);
  39. }
  40. /**
  41. * 获取指标源各状态数量
  42. *
  43. * @return {Array} - 返回数量列表数据
  44. */
  45. async getStatusNum() {
  46. const pend = await this.db.count(this.tableName, { status: libConst.status.pend });
  47. const enter = await this.db.count(this.tableName, { status: libConst.status.enter });
  48. const data = {
  49. pend,
  50. enter
  51. };
  52. return data;
  53. }
  54. /**
  55. * 新增指标源
  56. *
  57. * @param {Object} postData - 文件上传过来的数据
  58. * @return {Boolean} - 返回新增结果
  59. */
  60. async add(postData) {
  61. const insertData = {
  62. filename: postData.name,
  63. status: libConst.status.pend,
  64. filepath: postData.path,
  65. create_time: postData.create_time,
  66. enter_time: ''
  67. };
  68. const operate = await this.db.insert(this.tableName, insertData);
  69. return operate;
  70. }
  71. }
  72. return QuotaLib;
  73. }